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

Use rapids-cmake new parallel testing feature #1623

Merged
merged 10 commits into from
Jul 21, 2023
7 changes: 1 addition & 6 deletions ci/test_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ trap "EXITCODE=1" ERR
set +e

# Run libraft gtests from libraft-tests package
rapids-logger "Run gtests"
for gt in "$CONDA_PREFIX"/bin/gtests/libraft/* ; do
test_name=$(basename ${gt})
echo "Running gtest $test_name"
${gt} --gtest_output=xml:${RAPIDS_TESTS_DIR}
done
ctest -j8 --output-on-failure

rapids-logger "Test script exiting with value: $EXITCODE"
exit ${EXITCODE}
132 changes: 92 additions & 40 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,71 @@
# =============================================================================

# ##################################################################################################
# * compiler function -----------------------------------------------------------------------------
# enable testing ################################################################################
# ##################################################################################################
enable_testing()
include(rapids-test)
rapids_test_init()

function(ConfigureTest)

set(options OPTIONAL LIB EXPLICIT_INSTANTIATE_ONLY)
set(oneValueArgs NAME)
set(oneValueArgs NAME GPUS PERCENT)
set(multiValueArgs PATH TARGETS CONFIGURATIONS)

cmake_parse_arguments(ConfigureTest "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(TEST_NAME ${ConfigureTest_NAME})

add_executable(${TEST_NAME} ${ConfigureTest_PATH})
cmake_parse_arguments(_RAFT_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT DEFINED _RAFT_TEST_GPUS AND NOT DEFINED _RAFT_TEST_PERCENT)
set(_RAFT_TEST_GPUS 1)
set(_RAFT_TEST_PERCENT 30)
endif()
if(NOT DEFINED _RAFT_TEST_GPUS)
set(_RAFT_TEST_GPUS 1)
endif()
if(NOT DEFINED _RAFT_TEST_PERCENT)
set(_RAFT_TEST_PERCENT 100)
endif()

message("TEST PATH: ${ConfigureTest_PATH}")
set(TEST_NAME ${_RAFT_TEST_NAME})

add_executable(${TEST_NAME} ${_RAFT_TEST_PATH})
target_link_libraries(
${TEST_NAME}
PRIVATE raft
raft_internal
$<$<BOOL:${ConfigureTest_LIB}>:raft::compiled>
$<$<BOOL:${_RAFT_TEST_LIB}>:raft::compiled>
GTest::gtest
GTest::gtest_main
Threads::Threads
${RAFT_CTK_MATH_DEPENDENCIES}
$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_CXX>
$<TARGET_NAME_IF_EXISTS:conda_env>
)

add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})

set_target_properties(
${TEST_NAME}
PROPERTIES # set target compile options
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "$<BUILD_INTERFACE:${RAFT_BINARY_DIR}/gtests>"
INSTALL_RPATH "\$ORIGIN/../../../lib"
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
)

target_compile_options(
${TEST_NAME} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${RAFT_CXX_FLAGS}>"
"$<$<COMPILE_LANGUAGE:CUDA>:${RAFT_CUDA_FLAGS}>"
)

if(ConfigureTest_EXPLICIT_INSTANTIATE_ONLY)
if(_RAFT_TEST_EXPLICIT_INSTANTIATE_ONLY)
target_compile_definitions(${TEST_NAME} PRIVATE "RAFT_EXPLICIT_INSTANTIATE_ONLY")
endif()

target_include_directories(${TEST_NAME} PUBLIC "$<BUILD_INTERFACE:${RAFT_SOURCE_DIR}/test>")

install(
TARGETS ${TEST_NAME}
COMPONENT testing
DESTINATION bin/gtests/libraft
EXCLUDE_FROM_ALL
rapids_test_add(
NAME ${TEST_NAME}
COMMAND ${TEST_NAME}
GPUS ${_RAFT_TEST_GPUS}
PERCENT ${_RAFT_TEST_PERCENT}
INSTALL_COMPONENT_SET testing
)
endfunction()

Expand All @@ -90,7 +98,6 @@ if(BUILD_TESTS)
test/cluster/cluster_solvers.cu
test/cluster/linkage.cu
test/cluster/kmeans_find_k.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)
Expand All @@ -117,7 +124,6 @@ if(BUILD_TESTS)
test/core/span.cu
test/core/temporary_device_buffer.cu
test/test.cpp
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)
Expand Down Expand Up @@ -147,7 +153,6 @@ if(BUILD_TESTS)
test/distance/masked_nn_compress_to_bits.cu
test/distance/fused_l2_nn.cu
test/distance/gram.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)
Expand Down Expand Up @@ -181,11 +186,11 @@ if(BUILD_TESTS)
# * EXT_HEADERS_TEST_COMPILED_IMPLICIT: RAFT_COMPILED defined
# * EXT_HEADERS_TEST_IMPLICIT: no macros defined.
ConfigureTest(
NAME EXT_HEADERS_TEST_COMPILED_EXPLICIT PATH ${EXT_HEADER_TEST_SOURCES} OPTIONAL LIB
NAME EXT_HEADERS_TEST_COMPILED_EXPLICIT PATH ${EXT_HEADER_TEST_SOURCES} LIB
EXPLICIT_INSTANTIATE_ONLY
)
ConfigureTest(
NAME EXT_HEADERS_TEST_COMPILED_IMPLICIT PATH ${EXT_HEADER_TEST_SOURCES} OPTIONAL LIB
NAME EXT_HEADERS_TEST_COMPILED_IMPLICIT PATH ${EXT_HEADER_TEST_SOURCES} LIB
)
ConfigureTest(NAME EXT_HEADERS_TEST_IMPLICIT PATH ${EXT_HEADER_TEST_SOURCES})

Expand Down Expand Up @@ -244,15 +249,33 @@ if(BUILD_TESTS)
test/matrix/matrix.cu
test/matrix/norm.cu
test/matrix/reverse.cu
test/matrix/select_k.cu
test/matrix/slice.cu
test/matrix/triangular.cu
test/sparse/spectral_matrix.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)


ConfigureTest(
NAME
MATRIX_SELECT_TEST
PATH
test/matrix/select_k.cu
LIB
EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
NAME
MATRIX_SELECT_LARGE_TEST
PATH
test/matrix/select_large_k.cu
LIB
EXPLICIT_INSTANTIATE_ONLY
)


ConfigureTest(
NAME
RANDOM_TEST
Expand All @@ -270,7 +293,7 @@ if(BUILD_TESTS)

ConfigureTest(
NAME SOLVERS_TEST PATH test/cluster/cluster_solvers_deprecated.cu test/linalg/eigen_solvers.cu
test/lap/lap.cu test/sparse/mst.cu OPTIONAL LIB EXPLICIT_INSTANTIATE_ONLY
test/lap/lap.cu test/sparse/mst.cu LIB EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
Expand All @@ -296,7 +319,7 @@ if(BUILD_TESTS)

ConfigureTest(
NAME SPARSE_DIST_TEST PATH test/sparse/dist_coo_spmv.cu test/sparse/distance.cu
test/sparse/gram.cu OPTIONAL LIB EXPLICIT_INSTANTIATE_ONLY
test/sparse/gram.cu LIB EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
Expand All @@ -306,7 +329,6 @@ if(BUILD_TESTS)
test/sparse/neighbors/connect_components.cu
test/sparse/neighbors/brute_force.cu
test/sparse/neighbors/knn_graph.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)
Expand All @@ -315,6 +337,21 @@ if(BUILD_TESTS)
NAME
NEIGHBORS_TEST
PATH
test/neighbors/knn.cu
test/neighbors/fused_l2_knn.cu
test/neighbors/tiled_knn.cu
test/neighbors/haversine.cu
test/neighbors/ball_cover.cu
test/neighbors/epsilon_neighborhood.cu
test/neighbors/refine.cu
LIB
EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
NAME
NEIGHBORS_ANN_CAGRA_TEST
PATH
test/neighbors/ann_cagra/test_float_uint32_t.cu
test/neighbors/ann_cagra/test_int8_t_uint32_t.cu
test/neighbors/ann_cagra/test_uint8_t_uint32_t.cu
Expand All @@ -327,6 +364,15 @@ if(BUILD_TESTS)
src/neighbors/detail/cagra/search_single_cta_float_uint64_dim256_t16.cu
src/neighbors/detail/cagra/search_single_cta_float_uint64_dim512_t32.cu
src/neighbors/detail/cagra/search_single_cta_float_uint64_dim1024_t32.cu
LIB
EXPLICIT_INSTANTIATE_ONLY
GPUS 1 PERCENT 100
)

ConfigureTest(
NAME
NEIGHBORS_ANN_IVF_TEST
PATH
test/neighbors/ann_ivf_flat/test_float_int64_t.cu
test/neighbors/ann_ivf_flat/test_int8_t_int64_t.cu
test/neighbors/ann_ivf_flat/test_uint8_t_int64_t.cu
Expand All @@ -335,17 +381,19 @@ if(BUILD_TESTS)
test/neighbors/ann_ivf_pq/test_float_int64_t.cu
test/neighbors/ann_ivf_pq/test_int8_t_int64_t.cu
test/neighbors/ann_ivf_pq/test_uint8_t_int64_t.cu
test/neighbors/knn.cu
test/neighbors/fused_l2_knn.cu
test/neighbors/tiled_knn.cu
test/neighbors/haversine.cu
test/neighbors/ball_cover.cu
test/neighbors/epsilon_neighborhood.cu
test/neighbors/refine.cu
LIB
EXPLICIT_INSTANTIATE_ONLY
GPUS 1 PERCENT 100
)

ConfigureTest(
NAME
NEIGHBORS_SELECTION_TEST
PATH
test/neighbors/selection.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
GPUS 1 PERCENT 50
)

ConfigureTest(
Expand Down Expand Up @@ -377,7 +425,6 @@ if(BUILD_TESTS)
test/stats/trustworthiness.cu
test/stats/weighted_mean.cu
test/stats/v_measure.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)
Expand All @@ -395,3 +442,8 @@ if(BUILD_TESTS)
test/util/reduction.cu
)
endif()

# ##################################################################################################
# Install tests ####################################################################################
# ##################################################################################################
rapids_test_install_relocatable(INSTALL_COMPONENT_SET testing DESTINATION bin/gtests/libraft)
18 changes: 12 additions & 6 deletions cpp/test/distance/gram.cu
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ template <typename math_t>
class GramMatrixTest : public ::testing::TestWithParam<GramMatrixInputs> {
protected:
GramMatrixTest()
: params(GetParam()), stream(0), x1(0, stream), x2(0, stream), gram(0, stream), gram_host(0)
: params(GetParam()),
handle(),
x1(0, resource::get_cuda_stream(handle)),
x2(0, resource::get_cuda_stream(handle)),
gram(0, resource::get_cuda_stream(handle)),
gram_host(0)
{
RAFT_CUDA_TRY(cudaStreamCreate(&stream));
auto stream = resource::get_cuda_stream(handle);

if (params.ld1 == 0) { params.ld1 = params.is_row_major ? params.n_cols : params.n1; }
if (params.ld2 == 0) { params.ld2 = params.is_row_major ? params.n_cols : params.n2; }
Expand All @@ -99,7 +104,7 @@ class GramMatrixTest : public ::testing::TestWithParam<GramMatrixInputs> {
r.uniform(x2.data(), x2.size(), math_t(0), math_t(1), stream);
}

~GramMatrixTest() override { RAFT_CUDA_TRY_NO_THROW(cudaStreamDestroy(stream)); }
~GramMatrixTest() override {}

void runTest()
{
Expand Down Expand Up @@ -127,6 +132,7 @@ class GramMatrixTest : public ::testing::TestWithParam<GramMatrixInputs> {

(*kernel)(handle, x1_span, x2_span, out_span);

auto stream = resource::get_cuda_stream(handle);
naiveGramMatrixKernel(params.n1,
params.n2,
params.n_cols,
Expand All @@ -142,16 +148,16 @@ class GramMatrixTest : public ::testing::TestWithParam<GramMatrixInputs> {
handle);

ASSERT_TRUE(raft::devArrMatchHost(
gram_host.data(), gram.data(), gram.size(), raft::CompareApprox<math_t>(1e-6f)));
gram_host.data(), gram.data(), gram.size(), raft::CompareApprox<math_t>(1e-6f), stream));
}

raft::resources handle;
cudaStream_t stream = 0;
GramMatrixInputs params;
raft::resources handle;

rmm::device_uvector<math_t> x1;
rmm::device_uvector<math_t> x2;
rmm::device_uvector<math_t> gram;

std::vector<math_t> gram_host;
};

Expand Down
Loading