-
Notifications
You must be signed in to change notification settings - Fork 24.2k
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
Conversation
[ghstack-poisoned]
🔗 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 FailuresAs of commit 58348cb with merge base bdd83c4 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…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]
…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]
…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]
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.
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 the
values` 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:
- 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.
- Allow for these to be out-of-sync
sparse.is_pinned()
should be a short hand forvalues.is_pinned() && indices.is_pinned()
(and the plain/compressed indices for sparse compressed layouts) the same way thatsparse.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.
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]
…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]
…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]
…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]
@pytorchbot merge |
Merge startedYour 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 |
) 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
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