diff --git a/src/common/common.h b/src/common/common.h index 7ea15a54c..9d1f1e48a 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -39,41 +39,6 @@ #endif // defined(__CUDACC__) -namespace dh { -#if defined(__CUDACC__) -/* - * Error handling functions - */ -#define safe_cuda(ans) ThrowOnCudaError((ans), __FILE__, __LINE__) - -inline cudaError_t ThrowOnCudaError(cudaError_t code, const char *file, int line) -{ - if (code != cudaSuccess) { - LOG(FATAL) << thrust::system_error(code, thrust::cuda_category(), - std::string{file} + ": " + // NOLINT - std::to_string(line)).what(); - } - return code; -} - -#elif defined(__HIP_PLATFORM_AMD__) -/* - * Error handling functions - */ -#define safe_cuda(ans) ThrowOnCudaError((ans), __FILE__, __LINE__) - -inline hipError_t ThrowOnCudaError(hipError_t code, const char *file, int line) -{ - if (code != hipSuccess) { - LOG(FATAL) << thrust::system_error(code, thrust::hip_category(), - std::string{file} + ": " + // NOLINT - std::to_string(line)).what(); - } - return code; -} -#endif -} // namespace dh - namespace xgboost { namespace common { /*! diff --git a/src/common/device_helpers.hip.h b/src/common/device_helpers.hip.h index 2044f985a..618efdd39 100644 --- a/src/common/device_helpers.hip.h +++ b/src/common/device_helpers.hip.h @@ -59,6 +59,41 @@ #endif // defined(XGBOOST_USE_RMM) && XGBOOST_USE_RMM == 1 +namespace dh { +#if defined(__CUDACC__) +/* + * Error handling functions + */ +#define safe_cuda(ans) ThrowOnCudaError((ans), __FILE__, __LINE__) + +inline cudaError_t ThrowOnCudaError(cudaError_t code, const char *file, int line) +{ + if (code != cudaSuccess) { + LOG(FATAL) << thrust::system_error(code, thrust::cuda_category(), + std::string{file} + ": " + // NOLINT + std::to_string(line)).what(); + } + return code; +} + +#elif defined(__HIP_PLATFORM_AMD__) +/* + * Error handling functions + */ +#define safe_cuda(ans) ThrowOnCudaError((ans), __FILE__, __LINE__) + +inline hipError_t ThrowOnCudaError(hipError_t code, const char *file, int line) +{ + if (code != hipSuccess) { + LOG(FATAL) << thrust::system_error(code, thrust::hip_category(), + std::string{file} + ": " + // NOLINT + std::to_string(line)).what(); + } + return code; +} +#endif +} // namespace dh + namespace dh { // FIXME(jiamingy): Remove this once we get rid of cub submodule.