Medial Code Documentation
Loading...
Searching...
No Matches
External
xgboost
src
common
optional_weight.h
1
4
#ifndef XGBOOST_COMMON_OPTIONAL_WEIGHT_H_
5
#define XGBOOST_COMMON_OPTIONAL_WEIGHT_H_
6
#include "
xgboost/base.h
"
// XGBOOST_DEVICE
7
#include "
xgboost/context.h
"
// Context
8
#include "
xgboost/host_device_vector.h
"
// HostDeviceVector
9
#include "xgboost/span.h"
// Span
10
11
namespace
xgboost::common
{
12
struct
OptionalWeights
{
13
Span<float const>
weights;
14
float
dft{1.0f};
// fixme: make this compile time constant
15
16
explicit
OptionalWeights
(
Span<float const>
w) : weights{w} {}
17
explicit
OptionalWeights
(
float
w) : dft{w} {}
18
19
XGBOOST_DEVICE
float
operator[](
size_t
i)
const
{
return
weights.empty() ? dft : weights[i]; }
20
[[nodiscard]]
auto
Empty()
const
{
return
weights.empty(); }
21
[[nodiscard]]
auto
Size()
const
{
return
weights.size(); }
22
};
23
24
inline
OptionalWeights
MakeOptionalWeights(
Context
const
* ctx,
25
HostDeviceVector<float>
const
& weights) {
26
if
(ctx->
IsCUDA
()) {
27
weights.SetDevice(ctx->gpu_id);
28
}
29
return
OptionalWeights{ctx->
IsCPU
() ? weights.ConstHostSpan() : weights.ConstDeviceSpan()};
30
}
31
}
// namespace xgboost::common
32
#endif
// XGBOOST_COMMON_OPTIONAL_WEIGHT_H_
xgboost::HostDeviceVector
Definition
host_device_vector.h:87
xgboost::common::Span
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition
span.h:424
context.h
Copyright 2014-2023, XGBoost Contributors.
host_device_vector.h
A device-and-host vector abstraction layer.
base.h
Copyright 2015-2023 by XGBoost Contributors.
XGBOOST_DEVICE
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition
base.h:64
xgboost::common
Copyright 2017-2023, XGBoost Contributors.
Definition
span.h:77
xgboost::Context
Runtime context for XGBoost.
Definition
context.h:84
xgboost::Context::IsCPU
bool IsCPU() const
Is XGBoost running on CPU?
Definition
context.h:133
xgboost::Context::IsCUDA
bool IsCUDA() const
Is XGBoost running on a CUDA device?
Definition
context.h:137
xgboost::common::OptionalWeights
Definition
optional_weight.h:12
Generated on Mon Sep 15 2025 12:12:20 for Medial Code Documentation by
1.9.8