CMS 3D CMS Logo

AllocatorPolicy.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_AlpakaInterface_interface_AllocatorPolicy_h
2 #define HeterogeneousCore_AlpakaInterface_interface_AllocatorPolicy_h
3 
4 #include <alpaka/alpaka.hpp>
5 
6 namespace cms::alpakatools {
7 
8  // Which memory allocator to use
9  // - Synchronous: (device and host) cudaMalloc/hipMalloc and cudaMallocHost/hipMallocHost
10  // - Asynchronous: (device only) cudaMallocAsync (requires CUDA >= 11.2)
11  // - Caching: (device and host) caching allocator
12  enum class AllocatorPolicy { Synchronous = 0, Asynchronous = 1, Caching = 2 };
13 
14  template <typename TDev, typename = std::enable_if_t<alpaka::isDevice<TDev>>>
16 
17 #if defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED || defined ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
18  template <>
19  constexpr inline AllocatorPolicy allocator_policy<alpaka::DevCpu> =
20 #if !defined ALPAKA_DISABLE_CACHING_ALLOCATOR
22 #else
24 #endif
25 #endif // defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED || defined ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
26 
27 #if defined ALPAKA_ACC_GPU_CUDA_ENABLED
28  template <>
29  constexpr inline AllocatorPolicy allocator_policy<alpaka::DevCudaRt> =
30 #if !defined ALPAKA_DISABLE_CACHING_ALLOCATOR
32 #elif CUDA_VERSION >= 11020 && !defined ALPAKA_DISABLE_ASYNC_ALLOCATOR
34 #else
36 #endif
37 #endif // ALPAKA_ACC_GPU_CUDA_ENABLED
38 
39 #if defined ALPAKA_ACC_GPU_HIP_ENABLED
40  template <>
41  constexpr inline AllocatorPolicy allocator_policy<alpaka::DevHipRt> =
42 #if !defined ALPAKA_DISABLE_CACHING_ALLOCATOR
44 #elif HIP_VERSION >= 50400000 && !defined ALPAKA_DISABLE_ASYNC_ALLOCATOR
46 #else
48 #endif
49 #endif // ALPAKA_ACC_GPU_HIP_ENABLED
50 
51 } // namespace cms::alpakatools
52 
53 #endif // HeterogeneousCore_AlpakaInterface_interface_AllocatorPolicy_h
constexpr AllocatorPolicy allocator_policy