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

[ENH] [3/5] Header structure: force explicit instantiation in tests and benchmarks #1439

Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d9801e8
MV: add -inl suffix to header paths
ahendriksen Apr 20, 2023
50b374d
MV: raft_runtime src files
ahendriksen Apr 13, 2023
8974ae3
FIX: add missing includes
ahendriksen Apr 20, 2023
95ef31b
FIX: getWorkspaceSize
ahendriksen Apr 20, 2023
7edcb6a
PREP: Separate rbf_fin_op
ahendriksen Apr 20, 2023
71de7bd
PREP: registers: Add _types header
ahendriksen Apr 20, 2023
541cabc
Change RAFT_COMPILED from INTERFACE to PUBLIC
ahendriksen Apr 20, 2023
d81b14e
Define RAFT_EXPLICIT and RAFT_EXPLICIT_INSTANTIATE_ONLY
ahendriksen Apr 20, 2023
48ea769
Update docs
ahendriksen Apr 20, 2023
e6bb5d5
Replace specializations by split headers
ahendriksen Apr 20, 2023
ff79abf
Deprecate specialization headers
ahendriksen Apr 20, 2023
c9e7413
Add interleaved scan instances
ahendriksen Apr 20, 2023
0c889dc
Separate fused_l2_nn_helpers
ahendriksen Apr 20, 2023
f97b2a8
Remove pairwise_matrix_instantiation_point
ahendriksen Apr 20, 2023
fb637f7
Rename specialization => instantiation
ahendriksen Apr 20, 2023
7b065af
test/neighbors/selection.cu: Expose kFaissMaxK
ahendriksen Apr 20, 2023
d5b5673
Remove includes of specialization headers
ahendriksen Apr 20, 2023
94d8117
test/distance/dist_adj.cu: Add instance
ahendriksen Apr 20, 2023
361570b
test/cluster/linkage.cu: Allow instance
ahendriksen Apr 20, 2023
5171de3
test/sparse/neighbors/connect_components.cu: Allow instance
ahendriksen Apr 20, 2023
4426c50
test/neighbors/ann_ivf_pq/test_float_uint32_t.cu: Allow instance
ahendriksen Apr 20, 2023
e527efc
test/matrix/select_k.cu: Change index type
ahendriksen Apr 20, 2023
17902e9
test/neighbors/fused_l2_knn.cu: Change index type
ahendriksen Apr 20, 2023
976189b
Force explicit instantiations in tests
ahendriksen Apr 20, 2023
bdae61d
Force explicit instantiations in benchmarks
ahendriksen Apr 20, 2023
b0b8fe5
Test that headers are free standing
ahendriksen Apr 20, 2023
4b9700e
Update cpp/test/matrix/select_k.cu
ahendriksen Apr 27, 2023
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
12 changes: 9 additions & 3 deletions cpp/bench/prims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

function(ConfigureBench)

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

Expand Down Expand Up @@ -55,6 +55,10 @@ function(ConfigureBench)
"$<$<COMPILE_LANGUAGE:CUDA>:${RAFT_CUDA_FLAGS}>"
)

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

target_include_directories(
${BENCH_NAME} PUBLIC "$<BUILD_INTERFACE:${RAFT_SOURCE_DIR}/bench/prims>"
)
Expand All @@ -71,7 +75,7 @@ endfunction()
if(BUILD_PRIMS_BENCH)
ConfigureBench(
NAME CLUSTER_BENCH PATH bench/prims/cluster/kmeans_balanced.cu bench/prims/cluster/kmeans.cu
bench/prims/main.cpp OPTIONAL LIB
bench/prims/main.cpp OPTIONAL LIB EXPLICIT_INSTANTIATE_ONLY
)

ConfigureBench(
Expand All @@ -93,6 +97,7 @@ if(BUILD_PRIMS_BENCH)
bench/prims/main.cpp
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)

