Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-07 08:11:42

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Plugins/Cuda/Cuda.hpp"
0012 
0013 #include <Eigen/Dense>
0014 #include <cuda_profiler_api.h>
0015 
0016 template <typename AFloat, int row, int col>
0017 __global__ void MatrixLoadStore(const Eigen::Matrix<AFloat, row, col>* input,
0018                                 Eigen::Matrix<AFloat, row, col>* output) {
0019   for (int i = 0; i < col; i++) {
0020     output[blockIdx.x](threadIdx.x, i) = input[blockIdx.x](threadIdx.x, i);
0021   }
0022 }
0023 
0024 namespace Acts {
0025 namespace Test {
0026 
0027 BOOST_AUTO_TEST_SUITE(Utilities)
0028 BOOST_AUTO_TEST_CASE(CUDAOBJ_TEST) {
0029   const int vecDim = 100;  // Vector imension
0030   const int nVec = 128;    // Number of vectors
0031 
0032   dim3 gridSize(1, 1, 1);
0033   dim3 blockSize(vecDim, 1, 1);
0034   int bufSize;
0035 
0036   bufSize = gridSize.x * blockSize.x;
0037   Eigen::Matrix<float, vecDim, nVec> inMat_cpu[bufSize];
0038   for (int i = 0; i < bufSize; i++) {
0039     inMat_cpu[i] = Eigen::Matrix<float, vecDim, nVec>::Random();
0040   }
0041 
0042   cudaProfilerStart();
0043 
0044   CudaVector<Eigen::Matrix<float, vecDim, nVec>> inMat_cuda(bufSize, inMat_cpu,
0045                                                             bufSize, 0);
0046   CudaVector<Eigen::Matrix<float, vecDim, nVec>> outMat_cuda(bufSize);
0047   MatrixLoadStore<float, vecDim, nVec>
0048       <<<gridSize, blockSize>>>(inMat_cuda.get(), outMat_cuda.get());
0049   CpuVector<Eigen::Matrix<float, vecDim, nVec>> outMat_cpu(bufSize,
0050                                                            &outMat_cuda);
0051 
0052   cudaProfilerStop();
0053 
0054   BOOST_REQUIRE_EQUAL(inMat_cpu[0], *outMat_cpu.get(0));
0055 }
0056 BOOST_AUTO_TEST_SUITE_END()
0057 
0058 }  // namespace Test
0059 }  // namespace Acts