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

Made cudftestutil header-only and removed GTest dependency #16839

Merged
merged 21 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4eb2ce0
moved cudf_test symbols to header units
lamarrr Sep 19, 2024
f83f7f3
removed cudftestutil's gtest dependency and made it header-only
lamarrr Sep 19, 2024
d23b392
optimized build of cudf's tests
lamarrr Sep 19, 2024
1e5ed0a
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Sep 28, 2024
57954a0
switched cudftestutil to source file injection via interface sources
lamarrr Oct 4, 2024
5f8d6f1
fixed install directory for cudftestutil_impl
lamarrr Oct 4, 2024
76fcb17
fixed CMake style formatting
lamarrr Oct 4, 2024
7ae9ed5
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Oct 4, 2024
1a6823f
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Oct 4, 2024
89a17d1
added installation and exporting of cudftestutil_impl target
lamarrr Oct 7, 2024
07127e6
Merge branch 'cudftestutil-header' of https://github.com/lamarrr/cudf…
lamarrr Oct 7, 2024
9f3d847
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Oct 7, 2024
34811c9
removed testing_api header
lamarrr Oct 7, 2024
b99b315
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Oct 7, 2024
6d9d8d4
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Oct 7, 2024
6d8edfe
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Oct 11, 2024
3c07115
updated cudftestutil_impl doc
lamarrr Oct 11, 2024
cd5e817
added tests config setup overrides
lamarrr Oct 11, 2024
e930caa
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Oct 11, 2024
29f5c23
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Oct 11, 2024
bb7809f
Merge branch 'branch-24.12' into cudftestutil-header
lamarrr Oct 14, 2024
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
27 changes: 7 additions & 20 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -861,15 +861,7 @@ if(CUDF_BUILD_TESTUTIL)

add_library(cudf::cudftest_default_stream ALIAS cudftest_default_stream)

add_library(
cudftestutil SHARED
tests/io/metadata_utilities.cpp
tests/utilities/column_utilities.cu
tests/utilities/debug_utilities.cu
tests/utilities/random_seed.cpp
tests/utilities/table_utilities.cu
tests/utilities/tdigest_utilities.cu
)
add_library(cudftestutil INTERFACE)

set_target_properties(
cudftestutil
Expand All @@ -878,28 +870,23 @@ if(CUDF_BUILD_TESTUTIL)
# set target compile options
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_VISIBILITY_PRESET hidden
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
CUDA_VISIBILITY_PRESET hidden
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)

target_compile_options(
cudftestutil PUBLIC "$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CXX>:${CUDF_CXX_FLAGS}>>"
"$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CUDA>:${CUDF_CUDA_FLAGS}>>"
cudftestutil INTERFACE "$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CXX>:${CUDF_CXX_FLAGS}>>"
"$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CUDA>:${CUDF_CUDA_FLAGS}>>"
)

target_link_libraries(
cudftestutil
PUBLIC Threads::Threads cudf cudftest_default_stream
PRIVATE GTest::gmock GTest::gtest $<TARGET_NAME_IF_EXISTS:conda_env>
cudftestutil INTERFACE Threads::Threads cudf cudftest_default_stream
$<TARGET_NAME_IF_EXISTS:conda_env>
)

