Define CUDA Context. (#8604)
We will transition to non-default and non-blocking CUDA stream.
This commit is contained in:
28
src/common/cuda_context.cuh
Normal file
28
src/common/cuda_context.cuh
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright 2022 by XGBoost Contributors
|
||||
*/
|
||||
#ifndef XGBOOST_COMMON_CUDA_CONTEXT_CUH_
|
||||
#define XGBOOST_COMMON_CUDA_CONTEXT_CUH_
|
||||
#include <thrust/execution_policy.h>
|
||||
|
||||
#include "device_helpers.cuh"
|
||||
|
||||
namespace xgboost {
|
||||
struct CUDAContext {
|
||||
private:
|
||||
dh::XGBCachingDeviceAllocator<char> caching_alloc_;
|
||||
dh::XGBDeviceAllocator<char> alloc_;
|
||||
|
||||
public:
|
||||
/**
|
||||
* \brief Caching thrust policy.
|
||||
*/
|
||||
auto CTP() const { return thrust::cuda::par(caching_alloc_).on(dh::DefaultStream()); }
|
||||
/**
|
||||
* \brief Thrust policy without caching allocator.
|
||||
*/
|
||||
auto TP() const { return thrust::cuda::par(alloc_).on(dh::DefaultStream()); }
|
||||
auto Stream() const { return dh::DefaultStream(); }
|
||||
};
|
||||
} // namespace xgboost
|
||||
#endif // XGBOOST_COMMON_CUDA_CONTEXT_CUH_
|
||||
Reference in New Issue
Block a user