xgboost
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
xgboost::Context Struct Reference

Runtime context for XGBoost. Contains information like threads and device. More...

#include <context.h>

Inheritance diagram for xgboost::Context:
Inheritance graph
Collaboration diagram for xgboost::Context:
Collaboration graph

Public Member Functions

 Context ()
 
void Init (Args const &kwargs)
 
template<typename Container >
Args UpdateAllowUnknown (Container const &kwargs)
 
void ConfigureGpuId (bool require_gpu)
 Configure the parameter ‘device’. Deprecated, will remove once gpu_id is removed. More...
 
std::int32_t Threads () const
 Returns the automatically chosen number of threads based on the nthread parameter and the system settting. More...
 
bool IsCPU () const
 Is XGBoost running on CPU? More...
 
bool IsCUDA () const
 Is XGBoost running on a CUDA device? More...
 
bool IsSyclDefault () const
 Is XGBoost running on the default SYCL device? More...
 
bool IsSyclCPU () const
 Is XGBoost running on a SYCL CPU? More...
 
bool IsSyclGPU () const
 Is XGBoost running on a SYCL GPU? More...
 
bool IsSycl () const
 Is XGBoost running on any SYCL device? More...
 
DeviceOrd Device () const
 Get the current device and ordinal. More...
 
bst_d_ordinal_t Ordinal () const
 Get the CUDA device ordinal. -1 if XGBoost is running on CPU. More...
 
std::string DeviceName () const
 Name of the current device. More...
 
CUDAContext const * CUDACtx () const
 Get a CUDA device context for allocator and stream. More...
 
Context MakeCUDA (bst_d_ordinal_t ordinal=0) const
 Make a CUDA context based on the current context. More...
 
Context MakeCPU () const
 Make a CPU context based on the current context. More...
 
template<typename CPUFn , typename CUDAFn >
decltype(auto) DispatchDevice (CPUFn &&cpu_fn, CUDAFn &&cuda_fn) const
 Call function based on the current device. More...
 
template<typename CPUFn , typename CUDAFn , typename SYCLFn >
decltype(auto) DispatchDevice (CPUFn &&cpu_fn, CUDAFn &&cuda_fn, SYCLFn &&sycl_fn) const
 Call function for sycl devices. More...
 
 DMLC_DECLARE_PARAMETER (Context)
 
- Public Member Functions inherited from xgboost::XGBoostParameter< Context >
Args UpdateAllowUnknown (Container const &kwargs)
 
bool GetInitialised () const
 

Public Attributes

std::int32_t nthread {0}
 
std::int64_t seed {kDefaultSeed}
 
bool seed_per_iteration {false}
 
bool fail_on_invalid_gpu_id {false}
 
bool validate_parameters {false}
 

Static Public Attributes

static constexpr std::int64_t kDefaultSeed = 0
 

Additional Inherited Members

- Protected Attributes inherited from xgboost::XGBoostParameter< Context >
bool initialised_
 

Detailed Description

Runtime context for XGBoost. Contains information like threads and device.

Constructor & Destructor Documentation

◆ Context()

xgboost::Context::Context ( )

Member Function Documentation

◆ ConfigureGpuId()

void xgboost::Context::ConfigureGpuId ( bool  require_gpu)

Configure the parameter ‘device’. Deprecated, will remove once gpu_id is removed.

Parameters
require_gpuWhether GPU is explicitly required by the user through other configurations.

◆ CUDACtx()

CUDAContext const* xgboost::Context::CUDACtx ( ) const

Get a CUDA device context for allocator and stream.

◆ Device()

DeviceOrd xgboost::Context::Device ( ) const
inline

Get the current device and ordinal.

◆ DeviceName()

std::string xgboost::Context::DeviceName ( ) const
inline

Name of the current device.

◆ DispatchDevice() [1/2]

template<typename CPUFn , typename CUDAFn >
decltype(auto) xgboost::Context::DispatchDevice ( CPUFn &&  cpu_fn,
CUDAFn &&  cuda_fn 
) const
inline

Call function based on the current device.

◆ DispatchDevice() [2/2]

template<typename CPUFn , typename CUDAFn , typename SYCLFn >
decltype(auto) xgboost::Context::DispatchDevice ( CPUFn &&  cpu_fn,
CUDAFn &&  cuda_fn,
SYCLFn &&  sycl_fn 
) const
inline

Call function for sycl devices.

◆ DMLC_DECLARE_PARAMETER()

xgboost::Context::DMLC_DECLARE_PARAMETER ( Context  )
inline

◆ Init()

void xgboost::Context::Init ( Args const &  kwargs)

◆ IsCPU()

bool xgboost::Context::IsCPU ( ) const
inline

Is XGBoost running on CPU?

◆ IsCUDA()

bool xgboost::Context::IsCUDA ( ) const
inline

Is XGBoost running on a CUDA device?

◆ IsSycl()

bool xgboost::Context::IsSycl ( ) const
inline

Is XGBoost running on any SYCL device?

◆ IsSyclCPU()

bool xgboost::Context::IsSyclCPU ( ) const
inline

Is XGBoost running on a SYCL CPU?

◆ IsSyclDefault()

bool xgboost::Context::IsSyclDefault ( ) const
inline

Is XGBoost running on the default SYCL device?

◆ IsSyclGPU()

bool xgboost::Context::IsSyclGPU ( ) const
inline

Is XGBoost running on a SYCL GPU?

◆ MakeCPU()

Context xgboost::Context::MakeCPU ( ) const
inline

Make a CPU context based on the current context.

◆ MakeCUDA()

Context xgboost::Context::MakeCUDA ( bst_d_ordinal_t  ordinal = 0) const
inline

Make a CUDA context based on the current context.

Parameters
ordinalThe CUDA device ordinal.

◆ Ordinal()

bst_d_ordinal_t xgboost::Context::Ordinal ( ) const
inline

Get the CUDA device ordinal. -1 if XGBoost is running on CPU.

◆ Threads()

std::int32_t xgboost::Context::Threads ( ) const

Returns the automatically chosen number of threads based on the nthread parameter and the system settting.

◆ UpdateAllowUnknown()

template<typename Container >
Args xgboost::Context::UpdateAllowUnknown ( Container const &  kwargs)
inline

Member Data Documentation

◆ fail_on_invalid_gpu_id

bool xgboost::Context::fail_on_invalid_gpu_id {false}

◆ kDefaultSeed

constexpr std::int64_t xgboost::Context::kDefaultSeed = 0
staticconstexpr

◆ nthread

std::int32_t xgboost::Context::nthread {0}

◆ seed

std::int64_t xgboost::Context::seed {kDefaultSeed}

◆ seed_per_iteration

bool xgboost::Context::seed_per_iteration {false}

◆ validate_parameters

bool xgboost::Context::validate_parameters {false}

The documentation for this struct was generated from the following file: