Skip to content

Commit

Permalink
Merge branch 'branch-24.12' into nvcomp-wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed Oct 1, 2024
2 parents caed5d6 + 9643fab commit 21adace
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 45 deletions.
8 changes: 6 additions & 2 deletions ci/run_ctests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ 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
./BASIC_IO_EXAMPLE
./BASIC_NO_CUDA_EXAMPLE

# Run gtests
ctest --no-tests=error --output-on-failure "$@"
9 changes: 7 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ rapids_cmake_build_type(Release)

# build options
option(KvikIO_BUILD_EXAMPLES "Configure CMake to build examples" ON)
option(KvikIO_BUILD_TESTS "Configure CMake to build tests" ON)

rapids_cmake_support_conda_env(conda_env MODIFY_PREFIX_PATH)

Expand Down Expand Up @@ -144,10 +145,14 @@ if(KvikIO_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

# optionally build tests
if(KvikIO_BUILD_TESTS AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(cmake/thirdparty/get_gtest.cmake)
include(CTest) # calls enable_testing()

# include CTest module -- automatically calls enable_testing()
include(CTest)

# Always print verbose output when tests fail if run using `make test`.
list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
add_subdirectory(tests)
endif()

Expand Down
21 changes: 2 additions & 19 deletions cpp/cmake/thirdparty/get_gtest.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# =============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# Copyright (c) 2021-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
Expand All @@ -17,24 +17,7 @@ function(find_and_configure_gtest)
include(${rapids-cmake-dir}/cpm/gtest.cmake)

# Find or install GoogleTest
rapids_cpm_gtest(
BUILD_EXPORT_SET kvikio-testing-exports INSTALL_EXPORT_SET kvikio-testing-exports
)

if(GTest_ADDED)
rapids_export(
BUILD GTest
VERSION ${GTest_VERSION}
EXPORT_SET GTestTargets
GLOBAL_TARGETS gtest gmock gtest_main gmock_main
NAMESPACE GTest::
)

include("${rapids-cmake-dir}/export/find_package_root.cmake")
rapids_export_find_package_root(
BUILD GTest [=[${CMAKE_CURRENT_LIST_DIR}]=] EXPORT_SET kvikio-testing-exports
)
endif()
rapids_cpm_gtest(BUILD_STATIC)

endfunction()

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
27 changes: 26 additions & 1 deletion cpp/include/kvikio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <iostream>
#include <map>
#include <optional>
#include <stdexcept>
#include <tuple>
#include <type_traits>

#include <nvtx3/nvtx3.hpp>

Expand Down Expand Up @@ -69,6 +71,29 @@ inline constexpr std::size_t page_size = 4096;
return reinterpret_cast<CUdeviceptr>(devPtr);
}

/**
* @brief Help function to convert value to 64 bit signed integer
*/
template <typename T, std::enable_if_t<std::is_integral_v<T>>* = nullptr>
[[nodiscard]] std::int64_t convert_to_64bit(T value)
{
if constexpr (std::numeric_limits<T>::max() > std::numeric_limits<std::int64_t>::max()) {
if (value > std::numeric_limits<std::int64_t>::max()) {
throw std::overflow_error("convert_to_64bit(x): x too large to fit std::int64_t");
}
}
return std::int64_t(value);
}

/**
* @brief Help function to convert value to 64 bit float
*/
template <typename T, std::enable_if_t<std::is_floating_point_v<T>>* = nullptr>
[[nodiscard]] double convert_to_64bit(T value)
{
return double(value);
}

/**
* @brief Check if `ptr` points to host memory (as opposed to device memory)
*
Expand Down Expand Up @@ -280,7 +305,7 @@ struct libkvikio_domain {
{ \
nvtx3::event_attributes \
{ \
msg, nvtx3::payload { val } \
msg, nvtx3::payload { convert_to_64bit(val) } \
} \
}
#define GET_KVIKIO_NVTX_FUNC_RANGE_MACRO(_1, _2, NAME, ...) NAME
Expand Down
43 changes: 43 additions & 0 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# =============================================================================
# Copyright (c) 2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================

# ##################################################################################################
# enable testing -----------------------------------------------------------------------------------
# ##################################################################################################
enable_testing()

include(rapids-test)
rapids_test_init()

file(GLOB SOURCES "*.cpp")
add_executable(cpp_tests ${SOURCES})
set_target_properties(
cpp_tests
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$<BUILD_INTERFACE:${KvikIO_BINARY_DIR}/gtests>"
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
# For std:: support of __int128_t. Can be removed once using cuda::std
CXX_EXTENSIONS ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
)
target_link_libraries(cpp_tests PRIVATE kvikio::kvikio GTest::gmock GTest::gtest)
rapids_test_add(
NAME cpp_tests
COMMAND cpp_tests
GPUS 1
INSTALL_COMPONENT_SET testing
)

rapids_test_install_relocatable(INSTALL_COMPONENT_SET testing DESTINATION bin/tests/libkvikio)
23 changes: 23 additions & 0 deletions cpp/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <gtest/gtest.h>

int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
43 changes: 43 additions & 0 deletions cpp/tests/test_basic_io.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <kvikio/file_handle.hpp>

#include "utils.hpp"

using namespace kvikio::test;

TEST(BasicIO, write_read)
{
TempDir tmp_dir{false};
auto filepath = tmp_dir.path() / "test";

auto dev_a = DevBuffer::arange(100);
auto dev_b = DevBuffer::zero_like(dev_a);

{
kvikio::FileHandle f(filepath, "w");
auto nbytes = f.write(dev_a.ptr, dev_a.nbytes, 0, 0);
EXPECT_EQ(nbytes, dev_a.nbytes);
}

{
kvikio::FileHandle f(filepath, "r");
auto nbytes = f.read(dev_b.ptr, dev_b.nbytes, 0, 0);
EXPECT_EQ(nbytes, dev_b.nbytes);
expect_equal(dev_a, dev_b);
}
}
Loading

0 comments on commit 21adace

Please sign in to comment.