Skip to content

Commit

Permalink
Add tests for the Alpaka CCL algorithm
Browse files Browse the repository at this point in the history
This PR enables the CCL testing harness for the Alpaka code, allowing us
to make sure it is working correctly.
  • Loading branch information
stephenswat committed Jul 22, 2024
1 parent ebef105 commit 57239aa
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/alpaka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

Expand Down
84 changes: 84 additions & 0 deletions tests/alpaka/test_cca.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

#include <functional>
#include <vecmem/memory/host_memory_resource.hpp>

#include "tests/cca_test.hpp"
#include "traccc/alpaka/clusterization/clusterization_algorithm.hpp"

#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED)
#include <vecmem/memory/cuda/device_memory_resource.hpp>
#include <vecmem/memory/cuda/host_memory_resource.hpp>
#include <vecmem/utils/cuda/copy.hpp>
#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED)
#include <vecmem/memory/hip/device_memory_resource.hpp>
#include <vecmem/memory/hip/host_memory_resource.hpp>
#include <vecmem/utils/hip/copy.hpp>
#endif

namespace {

cca_function_t f = [](const traccc::cell_collection_types::host& cells,
const traccc::cell_module_collection_types::host&
modules) {
std::map<traccc::geometry_id, vecmem::vector<traccc::measurement>> 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<traccc::cell_collection_types::buffer::size_type>(
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<traccc::cell_module_collection_types::buffer::size_type>(
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);

0 comments on commit 57239aa

Please sign in to comment.