diff --git a/tests/alpaka/CMakeLists.txt b/tests/alpaka/CMakeLists.txt index 30991a4bb1..1d5b6f7d53 100644 --- a/tests/alpaka/CMakeLists.txt +++ b/tests/alpaka/CMakeLists.txt @@ -4,23 +4,30 @@ # # Mozilla Public License Version 2.0 +set(TRACCC_ALPAKA_TEST_SOURCES + alpaka_basic.cpp + test_cca.cpp +) + if(alpaka_ACC_GPU_CUDA_ENABLE) enable_language(CUDA) - set_source_files_properties(alpaka_basic.cpp PROPERTIES LANGUAGE CUDA) + set_source_files_properties(${TRACCC_ALPAKA_TEST_SOURCES} PROPERTIES LANGUAGE CUDA) include( traccc-compiler-options-cuda ) list(APPEND DEVICE_LIBRARIES vecmem::cuda) elseif(alpaka_ACC_GPU_HIP_ENABLE) enable_language(HIP) - set_source_files_properties(alpaka_basic.cpp PROPERTIES LANGUAGE HIP) + set_source_files_properties(${TRACCC_ALPAKA_TEST_SOURCES} PROPERTIES LANGUAGE HIP) list(APPEND DEVICE_LIBRARIES vecmem::hip) endif() traccc_add_test( alpaka - alpaka_basic.cpp + ${TRACCC_ALPAKA_TEST_SOURCES} LINK_LIBRARIES GTest::gtest_main + traccc_tests_common alpaka::alpaka vecmem::core + traccc::alpaka ${DEVICE_LIBRARIES} ) diff --git a/tests/alpaka/test_cca.cpp b/tests/alpaka/test_cca.cpp new file mode 100644 index 0000000000..c74109ed72 --- /dev/null +++ b/tests/alpaka/test_cca.cpp @@ -0,0 +1,84 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2022-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include + +#include +#include + +#include "tests/cca_test.hpp" +#include "traccc/alpaka/clusterization/clusterization_algorithm.hpp" + +#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) +#include +#include +#include +#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) +#include +#include +#include +#endif + +namespace { + +cca_function_t f = [](const traccc::cell_collection_types::host& cells, + const traccc::cell_module_collection_types::host& + modules) { + std::map> result; + + vecmem::host_memory_resource host_mr; + +#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) + vecmem::cuda::copy copy; + vecmem::cuda::device_memory_resource device_mr; +#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) + vecmem::hip::copy copy; + vecmem::hip::device_memory_resource device_mr; +#else + vecmem::copy copy; + vecmem::host_memory_resource device_mr; +#endif + + traccc::alpaka::clusterization_algorithm cc({device_mr}, copy, 1024); + + traccc::cell_collection_types::buffer cells_buffer{ + static_cast( + cells.size()), + device_mr}; + copy.setup(cells_buffer)->wait(); + copy(vecmem::get_data(cells), cells_buffer)->wait(); + + traccc::cell_module_collection_types::buffer modules_buffer{ + static_cast( + modules.size()), + device_mr}; + copy.setup(modules_buffer)->wait(); + copy(vecmem::get_data(modules), modules_buffer)->wait(); + + auto measurements_buffer = cc(cells_buffer, modules_buffer); + traccc::measurement_collection_types::host measurements{&host_mr}; + copy(measurements_buffer, measurements)->wait(); + + for (std::size_t i = 0; i < measurements.size(); i++) { + result[modules.at(measurements.at(i).module_link).surface_link.value()] + .push_back(measurements.at(i)); + } + + return result; +}; +} // namespace + +TEST_P(ConnectedComponentAnalysisTests, Run) { + test_connected_component_analysis(GetParam()); +} + +INSTANTIATE_TEST_SUITE_P( + AlpakaFastSvAlgorithm, ConnectedComponentAnalysisTests, + ::testing::Combine( + ::testing::Values(f), + ::testing::ValuesIn(ConnectedComponentAnalysisTests::get_test_files())), + ConnectedComponentAnalysisTests::get_test_name);