6#ifndef XGBOOST_COMMON_COMMON_H_
7#define XGBOOST_COMMON_COMMON_H_
23#if defined(__CUDACC__)
24#include <thrust/system/cuda/error.h>
25#include <thrust/system_error.h>
27#define WITH_CUDA() true
31#define WITH_CUDA() false
36#if defined(__CUDACC__)
40#define safe_cuda(ans) ThrowOnCudaError((ans), __FILE__, __LINE__)
42inline cudaError_t ThrowOnCudaError(cudaError_t code,
const char *file,
44 if (code != cudaSuccess) {
45 LOG(FATAL) << thrust::system_error(code, thrust::cuda_category(),
46 std::string{file} +
": " +
47 std::to_string(line)).what();
60inline std::vector<std::string>
Split(
const std::string& s,
char delim) {
62 std::istringstream is(s);
63 std::vector<std::string> ret;
64 while (std::getline(is, item, delim)) {
70void EscapeU8(std::string
const &
string, std::string *p_buffer);
77template <
typename T1,
typename T2>
79 return static_cast<T1
>(std::ceil(
static_cast<double>(a) / b));
83template <
class T, std::size_t
N, std::size_t... Idx>
84constexpr auto UnpackArr(std::array<T, N> &&arr, std::index_sequence<Idx...>) {
85 return std::make_tuple(std::forward<std::array<T, N>>(arr)[Idx]...);
89template <
class T, std::
size_t N>
90constexpr auto UnpackArr(std::array<T, N> &&arr) {
91 return detail::UnpackArr(std::forward<std::array<T, N>>(arr),
92 std::make_index_sequence<N>{});
100 using DifferenceType = int64_t;
118 return i_ >= other.i_;
121 return i_ < other.i_;
129 i_{start}, step_{step} {}
133 DifferenceType step_ = 1;
140 : begin_(begin), end_(end) {}
143 : begin_(begin, step), end_(end) {}
146 return *begin_ == *other.begin_ && *end_ == *other.end_;
149 return !(*
this == other);
161inline void AssertGPUSupport() {
162#ifndef XGBOOST_USE_CUDA
163 LOG(FATAL) <<
"XGBoost version not compiled with GPU support.";
167inline void AssertOneAPISupport() {
168#ifndef XGBOOST_USE_ONEAPI
169 LOG(FATAL) <<
"XGBoost version not compiled with OneAPI support.";
173void SetDevice(std::int32_t device);
175#if !defined(XGBOOST_USE_CUDA)
176inline void SetDevice(std::int32_t device) {
186template <
typename Indexable>
188 return indptr[group + 1] - 1;
@ Max
"max" - take max on conflict
Copyright 2015-2023 by XGBoost Contributors.
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition base.h:64
defines console logging options for xgboost. Use to enforce unified print behavior.
detail namespace with internal helper functions
Definition json.hpp:249
int N
Simulate some binary data with a single categorical and single continuous predictor.
Definition logistic_regression.py:26
Copyright 2017-2023, XGBoost Contributors.
Definition span.h:77
XGBOOST_DEVICE size_t LastOf(size_t group, Indexable const &indptr)
Last index of a group in a CSR style of index pointer.
Definition common.h:187
std::vector< std::string > Split(const std::string &s, char delim)
Split a string by delimiter.
Definition common.h:60