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

[FEA] Codepacking for IVF-flat #1632

Merged
merged 34 commits into from
Aug 1, 2023

Conversation

tarang-jain
Copy link
Contributor

Support reading interleaved lists from a packed non-interleaved dense IVF-list matrix and vice versa.

@tarang-jain tarang-jain requested a review from a team as a code owner July 1, 2023 00:08
@github-actions github-actions bot added the cpp label Jul 1, 2023
@tarang-jain tarang-jain added 2 - In Progress Currenty a work in progress feature request New feature or request labels Jul 1, 2023
@tarang-jain tarang-jain changed the title Codepacking for IVF-flat [FEA] Codepacking for IVF-flat Jul 1, 2023
@cjnolet cjnolet added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function Vector Search labels Jul 6, 2023
@tfeher
Copy link
Contributor

tfeher commented Jul 14, 2023

To resolve style errors, you could install pre-commit hooks.

tfeher
tfeher previously requested changes Jul 17, 2023
Copy link
Contributor

@tfeher tfeher left a comment

Choose a reason for hiding this comment

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

Thanks @tarang-jain for the PR! The new pack/unpack funcions look good, but we shall have test for that. Also, I see a lot of commented out code here, please let me know what is the plan with that.

cpp/include/raft/neighbors/ivf_flat_helpers.cuh Outdated Show resolved Hide resolved
cpp/include/raft/spatial/knn/detail/ann_quantized.cuh Outdated Show resolved Hide resolved
* @param[in] offset how many records to skip before writing the data into the list
*/
template <typename T>
__host__ __device__ void pack_1_interleaved(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a reason to add the _interleaved suffix? Faiss has a function called (un)pack_1.
Alternativele, IVF-PQ has functions (un)pack, that can take one or many vectors at once. We shall aim for consistency with one of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, (un)pack_1 sounds like the better naming convention to avoid confusion. I was also told by @cjnolet that the current IVF-PQ CodePacker needs some refactoring and the names of the IVF-PQ functions can be changed to (un)pack_1 then.

Copy link
Contributor

Choose a reason for hiding this comment

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

IVF-PQ functions can unpack multiple vectors at a time, I would not name them (un)pack_1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way to think of ivf_flat_codepacker.hpp is that the codepacker a public API and is the smallest atomic unit (packing and unpacking one single row). This can now be used in host and device functions alike -- for packing and unpacking multiple records either through a kernel, or through a CPU for loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The helper pack_full_list is just an example of using the CodePacker for packing a full list.

@tarang-jain tarang-jain requested a review from a team as a code owner July 17, 2023 16:52
@tarang-jain tarang-jain removed the feature request New feature or request label Jul 31, 2023
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 we could/should consolidate the kernels into map/map_offset thunks eventually but given that this is going to enable the faiss integration in the meantime, I think we should be good to go for 23.08. Thanks for all your hard work on this @tarang-jain!

@@ -113,6 +113,7 @@ struct list_spec {
/** Determine the extents of an array enough to hold a given amount of data. */
constexpr auto make_list_extents(SizeT n_rows) const -> list_extents
{
// return make_extents<SizeT>(round_up_safe(n_rows, this->align_min), dim);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to revert this?

dim3 blocks(div_rounding_up_safe<uint32_t>(n_rows, kBlockSize), 1, 1);
dim3 threads(kBlockSize, 1, 1);
auto stream = resource::get_cuda_stream(res);
pack_interleaved_list_kernel<<<blocks, threads, 0, stream>>>(
Copy link
Member

Choose a reason for hiding this comment

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

Any reason we couldn't just use a map() or map_offset() for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is no particular reason. this can indeed be put inside a map_offset.

@raydouglass raydouglass removed the request for review from a team July 31, 2023 22:56
@cjnolet cjnolet requested a review from tfeher July 31, 2023 23:26
@cjnolet cjnolet dismissed tfeher’s stale review July 31, 2023 23:27

Tamas is on PTO and Tarang has addressed the review items. We need this functionality to release FAISS in August and we can follow up in 23.10 if needed.

@raydouglass raydouglass merged commit f42fa40 into rapidsai:branch-23.08 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 - In Progress Currenty a work in progress cpp improvement Improvement / enhancement to an existing function non-breaking Non-breaking change Vector Search
Projects
Development

Successfully merging this pull request may close these issues.

4 participants