-
Notifications
You must be signed in to change notification settings - Fork 184
Use int64_t for getters in the cagra/ivf_flat c-api #1272
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c912fb
Use int64_t for getters in the cagra/ivf_flat c-api
benfred 548bbce
Merge branch 'branch-25.10' into int64_getters
benfred 8bbc967
Merge branch 'branch-25.10' into int64_getters
benfred 6c11966
Merge branch 'branch-25.10' into int64_getters
cjnolet ce8016a
int64 getters for ivf-pq
benfred 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
|
|
||
| /* | ||
| * Copyright (c) 2024, NVIDIA CORPORATION. | ||
| * Copyright (c) 2024-2025, NVIDIA CORPORATION. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
|
|
@@ -395,50 +395,54 @@ extern "C" cuvsError_t cuvsIvfFlatExtend(cuvsResources_t res, | |
| }); | ||
| } | ||
|
|
||
| extern "C" uint32_t cuvsIvfFlatIndexGetNLists(cuvsIvfFlatIndex_t index) | ||
| extern "C" cuvsError_t cuvsIvfFlatIndexGetNLists(cuvsIvfFlatIndex_t index, int64_t* n_lists) | ||
| { | ||
| if (index->dtype.code == kDLFloat && index->dtype.bits == 32) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<float, int64_t>*>(index->addr); | ||
| return index_ptr->n_lists(); | ||
| } else if (index->dtype.code == kDLFloat && index->dtype.bits == 16) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<half, int64_t>*>(index->addr); | ||
| return index_ptr->n_lists(); | ||
| } else if (index->dtype.code == kDLInt && index->dtype.bits == 8) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<int8_t, int64_t>*>(index->addr); | ||
| return index_ptr->n_lists(); | ||
| } else if (index->dtype.code == kDLUInt && index->dtype.bits == 8) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<uint8_t, int64_t>*>(index->addr); | ||
| return index_ptr->n_lists(); | ||
| } else { | ||
| return 0; | ||
| } | ||
| return cuvs::core::translate_exceptions([=] { | ||
| if (index->dtype.code == kDLFloat && index->dtype.bits == 32) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<float, int64_t>*>(index->addr); | ||
| *n_lists = index_ptr->n_lists(); | ||
|
Contributor
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. Since this is a non-narrowing conversion (uint32_t -> int64_t), an explicit |
||
| } else if (index->dtype.code == kDLFloat && index->dtype.bits == 16) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<half, int64_t>*>(index->addr); | ||
| *n_lists = index_ptr->n_lists(); | ||
| } else if (index->dtype.code == kDLInt && index->dtype.bits == 8) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<int8_t, int64_t>*>(index->addr); | ||
| *n_lists = index_ptr->n_lists(); | ||
| } else if (index->dtype.code == kDLUInt && index->dtype.bits == 8) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<uint8_t, int64_t>*>(index->addr); | ||
| *n_lists = index_ptr->n_lists(); | ||
| } else { | ||
| RAFT_FAIL("Unsupported index dtype: %d and bits: %d", index->dtype.code, index->dtype.bits); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| extern "C" uint32_t cuvsIvfFlatIndexGetDim(cuvsIvfFlatIndex_t index) | ||
| extern "C" cuvsError_t cuvsIvfFlatIndexGetDim(cuvsIvfFlatIndex_t index, int64_t* dim) | ||
|
benfred marked this conversation as resolved.
|
||
| { | ||
| if (index->dtype.code == kDLFloat && index->dtype.bits == 32) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<float, int64_t>*>(index->addr); | ||
| return index_ptr->dim(); | ||
| } else if (index->dtype.code == kDLFloat && index->dtype.bits == 16) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<half, int64_t>*>(index->addr); | ||
| return index_ptr->dim(); | ||
| } else if (index->dtype.code == kDLInt && index->dtype.bits == 8) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<int8_t, int64_t>*>(index->addr); | ||
| return index_ptr->dim(); | ||
| } else if (index->dtype.code == kDLUInt && index->dtype.bits == 8) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<uint8_t, int64_t>*>(index->addr); | ||
| return index_ptr->dim(); | ||
| } else { | ||
| return 0; | ||
| } | ||
| return cuvs::core::translate_exceptions([=] { | ||
| if (index->dtype.code == kDLFloat && index->dtype.bits == 32) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<float, int64_t>*>(index->addr); | ||
| *dim = index_ptr->dim(); | ||
| } else if (index->dtype.code == kDLFloat && index->dtype.bits == 16) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<half, int64_t>*>(index->addr); | ||
| *dim = index_ptr->dim(); | ||
| } else if (index->dtype.code == kDLInt && index->dtype.bits == 8) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<int8_t, int64_t>*>(index->addr); | ||
| *dim = index_ptr->dim(); | ||
| } else if (index->dtype.code == kDLUInt && index->dtype.bits == 8) { | ||
| auto index_ptr = | ||
| reinterpret_cast<cuvs::neighbors::ivf_flat::index<uint8_t, int64_t>*>(index->addr); | ||
| *dim = index_ptr->dim(); | ||
| } else { | ||
| RAFT_FAIL("Unsupported index dtype: %d and bits: %d", index->dtype.code, index->dtype.bits); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| extern "C" cuvsError_t cuvsIvfFlatIndexGetCenters(cuvsResources_t res, | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Tangential question: How come
index->addris auintprt_tand not avoid*?(Functionally, it's likely equivalent, except for the ability to use
static_castinstead ofreinterpret_cast.)