Code Monkey home page Code Monkey logo

Comments (9)

ahendriksen avatar ahendriksen commented on September 22, 2024 1

Hi Daniel, adding a custom distance function requires some plumbing:

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:
src/distance/detail/pairwise_matrix/dispatch_kl_divergence_double_double_double_int.cu

Hope this helps you get started!

from raft.

ahendriksen avatar ahendriksen commented on September 22, 2024 1

The DI is a macro that expands to __device__ inline. It is defined here:

/** helper macro for device inlined functions */

from raft.

daniellengyel avatar daniellengyel commented on September 22, 2024 1

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.

daniellengyel avatar daniellengyel commented on September 22, 2024

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.

ahendriksen avatar ahendriksen commented on September 22, 2024

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.

ahendriksen avatar ahendriksen commented on September 22, 2024

Great! I am curious which distance function you are trying to implement?

from raft.

daniellengyel avatar daniellengyel commented on September 22, 2024

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.

ahendriksen avatar ahendriksen commented on September 22, 2024

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:

for (int kidx = P::Kblk; kidx < this->k; kidx += P::Kblk) {

We use the "standard" tricks like tiling in shared memory, avoiding shared memory bank conflicts, and loading data using vectorized loads.

from raft.

ahendriksen avatar ahendriksen commented on September 22, 2024

I am closing this issue. Feel free to open a new one if any questions arise!

from raft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.