-
Notifications
You must be signed in to change notification settings - Fork 197
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
Add cutlass 3xTF32,DMMA based L2/cosine distance kernels for SM 8.0 or higher #939
Merged
rapids-bot
merged 28 commits into
rapidsai:branch-22.12
from
mdoijade:cutlass_dist_kernels
Nov 16, 2022
Merged
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
20648c5
cutlass based euclidean expanded, cosine kernels
mdoijade a9dabc8
add prior ampere pairwisedistmat kernel to prevent redundant kernel c…
mdoijade 1a45bfa
add noexcept to the functor methods
mdoijade c6f091b
merge branch 22.12 and resolve conflicts
mdoijade 7786fcb
fix comments, remove redundant code and fix formatting issues
mdoijade 181fc40
add cutlass cmake support for raft with custom namespace, fix formati…
mdoijade 3d34545
fix formatting issues
mdoijade 02c23ed
fix the cutlass_include_dir path in cmake
mdoijade 7933436
fix bugs in get_cutlass cmake to use cutlass provided properties corr…
mdoijade d4bdec5
remove the cutlass namespace setting in test cmakefiles as it is not …
mdoijade d26bcef
temp remove dist dependency from cutlass to check if it works in ci/cd
mdoijade 4df4185
merge branch-22.12 latest changes
mdoijade 451c3c0
fix get_cutlass.cmake to work with pylibraft by using NvidiaCutlass i…
mdoijade 7b512f9
fix get_cutlass install path, make changes as per review comments
mdoijade a05e1e2
merge branch-22.12
mdoijade d32b4c0
fix clang format issues
mdoijade f7c440a
temp fix to check if python build works
mdoijade b1a1fd7
add raft-exports instead of raft-distance-exports as other raft compo…
mdoijade 4ef44e7
make cutlass to depend only on raft_distance and add raft_distance de…
mdoijade 186fcc7
fix cmake formatting issues
mdoijade 8aa8909
prevent cutlass based pairwise dist kernels to be disabled on cuda 12…
mdoijade abfd493
Moving cutlass dependency to distance and nn to keep them separate.
cjnolet f1b1239
Adding CUTLASS to build docs as dependency
cjnolet 32e6052
Updating to export to both distance and nn
cjnolet f6de9ee
Adding cutlass as private dependency
cjnolet 9bf0647
Making cutlass INTERFACE in raft::nn and raft::distance
cjnolet 8f0119a
Using proper exports per Robert Maynard's suggestion.
cjnolet 6ad4fd1
Adding cutlass as private dependency of lib targets
cjnolet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# ============================================================================= | ||
# Copyright (c) 2021-2022, 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. | ||
# ============================================================================= | ||
|
||
function(find_and_configure_cutlass) | ||
set(oneValueArgs VERSION REPOSITORY PINNED_TAG) | ||
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
|
||
# if(RAFT_ENABLE_DIST_DEPENDENCIES OR RAFT_COMPILE_LIBRARIES) | ||
set(CUTLASS_ENABLE_HEADERS_ONLY | ||
ON | ||
CACHE BOOL "Enable only the header library" | ||
) | ||
set(CUTLASS_NAMESPACE | ||
"raft_cutlass" | ||
CACHE STRING "Top level namespace of CUTLASS" | ||
) | ||
set(CUTLASS_ENABLE_CUBLAS | ||
OFF | ||
CACHE BOOL "Disable CUTLASS to build with cuBLAS library." | ||
) | ||
|
||
rapids_cpm_find( | ||
NvidiaCutlass ${PKG_VERSION} | ||
GLOBAL_TARGETS nvidia::cutlass::cutlass | ||
CPM_ARGS | ||
GIT_REPOSITORY ${PKG_REPOSITORY} | ||
GIT_TAG ${PKG_PINNED_TAG} | ||
GIT_SHALLOW TRUE | ||
OPTIONS "CUDAToolkit_ROOT ${CUDAToolkit_LIBRARY_DIR}" | ||
) | ||
|
||
if(TARGET CUTLASS AND NOT TARGET nvidia::cutlass::cutlass) | ||
add_library(nvidia::cutlass::cutlass ALIAS CUTLASS) | ||
endif() | ||
|
||
if(NvidiaCutlass_ADDED) | ||
rapids_export( | ||
BUILD NvidiaCutlass | ||
EXPORT_SET NvidiaCutlass | ||
GLOBAL_TARGETS nvidia::cutlass::cutlass | ||
NAMESPACE nvidia::cutlass:: | ||
) | ||
endif() | ||
# endif() | ||
|
||
# We generate the cutlass-config files when we built cutlass locally, so always do | ||
# `find_dependency` | ||
rapids_export_package( | ||
BUILD NvidiaCutlass raft-distance-exports GLOBAL_TARGETS nvidia::cutlass::cutlass | ||
) | ||
rapids_export_package( | ||
INSTALL NvidiaCutlass raft-distance-exports GLOBAL_TARGETS nvidia::cutlass::cutlass | ||
) | ||
|
||
# Tell cmake where it can find the generated NvidiaCutlass-config.cmake we wrote. | ||
include("${rapids-cmake-dir}/export/find_package_root.cmake") | ||
rapids_export_find_package_root( | ||
INSTALL NvidiaCutlass [=[${CMAKE_CURRENT_LIST_DIR}/../]=] raft-distance-exports | ||
) | ||
rapids_export_find_package_root( | ||
BUILD NvidiaCutlass [=[${CMAKE_CURRENT_LIST_DIR}]=] raft-distance-exports | ||
) | ||
endfunction() | ||
|
||
if(NOT RAFT_CUTLASS_GIT_TAG) | ||
set(RAFT_CUTLASS_GIT_TAG v2.9.1) | ||
endif() | ||
|
||
if(NOT RAFT_CUTLASS_GIT_REPOSITORY) | ||
set(RAFT_CUTLASS_GIT_REPOSITORY https://github.com/NVIDIA/cutlass.git) | ||
endif() | ||
|
||
find_and_configure_cutlass( | ||
VERSION 2.9.1 REPOSITORY ${RAFT_CUTLASS_GIT_REPOSITORY} PINNED_TAG ${RAFT_CUTLASS_GIT_TAG} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -615,6 +615,19 @@ void distance(const InType* x, | |
* @note if workspace is passed as nullptr, this will return in | ||
* worksize, the number of bytes of workspace required | ||
*/ | ||
|
||
// Default final op functor which facilitates elementwise operation on | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, then even the previous overload of distance requires its FinalLambda to be such a functor. Could you amend the docstring at line 568 accordingly? |
||
// final distance value if any. | ||
template <typename AccType, typename OutType, typename Index> | ||
struct default_fin_op { | ||
__host__ __device__ default_fin_op() noexcept {}; | ||
// functor signature. | ||
__host__ __device__ OutType operator()(AccType d_val, Index g_d_idx) const noexcept | ||
{ | ||
return d_val; | ||
} | ||
}; | ||
|
||
template <raft::distance::DistanceType distanceType, | ||
typename InType, | ||
typename AccType, | ||
|
@@ -632,9 +645,15 @@ void distance(const InType* x, | |
bool isRowMajor = true, | ||
InType metric_arg = 2.0f) | ||
{ | ||
auto default_fin_op = [] __device__(AccType d_val, Index_ g_d_idx) { return d_val; }; | ||
distance<distanceType, InType, AccType, OutType, decltype(default_fin_op), Index_>( | ||
x, y, dist, m, n, k, workspace, worksize, default_fin_op, stream, isRowMajor, metric_arg); | ||
using final_op_type = default_fin_op<AccType, OutType, Index_>; | ||
final_op_type fin_op; | ||
|
||
// raft distance support inputs as float/double and output as uint8_t/float/double. | ||
static_assert(!((sizeof(OutType) > 1) && (sizeof(AccType) != sizeof(OutType))), | ||
"OutType can be uint8_t, float, double," | ||
"if sizeof(OutType) > 1 then sizeof(AccType) == sizeof(OutType)."); | ||
distance<distanceType, InType, AccType, OutType, final_op_type, Index_>( | ||
x, y, dist, m, n, k, workspace, worksize, fin_op, stream, isRowMajor, metric_arg); | ||
RAFT_CUDA_TRY(cudaPeekAtLastError()); | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does
raft_nn_lib
need theraft_distance
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raft_nn_lib
sources make use of distance headers such as cosine.cuh/euclidean.cuh where it encounters build failure with missing cutlass headers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is raft_nn_lib srcs that have this dependency, the
target_link_libraries
usage should bePRIVATE
. Secondly it should be a dependency on the cutlass target and notraft_distance
.This currently creates a hard dependency for downstream consumers of raft, which breaks requests like
find_package(raft COMPONENTS nn)
since theraft_distance
target won't exist for those users.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so can I make it
target_link_libraries(raft_nn_lib PUBLIC faiss::faiss raft::raft nvidia::cutlass::cutlass)
?and then will I need to modify
get_cutlass.cmake
to addrapids_export_package
toraft-nn-lib-exports
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you would want
target_link_libraries(raft_nn_lib PUBLIC faiss::faiss raft::raft PRIVATE nvidia::cutlass::cutlass)
and no other change would be required.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made these changes and pushed them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cjnolet and @robertmaynard for quick help and fixes!