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 RAFT template instantations for distances #4302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
977d337
Testing raft branch
cjnolet Oct 12, 2021
b2134d6
Updates
cjnolet Oct 12, 2021
0c7ae87
Updates
cjnolet Oct 12, 2021
6d9cde3
Removing individual pairwise dists
cjnolet Oct 12, 2021
60f87dd
Fixing style
cjnolet Oct 12, 2021
4a634b2
Updates
cjnolet Oct 13, 2021
b86d069
More fixes
cjnolet Oct 13, 2021
fac03f3
Revert "Removing individual pairwise dists"
cjnolet Oct 14, 2021
23654f9
Adding separate pw dist calls back in
cjnolet Oct 14, 2021
5265d7d
Ugh
cjnolet Oct 14, 2021
670e090
Updates
cjnolet Oct 14, 2021
1306a48
Fixing l2 knn bench
cjnolet Oct 15, 2021
d590b95
Using new raft branch pinning
cjnolet Oct 15, 2021
5b54dff
Trying to import raft
cjnolet Oct 21, 2021
160756f
Updates
cjnolet Oct 22, 2021
a19c912
Updating pinned raft location
cjnolet Oct 22, 2021
342f193
Removing whitespace
cjnolet Oct 22, 2021
beada4e
Updating style
cjnolet Oct 22, 2021
524aaeb
Merge branch 'test_distance_prims_public_API' into imp-2112-raft_dist…
cjnolet Oct 22, 2021
960343d
Adding libraft-nn
cjnolet Oct 22, 2021
92fe3ca
Merge branch 'branch-21.12' into imp-2112-raft_distance_package
cjnolet Oct 27, 2021
14c5b82
Merge branch 'branch-21.12' into imp-2112-raft_distance_package
cjnolet Nov 1, 2021
a127bfd
Updates
cjnolet Nov 5, 2021
0fc00a1
Merge branch 'branch-22.02' into imp-2112-raft_distance_package
cjnolet Nov 17, 2021
5967d43
Fixing style
cjnolet Nov 17, 2021
93daf6f
Fixing style
cjnolet Nov 17, 2021
e8e1ae5
Merge branch 'branch-22.02' into imp-2112-raft_distance_package
cjnolet Dec 6, 2021
fa16846
Merge branch 'branch-22.02' into imp-2112-raft_distance_package
cjnolet Dec 6, 2021
d6d6c91
Using proper branch
cjnolet Dec 7, 2021
2677860
Merge branch 'branch-22.02' into imp-2112-raft_distance_package
cjnolet Dec 7, 2021
e20c339
Updating includes for new naming scheme
cjnolet Dec 8, 2021
6871435
Updating remaining header specializations
cjnolet Dec 8, 2021
1007c79
Adding raft nn and distance to install targets
cjnolet Dec 13, 2021
5227dd5
Trying to properly depend on libraft package
cjnolet Dec 13, 2021
915570b
iTrying again
cjnolet Dec 13, 2021
53e8ee0
Still trying to figure out how to make the install targets work
cjnolet Dec 13, 2021
7fcd14f
Rolling back libraft install targets
cjnolet Dec 13, 2021
5dbba82
DBG Copy libraft artifacts to build folder for libcuml tests
dantegd Dec 14, 2021
643fa4c
Merge branch 'branch-22.02' into imp-2112-raft_distance_package
cjnolet Dec 14, 2021
cb5069f
Using distance instead of distances
cjnolet Dec 14, 2021
703f765
Updating namespace in bench
cjnolet Dec 15, 2021
38b757b
Updating get_raft
cjnolet Dec 15, 2021
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
5 changes: 5 additions & 0 deletions ci/gpu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ else
cd $LIBCUML_BUILD_DIR
chrpath -d ./test/ml
patchelf --replace-needed `patchelf --print-needed ./test/ml | grep faiss` libfaiss.so ./test/ml
cp _deps/raft-build/libraft_nn.so $PWD
patchelf --replace-needed `patchelf --print-needed libraft_nn.so | grep faiss` libfaiss.so libraft_nn.so
cp _deps/raft-build/libraft_distance.so $PWD

gpuci_logger "Running libcuml binaries"
GTEST_OUTPUT="xml:${WORKSPACE}/test-results/libcuml_cpp/" ./test/ml

