Comments (9)
Hi Daniel, adding a custom distance function requires some plumbing:
- Add the distance type to the enum here:
- Add to the switch case here:
- Add an overload of distance_impl here:
- Add a distance op, implementing the distance using the template that you already found here:
I might be missing some things, like adding some includes, but this should mostly cover it for the header-only use case. This way, you can call the function using raft::distance::pairwise_distance(...)
.
If you want the distance operation to be built as part of the shared library, you may need to add an instance here:
and also add it to the cmakelists.txt here:Line 279 in affd29b
Hope this helps you get started!
from raft.
The DI
is a macro that expands to __device__ inline
. It is defined here:
from raft.
It worked! Fantastic! I will keep the question open for now in case there are any other issues while setting up a custom distance function. Thank you!
from raft.
Thanks for the answers! I am stuck at a much simpler step when trying to compile the template.
I installed raft via mamba:
mamba install -c rapidsai -c conda-forge -c nvidia raft-dask pylibraft cuda-version=11.4
which worked.
Then I copied the template code from the repository into a seperate directory and set-up the following cmake file
cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR)
project(test_raft LANGUAGES CXX CUDA)
enable_language(CUDA)
find_package(raft REQUIRED)
add_executable(basic_example test.cu)
target_link_libraries(basic_example PRIVATE raft::raft)
which runs without any issues.
However, I then run the make
command and receive the following error
[ 50%] Building CUDA object CMakeFiles/basic_example.dir/test.cu.o
[100%] Linking CUDA executable basic_example
CMakeFiles/basic_example.dir/test.cu.o: In function `raft::resource::cublas_resource::cublas_resource(rmm::cuda_stream_view)':
tmpxft_00004343_00000000-6_test.cudafe1.cpp:(.text._ZN4raft8resource15cublas_resourceC2EN3rmm16cuda_stream_viewE[_ZN4raft8resource15cublas_resourceC5EN3rmm16cuda_stream_viewE]+0x35): undefined reference to `cublasCreate_v2'
tmpxft_00004343_00000000-6_test.cudafe1.cpp:(.text._ZN4raft8resource15cublas_resourceC2EN3rmm16cuda_stream_viewE[_ZN4raft8resource15cublas_resourceC5EN3rmm16cuda_stream_viewE]+0x8b): undefined reference to `cublasSetStream_v2'
CMakeFiles/basic_example.dir/test.cu.o: In function `raft::resource::cublas_resource::~cublas_resource()':
tmpxft_00004343_00000000-6_test.cudafe1.cpp:(.text._ZN4raft8resource15cublas_resourceD2Ev[_ZN4raft8resource15cublas_resourceD5Ev]+0x24): undefined reference to `cublasDestroy_v2'
CMakeFiles/basic_example.dir/test.cu.o: In function `raft::resource::get_cublas_handle(raft::resources const&)':
tmpxft_00004343_00000000-6_test.cudafe1.cpp:(.text._ZN4raft8resource17get_cublas_handleERKNS_9resourcesE[_ZN4raft8resource17get_cublas_handleERKNS_9resourcesE]+0x119): undefined reference to `cublasSetStream_v2'
CMakeFiles/basic_example.dir/test.cu.o: In function `cublasStatus_t raft::linalg::detail::cublasgemm<float>(cublasContext*, cublasOperation_t, cublasOperation_t, int, int, int, float const*, float const*, int, float const*, int, float const*, float*, int, CUstream_st*)':
tmpxft_00004343_00000000-6_test.cudafe1.cpp:(.text._ZN4raft6linalg6detail10cublasgemmIfEE14cublasStatus_tP13cublasContext17cublasOperation_tS6_iiiPKT_S9_iS9_iS9_PS7_iP11CUstream_st[_ZN4raft6linalg6detail10cublasgemmIfEE14cublasStatus_tP13cublasContext17cublasOperation_tS6_iiiPKT_S9_iS9_iS9_PS7_iP11CUstream_st]+0x49): undefined reference to `cublasSetStream_v2'
tmpxft_00004343_00000000-6_test.cudafe1.cpp:(.text._ZN4raft6linalg6detail10cublasgemmIfEE14cublasStatus_tP13cublasContext17cublasOperation_tS6_iiiPKT_S9_iS9_iS9_PS7_iP11CUstream_st[_ZN4raft6linalg6detail10cublasgemmIfEE14cublasStatus_tP13cublasContext17cublasOperation_tS6_iiiPKT_S9_iS9_iS9_PS7_iP11CUstream_st]+0x38a): undefined reference to `cublasSgemm_v2'
collect2: error: ld returned 1 exit status
make[2]: *** [basic_example] Error 1
make[1]: *** [CMakeFiles/basic_example.dir/all] Error 2
make: *** [all] Error 2
The reason I used mamba was because I thought I may not be installing from source correctly. I had ran the 'build.sh' file with a combination of flags and tags but I kept getting the same error when I tried to compile. Then I installed the latest cuBLAS version, but that does not seem to help. Do you have any advice?
nvcc --version: 11.4
cmake --version: 3.27.1
from raft.
Add something like this to the CMake:
target_link_libraries (name_of_your_program PRIVATE
raft::raft
other_deps
CUDA::cublas // <- this one might be missing
)
from raft.
Great! I am curious which distance function you are trying to implement?
from raft.
I would like to have a different distance metric for various features and change their weighting as well. For example, when using the correlation metric, the correlation measure normalizes the data implicitly, so I can not simply scale the feature to change its contribution to the overall distance.
I have some cuda code for my own kNN implementation, but it seems to be quite a bit slower than the implementation of raft. Seems like it may be a combination of RMM and other optimization tricks?
from raft.
Interesting! Weighting indeed seems like a useful feature.
Seems like it may be a combination of RMM and other optimization tricks?
I cannot speak for your code, but the meat of the algorithm can be found here:
We use the "standard" tricks like tiling in shared memory, avoiding shared memory bank conflicts, and loading data using vectorized loads.
from raft.
I am closing this issue. Feel free to open a new one if any questions arise!
from raft.
Related Issues (20)
- [BUG] IVF-PQ index creation crashes on aarch64 for wiki_all_1M benchmark HOT 1
- [FEA] Better exception handling
- [FEA] use of COO to balance the `faster_dot kernel` across the blocks
- [FEA]creating the masked_matmul function to front the SDDMM+custom kernel.
- [BUG] wheel tests do not fail when `raft-dask` wheel has unsatisfiable dependency requirements HOT 1
- [BUG] Error when running raft_ann_bench
- [BUG] Enable logging macros in downstream projects
- [BUG] Cagra To hnsw, the search api not use search param ef HOT 3
- [FEA] Consolidate SUM reductions across raft
- [BUG] `bitmap_view::set` not work
- [FEA] Support setting the bits in a bitmap filter via a user-defined CUDA functor.
- Updating RAFT ANN benchmark environment/containers to newer CUDA
- [FEA] conan support please HOT 1
- [BUG] next_float and next_double return values in range [0,1] HOT 1
- [BUG] Nightly CI issue: CUDA 11.4 jobs were running with CUDA 11.8 when nccl wasn't available
- [BUG] 'list' object has no attribute '__array_interface__' HOT 2
- [FEA] Support for more general use of `COO` with `Index_Type` other than `int`
- [BUG]An illegal instruction caused by `masked_matmul` on v100 when the dim isn't multiple of 32.
- [QST] How to use RAFT installed by mamba?
- (Flaky?) C++ test `CLUSTER_TEST`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raft.