[WIP] Clarify dataset ownership and allocation semantics#1738
[WIP] Clarify dataset ownership and allocation semantics#1738seunghwak wants to merge 5 commits intorapidsai:mainfrom
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
@cjnolet Let me know whether this PR aligns with what you are thinking. |
|
Hey @seunghwak, thank you for giving this some initial thought and sharing here. I think this is a good start. It might also be worth me mentioning some of the other dataset types that this design is going to prepare us for- in addition to the I wonder if maybe we should make the dataset memory type explicit too? ( The nice thing about the dataset abstraction is that it'll allow us to have the pq_dataset contain additoinal state like trained centroids and codebooks, which need to be passed along w/ the pq-encoded vectors because they are used to compute the distances. It's nice to have these things abstracted behind the dataset class so that, for example, we aren't having to provide additional additional overloads for each different combination we support- we can support a // create strided dataset (zero-copy if aligned, throws if not)
auto dataset = make_strided_dataset_zerocopy(dataset_matrix.view());I wonder if maybe instead of |
Yes, if there is a need to support padded data set for host as well. I though the current strided_dataset is implicitly device-only, considering cuvs/cpp/include/cuvs/neighbors/common.hpp Line 165 in fcc5031 cuvs/cpp/include/cuvs/neighbors/common.hpp Line 267 in fcc5031 but if you see a need to support padded dataset for host data as well, I will explicitly create a class (or an alias like
You mean that we want to take a
No problem, I will update the function names. |
Initial attempt to address #1574 and #1571.
Currently,
indexconstructors accept anmdspanand internally invokemake_strided|aligned_datasetto construct astrided_datasetfrom input data with potentially unknown alignment. When the input is properly aligned, a zero-copy view is used; otherwise, an aligned copy is created. This implicit copy can unexpectedly double GPU memory usage, which may be surprising to API users.Current API
New API (explicitly create
strided_dataset)We deprecate the
indexconstructors that take devicemdspan(device_matrix_view) to avoid surprising implicit copy.In addition, this PR makes an initial attempt to update the
buildfunctions to acceptstrided_dataset, in addition tohost_matrix_view. At present, thebuildoverload that takesstrided_datasetsupports only iterative-CAGRA for initial graph construction. Supporting NN-descent or IVF-PQ is more involved, as these implementations assume a row-major layout; extending them to handle strided layouts would require more substantial code changes.Closes #1571
Closes #1574