Skip to content

Commit

Permalink
Add tests for scratch space CCA
Browse files Browse the repository at this point in the history
This commit adds some tests for running CCA with the scratch space by
reducing the thread groups to handle extremely small numbers of cells.
This will force the edge case of running out of shared memory to occur.
  • Loading branch information
stephenswat committed Jul 16, 2024
1 parent 53f5d92 commit 2a3d874
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 64 deletions.
28 changes: 28 additions & 0 deletions tests/common/tests/cca_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ inline traccc::clustering_config default_ccl_test_config() {
return rv;
}

inline traccc::clustering_config tiny_ccl_test_config() {
traccc::clustering_config rv;

rv.threads_per_partition = 128;
rv.max_cells_per_thread = 1;
rv.target_cells_per_thread = 1;
rv.backup_size_multiplier = 16384;

return rv;
}

class ConnectedComponentAnalysisTests
: public traccc::tests::data_test,
public testing::WithParamInterface<
Expand Down Expand Up @@ -95,6 +106,23 @@ class ConnectedComponentAnalysisTests
return out;
}

inline static std::vector<std::string> get_test_files_short(void) {
const std::vector<std::pair<std::string, std::size_t>> cases = {
{"trackml_like", 10},
};
std::vector<std::string> out;

for (const std::pair<std::string, std::size_t> &c : cases) {
for (std::size_t i = 0; i < c.second; ++i) {
std::ostringstream ss;
ss << c.first << "_" << std::setfill('0') << std::setw(10) << i;
out.push_back(ss.str());
}
}

return out;
}

inline void test_connected_component_analysis(ParamType p) {
cca_function_t f = std::get<0>(p);
std::string file_prefix = std::get<1>(p);
Expand Down
77 changes: 45 additions & 32 deletions tests/cuda/test_cca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,54 @@
#include <vecmem/utils/cuda/async_copy.hpp>

#include "tests/cca_test.hpp"
#include "traccc/clusterization/clustering_config.hpp"
#include "traccc/cuda/clusterization/clusterization_algorithm.hpp"
#include "traccc/cuda/utils/stream.hpp"

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;
cca_function_t get_f_with(traccc::clustering_config cfg) {
return [cfg](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;
traccc::cuda::stream stream;
vecmem::cuda::device_memory_resource device_mr;
vecmem::cuda::async_copy copy{stream.cudaStream()};
vecmem::host_memory_resource host_mr;
traccc::cuda::stream stream;
vecmem::cuda::device_memory_resource device_mr;
vecmem::cuda::async_copy copy{stream.cudaStream()};

traccc::cuda::clusterization_algorithm cc({device_mr}, copy, stream,
default_ccl_test_config());
traccc::cuda::clusterization_algorithm cc({device_mr}, copy, stream,
cfg);

traccc::cell_collection_types::buffer cells_buffer{
static_cast<traccc::cell_collection_types::buffer::size_type>(
cells.size()),
device_mr};
copy.setup(cells_buffer);
copy(vecmem::get_data(cells), cells_buffer)->ignore();
traccc::cell_collection_types::buffer cells_buffer{
static_cast<traccc::cell_collection_types::buffer::size_type>(
cells.size()),
device_mr};
copy.setup(cells_buffer);
copy(vecmem::get_data(cells), cells_buffer)->ignore();

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);
copy(vecmem::get_data(modules), modules_buffer)->ignore();
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);
copy(vecmem::get_data(modules), modules_buffer)->ignore();

auto measurements_buffer = cc(cells_buffer, modules_buffer);
traccc::measurement_collection_types::host measurements{&host_mr};
copy(measurements_buffer, measurements)->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));
}
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;
};
return result;
};
}
} // namespace

TEST_P(ConnectedComponentAnalysisTests, Run) {
Expand All @@ -65,6 +70,14 @@ TEST_P(ConnectedComponentAnalysisTests, Run) {
INSTANTIATE_TEST_SUITE_P(
CUDAFastSvAlgorithm, ConnectedComponentAnalysisTests,
::testing::Combine(
::testing::Values(f),
::testing::Values(get_f_with(default_ccl_test_config())),
::testing::ValuesIn(ConnectedComponentAnalysisTests::get_test_files())),
ConnectedComponentAnalysisTests::get_test_name);

INSTANTIATE_TEST_SUITE_P(
CUDAFastSvAlgorithmWithScratch, ConnectedComponentAnalysisTests,
::testing::Combine(
::testing::Values(get_f_with(tiny_ccl_test_config())),
::testing::ValuesIn(
ConnectedComponentAnalysisTests::get_test_files_short())),
ConnectedComponentAnalysisTests::get_test_name);
76 changes: 44 additions & 32 deletions tests/sycl/test_cca.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,48 @@

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;
cca_function_t get_f_with(traccc::clustering_config cfg) {
return [cfg](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;
cl::sycl::queue queue;
vecmem::sycl::device_memory_resource device_mr;
vecmem::sycl::async_copy copy{&queue};
vecmem::host_memory_resource host_mr;
cl::sycl::queue queue;
vecmem::sycl::device_memory_resource device_mr;
vecmem::sycl::async_copy copy{&queue};

traccc::sycl::clusterization_algorithm cc({device_mr}, copy, &queue,
default_ccl_test_config());
traccc::sycl::clusterization_algorithm cc({device_mr}, copy, &queue,
cfg);

traccc::cell_collection_types::buffer cells_buffer{
static_cast<traccc::cell_collection_types::buffer::size_type>(
cells.size()),
device_mr};
copy.setup(cells_buffer);
copy(vecmem::get_data(cells), cells_buffer)->ignore();
traccc::cell_collection_types::buffer cells_buffer{
static_cast<traccc::cell_collection_types::buffer::size_type>(
cells.size()),
device_mr};
copy.setup(cells_buffer);
copy(vecmem::get_data(cells), cells_buffer)->ignore();

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);
copy(vecmem::get_data(modules), modules_buffer)->ignore();
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);
copy(vecmem::get_data(modules), modules_buffer)->ignore();

auto measurements_buffer = cc(cells_buffer, modules_buffer);
traccc::measurement_collection_types::host measurements{&host_mr};
copy(measurements_buffer, measurements)->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));
}
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;
};
return result;
};
}
} // namespace

TEST_P(ConnectedComponentAnalysisTests, Run) {
Expand All @@ -66,6 +70,14 @@ TEST_P(ConnectedComponentAnalysisTests, Run) {
INSTANTIATE_TEST_SUITE_P(
SYCLFastSvAlgorithm, ConnectedComponentAnalysisTests,
::testing::Combine(
::testing::Values(f),
::testing::Values(get_f_with(default_ccl_test_config())),
::testing::ValuesIn(ConnectedComponentAnalysisTests::get_test_files())),
ConnectedComponentAnalysisTests::get_test_name);

INSTANTIATE_TEST_SUITE_P(
SYCLFastSvAlgorithmWithScratch, ConnectedComponentAnalysisTests,
::testing::Combine(
::testing::Values(get_f_with(tiny_ccl_test_config())),
::testing::ValuesIn(
ConnectedComponentAnalysisTests::get_test_files_short())),
ConnectedComponentAnalysisTests::get_test_name);

0 comments on commit 2a3d874

Please sign in to comment.