CONDA_FILE=`find ${CONDA_ARTIFACT_PATH} -name "libcuml*.tar.bz2"`
Expand Down
2 changes: 2 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ if(BUILD_CUML_CPP_LIBRARY)
rmm::rmm
cuml::Thrust
raft::raft
raft::raft_nn
raft::raft_distance
PRIVATE
CUDA::cublas
CUDA::cufft
Expand Down
4 changes: 4 additions & 0 deletions cpp/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ if(BUILD_CUML_BENCH)
cuml::${CUML_CPP_TARGET}
benchmark::benchmark
raft::raft
raft::raft_nn
raft::raft_distance
$<IF:$<BOOL:${Treelite_ADDED}>,treelite::treelite_static,treelite::treelite>
$<IF:$<BOOL:${Treelite_ADDED}>,treelite::treelite_runtime_static,treelite::treelite_runtime>
)
Expand Down Expand Up @@ -87,6 +89,8 @@ if(BUILD_CUML_PRIMS_BENCH)
CUDA::cublas
benchmark::benchmark
raft::raft
raft::raft_nn
raft::raft_distance
$<IF:$<BOOL:${Treelite_ADDED}>,treelite::treelite_static,treelite::treelite>
$<IF:$<BOOL:${Treelite_ADDED}>,treelite::treelite_runtime_static,treelite::treelite_runtime>
)
Expand Down
1 change: 1 addition & 0 deletions cpp/bench/prims/distance_common.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <raft/cudart_utils.h>
#include <common/ml_benchmark.hpp>
#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>

namespace MLCommon {
namespace Bench {
Expand Down
30 changes: 15 additions & 15 deletions cpp/cmake/thirdparty/get_raft.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@ function(find_and_configure_raft)

set(oneValueArgs VERSION FORK PINNED_TAG)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )
"${multiValueArgs}" ${ARGN} )

if(DEFINED CPM_raft_SOURCE OR NOT DISABLE_FORCE_CLONE_RAFT)
set(CPM_DL_ALL_CACHE ${CPM_DOWNLOAD_ALL})
set(CPM_DOWNLOAD_ALL ON)
set(CPM_DL_ALL_CACHE ${CPM_DOWNLOAD_ALL})
set(CPM_DOWNLOAD_ALL ON)
endif()

rapids_cpm_find(raft ${PKG_VERSION}
GLOBAL_TARGETS raft::raft
BUILD_EXPORT_SET cuml-exports
INSTALL_EXPORT_SET cuml-exports
CPM_ARGS
GLOBAL_TARGETS raft::raft
BUILD_EXPORT_SET cuml-exports
INSTALL_EXPORT_SET cuml-exports
CPM_ARGS
GIT_REPOSITORY https://github.com/${PKG_FORK}/raft.git
GIT_TAG ${PKG_PINNED_TAG}
SOURCE_SUBDIR cpp
OPTIONS
"BUILD_TESTS OFF"
)
"BUILD_TESTS OFF"
)

if(raft_ADDED)
message(VERBOSE "CUML: Using RAFT located in ${raft_SOURCE_DIR}")
message(VERBOSE "CUML: Using RAFT located in ${raft_SOURCE_DIR}")
else()
message(VERBOSE "CUML: Using RAFT located in ${raft_DIR}")
message(VERBOSE "CUML: Using RAFT located in ${raft_DIR}")
endif()

if(DEFINED CPM_raft_SOURCE OR NOT DISABLE_FORCE_CLONE_RAFT)
set(CPM_DOWNLOAD_ALL ${CPM_DL_ALL_CACHE})
set(CPM_DOWNLOAD_ALL ${CPM_DL_ALL_CACHE})
endif()

endfunction()
Expand All @@ -56,6 +56,6 @@ set(CUML_BRANCH_VERSION_raft "${CUML_VERSION_MAJOR}.${CUML_VERSION_MINOR}")
# To use a different RAFT locally, set the CMake variable
# CPM_raft_SOURCE=/path/to/local/raft
find_and_configure_raft(VERSION ${CUML_MIN_VERSION_raft}
FORK rapidsai
PINNED_TAG branch-${CUML_BRANCH_VERSION_raft}
)
FORK rapidsai
PINNED_TAG branch-${CUML_BRANCH_VERSION_raft}
)
30 changes: 16 additions & 14 deletions cpp/src/knn/knn.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <raft/label/classlabels.cuh>
#include <raft/spatial/knn/ann.hpp>
#include <raft/spatial/knn/ball_cover.hpp>

#include <raft/spatial/knn/knn.hpp>
#include <raft/spatial/knn/specializations.hpp>
#include <rmm/device_uvector.hpp>

