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 
7 
8 namespace cms::alpakatools {
9 
10  // Which memory allocator to use
11  // - Synchronous: (device and host) cudaMalloc/hipMalloc and cudaMallocHost/hipMallocHost
12  // - Asynchronous: (device only) cudaMallocAsync (requires CUDA >= 11.2)
13  // - Caching: (device and host) caching allocator
14  enum class AllocatorPolicy { Synchronous = 0, Asynchronous = 1, Caching = 2 };
15 
16  template <typename TDev, typename = std::enable_if_t<alpaka::isDevice<TDev>>>
18 
19 #if defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED || defined ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
20  template <>
21  constexpr inline AllocatorPolicy allocator_policy<alpaka::DevCpu> =
22 #if !defined ALPAKA_DISABLE_CACHING_ALLOCATOR
24 #else
26 #endif
27 #endif // defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED || defined ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
28 
29 #if defined ALPAKA_ACC_GPU_CUDA_ENABLED
30  template <>
31  constexpr inline AllocatorPolicy allocator_policy<alpaka::DevCudaRt> =
32 #if !defined ALPAKA_DISABLE_CACHING_ALLOCATOR
34 #elif CUDA_VERSION >= 11020 && !defined ALPAKA_DISABLE_ASYNC_ALLOCATOR
36 #else
38 #endif
39 #endif // ALPAKA_ACC_GPU_CUDA_ENABLED
40 
41 #if defined ALPAKA_ACC_GPU_HIP_ENABLED
42  template <>
43  constexpr inline AllocatorPolicy allocator_policy<alpaka::DevHipRt> =
44 #if !defined ALPAKA_DISABLE_CACHING_ALLOCATOR
46 #elif HIP_VERSION >= 50400000 && !defined ALPAKA_DISABLE_ASYNC_ALLOCATOR
48 #else
50 #endif
51 #endif // ALPAKA_ACC_GPU_HIP_ENABLED
52 
53 } // namespace cms::alpakatools
54 
55 #endif // HeterogeneousCore_AlpakaInterface_interface_AllocatorPolicy_h
constexpr AllocatorPolicy allocator_policy