Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for the PDI wrapper #743

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
127 changes: 127 additions & 0 deletions tests/pdi/pdi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// 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);

// 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<int*>(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<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 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);
}
Loading