Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-26 22:25:19

0001 #ifndef HeterogeneousCore_AlpakaInterface_interface_config_h
0002 #define HeterogeneousCore_AlpakaInterface_interface_config_h
0003 
0004 #include <type_traits>
0005 
0006 #include <alpaka/alpaka.hpp>
0007 
0008 #include "FWCore/Utilities/interface/stringize.h"
0009 
0010 namespace alpaka_common {
0011 
0012   // common types and dimensions
0013   using Idx = uint32_t;
0014   using Extent = uint32_t;
0015   using Offsets = Extent;
0016 
0017   using Dim0D = alpaka::DimInt<0u>;
0018   using Dim1D = alpaka::DimInt<1u>;
0019   using Dim2D = alpaka::DimInt<2u>;
0020   using Dim3D = alpaka::DimInt<3u>;
0021 
0022   template <typename TDim>
0023   using Vec = alpaka::Vec<TDim, Idx>;
0024   using Vec1D = Vec<Dim1D>;
0025   using Vec2D = Vec<Dim2D>;
0026   using Vec3D = Vec<Dim3D>;
0027   using Scalar = Vec<Dim0D>;
0028 
0029   template <typename TDim>
0030   using WorkDiv = alpaka::WorkDivMembers<TDim, Idx>;
0031   using WorkDiv1D = WorkDiv<Dim1D>;
0032   using WorkDiv2D = WorkDiv<Dim2D>;
0033   using WorkDiv3D = WorkDiv<Dim3D>;
0034 
0035   // host types
0036   using DevHost = alpaka::DevCpu;
0037   using PltfHost = alpaka::Pltf<DevHost>;
0038 
0039 }  // namespace alpaka_common
0040 
0041 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
0042 namespace alpaka_cuda_async {
0043   using namespace alpaka_common;
0044 
0045   using Platform = alpaka::PltfCudaRt;
0046   using Device = alpaka::DevCudaRt;
0047   using Queue = alpaka::QueueCudaRtNonBlocking;
0048   using Event = alpaka::EventCudaRt;
0049 
0050   template <typename TDim>
0051   using Acc = alpaka::AccGpuCudaRt<TDim, Idx>;
0052   using Acc1D = Acc<Dim1D>;
0053   using Acc2D = Acc<Dim2D>;
0054   using Acc3D = Acc<Dim3D>;
0055 
0056 }  // namespace alpaka_cuda_async
0057 
0058 #ifdef ALPAKA_ACCELERATOR_NAMESPACE
0059 #define ALPAKA_DUPLICATE_NAMESPACE
0060 #else
0061 #define ALPAKA_ACCELERATOR_NAMESPACE alpaka_cuda_async
0062 #define ALPAKA_TYPE_SUFFIX CudaAsync
0063 #endif
0064 
0065 #endif  // ALPAKA_ACC_GPU_CUDA_ENABLED
0066 
0067 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED
0068 namespace alpaka_hip_async {
0069   using namespace alpaka_common;
0070 
0071   using Platform = alpaka::PltfHipRt;
0072   using Device = alpaka::DevHipRt;
0073   using Queue = alpaka::QueueHipRtNonBlocking;
0074   using Event = alpaka::EventHipRt;
0075 
0076   template <typename TDim>
0077   using Acc = alpaka::AccGpuHipRt<TDim, Idx>;
0078   using Acc1D = Acc<Dim1D>;
0079   using Acc2D = Acc<Dim2D>;
0080   using Acc3D = Acc<Dim3D>;
0081 
0082 }  // namespace alpaka_hip_async
0083 
0084 #ifdef ALPAKA_ACCELERATOR_NAMESPACE
0085 #define ALPAKA_DUPLICATE_NAMESPACE
0086 #else
0087 #define ALPAKA_ACCELERATOR_NAMESPACE alpaka_hip_async
0088 #define ALPAKA_TYPE_SUFFIX HipAsync
0089 #endif
0090 
0091 #endif  // ALPAKA_ACC_GPU_HIP_ENABLED
0092 
0093 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0094 namespace alpaka_serial_sync {
0095   using namespace alpaka_common;
0096 
0097   using Platform = alpaka::PltfCpu;
0098   using Device = alpaka::DevCpu;
0099   using Queue = alpaka::QueueCpuBlocking;
0100   using Event = alpaka::EventCpu;
0101 
0102   template <typename TDim>
0103   using Acc = alpaka::AccCpuSerial<TDim, Idx>;
0104   using Acc1D = Acc<Dim1D>;
0105   using Acc2D = Acc<Dim2D>;
0106   using Acc3D = Acc<Dim3D>;
0107 
0108 }  // namespace alpaka_serial_sync
0109 
0110 #ifdef ALPAKA_ACCELERATOR_NAMESPACE
0111 #define ALPAKA_DUPLICATE_NAMESPACE
0112 #else
0113 #define ALPAKA_ACCELERATOR_NAMESPACE alpaka_serial_sync
0114 #define ALPAKA_TYPE_SUFFIX SerialSync
0115 #endif
0116 
0117 #endif  // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0118 
0119 #ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
0120 namespace alpaka_tbb_async {
0121   using namespace alpaka_common;
0122 
0123   using Platform = alpaka::PltfCpu;
0124   using Device = alpaka::DevCpu;
0125   using Queue = alpaka::QueueCpuNonBlocking;
0126   using Event = alpaka::EventCpu;
0127 
0128   template <typename TDim>
0129   using Acc = alpaka::AccCpuTbbBlocks<TDim, Idx>;
0130   using Acc1D = Acc<Dim1D>;
0131   using Acc2D = Acc<Dim2D>;
0132   using Acc3D = Acc<Dim3D>;
0133 
0134 }  // namespace alpaka_tbb_async
0135 
0136 #ifdef ALPAKA_ACCELERATOR_NAMESPACE
0137 #define ALPAKA_DUPLICATE_NAMESPACE
0138 #else
0139 #define ALPAKA_ACCELERATOR_NAMESPACE alpaka_tbb_async
0140 #define ALPAKA_TYPE_SUFFIX TbbAsync
0141 #endif
0142 
0143 #endif  // ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
0144 
0145 #if defined ALPAKA_DUPLICATE_NAMESPACE
0146 #error Only one alpaka backend symbol can be defined at the same time: ALPAKA_ACC_GPU_CUDA_ENABLED, ALPAKA_ACC_GPU_HIP_ENABLED, ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED, ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED.
0147 #endif
0148 
0149 #if defined ALPAKA_ACCELERATOR_NAMESPACE
0150 
0151 // create a new backend-specific identifier based on the original type name and a backend-specific suffix
0152 #define ALPAKA_TYPE_ALIAS__(TYPE, SUFFIX) TYPE##SUFFIX
0153 #define ALPAKA_TYPE_ALIAS_(TYPE, SUFFIX) ALPAKA_TYPE_ALIAS__(TYPE, SUFFIX)
0154 #define ALPAKA_TYPE_ALIAS(TYPE) ALPAKA_TYPE_ALIAS_(TYPE, ALPAKA_TYPE_SUFFIX)
0155 
0156 // declare the backend-specific identifier as an alias for the namespace-based type name
0157 #define DECLARE_ALPAKA_TYPE_ALIAS(TYPE) using ALPAKA_TYPE_ALIAS(TYPE) = ALPAKA_ACCELERATOR_NAMESPACE::TYPE
0158 
0159 // define a null-terminated string containing the backend-specific identifier
0160 #define ALPAKA_TYPE_ALIAS_NAME(TYPE) EDM_STRINGIZE(ALPAKA_TYPE_ALIAS(TYPE))
0161 
0162 #endif  // ALPAKA_ACCELERATOR_NAMESPACE
0163 
0164 #endif  // HeterogeneousCore_AlpakaInterface_interface_config_h