#include <cuml/common/logger.hpp>
Expand Down Expand Up @@ -49,20 +51,20 @@ void brute_force_knn(const raft::handle_t& handle,
{
ASSERT(input.size() == sizes.size(), "input and sizes vectors must be the same size");

raft::spatial::knn::brute_force_knn(handle,
input,
sizes,
D,
search_items,
n,
res_I,
res_D,
k,
rowMajorIndex,
rowMajorQuery,
nullptr,
metric,
metric_arg);
raft::spatial::knn::brute_force_knn<int64_t, float, int>(handle,
input,
sizes,
D,
search_items,
n,
res_I,
res_D,
k,
rowMajorIndex,
rowMajorQuery,
nullptr,
metric,
metric_arg);
}

void rbc_build_index(const raft::handle_t& handle,
Expand Down
29 changes: 15 additions & 14 deletions cpp/src/knn/knn_opg_common.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void perform_local_knn(opg_knn_param<in_t, ind_t, dist_t, out_t>& params,
size_t query_size)
{
std::vector<in_t*> ptrs(params.idx_data->size());
std::vector<int> sizes(params.idx_data->size());
std::vector<std::size_t> sizes(params.idx_data->size());

for (std::size_t cur_idx = 0; cur_idx < params.idx_data->size(); cur_idx++) {
ptrs[cur_idx] = params.idx_data->at(cur_idx)->ptr;
Expand All @@ -444,19 +444,20 @@ void perform_local_knn(opg_knn_param<in_t, ind_t, dist_t, out_t>& params,

// ID ranges need to be offset by each local partition's
// starting indices.
raft::spatial::knn::brute_force_knn(handle,
ptrs,
sizes,
params.idx_desc->N,
query,
query_size,
work.res_I.data(),
work.res_D.data(),
params.k,
params.rowMajorIndex,
params.rowMajorQuery,
&start_indices_long,
raft::distance::DistanceType::L2SqrtExpanded);
raft::spatial::knn::brute_force_knn<std::int64_t, float, std::size_t>(
handle,
ptrs,
sizes,
params.idx_desc->N,
query,
query_size,
work.res_I.data(),
work.res_D.data(),
params.k,
params.rowMajorIndex,
params.rowMajorQuery,
&start_indices_long,
raft::distance::DistanceType::L2SqrtExpanded);
CUDA_CHECK(cudaStreamSynchronize(handle.get_stream()));
CUDA_CHECK(cudaPeekAtLastError());
}
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <raft/sparse/distance/common.h>
#include <cuml/metrics/metrics.hpp>
#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>
#include <raft/sparse/distance/distance.hpp>
#include "pairwise_distance_canberra.cuh"
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance_canberra.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/metrics/pairwise_distance_chebyshev.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
* limitations under the License.
*/
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance_correlation.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance_cosine.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance_euclidean.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#pragma once
#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance_hamming.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance_hellinger.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance_jensen_shannon.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance_kl_divergence.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/metrics/pairwise_distance_l1.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
* limitations under the License.
*/
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/metrics/pairwise_distance_minkowski.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/

#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/metrics/pairwise_distance_russell_rao.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/handle.hpp>

namespace ML {
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/metrics/trustworthiness.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <cuml/metrics/metrics.hpp>

#include <raft/distance/distance.hpp>
#include <raft/distance/specializations.hpp>

#include <raft/handle.hpp>

namespace ML {
Expand Down
34 changes: 21 additions & 13 deletions cpp/src/tsne/distances.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,27 @@ void get_distances(const raft::handle_t& handle,
std::vector<float*> input_vec = {input.X};
std::vector<int> sizes_vec = {input.n};

raft::spatial::knn::brute_force_knn(handle,
input_vec,
sizes_vec,
input.d,
input.X,
input.n,
k_graph.knn_indices,
k_graph.knn_dists,
k_graph.n_neighbors,
true,
true,
nullptr,
DEFAULT_DISTANCE_METRIC);
/**
* std::vector<float *> &input, std::vector<int> &sizes,
IntType D, float *search_items, IntType n, int64_t *res_I,
float *res_D, IntType k,
std::shared_ptr<deviceAllocator> allocator,
cudaStream_t userStream,
*/

raft::spatial::knn::brute_force_knn<int64_t, float, int>(handle,
input_vec,
sizes_vec,
input.d,
input.X,
input.n,
k_graph.knn_indices,
k_graph.knn_dists,
k_graph.n_neighbors,
true,
true,
nullptr,
DEFAULT_DISTANCE_METRIC);
}

// dense, int32 indices
Expand Down
28 changes: 15 additions & 13 deletions cpp/src_prims/metrics/trustworthiness_score.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/

#include <cuml/metrics/metrics.hpp>
#include <raft/distance/specializations.hpp>
#include <raft/spatial/knn/knn.hpp>
#include <raft/spatial/knn/specializations.hpp>
#include <rmm/device_scalar.hpp>
#include <rmm/device_uvector.hpp>
#include <selection/columnWiseSort.cuh>
Expand Down Expand Up @@ -99,19 +101,19 @@ void run_knn(const raft::handle_t& h,
ptrs[0] = input;
sizes[0] = n;

raft::spatial::knn::brute_force_knn(h,
ptrs,
sizes,
d,
input,
n,
indices,
distances,
n_neighbors,
true,
true,
nullptr,
distance_type);
raft::spatial::knn::brute_force_knn<int64_t, float, int>(h,
ptrs,
sizes,
d,
input,
n,
indices,
distances,
n_neighbors,
true,
true,
nullptr,
distance_type);
}

/**
Expand Down
Loading