Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2021-2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #include "../../device/cuda/src/utils/cuda_error_handling.hpp"
0009 
0010 // Traccc test include(s)
0011 #include "tests/grid2_test.hpp"
0012 
0013 // Vecmem include(s)
0014 #include <vecmem/containers/device_vector.hpp>
0015 
0016 namespace traccc {
0017 
0018 /*---------------------------------------------------
0019   test function for grid data with replace populator
0020   ---------------------------------------------------*/
0021 
0022 // cuda kernel for grid_replace_test
0023 __global__ void grid_replace_test_kernel(
0024     grid2_view<host_grid2_replace> grid_view) {
0025   // Let's try building the grid object
0026   device_grid2_replace g2_device(grid_view);
0027 
0028   const auto& axis0 = g2_device.axis_p0();
0029   const auto& axis1 = g2_device.axis_p1();
0030 
0031   auto x_interval = (axis0.max - axis0.min) / axis0.n_bins;
0032   auto y_interval = (axis1.max - axis1.min) / axis1.n_bins;
0033 
0034   auto gid = threadIdx.x + threadIdx.y * blockDim.x;
0035   auto pt =
0036       point3{axis0.min + gid * x_interval, axis1.min + gid * y_interval, 0.5f};
0037 
0038   // replace the bin elements
0039   g2_device.populate(threadIdx.x, threadIdx.y, std::move(pt));
0040 }
0041 
0042 // grid_replace_test implementation
0043 void grid_replace_test(grid2_view<host_grid2_replace> grid_view) {
0044   const auto& axis0 = grid_view._axis_p0_view;
0045   const auto& axis1 = grid_view._axis_p1_view;
0046 
0047   unsigned int block_dim = 1;
0048   dim3 thread_dim(axis0.n_bins, axis1.n_bins);
0049 
0050   // run the kernel
0051   grid_replace_test_kernel<<<block_dim, thread_dim>>>(grid_view);
0052 
0053   // cuda error check
0054   TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
0055   TRACCC_CUDA_ERROR_CHECK(cudaDeviceSynchronize());
0056 }
0057 
0058 // cuda kernel for grid_replace_ci_test
0059 __global__ void grid_replace_ci_test_kernel(
0060     grid2_view<host_grid2_replace_ci> grid_view) {
0061   // Let's try building the grid object
0062   device_grid2_replace_ci g2_device(grid_view);
0063 
0064   const auto& axis0 = g2_device.axis_p0();
0065   const auto& axis1 = g2_device.axis_p1();
0066 
0067   auto x_interval = (axis0.max - axis0.min) / axis0.n_bins;
0068   auto y_interval =
0069       axis1.boundaries[threadIdx.y + 1] - axis1.boundaries[threadIdx.y];
0070 
0071   auto gid = threadIdx.x + threadIdx.y * blockDim.x;
0072   auto pt =
0073       point3{axis0.min + gid * x_interval, axis1.min + gid * y_interval, 0.5f};
0074 
0075   // replace the bin elements
0076   g2_device.populate(threadIdx.x, threadIdx.y, std::move(pt));
0077 }
0078 
0079 // test function for replace populator with circular and irregular axis
0080 void grid_replace_ci_test(grid2_view<host_grid2_replace_ci> grid_view) {
0081   const auto& axis0 = grid_view._axis_p0_view;
0082   const auto& axis1 = grid_view._axis_p1_view;
0083 
0084   unsigned int block_dim = 1;
0085   dim3 thread_dim(axis0.n_bins, axis1.n_bins);
0086 
0087   // run the kernel
0088   grid_replace_ci_test_kernel<<<block_dim, thread_dim>>>(grid_view);
0089 
0090   // cuda error check
0091   TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
0092   TRACCC_CUDA_ERROR_CHECK(cudaDeviceSynchronize());
0093 }
0094 
0095 /*---------------------------------------------------------------
0096   test function for grid data with complete populator
0097   ---------------------------------------------------------------*/
0098 
0099 // cuda kernel for grid_complete_test
0100 __global__ void grid_complete_kernel(
0101     grid2_view<host_grid2_complete> grid_view) {
0102   // Let's try building the grid object
0103   device_grid2_complete g2_device(grid_view, point3{0.f, 0.f, 0.f});
0104 
0105   const auto& axis0 = g2_device.axis_p0();
0106   const auto& axis1 = g2_device.axis_p1();
0107 
0108   auto x_interval = (axis0.max - axis0.min) / axis0.n_bins;
0109   auto y_interval = (axis1.max - axis1.min) / axis1.n_bins;
0110 
0111   auto bin_id = threadIdx.x + threadIdx.y * blockDim.x;
0112 
0113   for (int i_p = 0; i_p < n_points; i_p++) {
0114     auto gid = i_p + bin_id * n_points;
0115     auto pt = point3{axis0.min + gid * x_interval, axis1.min + gid * y_interval,
0116                      0.5f};
0117     g2_device.populate(threadIdx.x, threadIdx.y, std::move(pt));
0118   }
0119 }
0120 
0121 // grid_complete_test implementation
0122 void grid_complete_test(grid2_view<host_grid2_complete> grid_view) {
0123   const auto& axis0 = grid_view._axis_p0_view;
0124   const auto& axis1 = grid_view._axis_p1_view;
0125 
0126   unsigned int block_dim = 1;
0127   dim3 thread_dim(axis0.n_bins, axis1.n_bins);
0128 
0129   // run the kernel
0130   grid_complete_kernel<<<block_dim, thread_dim>>>(grid_view);
0131 
0132   // cuda error check
0133   TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
0134   TRACCC_CUDA_ERROR_CHECK(cudaDeviceSynchronize());
0135 }
0136 
0137 /*---------------------------------------------------------
0138   read test function for grid with attach populator
0139   ---------------------------------------------------------*/
0140 
0141 // cuda kernel for attach_read_test
0142 __global__ void grid_attach_read_test_kernel(
0143     const_grid2_view<host_grid2_attach> grid_view) {
0144   // Let's try building the grid object
0145   const const_device_grid2_attach g2_device(grid_view, point3{0.f, 0.f, 0.f});
0146 
0147   auto data = g2_device.bin(threadIdx.x, threadIdx.y);
0148 
0149   for (auto& pt : data) {
0150     // printf("%f %f %f \n", pt[0], pt[1], pt[2]);
0151   }
0152 }
0153 
0154 // attach_read_test implementation
0155 void grid_attach_read_test(const_grid2_view<host_grid2_attach> grid_view) {
0156   const auto& axis0 = grid_view._axis_p0_view;
0157   const auto& axis1 = grid_view._axis_p1_view;
0158 
0159   unsigned int block_dim = 1;
0160   dim3 thread_dim(axis0.n_bins, axis1.n_bins);
0161 
0162   // run the kernel
0163   grid_attach_read_test_kernel<<<block_dim, thread_dim>>>(grid_view);
0164 
0165   // cuda error check
0166   TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
0167   TRACCC_CUDA_ERROR_CHECK(cudaDeviceSynchronize());
0168 }
0169 
0170 /*---------------------------------------------------------
0171   fill test function for grid buffer with attach populator
0172   ---------------------------------------------------------*/
0173 
0174 // cuda kernel for attach_fill_test
0175 __global__ void grid_attach_fill_test_kernel(
0176     grid2_view<host_grid2_attach> grid_view) {
0177   // Let's try building the grid object
0178   device_grid2_attach g2_device(grid_view);
0179 
0180   // Fill with 100 points
0181   auto pt = point3{scalar(1.) * threadIdx.x, scalar(1.) * threadIdx.x,
0182                    scalar(1.) * threadIdx.x};
0183   g2_device.populate(blockIdx.x, blockIdx.y, std::move(pt));
0184 
0185   __syncthreads();
0186 
0187   if (threadIdx.x == 0 && blockIdx.x == 0 && blockIdx.y == 0) {
0188     auto pts = g2_device.bin(blockIdx.x, blockIdx.y);
0189     for (int i = 0; i < 100; i++) {
0190       // printf("%f %f %f \n", pts[i][0], pts[i][1], pts[i][2]);
0191     }
0192   }
0193 }
0194 
0195 // attach_fill_test implementation
0196 void grid_attach_fill_test(grid2_view<host_grid2_attach> grid_view) {
0197   const auto& axis0 = grid_view._axis_p0_view;
0198   const auto& axis1 = grid_view._axis_p1_view;
0199 
0200   dim3 block_dim(axis0.n_bins, axis1.n_bins);
0201   unsigned int thread_dim = 100;
0202 
0203   // run the kernel
0204   grid_attach_fill_test_kernel<<<block_dim, thread_dim>>>(grid_view);
0205 
0206   // cuda error check
0207   TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
0208   TRACCC_CUDA_ERROR_CHECK(cudaDeviceSynchronize());
0209 }
0210 
0211 /*---------------------------------------------------------
0212   assign test function for grid buffer with attach populator
0213   ---------------------------------------------------------*/
0214 
0215 __global__ void grid_attach_assign_test_kernel(
0216     grid2_view<host_grid2_attach> grid_view) {
0217   // Let's try building the grid object
0218   device_grid2_attach g2_device(grid_view);
0219 
0220   auto pts = g2_device.bin(threadIdx.x, threadIdx.y);
0221 
0222   for (std::size_t i = 0u; i < pts.size(); i++) {
0223     pts[i] = {static_cast<scalar>(i), static_cast<scalar>(i + 1u),
0224               static_cast<scalar>(i + 2u)};
0225   }
0226 }
0227 
0228 // attach_fill_test implementation
0229 void grid_attach_assign_test(grid2_view<host_grid2_attach> grid_view) {
0230   unsigned int block_dim = 1;
0231   dim3 thread_dim(2, 2);
0232 
0233   // run the kernel
0234   grid_attach_assign_test_kernel<<<block_dim, thread_dim>>>(grid_view);
0235 
0236   // cuda error check
0237   TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
0238   TRACCC_CUDA_ERROR_CHECK(cudaDeviceSynchronize());
0239 }
0240 
0241 }  // namespace traccc