Back to home page

EIC code displayed by LXR

 
 

    


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

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 // Detray test include(s)
0010 #include "detector_hip_kernel.hpp"
0011 #include "detray/definitions/algebra.hpp"
0012 #include "detray/test/common/build_toy_detector.hpp"
0013 #include "detray/test/framework/assert.hpp"
0014 #include "detray/test/framework/types.hpp"
0015 
0016 // Vecmem include(s)
0017 #include <vecmem/memory/hip/managed_memory_resource.hpp>
0018 #include <vecmem/memory/host_memory_resource.hpp>
0019 
0020 // Google Test include(s)
0021 #include <gtest/gtest.h>
0022 
0023 // System include(s)
0024 #include <limits>
0025 
0026 using namespace detray;
0027 
0028 TEST(detector_hip, detector) {
0029   // memory resource
0030   vecmem::hip::managed_memory_resource mng_mr;
0031 
0032   // create toy geometry
0033   auto [toy_det, names] = build_toy_detector<test::algebra>(mng_mr);
0034 
0035   auto ctx0 = typename detector_host_t::geometry_context();
0036 
0037   // host objects
0038   auto& volumes_host = toy_det.volumes();
0039   auto& surfaces_host = toy_det.surfaces();
0040   auto& transforms_host = toy_det.transform_store();
0041   auto& masks_host = toy_det.mask_store();
0042   auto& discs_host = masks_host.get<disc_id>();
0043   auto& cylinders_host = masks_host.get<cylinder_id>();
0044   auto& rectangles_host = masks_host.get<rectangle_id>();
0045 
0046   // copied outputs from device side
0047   vecmem::vector<det_volume_t> volumes_device(volumes_host.size(), &mng_mr);
0048   vecmem::vector<det_surface_t> surfaces_device(surfaces_host.size(), &mng_mr);
0049   vecmem::vector<transform_t> transforms_device(transforms_host.size(),
0050                                                 &mng_mr);
0051   vecmem::vector<rectangle_t> rectangles_device(rectangles_host.size(),
0052                                                 &mng_mr);
0053   vecmem::vector<disc_t> discs_device(discs_host.size(), &mng_mr);
0054   vecmem::vector<cylinder_t> cylinders_device(cylinders_host.size(), &mng_mr);
0055 
0056   // get data object for toy detector
0057   auto toy_det_data = detray::get_data(toy_det);
0058 
0059   // get data object for device outputs
0060   auto volumes_data = vecmem::get_data(volumes_device);
0061   auto surfaces_data = vecmem::get_data(surfaces_device);
0062   auto transforms_data = vecmem::get_data(transforms_device);
0063   auto rectangles_data = vecmem::get_data(rectangles_device);
0064   auto discs_data = vecmem::get_data(discs_device);
0065   auto cylinders_data = vecmem::get_data(cylinders_device);
0066 
0067   // run the test code to copy the objects
0068   detector_test(toy_det_data, volumes_data, surfaces_data, transforms_data,
0069                 rectangles_data, discs_data, cylinders_data);
0070 
0071   // check if the same volume objects are copied
0072   for (unsigned int i = 0u; i < volumes_host.size(); i++) {
0073     EXPECT_EQ(volumes_host[i] == volumes_device[i], true);
0074   }
0075 
0076   // check if the same surface objects are copied
0077   for (unsigned int i = 0u; i < surfaces_host.size(); i++) {
0078     EXPECT_EQ(surfaces_device[i] == surfaces_host[i], true);
0079   }
0080 
0081   // check if the same transform objects are copied
0082   for (unsigned int i = 0u; i < transforms_host.size(ctx0); i++) {
0083     EXPECT_EQ(transforms_host.at(i, ctx0) == transforms_device[i], true);
0084   }
0085 
0086   // check if the same masks are copied
0087   for (unsigned int i = 0u; i < rectangles_host.size(); i++) {
0088     EXPECT_EQ(rectangles_host[i] == rectangles_device[i], true);
0089   }
0090 
0091   for (unsigned int i = 0u; i < discs_host.size(); i++) {
0092     EXPECT_EQ(discs_host[i] == discs_device[i], true);
0093   }
0094 
0095   for (unsigned int i = 0u; i < cylinders_host.size(); i++) {
0096     EXPECT_EQ(cylinders_host[i] == cylinders_device[i], true);
0097   }
0098 }