Skip to content

Commit

Permalink
Moving and renaming distance namespaces from raft -> cuvs (#85)
Browse files Browse the repository at this point in the history
This PR moves the `raft::distance` APIs over to cuVS. We're ripping the band-aid off quickly here so moving all over at once. 

All of the non-public APIs are being moved to `src/distance` and only the public APIs being moved to `include/cuvs/distance`.

Authors:
  - Corey J. Nolet (https://github.com/cjnolet)

Approvers:
  - Ben Frederickson (https://github.com/benfred)
  - Ray Douglass (https://github.com/raydouglass)

URL: #85
  • Loading branch information
cjnolet authored Apr 29, 2024
1 parent 32235a4 commit 8db4638
Show file tree
Hide file tree
Showing 126 changed files with 17,390 additions and 147 deletions.
1 change: 1 addition & 0 deletions conda/environments/all_cuda-122_arch-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies:
- libcurand-dev
- libcusolver-dev
- libcusparse-dev
- libnvjitlink
- make
- nccl>=2.9.9
- ninja
Expand Down
1 change: 1 addition & 0 deletions conda/environments/all_cuda-122_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies:
- libcurand-dev
- libcusolver-dev
- libcusparse-dev
- libnvjitlink
- make
- nccl>=2.9.9
- ninja
Expand Down
91 changes: 56 additions & 35 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,35 @@ include(cmake/thirdparty/get_cutlass.cmake)

add_library(
cuvs SHARED
src/distance/detail/pairwise_matrix/dispatch_canberra_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_canberra_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_correlation_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_correlation_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_cosine_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_cosine_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_hamming_unexpanded_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_hamming_unexpanded_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_hellinger_expanded_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_hellinger_expanded_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_jensen_shannon_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_jensen_shannon_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_kl_divergence_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_kl_divergence_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_l1_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_l1_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_l2_expanded_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_l2_expanded_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_l2_unexpanded_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_l2_unexpanded_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_l_inf_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_l_inf_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_lp_unexpanded_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_lp_unexpanded_float_float_float_int.cu
src/distance/detail/pairwise_matrix/dispatch_rbf.cu
src/distance/detail/pairwise_matrix/dispatch_russel_rao_double_double_double_int.cu
src/distance/detail/pairwise_matrix/dispatch_russel_rao_float_float_float_int.cu
src/distance/distance.cu
src/distance/pairwise_distance.cu
src/neighbors/brute_force_index.cu
src/neighbors/brute_force.cu
src/neighbors/cagra_build_float.cpp
Expand Down Expand Up @@ -240,16 +269,13 @@ target_include_directories(

if(NOT BUILD_CPU_ONLY)
# Keep cuVS as lightweight as possible. Only CUDA libs and rmm should be used in global target.
target_link_libraries(cuvs
PUBLIC
rmm::rmm
$<$<NOT:$<BOOL:${CUDA_STATIC_RUNTIME}>>:raft::raft>
$<$<NOT:$<BOOL:${CUDA_STATIC_RUNTIME}>>:raft::compiled>
PRIVATE
$<$<BOOL:${CUDA_STATIC_RUNTIME}>:raft::raft>
$<$<BOOL:${CUDA_STATIC_RUNTIME}>:raft::compiled_static>
nvidia::cutlass::cutlass
)
target_link_libraries(
cuvs
PUBLIC rmm::rmm $<$<NOT:$<BOOL:${CUDA_STATIC_RUNTIME}>>:raft::raft>
$<$<NOT:$<BOOL:${CUDA_STATIC_RUNTIME}>>:raft::compiled>
PRIVATE $<$<BOOL:${CUDA_STATIC_RUNTIME}>:raft::raft>
$<$<BOOL:${CUDA_STATIC_RUNTIME}>:raft::compiled_static> nvidia::cutlass::cutlass
)
endif()

# Endian detection
Expand Down Expand Up @@ -304,14 +330,14 @@ endif()

set_target_properties(
cuvs
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
POSITION_INDEPENDENT_CODE ON
POSITION_INDEPENDENT_CODE ON
)

target_compile_options(
Expand All @@ -325,25 +351,21 @@ target_link_options(cuvs PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/fatbin.ld")
# * cuvs_c -------------------------------------------------------------------------------
if(BUILD_C_LIBRARY)
add_library(
cuvs_c SHARED
src/core/c_api.cpp
src/neighbors/brute_force_c.cpp
src/neighbors/ivf_flat_c.cpp
src/neighbors/ivf_pq_c.cpp
src/neighbors/cagra_c.cpp
cuvs_c SHARED src/core/c_api.cpp src/neighbors/brute_force_c.cpp src/neighbors/ivf_flat_c.cpp
src/neighbors/ivf_pq_c.cpp src/neighbors/cagra_c.cpp
)

add_library(cuvs::c_api ALIAS cuvs_c)

set_target_properties(
cuvs_c
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
EXPORT_NAME c_api
EXPORT_NAME c_api
)

target_compile_options(cuvs_c PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${CUVS_CXX_FLAGS}>")
Expand All @@ -354,12 +376,11 @@ if(BUILD_C_LIBRARY)
INTERFACE "$<INSTALL_INTERFACE:include>"
)

target_link_libraries(cuvs_c
PUBLIC
cuvs::cuvs
PRIVATE
$<$<BOOL:${CUDA_STATIC_RUNTIME}>:raft::raft>
)
target_link_libraries(
cuvs_c
PUBLIC cuvs::cuvs
PRIVATE $<$<BOOL:${CUDA_STATIC_RUNTIME}>:raft::raft>
)

# ensure CUDA symbols aren't relocated to the middle of the debug build binaries
target_link_options(cuvs_c PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/fatbin.ld")
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/cuvs/distance/distance_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {
#endif

/** enum to tell how to compute distance */
enum DistanceType {
typedef enum {

/** evaluate as dist_ij = sum(x_ik^2) + sum(y_ij)^2 - 2*sum(x_ik * y_jk) */
L2Expanded = 0,
Expand Down Expand Up @@ -64,7 +64,7 @@ enum DistanceType {
DiceExpanded = 19,
/** Precomputed (special value) **/
Precomputed = 100
};
} cuvsDistanceType;

#ifdef __cplusplus
}
Expand Down
48 changes: 2 additions & 46 deletions cpp/include/cuvs/distance/distance_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,12 @@
* limitations under the License.
*/

#include "distance_types.h"
#pragma once

namespace cuvs::distance {

/** enum to tell how to compute distance */
enum DistanceType : unsigned short {

/** evaluate as dist_ij = sum(x_ik^2) + sum(y_ij)^2 - 2*sum(x_ik * y_jk) */
L2Expanded = 0,
/** same as above, but inside the epilogue, perform square root operation */
L2SqrtExpanded = 1,
/** cosine distance */
CosineExpanded = 2,
/** L1 distance */
L1 = 3,
/** evaluate as dist_ij += (x_ik - y-jk)^2 */
L2Unexpanded = 4,
/** same as above, but inside the epilogue, perform square root operation */
L2SqrtUnexpanded = 5,
/** basic inner product **/
InnerProduct = 6,
/** Chebyshev (Linf) distance **/
Linf = 7,
/** Canberra distance **/
Canberra = 8,
/** Generalized Minkowski distance **/
LpUnexpanded = 9,
/** Correlation distance **/
CorrelationExpanded = 10,
/** Jaccard distance **/
JaccardExpanded = 11,
/** Hellinger distance **/
HellingerExpanded = 12,
/** Haversine distance **/
Haversine = 13,
/** Bray-Curtis distance **/
BrayCurtis = 14,
/** Jensen-Shannon distance**/
JensenShannon = 15,
/** Hamming distance **/
HammingUnexpanded = 16,
/** KLDivergence **/
KLDivergence = 17,
/** RusselRao **/
RusselRaoExpanded = 18,
/** Dice-Sorensen distance **/
DiceExpanded = 19,
/** Precomputed (special value) **/
Precomputed = 100
};
using DistanceType = cuvsDistanceType;

/**
* Whether minimal distance corresponds to similar elements (using the given metric).
Expand Down
Loading

0 comments on commit 8db4638

Please sign in to comment.