Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2022-2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Test include(s).
0009 #include "tests/cca_test.hpp"
0010 
0011 // Project include(s).
0012 #include "traccc/clusterization/clustering_config.hpp"
0013 #include "traccc/geometry/detector_conditions_description.hpp"
0014 #include "traccc/geometry/detector_design_description.hpp"
0015 #include "traccc/sycl/clusterization/clusterization_algorithm.hpp"
0016 
0017 // VecMem include(s).
0018 #include <vecmem/memory/host_memory_resource.hpp>
0019 #include <vecmem/memory/sycl/device_memory_resource.hpp>
0020 #include <vecmem/utils/sycl/async_copy.hpp>
0021 
0022 // Google Test include(s).
0023 #include <gtest/gtest.h>
0024 
0025 namespace {
0026 
0027 /// Long-lived host memory resource for the tests.
0028 vecmem::host_memory_resource host_mr;
0029 
0030 cca_function_t get_f_with(traccc::clustering_config cfg) {
0031   return [cfg](const traccc::edm::silicon_cell_collection::host& cells,
0032                const traccc::detector_design_description::host& det_desc,
0033                const traccc::detector_conditions_description::host& det_cond)
0034              -> std::pair<
0035                  std::map<traccc::geometry_id,
0036                           traccc::edm::measurement_collection::host>,
0037                  std::optional<traccc::edm::silicon_cluster_collection::host>> {
0038     std::map<traccc::geometry_id, traccc::edm::measurement_collection::host>
0039         result;
0040 
0041     vecmem::sycl::queue_wrapper vecmem_queue;
0042     traccc::sycl::queue_wrapper traccc_queue{vecmem_queue.queue()};
0043     vecmem::sycl::device_memory_resource device_mr{vecmem_queue};
0044     vecmem::sycl::async_copy copy{vecmem_queue};
0045 
0046     traccc::sycl::clusterization_algorithm cc({device_mr, &host_mr}, copy,
0047                                               traccc_queue, cfg);
0048 
0049     traccc::detector_design_description::buffer det_descr_buffer{
0050         [&]() {
0051           std::vector<unsigned int> sizes(det_desc.size());
0052           for (std::size_t i = 0; i < det_desc.size(); ++i) {
0053             auto this_design = det_desc.at(i);
0054             // now for each element, set the size to the largest
0055             // size of that element across all modules
0056             sizes[i] = std::max(
0057                 static_cast<unsigned int>(((this_design.bin_edges_x()).size())),
0058                 static_cast<unsigned int>(
0059                     ((this_design.bin_edges_y()).size())));
0060           }
0061           return sizes;
0062         }(),
0063         device_mr, &host_mr, vecmem::data::buffer_type::fixed_size};
0064     copy.setup(det_descr_buffer)->wait();
0065     copy(vecmem::get_data(det_desc), det_descr_buffer)->wait();
0066     traccc::detector_conditions_description::buffer det_cond_buffer{
0067         static_cast<traccc::detector_conditions_description::buffer::size_type>(
0068             det_cond.size()),
0069         device_mr};
0070     copy.setup(det_cond_buffer)->wait();
0071     copy(vecmem::get_data(det_cond), det_cond_buffer,
0072          vecmem::copy::type::host_to_device)
0073         ->wait();
0074     traccc::edm::silicon_cell_collection::buffer cells_buffer{
0075         static_cast<traccc::edm::silicon_cell_collection::buffer::size_type>(
0076             cells.size()),
0077         device_mr};
0078     copy.setup(cells_buffer)->wait();
0079     copy(vecmem::get_data(cells), cells_buffer)->wait();
0080 
0081     auto [measurements_buffer, cluster_buffer] =
0082         cc(cells_buffer, det_descr_buffer, det_cond_buffer,
0083            traccc::device::clustering_keep_disjoint_set{});
0084     traccc::edm::measurement_collection::host measurements{host_mr};
0085     copy(measurements_buffer, measurements)->wait();
0086 
0087     traccc::edm::silicon_cluster_collection::host clusters{host_mr};
0088     copy(cluster_buffer, clusters)->wait();
0089 
0090     for (std::size_t i = 0; i < measurements.size(); i++) {
0091       if (result.contains(measurements.at(i).surface_link().value()) == false) {
0092         result.insert({measurements.at(i).surface_link().value(),
0093                        traccc::edm::measurement_collection::host{host_mr}});
0094       }
0095       result.at(measurements.at(i).surface_link().value())
0096           .push_back(measurements.at(i));
0097     }
0098 
0099     return {result, clusters};
0100   };
0101 }
0102 }  // namespace
0103 
0104 TEST_P(ConnectedComponentAnalysisTests, Run) {
0105   test_connected_component_analysis(GetParam());
0106 }
0107 
0108 INSTANTIATE_TEST_SUITE_P(
0109     SYCLFastSvAlgorithm, ConnectedComponentAnalysisTests,
0110     ::testing::Combine(
0111         ::testing::Values(get_f_with(default_ccl_test_config())),
0112         ::testing::ValuesIn(ConnectedComponentAnalysisTests::get_test_files())),
0113     ConnectedComponentAnalysisTests::get_test_name);
0114 
0115 INSTANTIATE_TEST_SUITE_P(
0116     SYCLFastSvAlgorithmWithScratch, ConnectedComponentAnalysisTests,
0117     ::testing::Combine(
0118         ::testing::Values(get_f_with(tiny_ccl_test_config())),
0119         ::testing::ValuesIn(
0120             ConnectedComponentAnalysisTests::get_test_files_short())),
0121     ConnectedComponentAnalysisTests::get_test_name);