Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:04

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2024 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #pragma once
0009 
0010 #include <alpaka/alpaka.hpp>
0011 
0012 namespace traccc::alpaka {
0013 
0014 using Dim = ::alpaka::DimInt<1>;
0015 using Idx = uint32_t;
0016 using WorkDiv = ::alpaka::WorkDivMembers<Dim, Idx>;
0017 
0018 // Get alpaka accelerator - based on alpaka/examples/ExampleDefaultAcc.hpp
0019 #if defined(ALPAKA_ACC_GPU_CUDA_ENABLED)
0020 using Acc = ::alpaka::AccGpuCudaRt<Dim, Idx>;
0021 #elif defined(ALPAKA_ACC_GPU_HIP_ENABLED)
0022 using Acc = ::alpaka::AccGpuHipRt<Dim, Idx>;
0023 #elif defined(ALPAKA_ACC_SYCL_ENABLED)
0024 #if defined(ALPAKA_SYCL_ONEAPI_CPU)
0025 using Acc = ::alpaka::AccCpuSycl<Dim, Idx>;
0026 #elif defined(ALPAKA_SYCL_ONEAPI_FPGA)
0027 using Acc = ::alpaka::AccFpgaSyclIntel<Dim, Idx>;
0028 #elif defined(ALPAKA_SYCL_ONEAPI_GPU)
0029 using Acc = ::alpaka::AccGpuSyclIntel<Dim, Idx>;
0030 #endif
0031 #elif defined(ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLED)
0032 using Acc = ::alpaka::AccCpuThreads<Dim, Idx>;
0033 #else
0034 #error "No supported backend selected." //we definitely want to fail the build if no matching accelerator is found
0035 #endif
0036 
0037 // Set the queue type to blocking for CPU based accelerators, due to the
0038 // synchronous nature of vecmem there.
0039 #if defined(ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLED)
0040 using QueueType = ::alpaka::Blocking;
0041 #else
0042 using QueueType = ::alpaka::NonBlocking;
0043 #endif
0044 
0045 using Host = ::alpaka::DevCpu;
0046 using Queue = ::alpaka::Queue<Acc, QueueType>;
0047 
0048 template <typename TAcc>
0049 consteval Idx getWarpSize() {
0050   if constexpr (::alpaka::accMatchesTags<TAcc, ::alpaka::TagGpuCudaRt,
0051                                          ::alpaka::TagGpuSyclIntel>) {
0052     return 32;
0053   }
0054   if constexpr (::alpaka::accMatchesTags<TAcc, ::alpaka::TagGpuHipRt>) {
0055     return 64;
0056   } else {
0057     return 4;
0058   }
0059 }
0060 
0061 template <typename TAcc>
0062 inline WorkDiv makeWorkDiv(Idx blocks, Idx threadsOrElements) {
0063   const Idx blocksPerGrid = std::max(Idx{1}, blocks);
0064   if constexpr (::alpaka::isMultiThreadAcc<TAcc>) {
0065     const Idx threadsPerBlock(threadsOrElements);
0066     const Idx elementsPerThread = Idx{1};
0067     return WorkDiv{blocksPerGrid, threadsPerBlock, elementsPerThread};
0068   } else {
0069     const Idx threadsPerBlock = Idx{1};
0070     const Idx elementsPerThread(threadsOrElements);
0071     return WorkDiv{blocksPerGrid, threadsPerBlock, elementsPerThread};
0072   }
0073 }
0074 
0075 }  // namespace traccc::alpaka