Skip to content

Commit 3e0aabe

Browse files
authored
Merge pull request rapidsai#477 from rapidsai/branch-24.10
Forward-merge branch-24.10 into branch-24.12
2 parents 0f52afc + 2053638 commit 3e0aabe

File tree

9 files changed

+322
-42
lines changed

9 files changed

+322
-42
lines changed

ci/run_ctests.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ set -euo pipefail
66
# Support customizing the ctests' install location
77
cd "${INSTALL_PREFIX:-${CONDA_PREFIX:-/usr}}/bin/tests/libkvikio/"
88

9-
# Run BASIC_IO_TEST
10-
./BASIC_IO_TEST
9+
# Run basic tests
10+
./BASIC_IO_EXAMPLE
11+
./BASIC_NO_CUDA_EXAMPLE
12+
13+
# Run gtests
14+
ctest --no-tests=error --output-on-failure "$@"

cpp/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ rapids_cmake_build_type(Release)
3737

3838
# build options
3939
option(KvikIO_BUILD_EXAMPLES "Configure CMake to build examples" ON)
40+
option(KvikIO_BUILD_TESTS "Configure CMake to build tests" ON)
4041

4142
rapids_cmake_support_conda_env(conda_env MODIFY_PREFIX_PATH)
4243

@@ -144,10 +145,14 @@ if(KvikIO_BUILD_EXAMPLES)
144145
add_subdirectory(examples)
145146
endif()
146147

