8000 Add pinned memory support to sparse COO/CSR/CSC/BSR/BSC tensors by pearu · Pull Request #129645 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Add pinned memory support to sparse COO/CSR/CSC/BSR/BSC tensors #129645

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

Closed
wants to merge 14 commits into from

Conversation

pearu
Copy link
Collaborator
@pearu pearu commented Jun 27, 2024

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported

  • sparse_xyz_tensor(indices, values, pin_memory=True)
  • sparse_xyz_tensor(indices, values).pin_memory()
  • sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())

Fixes #115330

Stack from ghstack (oldest at bottom):

cc @alexsamardzic @nikitaved @cpuhrsch @amjames @bhosmer @jcaip

@pearu pearu requested review from eqy, a team, albanD and soulitzer as code owners June 27, 2024 09:52
Copy link
pytorch-bot bot commented Jun 27, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/129645

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 58348cb with merge base bdd83c4 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the release notes: sparse release notes category label Jun 27, 2024
@pearu pearu marked this pull request as draft June 27, 2024 10:41
…nsors"

As in the title.

Fixes #115330




[ghstack-poisoned]
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




[ghstack-poisoned]
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




[ghstack-poisoned]
pearu added a commit that referenced this pull request Jun 27, 2024
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




[ghstack-poisoned]
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




[ghstack-poisoned]
@pearu pearu added the keep-going Don't stop on first failure, keep running tests until the end label Jun 28, 2024
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




[ghstack-poisoned]
pearu added a commit that referenced this pull request Jun 28, 2024
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




[ghstack-poisoned]
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




[ghstack-poisoned]
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




[ghstack-poisoned]
@pearu pearu marked this pull request as ready for review June 28, 2024 14:40
@pearu pearu requested a review from amjames June 28, 2024 14:40
Copy link
Collaborator
@amjames amjames left a comment

Choose a reason for hiding this comment

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

I see one major issue that should be addressed.

What should happen when one component tensor passed to _with_tensorsconstructors, but not all. In particular consider when thevalues` are pinned, but indices tensor(s) are not.

a = torch.randn(10, 10)
a[::2, ::2] = 0
sp1 = a.to_sparse_coo()
values = a._values().clone().pin_memory()
indices = a._indices()
sp2 = torch.sparse_coo_tensor(indices, values, size=(10, 10))

Here sp2.is_pinned() would return true, but sp2._indices().is_pinned() is false. This is inconsistent with

sp3 = sp1.pin_memory()

which also has sp3.is_pinned() True, but sp3._indices().is_pinned() is True. Inconsistency like this will be a pain point for some users.

I see two options:

  1. Expect this meta data field to match across members -> We should add this to the invariant checks, or enforce this by pinning out-of-sync members if any member is pinned in the constructors.
  2. Allow for these to be out-of-sync
    • sparse.is_pinned() should be a short hand for values.is_pinned() && indices.is_pinned() (and the plain/compressed indices for sparse compressed layouts) the same way that sparse.pin_memory() is short hand for pinning all member tensors.

Personally I think option 1) is better for the simplicity and I can't see a reason why one would want some members to be pinned while others are not.

@amjames amjames added the module: sparse Related to torch.sparse label Jun 28, 2024
@pearu
Copy link
Collaborator Author
pearu commented Jun 29, 2024

I see two options: ...

Registering a CPU tensor with CUDA is essentially a copy operation to another device (although the pinned tensor can still be accessed by CPU processes). In the case of sparse tensors, we don't allow indices and values to be on different devices: an error is raised when trying to create a sparse tensor from indices and values that have different devices.

I suggest that we treat pinned and non-pinned tensors as having different devices. So, when one tries to create a sparse tensor from indices and values that have different pinning state then an exception will be raised. This corresponds to the first part of option 1).

…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




cc alexsamardzic nikitaved cpuhrsch amjames bhosmer jcaip

[ghstack-poisoned]
pearu added a commit that referenced this pull request Jun 29, 2024
@pearu pearu requested a review from amjames June 29, 2024 07:53
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




cc alexsamardzic nikitaved cpuhrsch amjames bhosmer jcaip

[ghstack-poisoned]
pearu added a commit that referenced this pull request Aug 1, 2024
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




cc alexsamardzic nikitaved cpuhrsch amjames bhosmer jcaip

[ghstack-poisoned]
pearu added a commit that referenced this pull request Aug 1, 2024
…nsors"

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330




cc alexsamardzic nikitaved cpuhrsch amjames bhosmer jcaip

[ghstack-poisoned]
pearu added a commit that referenced this pull request Aug 1, 2024
@pearu
Copy link
Collaborator Author
pearu commented Aug 2, 2024

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 2, 2024
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

aartbik pushed a commit that referenced this pull request Aug 3, 2024
)

As in the title:

To register indices/values of a sparse XYZ tensor with CUDA, the following methods are supported
- `sparse_xyz_tensor(indices, values, pin_memory=True)`
- `sparse_xyz_tensor(indices, values).pin_memory()`
- `sparse_xyz_tensor(indices.pin_memory(), values.pin_memory())`

Fixes #115330

Pull Request resolved: #129645
Approved by: https://github.com/amjames, https://github.com/cpuhrsch, https://github.com/eqy
@github-actions github-actions bot deleted the gh/pearu/130/head branch September 2, 2024 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request keep-going Don't stop on first failure, keep running tests until the end Merged module: sparse Related to torch.sparse open source release notes: sparse release notes category topic: new features topic category
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants
0