6 #ifndef XGBOOST_COMMON_COMMON_H_ 7 #define XGBOOST_COMMON_COMMON_H_ 10 #include <xgboost/logging.h> 14 #include <type_traits> 19 #if defined(__CUDACC__) 20 #include <thrust/system/cuda/error.h> 21 #include <thrust/system_error.h> 23 #define WITH_CUDA() true 27 #define WITH_CUDA() false 29 #endif // defined(__CUDACC__) 32 #if defined(__CUDACC__) 36 #define safe_cuda(ans) ThrowOnCudaError((ans), __FILE__, __LINE__) 38 inline cudaError_t ThrowOnCudaError(cudaError_t code,
const char *file,
40 if (code != cudaSuccess) {
41 LOG(FATAL) << thrust::system_error(code, thrust::cuda_category(),
42 std::string{file} +
": " +
43 std::to_string(line)).what();
47 #endif // defined(__CUDACC__) 57 inline std::vector<std::string>
Split(
const std::string& s,
char delim) {
59 std::istringstream is(s);
60 std::vector<std::string> ret;
61 while (std::getline(is, item, delim)) {
75 std::ostringstream os;
80 template <
typename T1,
typename T2>
82 return static_cast<T1
>(std::ceil(static_cast<double>(a) / b));
108 return i_ >= other.i_;
111 return i_ < other.i_;
119 i_{start}, step_{step} {}
130 : begin_(begin), end_(end) {}
133 : begin_(begin, step), end_(end) {}
136 return *begin_ == *other.begin_ && *end_ == *other.end_;
139 return !(*
this == other);
152 #ifndef XGBOOST_USE_CUDA 153 LOG(FATAL) <<
"XGBoost version not compiled with GPU support.";
154 #endif // XGBOOST_USE_CUDA 159 #endif // XGBOOST_COMMON_COMMON_H_ XGBOOST_DEVICE Iterator begin() const
Definition: common.h:126
XGBOOST_DEVICE Iterator(DifferenceType start)
Definition: common.h:117
XGBOOST_DEVICE bool operator!=(const Iterator &other) const
Definition: common.h:110
XGBOOST_DEVICE DifferenceType operator*() const
Definition: common.h:96
XGBOOST_DEVICE void Step(DifferenceType s)
Definition: common.h:142
XGBOOST_DEVICE Iterator operator++(int)
Definition: common.h:101
XGBOOST_DEVICE bool operator!=(const Range &other) const
Definition: common.h:138
int64_t DifferenceType
Definition: common.h:90
XGBOOST_DEVICE Iterator end() const
Definition: common.h:127
void AssertGPUSupport()
Definition: common.h:151
XGBOOST_DEVICE Iterator(DifferenceType start, DifferenceType step)
Definition: common.h:118
XGBOOST_DEVICE T1 DivRoundUp(const T1 a, const T2 b)
Definition: common.h:81
std::vector< std::string > Split(const std::string &s, char delim)
Split a string by delimiter.
Definition: common.h:57
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
namespace of xgboost
Definition: base.h:102
defines configuration macros of xgboost.
XGBOOST_DEVICE Range(DifferenceType begin, DifferenceType end)
Definition: common.h:129
XGBOOST_DEVICE bool operator==(const Iterator &other) const
Definition: common.h:107
XGBOOST_DEVICE const Iterator & operator++()
Definition: common.h:97
XGBOOST_DEVICE Range(DifferenceType begin, DifferenceType end, DifferenceType step)
Definition: common.h:131
XGBOOST_DEVICE bool operator==(const Range &other) const
Definition: common.h:135
XGBOOST_DEVICE T Max(T a, T b)
Definition: common.h:68
std::string ToString(const T &data)
Definition: common.h:74
XGBOOST_DEVICE void Step(DifferenceType s)
Definition: common.h:114