Back to home page

EIC code displayed by LXR

 
 

    


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

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 #include <functional>
0009 
0010 #include <gtest/gtest.h>
0011 #include <vecmem/memory/cuda/device_memory_resource.hpp>
0012 #include <vecmem/memory/host_memory_resource.hpp>
0013 #include <vecmem/utils/cuda/async_copy.hpp>
0014 #include <vecmem/utils/cuda/stream_wrapper.hpp>
0015 
0016 #include "tests/cca_test.hpp"
0017 #include "traccc/clusterization/clustering_config.hpp"
0018 #include "traccc/clusterization/device/tags.hpp"
0019 #include "traccc/cuda/clusterization/clusterization_algorithm.hpp"
0020 #include "traccc/cuda/utils/stream_wrapper.hpp"
0021 #include "traccc/geometry/detector_design_description.hpp"
0022 
0023 namespace {
0024 vecmem::host_memory_resource host_mr;
0025 
0026 cca_function_t get_f_with(traccc::clustering_config cfg) {
0027   return [cfg](const traccc::edm::silicon_cell_collection::host& cells,
0028                const traccc::detector_design_description::host& det_desc,
0029                const traccc::detector_conditions_description::host& det_cond)
0030              -> std::pair<std::map<traccc::geometry_id,
0031                                    traccc::edm::measurement_collection::host>,
0032                           traccc::edm::silicon_cluster_collection::host> {
0033     std::map<traccc::geometry_id, traccc::edm::measurement_collection::host>
0034         geom_to_meas_map;
0035 
0036     vecmem::cuda::stream_wrapper vecmem_stream;
0037     traccc::cuda::stream_wrapper stream{vecmem_stream.stream()};
0038     vecmem::cuda::device_memory_resource device_mr;
0039     vecmem::cuda::async_copy copy{stream.cudaStream()};
0040 
0041     traccc::cuda::clusterization_algorithm cc({device_mr, &host_mr}, copy,
0042                                               stream, cfg);
0043 
0044     traccc::detector_design_description::buffer det_descr_buffer{
0045         [&]() {
0046           std::vector<unsigned int> sizes(det_desc.size());
0047           for (std::size_t i = 0; i < det_desc.size(); ++i) {
0048             auto this_design = det_desc.at(i);
0049             // now for each element, set the size to the largest size of
0050             // that element across all modules
0051             sizes[i] = std::max(
0052                 static_cast<unsigned int>(((this_design.bin_edges_x()).size())),
0053                 static_cast<unsigned int>(
0054                     ((this_design.bin_edges_y()).size())));
0055           }
0056           return sizes;
0057         }(),
0058         device_mr, &host_mr, vecmem::data::buffer_type::fixed_size};
0059     copy.setup(det_descr_buffer)->wait();
0060     copy(vecmem::get_data(det_desc), det_descr_buffer)->wait();
0061     traccc::detector_conditions_description::buffer det_cond_buffer{
0062         static_cast<traccc::detector_conditions_description::buffer::size_type>(
0063             det_cond.size()),
0064         device_mr};
0065     copy.setup(det_cond_buffer)->ignore();
0066     copy(vecmem::get_data(det_cond), det_cond_buffer,
0067          vecmem::copy::type::host_to_device)
0068         ->ignore();
0069     traccc::edm::silicon_cell_collection::buffer cells_buffer{
0070         static_cast<traccc::edm::silicon_cell_collection::buffer::size_type>(
0071             cells.size()),
0072         device_mr};
0073     copy.setup(cells_buffer)->wait();
0074     copy(vecmem::get_data(cells), cells_buffer)->wait();
0075 
0076     auto [measurements_buffer, cluster_buffer] =
0077         cc(cells_buffer, det_descr_buffer, det_cond_buffer,
0078            traccc::device::clustering_keep_disjoint_set{});
0079     traccc::edm::measurement_collection::host measurements{host_mr};
0080     copy(measurements_buffer, measurements)->wait();
0081 
0082     traccc::edm::silicon_cluster_collection::host clusters{host_mr};
0083     copy(cluster_buffer, clusters)->wait();
0084 
0085     for (std::size_t i = 0; i < measurements.size(); i++) {
0086       if (geom_to_meas_map.contains(
0087               measurements.at(i).surface_link().value()) == false) {
0088         geom_to_meas_map.insert(
0089             {measurements.at(i).surface_link().value(),
0090              traccc::edm::measurement_collection::host{host_mr}});
0091       }
0092       geom_to_meas_map.at(measurements.at(i).surface_link().value())
0093           .push_back(measurements.at(i));
0094     }
0095 
0096     return {std::move(geom_to_meas_map), std::move(clusters)};
0097   };
0098 }
0099 }  // namespace
0100 
0101 TEST_P(ConnectedComponentAnalysisTests, Run) {
0102   test_connected_component_analysis(GetParam());
0103 }
0104 
0105 INSTANTIATE_TEST_SUITE_P(
0106     CUDAFastSvAlgorithm, ConnectedComponentAnalysisTests,
0107     ::testing::Combine(
0108         ::testing::Values(get_f_with(default_ccl_test_config())),
0109         ::testing::ValuesIn(ConnectedComponentAnalysisTests::get_test_files())),
0110     ConnectedComponentAnalysisTests::get_test_name);
0111 
0112 INSTANTIATE_TEST_SUITE_P(
0113     CUDAFastSvAlgorithmWithScratch, ConnectedComponentAnalysisTests,
0114     ::testing::Combine(
0115         ::testing::Values(get_f_with(tiny_ccl_test_config())),
0116         ::testing::ValuesIn(
0117             ConnectedComponentAnalysisTests::get_test_files_short())),
0118     ConnectedComponentAnalysisTests::get_test_name);