Skip to content

Commit

Permalink
Add tests for the PDI wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau committed Jan 6, 2025
1 parent 88c9392 commit c42cc74
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker/latest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions docker/oldest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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") \
Expand Down
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ endif()
if("${DDC_BUILD_KERNELS_SPLINES}")
add_subdirectory(splines)
endif()

if("${DDC_BUILD_PDI_WRAPPER}")
add_subdirectory(pdi)
endif()
13 changes: 13 additions & 0 deletions tests/pdi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
121 changes: 121 additions & 0 deletions tests/pdi/pdi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (C) The DDC development team, see COPYRIGHT.md file
//
// SPDX-License-Identifier: MIT

#include <cstddef>
#include <string>

#include <ddc/ddc.hpp>
#include <ddc/pdi.hpp>

#include <gtest/gtest.h>

#include <paraconf.h>
#include <pdi.h>

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<std::size_t*>(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<std::size_t*>(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<int*>(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);

// a_write_scalar
void* some_event_called_ptr;
ASSERT_EQ(PDI_access("some_event_called", &some_event_called_ptr, PDI_INOUT), PDI_OK);
int* const some_event_called = static_cast<int*>(some_event_called_ptr);
EXPECT_EQ(*some_event_called, 0);

*some_event_called = 1;

EXPECT_EQ(PDI_reclaim("some_event_called"), PDI_OK);
}
}

TEST(Pdi, ChunkSpan)
{
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]' ]
some_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<DDimX, DDimY> const
ddom_xy(ddc::DiscreteElement<DDimX, DDimY>(7, 11),
ddc::DiscreteVector<DDimX, DDimY>(3, 5));

ddc::Chunk chunk("ddc_chunk_label", ddom_xy, ddc::HostAllocator<int>());
ddc::parallel_fill(chunk, 3);

int some_event_called = 0;

ddc::PdiEvent("some_event")
.with("pdi_chunk_label", chunk.span_cview())
.and_with("some_event_called", some_event_called);

EXPECT_EQ(some_event_called, 1);
}

PDI_finalize();
PC_tree_destroy(&pdi_conf);
}

0 comments on commit c42cc74

Please sign in to comment.