-
Notifications
You must be signed in to change notification settings - Fork 215
[REVIEW] New Dataset API Clarifying Ownership #1846
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
base: release/26.08
Are you sure you want to change the base?
Changes from all commits
c15ed1e
8dd7436
34d499f
f41c355
b0e5369
81341c9
f9e83c5
5598753
b4892a5
485b820
7b9edda
14f6bfe
110f9f3
69d45fe
b7148c3
15a8834
9543191
2dee124
7071656
3bbf993
c8b5397
d81f873
98b5697
c88b23c
b32e868
1a88bb8
1f24980
5e5ed60
5cadbad
12272d2
e689b04
58ee2e5
88cfb37
706f95d
231a9e1
8aac5bd
d869208
ad30ca1
4c3faef
6676c3a
d53c4a8
adcb0a2
6a91ca4
7f0ba65
945a249
a2d937a
063e439
cc9c1f3
c3edfc7
5fa5bf3
c5cfcf2
58c7bbd
2b8801c
b12a6c2
8d99fa7
285e5ed
93557e4
e46300f
b1c979b
c6405c6
3ccbe5c
4117f23
0340038
0e2691c
7dfbf85
23b07d3
46935d4
cebcfd4
88da190
79d0fd8
f9adbc5
d1c1dd4
5223862
8c836ec
11b0c61
1de47f9
c6b4901
99ab789
3ea5f56
ea4c1d6
68c3f6b
f7f607d
34d2dc4
3298366
0af9527
6459568
e3cf3d3
e819312
1c1eb55
fa31267
40bc7eb
fd9d591
186d81e
06e879d
d95dd91
a8d27a6
44e8888
6021700
34f6460
8b3d8f8
5411928
de2000b
c0190fa
baab6a7
98ef788
6fdfebf
f356e48
53ef0e6
428542e
6e9b7a5
178eb3f
a09c834
c3af8bd
dfedfb9
6d756e5
828c371
c630451
4258dc5
f58c21e
e0fce27
73bb010
0dfeffe
9c024c6
55736de
af2fd42
598e861
e795819
26b87e5
2804440
48fc8d5
ff8cc82
4d7d0a6
bb275f1
217e5bd
8001bf4
3803e00
c31ea7c
df925ec
f722c2c
fadf92e
6c47d31
4dbceca
f22232e
77f238a
06c4050
809e466
3bfd17e
c5c060d
51b19f5
a69ca2e
6679a0f
262447a
48311e5
368d058
3b4fd60
0ca9cba
a5d8eb2
450dc58
bf23049
2ecd73b
10bd460
f0c980f
cce33bf
75972a6
e8929e1
19b0592
1aeeb85
292ede8
edfa4e9
753c276
3f4131f
121ad26
cdb56f0
fccae19
50870cb
ed81c08
62a8d14
5cd5d10
11f78ef
27bd293
4bb8d9b
2a28c81
c64e262
29913ba
a3e118e
ff00444
f9cd640
b67359e
db3c6be
ec196fa
0fa6675
414c1d3
1b60d3d
896916f
21347c2
77ab228
9dd900f
3c7e39b
152099c
0af07a6
6302ce1
803b266
f697057
33afe5d
c9adf11
07c730c
28caf00
5530224
1ba009e
c6346db
0aaad3d
acdb4cd
07dd2a7
a5fe56d
428cc28
1ff0cfd
6615232
c38d9a7
f6e17d7
96bc6fc
f9ecb66
5bcf917
ddc26b8
f85332e
30b8059
8ab8f73
e99e47a
c50a91a
abb5af3
e3a0b10
ecdbf5a
e53fce8
59e6376
5eca21b
4e652b8
087bf47
a12aed8
78e59a6
8ecfa65
e626144
72784d2
ed281a9
c18d29d
d58d3e3
d6016de
f5aaa1c
b50f027
c198066
8c0d164
2337295
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cuvs/core/c_api.h> | ||
| #include <cuvs/neighbors/common.h> | ||
|
|
||
| #include <dlpack/dlpack.h> | ||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Generic dataset layout kind for C API dataset handles. | ||
| */ | ||
| typedef enum { | ||
| CUVS_DATASET_LAYOUT_STANDARD = 0, | ||
| CUVS_DATASET_LAYOUT_PADDED = 1 | ||
| } cuvsDatasetLayout_t; | ||
|
|
||
| /** | ||
| * @brief Dataset view kind for host/device + layout dispatch. | ||
| */ | ||
| typedef enum { | ||
| CUVS_DATASET_VIEW_KIND_DEVICE_PADDED = 0, | ||
| CUVS_DATASET_VIEW_KIND_HOST_PADDED = 1, | ||
| CUVS_DATASET_VIEW_KIND_DEVICE_STANDARD = 2, | ||
| CUVS_DATASET_VIEW_KIND_HOST_STANDARD = 3 | ||
| } cuvsDatasetViewKind_t; | ||
|
|
||
| /** | ||
| * @brief Owning padded dataset handle. | ||
| * | ||
| * `addr` points to C++ owning dataset storage managed by the C API. | ||
| */ | ||
| typedef struct { | ||
| uintptr_t addr; | ||
| void (*destroy_addr)(void*); | ||
| DLDataType dtype; | ||
| cuvsDatasetLayout_t layout; | ||
| } cuvsDatasetPadded; | ||
| typedef cuvsDatasetPadded* cuvsDatasetPadded_t; | ||
|
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. We discussed this offline- we should probably just make a single dataset struct and use the enums to parameterize it so that we know what kind to cast it to in the C++ layer. |
||
|
|
||
| /** | ||
| * @brief Owning standard dataset handle. | ||
| * | ||
| * `addr` points to C++ owning dataset storage managed by the C API. | ||
| */ | ||
| typedef struct { | ||
| uintptr_t addr; | ||
| void (*destroy_addr)(void*); | ||
| DLDataType dtype; | ||
| cuvsDatasetLayout_t layout; | ||
| } cuvsDatasetStandard; | ||
| typedef cuvsDatasetStandard* cuvsDatasetStandard_t; | ||
|
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. The two structs are similar, can't there be just one struct definition and two typedefs? They already represent the same thing.
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. Same with the view struct just below |
||
|
|
||
| /** | ||
| * @brief Non-owning dataset view handle. | ||
| * | ||
| * `addr` points to C API-owned metadata that references caller-provided tensor memory. The | ||
| * `kind` and `layout` fields identify the concrete host/device and standard/padded view type. | ||
| */ | ||
| typedef struct { | ||
| uintptr_t addr; | ||
| void (*destroy_addr)(void*); | ||
| cuvsDatasetViewKind_t kind; | ||
| DLDataType dtype; | ||
| cuvsDatasetLayout_t layout; | ||
|
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.
|
||
| } cuvsDatasetView; | ||
| typedef cuvsDatasetView* cuvsDatasetView_t; | ||
|
|
||
| /** | ||
| * @brief Typed aliases for padded and standard non-owning dataset views. | ||
| */ | ||
| typedef cuvsDatasetView cuvsDatasetPaddedView; | ||
| typedef cuvsDatasetPaddedView* cuvsDatasetPaddedView_t; | ||
| typedef cuvsDatasetView cuvsDatasetStandardView; | ||
| typedef cuvsDatasetStandardView* cuvsDatasetStandardView_t; | ||
|
|
||
| /** | ||
| * @brief Generic storage kind for operation-specific dataset storage. | ||
| */ | ||
| typedef enum { | ||
| CUVS_DATASET_STORAGE_KIND_EXTENDED = 0, | ||
| CUVS_DATASET_STORAGE_KIND_MERGED = 1 | ||
| } cuvsDatasetStorageKind_t; | ||
|
|
||
| /** | ||
| * @brief Generic opaque storage handle for dataset-backed operation outputs. | ||
| * | ||
| * Used by operations like CAGRA extend/merge where storage shape is identical | ||
| * but semantics differ by operation kind. | ||
| */ | ||
| typedef struct { | ||
| uintptr_t addr; | ||
| DLDataType dtype; | ||
| cuvsDatasetStorageKind_t kind; | ||
| } cuvsDatasetStorage; | ||
| typedef cuvsDatasetStorage* cuvsDatasetStorage_t; | ||
|
|
||
| typedef struct cuvsCagraIndex* cuvsCagraIndex_t; | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsDatasetMakeDevicePadded(cuvsResources_t res, | ||
| DLManagedTensor* dataset, | ||
| cuvsDatasetPadded_t* padded_dataset); | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsDatasetMakeHostPadded(cuvsResources_t res, | ||
| DLManagedTensor* dataset, | ||
| cuvsDatasetPadded_t* padded_dataset); | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsDatasetMakeDevicePaddedView(cuvsResources_t res, | ||
| DLManagedTensor* dataset, | ||
| cuvsDatasetPaddedView_t* padded_dataset); | ||
|
|
||
| /** | ||
| * @brief Create a non-owning device padded view handle from an owning device padded dataset. | ||
| * | ||
| * This is useful when APIs require a padded view handle (e.g. attach-for-search), while callers | ||
| * keep ownership in a padded dataset handle created by `cuvsDatasetMakeDevicePadded`. | ||
| * | ||
| * @param[in] padded_dataset owning device padded dataset handle | ||
| * @param[out] padded_view output padded view handle | ||
| */ | ||
| CUVS_EXPORT cuvsError_t cuvsDatasetMakeViewFromOwningPadded( | ||
| cuvsDatasetPadded_t padded_dataset, cuvsDatasetPaddedView_t* padded_view); | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsDatasetMakeHostPaddedView(cuvsResources_t res, | ||
| DLManagedTensor* dataset, | ||
| cuvsDatasetPaddedView_t* padded_dataset); | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsDatasetPaddedDestroy(cuvsDatasetPadded_t padded_dataset); | ||
| CUVS_EXPORT cuvsError_t cuvsDatasetStandardDestroy(cuvsDatasetStandard_t standard_dataset); | ||
| CUVS_EXPORT cuvsError_t cuvsDatasetPaddedViewDestroy(cuvsDatasetPaddedView_t padded_dataset); | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsDatasetMakeDeviceStandardView(cuvsResources_t res, | ||
| DLManagedTensor* dataset, | ||
| cuvsDatasetStandardView_t* standard_dataset); | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsDatasetMakeHostStandardView(cuvsResources_t res, | ||
| DLManagedTensor* dataset, | ||
| cuvsDatasetStandardView_t* standard_dataset); | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsDatasetStandardViewDestroy(cuvsDatasetStandardView_t standard_dataset); | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsMakeMergedStorage(cuvsResources_t res, | ||
| cuvsCagraIndex_t* indices, | ||
| size_t num_indices, | ||
| cuvsFilter filter, | ||
| cuvsDatasetStorage_t* merged_storage); | ||
|
|
||
| CUVS_EXPORT cuvsError_t cuvsDatasetStorageDestroy(cuvsDatasetStorage_t dataset_storage); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
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.
Instead of view kind containing both host and device for each dataset type (this is going to quickly become unmaintainable), please just define the accessor type (HOST and DEVICE) here and reuse the dataset layout enum above.