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

Replace faiss bfKnn #1202

Merged
merged 92 commits into from
Mar 17, 2023
Merged

Replace faiss bfKnn #1202

merged 92 commits into from
Mar 17, 2023

Conversation

benfred
Copy link
Member

@benfred benfred commented Jan 27, 2023

Replace faiss bfKnn with code that leverages our pairwise_distance api and select_k api - by tiling over the inputs.

This lets us remove faiss as a dependency

Closes #798
Closes #1159

Replace faiss bfKnn with code that leverages our pairwise_distance api
and select_k api - by computing tiling over the inputs.

This lets us remove faiss as a dependency
@benfred benfred added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Jan 27, 2023
@benfred benfred requested review from a team as code owners January 27, 2023 19:32
@benfred benfred marked this pull request as draft January 27, 2023 19:32
Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is looking great! I'm just giving some intial feedback so far based on a quick scan through the files. I'll do another pass tomorrow.

docs/source/build.md Outdated Show resolved Hide resolved
docs/source/build.md Outdated Show resolved Hide resolved
| RAFT_STATIC_LINK_LIBRARIES | ON, OFF | ON | Build static link libraries instead of shared libraries |
| DETECT_CONDA_ENV | ON, OFF | ON | Enable detection of conda environment for dependencies |
| NVTX | ON, OFF | OFF | Enable NVTX Markers |
| CUDA_ENABLE_KERNELINFO | ON, OFF | OFF | Enables `kernelinfo` in nvcc. This is useful for `compute-sanitizer` |
| CUDA_ENABLE_LINEINFO | ON, OFF | OFF | Enable the -lineinfo option for nvcc |
| CUDA_STATIC_RUNTIME | ON, OFF | OFF | Statically link the CUDA runtime |

Currently, shared libraries are provided for the `libraft-nn` and `libraft-distance` components. The `libraft-nn` component depends upon [FAISS](https://github.com/facebookresearch/faiss) and the `RAFT_ENABLE_NN_DEPENDENCIES` option will build it from source if it is not already installed.
Currently, shared libraries are provided for the `libraft-nn` and `libraft-distance` components.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next step (after this PR and after the release) will be merging libraft-nn and libraft-distance into a single libraft.so. The only reason it was separated was to isolate the FAISS dependency as it's the only run-time dependency that's not in the CUDA toolkit.

@benfred benfred changed the base branch from branch-23.02 to branch-23.04 February 1, 2023 21:13
@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2023

Codecov Report

Base: 87.99% // Head: 87.99% // No change to project coverage 👍

Coverage data is based on head (8445aed) compared to base (bd0d86b).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@              Coverage Diff              @@
##           branch-23.04    #1202   +/-   ##
=============================================
  Coverage         87.99%   87.99%           
=============================================
  Files                21       21           
  Lines               483      483           
=============================================
  Hits                425      425           
  Misses               58       58           
Impacted Files Coverage Δ
python/pylibraft/pylibraft/cluster/__init__.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@benfred
Copy link
Member Author

benfred commented Feb 11, 2023

The remaining build time issues seem to be in the RBC code .

It look like

brute_force_knn_impl<value_int, value_idx>(handle,
and
raft::spatial::knn::detail::brute_force_knn_impl<uint32_t, int64_t>(handle,
access the detail brute_force_knn_api, and the specializations are on the public api.

Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think as a follow-on we should also make a note (maybe a github issue so we don't forget?) to profile the stream pool bits w/ nsight systems just to make sure it's actually parallelizing the way we think it is. Otherwise, I think we've already discussed the other follow-ons (like augmenting this so the HDBSCAN reachability computation can use it.

metric == raft::distance::DistanceType::LpUnexpanded) {
float p = 0.5; // standard l2
if (metric == raft::distance::DistanceType::LpUnexpanded) p = 1.0 / metricArg;
raft::linalg::unaryOp<float>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW- just as a note. The new raft::linalg::map primitive allows us to do this really nicely (it's now being invoked directly by unary_op, binary_op, and ternary_op).

default:
// Create a new handle with the current stream from the stream pool
raft::device_resources stream_pool_handle(handle);
raft::resource::set_cuda_stream(stream_pool_handle, stream);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to add a copy overload to the handle that accepts a stream to we can make this easier.

@cjnolet
Copy link
Member

cjnolet commented Mar 17, 2023

/merge

@rapids-bot rapids-bot bot merged commit 1a3c028 into rapidsai:branch-23.04 Mar 17, 2023
@benfred benfred deleted the bfknn branch March 17, 2023 17:29
rapids-bot bot pushed a commit that referenced this pull request Mar 18, 2023
This depends on #1202 so those changes are also included here. This should also not be merged until that PR is merged.

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

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

URL: #1340
rapids-bot bot pushed a commit that referenced this pull request Mar 20, 2023
…#1333)

Now that we no longer need to rely on the FAISS dependency, this PR:
1. Consolidates  the `libraft-distance` and `libraft-nn` targets into a single `libraft` artifact
2. Introduces a new `raft::compiled` target to link against the new `libraft.so` binary. Removes `raft::distance`and `raft::nn` targets.
3. Consolidates `RAFT_DISTANCE_COMPILED` and `RAFT_NN_COMPILED` pre-processor vars into a single `RAFT_COMPILED` (to match similar pattern implementated by `spdlog`)
4. Consolidates `specializations.cuh` headers
5. Updates all docs, scripts, and build infra

This change has been a long time coming and is intended to be a 23.04 feature. This is further going to require updates to several projects downstream. Here's a checklist to track that progress:
- [x] offline announcement
- [x] cuml rapidsai/cuml#5272
- [x] cugraph rapidsai/cugraph#3348
- [x] cuopt rapidsai/cuopt#1023
- [x] cugraph-ops rapidsai/cugraph-ops#429


This PR depended on #1340 (removing FAISS from the build) and on #1202 (replacing the FAISS bfknn w/ our own), both of which have been merged. 

Closes #824

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

Approvers:
  - Sevag H (https://github.com/sevagh)
  - Divye Gala (https://github.com/divyegala)
  - Ben Frederickson (https://github.com/benfred)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #1333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci CMake cpp improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
4 participants