-
Notifications
You must be signed in to change notification settings - Fork 143
[Java] Encapsulate on-heap float arrays into Dataset
#1024
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
[Java] Encapsulate on-heap float arrays into Dataset
#1024
Conversation
java/cuvs-java/src/main/java22/com/nvidia/cuvs/internal/ArrayDatasetImpl.java
Outdated
Show resolved
Hide resolved
java/cuvs-java/src/main/java22/com/nvidia/cuvs/internal/BruteForceIndexImpl.java
Outdated
Show resolved
Hide resolved
|
@chatman @mythrocks wdyt? |
DatasetDataset
|
I added another commit 3f348c6 in which I reduce the scope for the Dataset/MemorySegment: I think there is no need to keep it around once the index is built, it is not referenced again (but keep me honest here and point out if I'm wrong!) |
Looking forward to reading/reviewing this next week. |
|
Thanks @ldematte. Looks good. I'll take a closer look at the scope of the
memory segment. I remember extending to scope of the memory segment to
closing it at index close due to some issues otherwise. I'll take another
look today to make sure that's not happening.
…On Fri, 20 Jun, 2025, 7:48 pm MithunR, ***@***.***> wrote:
*mythrocks* left a comment (rapidsai/cuvs#1024)
<#1024 (comment)>
@chatman <https://github.com/chatman> @mythrocks
<https://github.com/mythrocks> wdyt?
Looking forward to reading/reviewing this next week.
—
Reply to this email directly, view it on GitHub
<#1024 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDCR5EJPEHUHFBOVUN3AY33EQJZXAVCNFSM6AAAAAB7NK52OWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOJRHAYDEMBXG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yes please; it might be that the C++ side of things holds a reference to the input memory (wrapped and managed by the |
|
BTW, no hurry -- I wasn't aware you guys were off this week. This can wait till next week, no prob. |
Hey @chatman, I dug into the C and C++ implementations of |
|
Thanks a lot for looking deeper. This was precisely my concern, and thanks
for looking into it. @cjnolet might know for sure, but it would be pretty
safe to keep the scope tied up with the lifecycle of the index.
…On Thu, 26 Jun, 2025, 9:49 pm Lorenzo Dematté, ***@***.***> wrote:
*ldematte* left a comment (rapidsai/cuvs#1024)
<#1024 (comment)>
I'll take a closer look at the scope of the
memory segment. I remember extending to scope of the memory segment to
closing it at index close due to some issues otherwise.
Hey @chatman <https://github.com/chatman>, I dug into the C and C++
implementations of cuvsCagraBuild/cuvs::neighbors::cagra::build and a
pointer to the original dataset seems to be passed down and
retained/referenced by Index. *Seems* because the DLTensor gets
transformed to a mdspan, but I think it's just wrapped and no copy happens
there, so we need to retain the dataset memorysegment "alive" for the
lifetime of the index. I'll change this PR to do that.
—
Reply to this email directly, view it on GitHub
<#1024 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDCR5DADMYMRXZJVYNZUX33FQMQ5AVCNFSM6AAAAAB7NK52OWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMBZGA2DCNBWGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
java/cuvs-java/src/main/java22/com/nvidia/cuvs/internal/BruteForceIndexImpl.java
Outdated
Show resolved
Hide resolved
java/cuvs-java/src/main/java22/com/nvidia/cuvs/internal/CagraIndexImpl.java
Show resolved
Hide resolved
java/cuvs-java/src/main/java22/com/nvidia/cuvs/internal/CagraIndexImpl.java
Outdated
Show resolved
Hide resolved
DatasetDataset
👍 |
ChrisHegarty
left a comment
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.
LGTM. This is a nice simplification.
| mvn clean integration-test -Dit.test=com.nvidia.cuvs.CagraBuildAndSearchIT | ||
| ``` | ||
| or, for a single test: | ||
| ```sh | ||
| mvn clean integration-test -Dit.test=com.nvidia.cuvs.CagraBuildAndSearchIT#testMergeStrategies |
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.
👍
mythrocks
left a comment
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.
LGTM! Will schedule to merge this once #1045 is merged.
…array-dataset # Conflicts: # java/cuvs-java/src/main/java22/com/nvidia/cuvs/internal/BruteForceIndexImpl.java # java/cuvs-java/src/main/java22/com/nvidia/cuvs/internal/CagraIndexImpl.java
|
@mythrocks rebased on top of #1045 and ready to go! 👍 |
DatasetDataset
|
/ok to test 3b36197 |
|
/ok to test b0b3552 |
|
I just resolved the conflicts from #1081. This should go in after CI passes. |
|
/merge |
f02ee48
into
rapidsai:branch-25.08
|
Thank you for this change, @ldematte. This has been merged. |
This PR adds the ability to define a Dataset directly over a MemorySegment, "wrapping" it instead of allocating a new one. - Depends on #1033 and #1024 - ~~The new API has a `Object memorySegment` parameter, as we target Java 21 for the API (but 22 for the implementation); it works but it's definitely a hack and we need to sort this out~~ - As discussed, we want to keep targeting Java 21 for the API. This means the API will return a `MethodHandle`, and the Java 22 implementation will use it to return a factory method to build a Dataset from a MemorySegment. - This factory method can then be used as shown in the tests (see the `DatasetHelper` convenience class/method). - Benchmarks show a sizeable speedup -- it is still tiny related to the "big picture" (index build time), but there is an improvement and above all we avoid a whole new copy of the input data (halving the memory requirements). Fixes #698 Authors: - Lorenzo Dematté (https://github.com/ldematte) - MithunR (https://github.com/mythrocks) - Ben Frederickson (https://github.com/benfred) Approvers: - Chris Hegarty (https://github.com/ChrisHegarty) - MithunR (https://github.com/mythrocks) URL: #1034
This PR adds the ability to define a Dataset directly over a MemorySegment, "wrapping" it instead of allocating a new one. - Depends on rapidsai#1033 and rapidsai#1024 - ~~The new API has a `Object memorySegment` parameter, as we target Java 21 for the API (but 22 for the implementation); it works but it's definitely a hack and we need to sort this out~~ - As discussed, we want to keep targeting Java 21 for the API. This means the API will return a `MethodHandle`, and the Java 22 implementation will use it to return a factory method to build a Dataset from a MemorySegment. - This factory method can then be used as shown in the tests (see the `DatasetHelper` convenience class/method). - Benchmarks show a sizeable speedup -- it is still tiny related to the "big picture" (index build time), but there is an improvement and above all we avoid a whole new copy of the input data (halving the memory requirements). Fixes rapidsai#698 Authors: - Lorenzo Dematté (https://github.com/ldematte) - MithunR (https://github.com/mythrocks) - Ben Frederickson (https://github.com/benfred) Approvers: - Chris Hegarty (https://github.com/ChrisHegarty) - MithunR (https://github.com/mythrocks) URL: rapidsai#1034
This PR is a follow-up from rapidsai#902. Still WIP (see self-comments on the changes) but I'd like some early feedback. Authors: - Lorenzo Dematté (https://github.com/ldematte) - MithunR (https://github.com/mythrocks) Approvers: - Chris Hegarty (https://github.com/ChrisHegarty) - MithunR (https://github.com/mythrocks) URL: rapidsai#1024
This PR adds the ability to define a Dataset directly over a MemorySegment, "wrapping" it instead of allocating a new one. - Depends on rapidsai#1033 and rapidsai#1024 - ~~The new API has a `Object memorySegment` parameter, as we target Java 21 for the API (but 22 for the implementation); it works but it's definitely a hack and we need to sort this out~~ - As discussed, we want to keep targeting Java 21 for the API. This means the API will return a `MethodHandle`, and the Java 22 implementation will use it to return a factory method to build a Dataset from a MemorySegment. - This factory method can then be used as shown in the tests (see the `DatasetHelper` convenience class/method). - Benchmarks show a sizeable speedup -- it is still tiny related to the "big picture" (index build time), but there is an improvement and above all we avoid a whole new copy of the input data (halving the memory requirements). Fixes rapidsai#698 Authors: - Lorenzo Dematté (https://github.com/ldematte) - MithunR (https://github.com/mythrocks) - Ben Frederickson (https://github.com/benfred) Approvers: - Chris Hegarty (https://github.com/ChrisHegarty) - MithunR (https://github.com/mythrocks) URL: rapidsai#1034
This PR tidies up the lifecycle of `MemorySegment`s by using specific confined `Arena`s where possible, and specific index-bound `Arena`s where the lifetime needs to be bound to the lifetime of an index. It addresses all remaining usages of `CuVSResources#arena` after #1024 and #1045; as such, we can remove `CuVSResources#arena` completely, and force native memory usages to be tracked and dealt with specifically. This would towards the goal of #1037 Authors: - Lorenzo Dematté (https://github.com/ldematte) - MithunR (https://github.com/mythrocks) - Ben Frederickson (https://github.com/benfred) Approvers: - Chris Hegarty (https://github.com/ChrisHegarty) - MithunR (https://github.com/mythrocks) URL: #1069
This PR tidies up the lifecycle of `MemorySegment`s by using specific confined `Arena`s where possible, and specific index-bound `Arena`s where the lifetime needs to be bound to the lifetime of an index. It addresses all remaining usages of `CuVSResources#arena` after rapidsai#1024 and rapidsai#1045; as such, we can remove `CuVSResources#arena` completely, and force native memory usages to be tracked and dealt with specifically. This would towards the goal of rapidsai#1037 Authors: - Lorenzo Dematté (https://github.com/ldematte) - MithunR (https://github.com/mythrocks) - Ben Frederickson (https://github.com/benfred) Approvers: - Chris Hegarty (https://github.com/ChrisHegarty) - MithunR (https://github.com/mythrocks) URL: rapidsai#1069
This PR is a follow-up from rapidsai#902. Still WIP (see self-comments on the changes) but I'd like some early feedback. Authors: - Lorenzo Dematté (https://github.com/ldematte) - MithunR (https://github.com/mythrocks) Approvers: - Chris Hegarty (https://github.com/ChrisHegarty) - MithunR (https://github.com/mythrocks) URL: rapidsai#1024
This PR adds the ability to define a Dataset directly over a MemorySegment, "wrapping" it instead of allocating a new one. - Depends on rapidsai#1033 and rapidsai#1024 - ~~The new API has a `Object memorySegment` parameter, as we target Java 21 for the API (but 22 for the implementation); it works but it's definitely a hack and we need to sort this out~~ - As discussed, we want to keep targeting Java 21 for the API. This means the API will return a `MethodHandle`, and the Java 22 implementation will use it to return a factory method to build a Dataset from a MemorySegment. - This factory method can then be used as shown in the tests (see the `DatasetHelper` convenience class/method). - Benchmarks show a sizeable speedup -- it is still tiny related to the "big picture" (index build time), but there is an improvement and above all we avoid a whole new copy of the input data (halving the memory requirements). Fixes rapidsai#698 Authors: - Lorenzo Dematté (https://github.com/ldematte) - MithunR (https://github.com/mythrocks) - Ben Frederickson (https://github.com/benfred) Approvers: - Chris Hegarty (https://github.com/ChrisHegarty) - MithunR (https://github.com/mythrocks) URL: rapidsai#1034
This PR is a follow-up from #902.
Still WIP (see self-comments on the changes) but I'd like some early feedback.