Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:40

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 "HeterogeneousCore/AlpakaInterface/interface/Backend.h"
0009 #include "FWCore/Utilities/interface/stringize.h"
0010 
0011 namespace alpaka_common {
0012 
0013   // common types and dimensions
0014   using Idx = uint32_t;
0015   using Extent = uint32_t;
0016   using Offsets = Extent;
0017 
0018   using Dim0D = alpaka::DimInt<0u>;
0019   using Dim1D = alpaka::DimInt<1u>;
0020   using Dim2D = alpaka::DimInt<2u>;
0021   using Dim3D = alpaka::DimInt<3u>;
0022 
0023   template <typename TDim>
0024   using Vec = alpaka::Vec<TDim, Idx>;
0025   using Vec1D = Vec<Dim1D>;
0026   using Vec2D = Vec<Dim2D>;
0027   using Vec3D = Vec<Dim3D>;
0028   using Scalar = Vec<Dim0D>;
0029 
0030   template <typename TDim>
0031   using WorkDiv = alpaka::WorkDivMembers<TDim, Idx>;
0032   using WorkDiv1D = WorkDiv<Dim1D>;
0033   using WorkDiv2D = WorkDiv<Dim2D>;
0034   using WorkDiv3D = WorkDiv<Dim3D>;
0035 
0036   // host types
0037   using DevHost = alpaka::DevCpu;
0038   using PlatformHost = alpaka::Platform<DevHost>;
0039 
0040 }  // namespace alpaka_common
0041 
0042 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
0043 namespace alpaka_cuda_async {
0044   using namespace alpaka_common;
0045 
0046   using Platform = alpaka::PlatformCudaRt;
0047   using Device = alpaka::DevCudaRt;
0048   using Queue = alpaka::QueueCudaRtNonBlocking;
0049   using Event = alpaka::EventCudaRt;
0050 
0051   template <typename TDim>
0052   using Acc = alpaka::AccGpuCudaRt<TDim, Idx>;
0053   using Acc1D = Acc<Dim1D>;
0054   using Acc2D = Acc<Dim2D>;
0055   using Acc3D = Acc<Dim3D>;
0056 
0057 }  // namespace alpaka_cuda_async
0058 
0059 #ifdef ALPAKA_HOST_ONLY
0060 
0061 namespace alpaka {
0062 
0063   template <typename TApi, typename TAcc, typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
0064   class TaskKernelGpuUniformCudaHipRt final {
0065     static_assert(std::is_same_v<TApi, alpaka::ApiCudaRt> and BOOST_LANG_CUDA,
0066                   "You should move this files to a .dev.cc file under the alpaka/ subdirectory.");
0067 
0068   public:
0069     template <typename TWorkDiv>
0070     ALPAKA_FN_HOST TaskKernelGpuUniformCudaHipRt(TWorkDiv&& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args) {
0071     }
0072   };
0073 
0074 }  // namespace alpaka
0075 
0076 #endif  // ALPAKA_HOST_ONLY
0077 
0078 #ifdef ALPAKA_ACCELERATOR_NAMESPACE
0079 #define ALPAKA_DUPLICATE_NAMESPACE
0080 #else
0081 #define ALPAKA_ACCELERATOR_NAMESPACE alpaka_cuda_async
0082 #define ALPAKA_TYPE_SUFFIX CudaAsync
0083 #endif
0084 
0085 #endif  // ALPAKA_ACC_GPU_CUDA_ENABLED
0086 
0087 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED
0088 namespace alpaka_rocm_async {
0089   using namespace alpaka_common;
0090 
0091   using Platform = alpaka::PlatformHipRt;
0092   using Device = alpaka::DevHipRt;
0093   using Queue = alpaka::QueueHipRtNonBlocking;
0094   using Event = alpaka::EventHipRt;
0095 
0096   template <typename TDim>
0097   using Acc = alpaka::AccGpuHipRt<TDim, Idx>;
0098   using Acc1D = Acc<Dim1D>;
0099   using Acc2D = Acc<Dim2D>;
0100   using Acc3D = Acc<Dim3D>;
0101 
0102 }  // namespace alpaka_rocm_async
0103 
0104 #ifdef ALPAKA_HOST_ONLY
0105 
0106 namespace alpaka {
0107 
0108   template <typename TApi, typename TAcc, typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
0109   class TaskKernelGpuUniformCudaHipRt final {
0110     static_assert(std::is_same_v<TApi, alpaka::ApiHipRt> and BOOST_LANG_HIP,
0111                   "You should move this files to a .dev.cc file under the alpaka/ subdirectory.");
0112 
0113   public:
0114     template <typename TWorkDiv>
0115     ALPAKA_FN_HOST TaskKernelGpuUniformCudaHipRt(TWorkDiv&& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args) {
0116     }
0117   };
0118 
0119 }  // namespace alpaka
0120 
0121 #endif  // ALPAKA_HOST_ONLY
0122 
0123 #ifdef ALPAKA_ACCELERATOR_NAMESPACE
0124 #define ALPAKA_DUPLICATE_NAMESPACE
0125 #else
0126 #define ALPAKA_ACCELERATOR_NAMESPACE alpaka_rocm_async
0127 #define ALPAKA_TYPE_SUFFIX ROCmAsync
0128 #endif
0129 
0130 #endif  // ALPAKA_ACC_GPU_HIP_ENABLED
0131 
0132 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0133 namespace alpaka_serial_sync {
0134   using namespace alpaka_common;
0135 
0136   using Platform = alpaka::PlatformCpu;
0137   using Device = alpaka::DevCpu;
0138   using Queue = alpaka::QueueCpuBlocking;
0139   using Event = alpaka::EventCpu;
0140 
0141   template <typename TDim>
0142   using Acc = alpaka::AccCpuSerial<TDim, Idx>;
0143   using Acc1D = Acc<Dim1D>;
0144   using Acc2D = Acc<Dim2D>;
0145   using Acc3D = Acc<Dim3D>;
0146 
0147 }  // namespace alpaka_serial_sync
0148 
0149 #ifdef ALPAKA_ACCELERATOR_NAMESPACE
0150 #define ALPAKA_DUPLICATE_NAMESPACE
0151 #else
0152 #define ALPAKA_ACCELERATOR_NAMESPACE alpaka_serial_sync
0153 #define ALPAKA_TYPE_SUFFIX SerialSync
0154 #endif
0155 
0156 #endif  // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0157 
0158 #ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
0159 namespace alpaka_tbb_async {
0160   using namespace alpaka_common;
0161 
0162   using Platform = alpaka::PlatformCpu;
0163   using Device = alpaka::DevCpu;
0164   using Queue = alpaka::QueueCpuNonBlocking;
0165   using Event = alpaka::EventCpu;
0166 
0167   template <typename TDim>
0168   using Acc = alpaka::AccCpuTbbBlocks<TDim, Idx>;
0169   using Acc1D = Acc<Dim1D>;
0170   using Acc2D = Acc<Dim2D>;
0171   using Acc3D = Acc<Dim3D>;
0172 
0173 }  // namespace alpaka_tbb_async
0174 
0175 #ifdef ALPAKA_ACCELERATOR_NAMESPACE
0176 #define ALPAKA_DUPLICATE_NAMESPACE
0177 #else
0178 #define ALPAKA_ACCELERATOR_NAMESPACE alpaka_tbb_async
0179 #define ALPAKA_TYPE_SUFFIX TbbAsync
0180 #endif
0181 
0182 #endif  // ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
0183 
0184 #if defined ALPAKA_DUPLICATE_NAMESPACE
0185 #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.
0186 #endif
0187 
0188 #if defined ALPAKA_ACCELERATOR_NAMESPACE
0189 
0190 // create a new backend-specific identifier based on the original type name and a backend-specific suffix
0191 #define ALPAKA_TYPE_ALIAS__(TYPE, SUFFIX) TYPE##SUFFIX
0192 #define ALPAKA_TYPE_ALIAS_(TYPE, SUFFIX) ALPAKA_TYPE_ALIAS__(TYPE, SUFFIX)
0193 #define ALPAKA_TYPE_ALIAS(TYPE) ALPAKA_TYPE_ALIAS_(TYPE, ALPAKA_TYPE_SUFFIX)
0194 
0195 // declare the backend-specific identifier as an alias for the namespace-based type name
0196 #define DECLARE_ALPAKA_TYPE_ALIAS(TYPE) using ALPAKA_TYPE_ALIAS(TYPE) = ALPAKA_ACCELERATOR_NAMESPACE::TYPE
0197 
0198 // define a null-terminated string containing the backend-specific identifier
0199 #define ALPAKA_TYPE_ALIAS_NAME(TYPE) EDM_STRINGIZE(ALPAKA_TYPE_ALIAS(TYPE))
0200 
0201 // Ensure the enumeration names are consistent with type suffix
0202 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0203   inline constexpr const cms::alpakatools::Backend kBackend = cms::alpakatools::Backend::ALPAKA_TYPE_SUFFIX;
0204 }
0205 
0206 #endif  // ALPAKA_ACCELERATOR_NAMESPACE
0207 
0208 #endif  // HeterogeneousCore_AlpakaInterface_interface_config_h