Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:08

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://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::Test {
0025 
0026 BOOST_AUTO_TEST_SUITE(Utilities)
0027 BOOST_AUTO_TEST_CASE(CUDAOBJ_TEST) {
0028   const int vecDim = 100;  // Vector imension
0029   const int nVec = 128;    // Number of vectors
0030 
0031   dim3 gridSize(1, 1, 1);
0032   dim3 blockSize(vecDim, 1, 1);
0033   int bufSize;
0034 
0035   bufSize = gridSize.x * blockSize.x;
0036   Eigen::Matrix<float, vecDim, nVec> inMat_cpu[bufSize];
0037   for (int i = 0; i < bufSize; i++) {
0038     inMat_cpu[i] = Eigen::Matrix<float, vecDim, nVec>::Random();
0039   }
0040 
0041   cudaProfilerStart();
0042 
0043   CudaVector<Eigen::Matrix<float, vecDim, nVec>> inMat_cuda(bufSize, inMat_cpu,
0044                                                             bufSize, 0);
0045   CudaVector<Eigen::Matrix<float, vecDim, nVec>> outMat_cuda(bufSize);
0046   MatrixLoadStore<float, vecDim, nVec>
0047       <<<gridSize, blockSize>>>(inMat_cuda.get(), outMat_cuda.get());
0048   CpuVector<Eigen::Matrix<float, vecDim, nVec>> outMat_cpu(bufSize,
0049                                                            &outMat_cuda);
0050 
0051   cudaProfilerStop();
0052 
0053   BOOST_REQUIRE_EQUAL(inMat_cpu[0], *outMat_cpu.get(0));
0054 }
0055 BOOST_AUTO_TEST_SUITE_END()
0056 
0057 }  // namespace Acts::Test