target_include_directories(
cudftestutil PUBLIC "$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}/src>"
cudftestutil INTERFACE "$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CUDF_SOURCE_DIR}/src>"
)
rapids_cuda_set_runtime(cudftestutil USE_STATIC ${CUDA_STATIC_RUNTIME})
add_library(cudf::cudftestutil ALIAS cudftestutil)
Expand Down
12 changes: 5 additions & 7 deletions cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ target_include_directories(
# Use an OBJECT library so we only compile these helper source files only once
add_library(
cudf_benchmark_common OBJECT
"${CUDF_SOURCE_DIR}/tests/utilities/random_seed.cpp"
synchronization/synchronization.cpp
io/cuio_common.cpp
common/table_utilities.cpp
common/benchmark_utilities.cpp
common/nvbench_utilities.cpp
common/random_seed_impl.cpp synchronization/synchronization.cpp io/cuio_common.cpp
common/table_utilities.cpp common/benchmark_utilities.cpp common/nvbench_utilities.cpp
)
target_link_libraries(
cudf_benchmark_common PRIVATE cudftestutil cudf_datagen $<TARGET_NAME_IF_EXISTS:conda_env>
)
target_link_libraries(cudf_benchmark_common PRIVATE cudf_datagen $<TARGET_NAME_IF_EXISTS:conda_env>)
add_custom_command(
OUTPUT CUDF_BENCHMARKS
COMMAND echo Running benchmarks
Expand Down
17 changes: 17 additions & 0 deletions cpp/benchmarks/common/random_seed_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 <cudf_test/random_seed_impl.hpp>
3 changes: 1 addition & 2 deletions cpp/include/cudf_test/cudf_gtest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

#pragma once

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <cudf_test/testing_api.hpp>

/**
* @brief test macro to be expects `expr` to return cudaSuccess
Expand Down
29 changes: 29 additions & 0 deletions cpp/include/cudf_test/cudf_test_impl.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/

#pragma once

/**
* @file cudf_test_impl.cuh
* @brief Contains CUDA C++ symbol definitions for cudf_test APIs. This header must be included to
* one translation unit.
*
*/

#include <cudf_test/column_utilities_impl.cuh>
#include <cudf_test/debug_utilities_impl.cuh>
#include <cudf_test/table_utilities_impl.cuh>
#include <cudf_test/tdigest_utilities_impl.cuh>
27 changes: 27 additions & 0 deletions cpp/include/cudf_test/cudf_test_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.
*/

#pragma once

/**
* @file cudf_test_impl.cuh
* @brief Contains C++ symbol definitions for cudf_test APIs. Must be included to one translation
* unit.
*
*/

#include <cudf_test/metadata_utilities_impl.hpp>
#include <cudf_test/random_seed_impl.hpp>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, 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.
Expand All @@ -15,8 +15,7 @@
*/

#include <cudf_test/io_metadata_utilities.hpp>

#include <gmock/gmock.h>
#include <cudf_test/testing_api.hpp>

namespace cudf::test {

Expand Down
35 changes: 35 additions & 0 deletions cpp/include/cudf_test/testing_api.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.
*/

#pragma once

/**
* @file testing_api.hpp
* @brief exposes the testing APIs, GTEST can be disabled by defining CUDF_TEST_EXCLUDE_GTEST=1, and
* then including a testing API that conforms to GTEST's API before including any cudf_test headers.
* The testing API must define CUDF_TEST_TESTING_API_IMPL to signal cudf_test that it conforms to
* the GTest API.
*
*/

#if !(defined(CUDF_TEST_EXCLUDE_GTEST) && CUDF_TEST_EXCLUDE_GTEST)
#include <cudf_test/testing_api_gtest.hpp>
#endif

#if !defined(CUDF_TEST_TESTING_API_IMPL)
#error \
"No CUDF Testing API implementation found, Include a testing API that conforms to the GoogleTest API before including libcudftestutil headers"
#endif
22 changes: 22 additions & 0 deletions cpp/include/cudf_test/testing_api_gtest.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

#pragma once

#define CUDF_TEST_TESTING_API_IMPL

#include <gmock/gmock.h>
#include <gtest/gtest.h>
35 changes: 22 additions & 13 deletions cpp/include/cudf_test/testing_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/cxxopts.hpp>
#include <cudf_test/stream_checking_resource_adaptor.hpp>
#include <cudf_test/testing_api.hpp>

#include <cudf/utilities/error.hpp>
#include <cudf/utilities/export.hpp>
Expand Down Expand Up @@ -191,22 +192,30 @@ inline auto make_stream_mode_adaptor(cxxopts::ParseResult const& cmd_opts)
return adaptor;
}

/**
* @brief Should be called in every test program that uses rmm allocators since it maintains the
* lifespan of the rmm default memory resource. this function parses the command line to customize
* test behavior, like the allocation mode used for creating the default memory resource.
*
*/
inline void init_cudf_test(int argc, char** argv)
{
// static lifetime to keep rmm resource alive till tests end
auto const cmd_opts = parse_cudf_test_opts(argc, argv);
[[maybe_unused]] static auto mr = make_memory_resource_adaptor(cmd_opts);
[[maybe_unused]] static auto adaptor = make_stream_mode_adaptor(cmd_opts);
}

/**
* @brief Macro that defines main function for gtest programs that use rmm
*
* Should be included in every test program that uses rmm allocators since
* it maintains the lifespan of the rmm default memory resource.
* This `main` function is a wrapper around the google test generated `main`,
* maintaining the original functionality. In addition, this custom `main`
* function parses the command line to customize test behavior, like the
* allocation mode used for creating the default memory resource.
* maintaining the original functionality.
*/
#define CUDF_TEST_PROGRAM_MAIN() \
int main(int argc, char** argv) \
{ \
::testing::InitGoogleTest(&argc, argv); \
auto const cmd_opts = parse_cudf_test_opts(argc, argv); \
[[maybe_unused]] auto mr = make_memory_resource_adaptor(cmd_opts); \
[[maybe_unused]] auto adaptor = make_stream_mode_adaptor(cmd_opts); \
return RUN_ALL_TESTS(); \
#define CUDF_TEST_PROGRAM_MAIN() \
int main(int argc, char** argv) \
{ \
::testing::InitGoogleTest(&argc, argv); \
init_cudf_test(argc, argv); \
return RUN_ALL_TESTS(); \
lamarrr marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 6 additions & 2 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ enable_testing()
include(rapids-test)
rapids_test_init()

add_library(cudftests_common OBJECT common/cudf_test_impl.cpp common/cudf_test_impl.cu)
target_link_libraries(cudftests_common PUBLIC cudftestutil GTest::gtest GTest::gmock)
target_compile_definitions(cudftests_common PUBLIC CUDF_TEST_EXCLUDE_GTEST=0)

# This function takes in a test name and test source and handles setting all of the associated
# properties and linking to build the test
function(ConfigureTest CMAKE_TEST_NAME)
Expand Down Expand Up @@ -56,8 +60,8 @@ function(ConfigureTest CMAKE_TEST_NAME)

target_link_libraries(
${CMAKE_TEST_NAME}
PRIVATE cudftestutil GTest::gmock GTest::gmock_main GTest::gtest GTest::gtest_main
nvtx3::nvtx3-cpp $<TARGET_NAME_IF_EXISTS:conda_env> "${_CUDF_TEST_EXTRA_LIBS}"
PRIVATE cudftestutil cudftests_common GTest::gmock_main GTest::gtest_main nvtx3::nvtx3-cpp
$<TARGET_NAME_IF_EXISTS:conda_env> "${_CUDF_TEST_EXTRA_LIBS}"
)
rapids_cuda_set_runtime(${CMAKE_TEST_NAME} USE_STATIC ${CUDA_STATIC_RUNTIME})
rapids_test_add(
Expand Down
17 changes: 17 additions & 0 deletions cpp/tests/common/cudf_test_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 <cudf_test/cudf_test_impl.hpp>
lamarrr marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 17 additions & 0 deletions cpp/tests/common/cudf_test_impl.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 <cudf_test/cudf_test_impl.cuh>
lamarrr marked this conversation as resolved.
Show resolved Hide resolved
Loading