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