Skip to content

Conversation

@ldematte
Copy link
Contributor

@ldematte ldematte commented Sep 13, 2025

This PR moves toHost/toDevice operations to CuVSMatrix in order to uniform them; implementations then do not need to worry or perform checks on the input type, but simply accept any CuVSMatrix and then "request" the type they want or need (no ifs, custom cudaAlloc or cudaMemcpy operations needed):

CuVSDeviceMatrix matrix = input.toDevice(resources);

If the source matrix is a CuVSHostMatrix, device memory will be allocated and data will be copied; if the source matrix is a already a CuVSDeviceMatrix, a (wrapped) reference to the original data is returned (very fast, no copies, no additional allocations).

The wrapper is currently implemented to follow C++ weak_ptr semantics: it delegates everything to the wrapped matrix, the only difference is on close() (which is a no-op in the wrapper, as you'd expect). The lifecycle of the data follows the one of the original matrix, the "weak" delegate does not influence it in any way. This way the caller can handle it uniformly (e.g. with try-with-resources), without side effects on the original matrix (which lifecycle will be already handled by its owner).

An alternative would be to give this C++ shared_ptr semantics, making it reference counted. I think this would be more complex and not necessary, but let me know.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Sep 13, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ldematte ldematte changed the title [WIP][Java] Uniform toHost/toDevice to work across all CuVSMatrix classes [Review][Java] Uniform toHost/toDevice to work across all CuVSMatrix classes Sep 16, 2025
@ldematte ldematte marked this pull request as ready for review September 16, 2025 14:16
@ldematte ldematte requested a review from a team as a code owner September 16, 2025 14:16
@mythrocks
Copy link
Contributor

/ok to test f92be71

@mythrocks mythrocks added breaking Introduces a breaking change improvement Improves an existing functionality labels Sep 17, 2025
@mythrocks
Copy link
Contributor

/ok to test 71fead2

@mythrocks
Copy link
Contributor

/ok to test fc01ca2

@mythrocks mythrocks changed the title [Review][Java] Uniform toHost/toDevice to work across all CuVSMatrix classes [Java] Uniform toHost/toDevice to work across all CuVSMatrix classes Sep 17, 2025
Copy link
Contributor

@mythrocks mythrocks left a comment

Choose a reason for hiding this comment

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

Thank you for making the fix.

This PR makes a good change. 👍

@mythrocks
Copy link
Contributor

/merge

@rapids-bot rapids-bot bot merged commit d5edf12 into rapidsai:branch-25.10 Sep 17, 2025
84 checks passed
@ldematte
Copy link
Contributor Author

This PR makes a good change. 👍

Thank you! :)

@ldematte ldematte deleted the java/seamless-matrix-type-change branch September 17, 2025 14:52
rapids-bot bot pushed a commit that referenced this pull request Sep 24, 2025
…1361)

This PR extract an internal interface that is used as a base to implement all internal CuVSMatrix types; the interface introduces commonly used field accessors like `memorySegment()` and `toTensor()` that we do not want/could not appear on the public interface (e.g. because they expose or require Panama types or internal types).

The new interface is implemented by all concrete matrix types, closing a gap that we had in #1328 (which I realized while working on separate PRs like #1283)

Follow-up of #1328

Authors:
  - Lorenzo Dematté (https://github.com/ldematte)

Approvers:
  - Ben Frederickson (https://github.com/benfred)

URL: #1361
enp1s0 pushed a commit to enp1s0/cuvs that referenced this pull request Oct 22, 2025
…apidsai#1361)

This PR extract an internal interface that is used as a base to implement all internal CuVSMatrix types; the interface introduces commonly used field accessors like `memorySegment()` and `toTensor()` that we do not want/could not appear on the public interface (e.g. because they expose or require Panama types or internal types).

The new interface is implemented by all concrete matrix types, closing a gap that we had in rapidsai#1328 (which I realized while working on separate PRs like rapidsai#1283)

Follow-up of rapidsai#1328

Authors:
  - Lorenzo Dematté (https://github.com/ldematte)

Approvers:
  - Ben Frederickson (https://github.com/benfred)

URL: rapidsai#1361
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Introduces a breaking change improvement Improves an existing functionality

Development

Successfully merging this pull request may close these issues.

2 participants