From 852fbff97a7fde20f5a218fe4467f05c3f1ebb3c Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Wed, 8 Jan 2025 10:20:44 +0100 Subject: [PATCH] Add tests for the PDI wrapper (#743) --- docker/latest/Dockerfile | 1 + docker/oldest/Dockerfile | 1 + tests/CMakeLists.txt | 4 ++ tests/pdi/CMakeLists.txt | 13 ++++ tests/pdi/pdi.cpp | 127 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 tests/pdi/CMakeLists.txt create mode 100644 tests/pdi/pdi.cpp diff --git a/docker/latest/Dockerfile b/docker/latest/Dockerfile index cba5379fc..adbb99312 100644 --- a/docker/latest/Dockerfile +++ b/docker/latest/Dockerfile @@ -54,6 +54,7 @@ RUN chmod +x /bin/bash_run \ libhwloc-dev \ libpdi-dev \ pdidev-archive-keyring \ + pdiplugin-user-code \ pkg-config \ # Installing cmake < 3.28 to workaround issue with Kokkos && wget https://github.com/Kitware/CMake/releases/download/v3.27.9/cmake-3.27.9-linux-x86_64.tar.gz \ diff --git a/docker/oldest/Dockerfile b/docker/oldest/Dockerfile index 814de6592..28ab392ea 100644 --- a/docker/oldest/Dockerfile +++ b/docker/oldest/Dockerfile @@ -54,6 +54,7 @@ RUN chmod +x /bin/bash_run \ libhwloc-dev \ libpdi-dev \ pdidev-archive-keyring \ + pdiplugin-user-code \ pkg-config \ && case "${BACKEND}" in \ "cpu") \ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5f65edc5c..8aeacaa23 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,3 +45,7 @@ endif() if("${DDC_BUILD_KERNELS_SPLINES}") add_subdirectory(splines) endif() + +if("${DDC_BUILD_PDI_WRAPPER}") + add_subdirectory(pdi) +endif() diff --git a/tests/pdi/CMakeLists.txt b/tests/pdi/CMakeLists.txt new file mode 100644 index 000000000..7c782679d --- /dev/null +++ b/tests/pdi/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright (C) The DDC development team, see COPYRIGHT.md file +# +# SPDX-License-Identifier: MIT + +cmake_minimum_required(VERSION 3.22) + +include(GoogleTest) + +add_executable(pdi_tests ../main.cpp pdi.cpp) +set_property(TARGET pdi_tests PROPERTY ENABLE_EXPORTS TRUE) +target_compile_features(pdi_tests PUBLIC cxx_std_17) +target_link_libraries(pdi_tests PUBLIC GTest::gtest DDC::core DDC::pdi) +gtest_discover_tests(pdi_tests DISCOVERY_MODE PRE_TEST) diff --git a/tests/pdi/pdi.cpp b/tests/pdi/pdi.cpp new file mode 100644 index 000000000..2ea64999c --- /dev/null +++ b/tests/pdi/pdi.cpp @@ -0,0 +1,127 @@ +// Copyright (C) The DDC development team, see COPYRIGHT.md file +// +// SPDX-License-Identifier: MIT + +#include +#include + +#include +#include + +#include + +#include +#include + +namespace { + +struct DDimX +{ +}; + +struct DDimY +{ +}; + +} // namespace + +extern "C" { + +void test_ddc_expose() +{ + // pdi_chunk_label_rank + void* pdi_chunk_label_rank_ptr; + ASSERT_EQ(PDI_access("pdi_chunk_label_rank", &pdi_chunk_label_rank_ptr, PDI_IN), PDI_OK); + std::size_t const* const pdi_chunk_label_rank + = static_cast(pdi_chunk_label_rank_ptr); + EXPECT_EQ(*pdi_chunk_label_rank, 2); + + // pdi_chunk_label_extents + void* pdi_chunk_label_extents_ptr; + ASSERT_EQ(PDI_access("pdi_chunk_label_extents", &pdi_chunk_label_extents_ptr, PDI_IN), PDI_OK); + std::size_t const* const pdi_chunk_label_extents + = static_cast(pdi_chunk_label_extents_ptr); + ASSERT_EQ(pdi_chunk_label_extents[0], 3); + ASSERT_EQ(pdi_chunk_label_extents[1], 5); + + // pdi_chunk_label + void* pdi_chunk_label_ptr; + ASSERT_EQ(PDI_access("pdi_chunk_label", &pdi_chunk_label_ptr, PDI_IN), PDI_OK); + int const* const pdi_chunk_label = static_cast(pdi_chunk_label_ptr); + for (std::size_t i = 0; i < pdi_chunk_label_extents[0]; ++i) { + for (std::size_t j = 0; j < pdi_chunk_label_extents[1]; ++j) { + EXPECT_EQ(pdi_chunk_label[pdi_chunk_label_extents[1] * i + j], 3); + } + } + + EXPECT_EQ(PDI_reclaim("pdi_chunk_label_rank"), PDI_OK); + EXPECT_EQ(PDI_reclaim("pdi_chunk_label_extents"), PDI_OK); + EXPECT_EQ(PDI_reclaim("pdi_chunk_label"), PDI_OK); + + // nb_event_called + void* nb_event_called_ptr; + ASSERT_EQ(PDI_access("nb_event_called", &nb_event_called_ptr, PDI_INOUT), PDI_OK); + int* const nb_event_called = static_cast(nb_event_called_ptr); + *nb_event_called += 1; + + EXPECT_EQ(PDI_reclaim("nb_event_called"), PDI_OK); +} +} + +TEST(Pdi, ChunkAndChunkSpan) +{ + std::string const pdi_cfg = R"PDI_CFG( +metadata: + pdi_chunk_label_rank: size_t + pdi_chunk_label_extents: + type: array + subtype: size_t + size: $pdi_chunk_label_rank + +data: + pdi_chunk_label: + type: array + subtype: int + size: [ '$pdi_chunk_label_extents[0]', '$pdi_chunk_label_extents[1]' ] + nb_event_called: int + +plugins: + user_code: + on_event: + some_event: + test_ddc_expose: {} +)PDI_CFG"; + + PC_tree_t pdi_conf = PC_parse_string(pdi_cfg.c_str()); + PDI_init(pdi_conf); + + PDI_errhandler(PDI_NULL_HANDLER); + + { + ddc::DiscreteDomain const + ddom_xy(ddc::DiscreteElement(7, 11), + ddc::DiscreteVector(3, 5)); + + ddc::Chunk chunk("ddc_chunk_label", ddom_xy, ddc::HostAllocator()); + ddc::parallel_fill(chunk, 3); + + int nb_event_called = 0; + + ddc::PdiEvent("some_event") + .with("pdi_chunk_label", chunk) + .and_with("nb_event_called", nb_event_called); + + ddc::PdiEvent("some_event") + .with("pdi_chunk_label", chunk.span_view()) + .and_with("nb_event_called", nb_event_called); + + ddc::PdiEvent("some_event") + .with("pdi_chunk_label", chunk.span_cview()) + .and_with("nb_event_called", nb_event_called); + + EXPECT_EQ(nb_event_called, 3); + } + + PDI_finalize(); + PC_tree_destroy(&pdi_conf); +}