147-
# optionally build tests
148148
if(KvikIO_BUILD_TESTS AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
149149
include(cmake/thirdparty/get_gtest.cmake)
150-
include(CTest) # calls enable_testing()
150+
151+
# include CTest module -- automatically calls enable_testing()
152+
include(CTest)
153+
154+
# Always print verbose output when tests fail if run using `make test`.
155+
list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
151156
add_subdirectory(tests)
152157
endif()
153158

cpp/cmake/thirdparty/get_gtest.cmake

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# =============================================================================
2-
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
2+
# Copyright (c) 2021-2024, NVIDIA CORPORATION.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
# in compliance with the License. You may obtain a copy of the License at
@@ -17,24 +17,7 @@ function(find_and_configure_gtest)
1717
include(${rapids-cmake-dir}/cpm/gtest.cmake)
1818

1919
# Find or install GoogleTest
20-
rapids_cpm_gtest(
21-
BUILD_EXPORT_SET kvikio-testing-exports INSTALL_EXPORT_SET kvikio-testing-exports
22-
)
23-
24-
if(GTest_ADDED)
25-
rapids_export(
26-
BUILD GTest
27-
VERSION ${GTest_VERSION}
28-
EXPORT_SET GTestTargets
29-
GLOBAL_TARGETS gtest gmock gtest_main gmock_main
30-
NAMESPACE GTest::
31-
)
32-
33-
include("${rapids-cmake-dir}/export/find_package_root.cmake")
34-
rapids_export_find_package_root(
35-
BUILD GTest [=[${CMAKE_CURRENT_LIST_DIR}]=] EXPORT_SET kvikio-testing-exports
36-
)
37-
endif()
20+
rapids_cpm_gtest(BUILD_STATIC)
3821

3922
endfunction()
4023

cpp/examples/CMakeLists.txt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@
1414

1515
set(TEST_INSTALL_PATH bin/tests/libkvikio)
1616

17+
# Example: basic_io
18+
1719
if(CUDAToolkit_FOUND)
18-
add_executable(BASIC_IO_TEST basic_io.cpp)
19-
set_target_properties(BASIC_IO_TEST PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib")
20-
target_include_directories(BASIC_IO_TEST PRIVATE ../include ${cuFile_INCLUDE_DIRS})
21-
target_link_libraries(BASIC_IO_TEST PRIVATE kvikio CUDA::cudart)
20+
add_executable(BASIC_IO_EXAMPLE basic_io.cpp)
21+
set_target_properties(BASIC_IO_EXAMPLE PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib")
22+
target_include_directories(BASIC_IO_EXAMPLE PRIVATE ../include ${cuFile_INCLUDE_DIRS})
23+
target_link_libraries(BASIC_IO_EXAMPLE PRIVATE kvikio CUDA::cudart)
2224

2325
if(CMAKE_COMPILER_IS_GNUCXX)
2426
set(KVIKIO_CXX_FLAGS "-Wall;-Werror;-Wno-unknown-pragmas")
25-
target_compile_options(BASIC_IO_TEST PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${KVIKIO_CXX_FLAGS}>")
27+
target_compile_options(
28+
BASIC_IO_EXAMPLE PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${KVIKIO_CXX_FLAGS}>"
29+
)
2630
endif()
2731

2832
install(
29-
TARGETS BASIC_IO_TEST
33+
TARGETS BASIC_IO_EXAMPLE
3034
COMPONENT testing
3135
DESTINATION ${TEST_INSTALL_PATH}
3236
EXCLUDE_FROM_ALL
@@ -35,20 +39,22 @@ else()
3539
message(STATUS "Cannot build the basic_io example when CUDA is not found")
3640
endif()
3741

38-
add_executable(BASIC_NO_CUDA_TEST basic_no_cuda.cpp)
39-
set_target_properties(BASIC_NO_CUDA_TEST PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib")
40-
target_include_directories(BASIC_NO_CUDA_TEST PRIVATE ../include)
41-
target_link_libraries(BASIC_NO_CUDA_TEST PRIVATE kvikio)
42+
# Example: basic_no_cuda
43+
44+
add_executable(BASIC_NO_CUDA_EXAMPLE basic_no_cuda.cpp)
45+
set_target_properties(BASIC_NO_CUDA_EXAMPLE PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib")
46+
target_include_directories(BASIC_NO_CUDA_EXAMPLE PRIVATE ../include)
47+
target_link_libraries(BASIC_NO_CUDA_EXAMPLE PRIVATE kvikio)
4248

4349
if(CMAKE_COMPILER_IS_GNUCXX)
4450
set(KVIKIO_CXX_FLAGS "-Wall;-Werror;-Wno-unknown-pragmas")
4551
target_compile_options(
46-
BASIC_NO_CUDA_TEST PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${KVIKIO_CXX_FLAGS}>"
52+
BASIC_NO_CUDA_EXAMPLE PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${KVIKIO_CXX_FLAGS}>"
4753
)
4854
endif()
4955

5056
install(
51-
TARGETS BASIC_NO_CUDA_TEST
57+
TARGETS BASIC_NO_CUDA_EXAMPLE
5258
COMPONENT testing
5359
DESTINATION ${TEST_INSTALL_PATH}
5460
EXCLUDE_FROM_ALL

cpp/tests/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# =============================================================================
2+
# Copyright (c) 2024, NVIDIA CORPORATION.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
# in compliance with the License. You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software distributed under the License
10+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
# or implied. See the License for the specific language governing permissions and limitations under
12+
# the License.
13+
# =============================================================================
14+
15+
# ##################################################################################################
16+
# enable testing -----------------------------------------------------------------------------------
17+
# ##################################################################################################
18+
enable_testing()
19+
20+
include(rapids-test)
21+
rapids_test_init()
22+
23+
file(GLOB SOURCES "*.cpp")
24+
add_executable(cpp_tests ${SOURCES})
25+
set_target_properties(
26+
cpp_tests
27+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$<BUILD_INTERFACE:${KvikIO_BINARY_DIR}/gtests>"
28+
CXX_STANDARD 17
29+
CXX_STANDARD_REQUIRED ON
30+
# For std:: support of __int128_t. Can be removed once using cuda::std
31+
CXX_EXTENSIONS ON
32+
CUDA_STANDARD 17
33+
CUDA_STANDARD_REQUIRED ON
34+
)
35+
target_link_libraries(cpp_tests PRIVATE kvikio::kvikio GTest::gmock GTest::gtest)
36+
rapids_test_add(
37+
NAME cpp_tests
38+
COMMAND cpp_tests
39+
GPUS 1
40+
INSTALL_COMPONENT_SET testing
41+
)
42+
43+
rapids_test_install_relocatable(INSTALL_COMPONENT_SET testing DESTINATION bin/tests/libkvikio)

cpp/tests/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2024, NVIDIA CORPORATION.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <gtest/gtest.h>
18+
19+
int main(int argc, char** argv)
20+
{
21+
::testing::InitGoogleTest(&argc, argv);
22+
return RUN_ALL_TESTS();
23+
}

cpp/tests/test_basic_io.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2024, NVIDIA CORPORATION.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <kvikio/file_handle.hpp>
18+
19+
#include "utils.hpp"
20+
21+
using namespace kvikio::test;
22+
23+
TEST(BasicIO, write_read)
24+
{
25+
TempDir tmp_dir{false};
26+
auto filepath = tmp_dir.path() / "test";
27+
28+
auto dev_a = DevBuffer::arange(100);
29+
auto dev_b = DevBuffer::zero_like(dev_a);
30+
31+
{
32+
kvikio::FileHandle f(filepath, "w");
33+
auto nbytes = f.write(dev_a.ptr, dev_a.nbytes, 0, 0);
34+
EXPECT_EQ(nbytes, dev_a.nbytes);
35+
}
36+
37+
{
38+
kvikio::FileHandle f(filepath, "r");
39+
auto nbytes = f.read(dev_b.ptr, dev_b.nbytes, 0, 0);
40+
EXPECT_EQ(nbytes, dev_b.nbytes);
41+
expect_equal(dev_a, dev_b);
42+
}
43+
}

0 commit comments

Comments
 (0)