ConfigureBench(
Expand All @@ -112,7 +117,7 @@ if(BUILD_PRIMS_BENCH)

ConfigureBench(
NAME MATRIX_BENCH PATH bench/prims/matrix/argmin.cu bench/prims/matrix/gather.cu
bench/prims/matrix/select_k.cu bench/prims/main.cpp OPTIONAL LIB
bench/prims/matrix/select_k.cu bench/prims/main.cpp OPTIONAL LIB EXPLICIT_INSTANTIATE_ONLY
)

ConfigureBench(
Expand All @@ -139,5 +144,6 @@ if(BUILD_PRIMS_BENCH)
bench/prims/main.cpp
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)
endif()
62 changes: 58 additions & 4 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

function(ConfigureTest)

set(options OPTIONAL LIB)
set(options OPTIONAL LIB EXPLICIT_INSTANTIATE_ONLY)
ahendriksen marked this conversation as resolved.
Show resolved Hide resolved
set(oneValueArgs NAME)
set(multiValueArgs PATH TARGETS CONFIGURATIONS)

Expand Down Expand Up @@ -59,6 +59,10 @@ function(ConfigureTest)
"$<$<COMPILE_LANGUAGE:CUDA>:${RAFT_CUDA_FLAGS}>"
)

if(ConfigureTest_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(
Expand Down Expand Up @@ -88,6 +92,7 @@ if(BUILD_TESTS)
test/cluster/kmeans_find_k.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
Expand All @@ -112,13 +117,17 @@ if(BUILD_TESTS)
test/core/span.cu
test/core/temporary_device_buffer.cu
test/test.cpp
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
NAME
DISTANCE_TEST
PATH
test/distance/dist_adj.cu
test/distance/dist_adj_distance_instance.cu
test/distance/dist_canberra.cu
test/distance/dist_correlation.cu
test/distance/dist_cos.cu
Expand All @@ -140,7 +149,41 @@ if(BUILD_TESTS)
test/distance/gram.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)

list(
APPEND
EXT_HEADER_TEST_SOURCES
test/ext_headers/raft_neighbors_brute_force.cu
test/ext_headers/raft_distance_distance.cu
test/ext_headers/raft_distance_detail_pairwise_matrix_dispatch.cu
test/ext_headers/raft_matrix_detail_select_k.cu
test/ext_headers/raft_neighbors_ball_cover.cu
test/ext_headers/raft_spatial_knn_detail_fused_l2_knn.cu
test/ext_headers/raft_distance_fused_l2_nn.cu
test/ext_headers/raft_neighbors_ivf_pq.cu
test/ext_headers/raft_neighbors_ivf_flat.cu
test/ext_headers/raft_neighbors_refine.cu
test/ext_headers/raft_neighbors_detail_ivf_flat_search.cu
test/ext_headers/raft_neighbors_detail_selection_faiss.cu
test/ext_headers/raft_linalg_detail_coalesced_reduction.cu
test/ext_headers/raft_spatial_knn_detail_ball_cover_registers.cu
)

# Test that the split headers compile in isolation with:
#
# * EXT_HEADERS_TEST_COMPILED_EXPLICIT: RAFT_COMPILED, RAFT_EXPLICIT_INSTANTIATE_ONLY defined
# * EXT_HEADERS_TEST_COMPILED_IMPLICIT: RAFT_COMPILED defined
# * EXT_HEADERS_TEST_IMPLICIT: no macros defined.
tfeher marked this conversation as resolved.
Show resolved Hide resolved
ConfigureTest(
NAME EXT_HEADERS_TEST_COMPILED_EXPLICIT PATH ${EXT_HEADER_TEST_SOURCES} OPTIONAL LIB
EXPLICIT_INSTANTIATE_ONLY
)
ConfigureTest(
NAME EXT_HEADERS_TEST_COMPILED_IMPLICIT PATH ${EXT_HEADER_TEST_SOURCES} OPTIONAL LIB
)
ConfigureTest(NAME EXT_HEADERS_TEST_IMPLICIT PATH ${EXT_HEADER_TEST_SOURCES})

ConfigureTest(NAME LABEL_TEST PATH test/label/label.cu test/label/merge_labels.cu)

Expand Down Expand Up @@ -201,6 +244,7 @@ if(BUILD_TESTS)
test/sparse/spectral_matrix.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
Expand All @@ -220,7 +264,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
test/lap/lap.cu test/sparse/mst.cu OPTIONAL LIB EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
Expand All @@ -245,11 +289,19 @@ if(BUILD_TESTS)

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

ConfigureTest(
NAME SPARSE_NEIGHBORS_TEST PATH test/sparse/neighbors/connect_components.cu
test/sparse/neighbors/brute_force.cu test/sparse/neighbors/knn_graph.cu OPTIONAL LIB
NAME
SPARSE_NEIGHBORS_TEST
PATH
test/sparse/neighbors/connect_components.cu
test/sparse/neighbors/brute_force.cu
test/sparse/neighbors/knn_graph.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
Expand All @@ -275,6 +327,7 @@ if(BUILD_TESTS)
test/neighbors/selection.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
Expand Down Expand Up @@ -308,6 +361,7 @@ if(BUILD_TESTS)
test/stats/v_measure.cu
OPTIONAL
LIB
EXPLICIT_INSTANTIATE_ONLY
)

ConfigureTest(
Expand Down
9 changes: 9 additions & 0 deletions cpp/test/cluster/linkage.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
* limitations under the License.
*/

// XXX: We allow the instantiation of fused_l2_nn here:
ahendriksen marked this conversation as resolved.
Show resolved Hide resolved
// raft::linkage::FixConnectivitiesRedOp<value_idx, value_t> red_op(colors.data(), params.n_row);
// raft::linkage::connect_components<value_idx, value_t>(
// handle, out_edges, data.data(), colors.data(), params.n_row, params.n_col, red_op);
//
// TODO: consider adding this to libraft.so or creating an instance in a
// separate translation unit for this test.
#undef RAFT_EXPLICIT_INSTANTIATE_ONLY
tfeher marked this conversation as resolved.
Show resolved Hide resolved

#include "../test_utils.cuh"

#include <raft/distance/distance_types.hpp>
Expand Down
16 changes: 3 additions & 13 deletions cpp/test/distance/dist_adj.cu
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <raft/util/cudart_utils.hpp>
#include <rmm/device_uvector.hpp>

#include "dist_adj.cuh"

namespace raft {
namespace distance {

Expand Down Expand Up @@ -74,18 +76,6 @@ struct DistanceAdjInputs {
unsigned long long int seed;
};

template <typename AccT, typename DataT, typename OutT, typename Index>
struct threshold_final_op {
DataT threshold_val;

__device__ __host__ threshold_final_op() noexcept : threshold_val(0.0) {}
__device__ __host__ threshold_final_op(DataT val) noexcept : threshold_val(val) {}
__device__ __host__ OutT operator()(AccT d_val, Index g_idx) const noexcept
{
return d_val <= threshold_val;
}
};

template <typename DataType>
::std::ostream& operator<<(::std::ostream& os, const DistanceAdjInputs<DataType>& dims)
{
Expand Down Expand Up @@ -140,7 +130,7 @@ class DistanceAdjTest : public ::testing::TestWithParam<DistanceAdjInputs<DataTy
n,
k,
workspace.data(),
workspace.size(),
worksize,
threshold_op,
isRowMajor);
handle.sync_stream(stream);
Expand Down
71 changes: 71 additions & 0 deletions cpp/test/distance/dist_adj.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2023, 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 "dist_adj_threshold.cuh"
#include <raft/distance/distance.cuh>

#define instantiate_raft_distance_distance(DT, DataT, AccT, OutT, FinalLambda, IdxT) \
extern template void raft::distance::distance<DT, DataT, AccT, OutT, FinalLambda, IdxT>( \
raft::resources const& handle, \
const DataT* x, \
const DataT* y, \
OutT* dist, \
IdxT m, \
IdxT n, \
IdxT k, \
void* workspace, \
size_t worksize, \
FinalLambda fin_op, \
bool isRowMajor, \
DataT metric_arg)

instantiate_raft_distance_distance(raft::distance::DistanceType::L2Expanded,
float,
float,
uint8_t,
raft::distance::threshold_float,
int);

instantiate_raft_distance_distance(raft::distance::DistanceType::L2Expanded,
double,
double,
uint8_t,
raft::distance::threshold_double,
int);

#undef instantiate_raft_distance_distance

#define instantiate_raft_distance_getWorkspaceSize(DistT, DataT, AccT, OutT, IdxT) \
extern template size_t raft::distance::getWorkspaceSize<DistT, DataT, AccT, OutT, IdxT>( \
const DataT* x, const DataT* y, IdxT m, IdxT n, IdxT k)

instantiate_raft_distance_getWorkspaceSize(
raft::distance::DistanceType::L2Expanded, float, float, uint8_t, int);
instantiate_raft_distance_getWorkspaceSize(
raft::distance::DistanceType::L2Expanded, double, double, uint8_t, int);

#undef instantiate_raft_distance_getWorkspaceSize

#define instantiate_raft_distance_getWorkspaceSize(DistT, DataT, AccT, OutT, IdxT) \
extern template size_t raft::distance::getWorkspaceSize<DistT, DataT, AccT, OutT, IdxT>( \
const DataT* x, const DataT* y, IdxT m, IdxT n, IdxT k)

instantiate_raft_distance_getWorkspaceSize(
raft::distance::DistanceType::L2Expanded, float, float, uint8_t, int);
instantiate_raft_distance_getWorkspaceSize(
raft::distance::DistanceType::L2Expanded, double, double, uint8_t, int);

#undef instantiate_raft_distance_getWorkspaceSize
63 changes: 63 additions & 0 deletions cpp/test/distance/dist_adj_distance_instance.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2023, 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.
*/

#undef RAFT_EXPLICIT_INSTANTIATE_ONLY

#include "dist_adj_threshold.cuh"
#include <cstdint>
#include <raft/distance/distance-inl.cuh>

#define instantiate_raft_distance_distance(DT, DataT, AccT, OutT, FinalLambda, IdxT) \
template void raft::distance::distance<DT, DataT, AccT, OutT, FinalLambda, IdxT>( \
raft::resources const& handle, \
const DataT* x, \
const DataT* y, \
OutT* dist, \
IdxT m, \
IdxT n, \
IdxT k, \
void* workspace, \
size_t worksize, \
FinalLambda fin_op, \
bool isRowMajor, \
DataT metric_arg)

instantiate_raft_distance_distance(raft::distance::DistanceType::L2Expanded,
float,
float,
uint8_t,
raft::distance::threshold_float,
int);

instantiate_raft_distance_distance(raft::distance::DistanceType::L2Expanded,
double,
double,
uint8_t,
raft::distance::threshold_double,
int);

#undef instantiate_raft_distance_distance

#define instantiate_raft_distance_getWorkspaceSize(DistT, DataT, AccT, OutT, IdxT) \
template size_t raft::distance::getWorkspaceSize<DistT, DataT, AccT, OutT, IdxT>( \
const DataT* x, const DataT* y, IdxT m, IdxT n, IdxT k)

instantiate_raft_distance_getWorkspaceSize(
raft::distance::DistanceType::L2Expanded, float, float, uint8_t, int);
instantiate_raft_distance_getWorkspaceSize(
raft::distance::DistanceType::L2Expanded, double, double, uint8_t, int);

#undef instantiate_raft_distance_getWorkspaceSize
Loading