Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Sep 16, 2024
1 parent 6f999e3 commit eebb208
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
16 changes: 14 additions & 2 deletions ci/run_ctests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@ set -euo pipefail
# Support customizing the ctests' install location
cd "${INSTALL_PREFIX:-${CONDA_PREFIX:-/usr}}/bin/tests/libkvikio/"

# Run BASIC_IO_TEST
./BASIC_IO_TEST
# Run basic tests
rapids-logger "Run BASIC_IO_EXAMPLE"
./BASIC_IO_EXAMPLE
rapids-logger "Run BASIC_NO_CUDA_EXAMPLE"
./BASIC_NO_CUDA_EXAMPLE

# Run gtests
rapids-logger "Run gtests"
./cpp_tests
# TODO: how to use ctest instead of executing the test directly?
# ctest --no-tests=error --output-on-failure "$@"

which ctest
ctest
1 change: 0 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ if(KvikIO_BUILD_TESTS AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(${rapids-cmake-dir}/cpm/gtest.cmake)
rapids_cpm_gtest(BUILD_STATIC)
include(CTest) # calls enable_testing()

add_subdirectory(tests)
endif()

Expand Down
30 changes: 18 additions & 12 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@

set(TEST_INSTALL_PATH bin/tests/libkvikio)

# Example: basic_io

if(CUDAToolkit_FOUND)
add_executable(BASIC_IO_TEST basic_io.cpp)
set_target_properties(BASIC_IO_TEST PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib")
target_include_directories(BASIC_IO_TEST PRIVATE ../include ${cuFile_INCLUDE_DIRS})
target_link_libraries(BASIC_IO_TEST PRIVATE kvikio CUDA::cudart)
add_executable(BASIC_IO_EXAMPLE basic_io.cpp)
set_target_properties(BASIC_IO_EXAMPLE PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib")
target_include_directories(BASIC_IO_EXAMPLE PRIVATE ../include ${cuFile_INCLUDE_DIRS})
target_link_libraries(BASIC_IO_EXAMPLE PRIVATE kvikio CUDA::cudart)

if(CMAKE_COMPILER_IS_GNUCXX)
set(KVIKIO_CXX_FLAGS "-Wall;-Werror;-Wno-unknown-pragmas")
target_compile_options(BASIC_IO_TEST PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${KVIKIO_CXX_FLAGS}>")
target_compile_options(
BASIC_IO_EXAMPLE PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${KVIKIO_CXX_FLAGS}>"
)
endif()

install(
TARGETS BASIC_IO_TEST
TARGETS BASIC_IO_EXAMPLE
COMPONENT testing
DESTINATION ${TEST_INSTALL_PATH}
EXCLUDE_FROM_ALL
Expand All @@ -35,20 +39,22 @@ else()
message(STATUS "Cannot build the basic_io example when CUDA is not found")
endif()

add_executable(BASIC_NO_CUDA_TEST basic_no_cuda.cpp)
set_target_properties(BASIC_NO_CUDA_TEST PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib")
target_include_directories(BASIC_NO_CUDA_TEST PRIVATE ../include)
target_link_libraries(BASIC_NO_CUDA_TEST PRIVATE kvikio)
# Example: basic_no_cuda

add_executable(BASIC_NO_CUDA_EXAMPLE basic_no_cuda.cpp)
set_target_properties(BASIC_NO_CUDA_EXAMPLE PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib")
target_include_directories(BASIC_NO_CUDA_EXAMPLE PRIVATE ../include)
target_link_libraries(BASIC_NO_CUDA_EXAMPLE PRIVATE kvikio)

if(CMAKE_COMPILER_IS_GNUCXX)
set(KVIKIO_CXX_FLAGS "-Wall;-Werror;-Wno-unknown-pragmas")
target_compile_options(
BASIC_NO_CUDA_TEST PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${KVIKIO_CXX_FLAGS}>"
BASIC_NO_CUDA_EXAMPLE PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${KVIKIO_CXX_FLAGS}>"
)
endif()

install(
TARGETS BASIC_NO_CUDA_TEST
TARGETS BASIC_NO_CUDA_EXAMPLE
COMPONENT testing
DESTINATION ${TEST_INSTALL_PATH}
EXCLUDE_FROM_ALL
Expand Down
3 changes: 2 additions & 1 deletion cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
enable_testing()

include(rapids-test)
# NB: calling `rapids_test_init()` to have CTest manage GPU resource doesn't work

file(GLOB SOURCES "*.cpp")
add_executable(cpp_tests ${SOURCES})
Expand All @@ -38,3 +37,5 @@ rapids_test_add(
COMMAND cpp_tests
INSTALL_COMPONENT_SET testing
)

rapids_test_install_relocatable(INSTALL_COMPONENT_SET testing DESTINATION bin/tests/libkvikio)
13 changes: 8 additions & 5 deletions cpp/tests/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ class TempDir {
std::filesystem::path _dir_path{};
};

/**
* @brief Help class for creating and comparing buffers.
*/
class DevBuffer {
public:
const std::size_t nelem;
const std::size_t nbytes;
void* ptr{nullptr};

DevBuffer(std::size_t nelem) : nelem{nelem}, nbytes{nelem * sizeof(std::int64_t)}
{
KVIKIO_CHECK_CUDA(cudaMalloc(&ptr, nbytes));
Expand Down Expand Up @@ -144,13 +151,9 @@ class DevBuffer {
}
std::cout << ")" << std::endl;
}

const std::size_t nelem;
const std::size_t nbytes;
void* ptr{nullptr};
};

void expect_equal(const DevBuffer& a, const DevBuffer& b)
inline void expect_equal(const DevBuffer& a, const DevBuffer& b)
{
EXPECT_EQ(a.nbytes, b.nbytes);
auto a_vec = a.to_vector();
Expand Down

0 comments on commit eebb208

Please sign in to comment.