Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:13

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 #pragma once
0010 
0011 // Test include(s).
0012 #include "detray/test/device/cuda/cuda_test_fixture.hpp"
0013 #include "detray/test/device/cuda/execute_cuda_test.cuh"
0014 #include "detray/test/device/execute_host_test.hpp"
0015 #include "detray/test/device/matrix_fixture.hpp"
0016 #include "detray/test/device/transform_fixture.hpp"
0017 #include "detray/test/device/vector_fixture.hpp"
0018 
0019 // GoogleTest include(s).
0020 #include <gtest/gtest.h>
0021 
0022 namespace detray::test::cuda {
0023 
0024 template <detray::concepts::algebra A>
0025 class cuda_vector_test : public cuda_test_fixture<vector_fixture<A>> {};
0026 
0027 template <detray::concepts::algebra A>
0028 class cuda_matrix_test : public cuda_test_fixture<matrix_fixture<A>> {};
0029 
0030 template <detray::concepts::algebra A>
0031 class cuda_transform_test : public cuda_test_fixture<transform_fixture<A>> {};
0032 
0033 TYPED_TEST_SUITE_P(cuda_vector_test);
0034 TYPED_TEST_SUITE_P(cuda_matrix_test);
0035 TYPED_TEST_SUITE_P(cuda_transform_test);
0036 
0037 /// Test for some basic 2D "vector operations"
0038 TYPED_TEST_P(cuda_vector_test, vector_2d_ops) {
0039   // Run the test on the host, and on the/a device.
0040   execute_host_test<vector_2d_ops_functor<TypeParam>>(
0041       this->m_p1->size(), vecmem::get_data(*(this->m_p1)),
0042       vecmem::get_data(*(this->m_p2)),
0043       vecmem::get_data(*(this->m_output_host)));
0044 
0045   execute_cuda_test<vector_2d_ops_functor<TypeParam>>(
0046       this->m_p1->size(), vecmem::get_data(*(this->m_p1)),
0047       vecmem::get_data(*(this->m_p2)),
0048       vecmem::get_data(*(this->m_output_device)));
0049 
0050   // Compare the outputs.
0051   this->compareOutputs();
0052 }
0053 
0054 /// Test for some basic 3D "vector operations"
0055 TYPED_TEST_P(cuda_vector_test, vector_3d_ops) {
0056   // This test is just not numerically stable at float precision in optimized
0057   // mode for some reason. :-(
0058 #ifdef NDEBUG
0059   if (typeid(dscalar<TypeParam>) == typeid(float)) {
0060     GTEST_SKIP();
0061   }
0062 #endif  // NDEBUG
0063 
0064   // Run the test on the host, and on the/a device.
0065   execute_host_test<vector_3d_ops_functor<TypeParam>>(
0066       this->m_v1->size(), vecmem::get_data(*(this->m_v1)),
0067       vecmem::get_data(*(this->m_v2)),
0068       vecmem::get_data(*(this->m_output_host)));
0069 
0070   execute_cuda_test<vector_3d_ops_functor<TypeParam>>(
0071       this->m_v1->size(), vecmem::get_data(*(this->m_v1)),
0072       vecmem::get_data(*(this->m_v2)),
0073       vecmem::get_data(*(this->m_output_device)));
0074 
0075   // Compare the outputs.
0076   this->compareOutputs();
0077 }
0078 
0079 /// Test for handling matrices
0080 TYPED_TEST_P(cuda_matrix_test, matrix64_ops) {
0081   // Run the test on the host, and on the/a device.
0082   execute_host_test<matrix64_ops_functor<TypeParam>>(
0083       this->m_m1->size(), vecmem::get_data(*(this->m_m1)),
0084       vecmem::get_data(*(this->m_output_host)));
0085 
0086   execute_cuda_test<matrix64_ops_functor<TypeParam>>(
0087       this->m_m1->size(), vecmem::get_data(*(this->m_m1)),
0088       vecmem::get_data(*(this->m_output_device)));
0089 
0090   // Compare the outputs.
0091   this->compareOutputs();
0092 }
0093 
0094 /// Test for handling matrices
0095 TYPED_TEST_P(cuda_matrix_test, matrix22_ops) {
0096   // Run the test on the host, and on the/a device.
0097   execute_host_test<matrix22_ops_functor<TypeParam>>(
0098       this->m_m2->size(), vecmem::get_data(*(this->m_m2)),
0099       vecmem::get_data(*(this->m_output_host)));
0100 
0101   execute_cuda_test<matrix22_ops_functor<TypeParam>>(
0102       this->m_m2->size(), vecmem::get_data(*(this->m_m2)),
0103       vecmem::get_data(*(this->m_output_device)));
0104 
0105   // Compare the outputs.
0106   this->compareOutputs();
0107 }
0108 
0109 /// Test for some operations with @c transform3
0110 TYPED_TEST_P(cuda_transform_test, transform3D) {
0111   // Run the test on the host, and on the/a device.
0112   execute_host_test<transform3_ops_functor<TypeParam>>(
0113       this->m_t1->size(), vecmem::get_data(*(this->m_t1)),
0114       vecmem::get_data(*(this->m_t2)), vecmem::get_data(*(this->m_t3)),
0115       vecmem::get_data(*(this->m_v1)), vecmem::get_data(*(this->m_v2)),
0116       vecmem::get_data(*(this->m_output_host)));
0117 
0118   execute_cuda_test<transform3_ops_functor<TypeParam>>(
0119       this->m_t1->size(), vecmem::get_data(*(this->m_t1)),
0120       vecmem::get_data(*(this->m_t2)), vecmem::get_data(*(this->m_t3)),
0121       vecmem::get_data(*(this->m_v1)), vecmem::get_data(*(this->m_v2)),
0122       vecmem::get_data(*(this->m_output_device)));
0123 
0124   // Compare the outputs.
0125   this->compareOutputs();
0126 }
0127 
0128 }  // namespace detray::test::cuda