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