Skip to content
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

Support conversion to/via pytorch #20

Open
sk1p opened this issue Aug 25, 2023 · 1 comment
Open

Support conversion to/via pytorch #20

sk1p opened this issue Aug 25, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@sk1p
Copy link
Member

sk1p commented Aug 25, 2023

The sparse support in pytorch is still in beta, but as this package also supports CPU<->GPU conversions for dense data, it makes sense to add pytorch support here. Using pytorch to efficiently transfer the building blocks of sparse arrays (indptr, indices, values) could also be interesting.

One argument is that pytorch supports efficient CPU->GPU transfers via pinned memory, which are lacking in cupy. Here the transfer in cupy:

image

(cell 88 is the interesting one - repeatedly transferring data and reducing it on the GPU is our use case, often in a single pass. Cell 89 then shows that running multiple kernels over the data is very efficient, too)

Same with torch and pinned tensors:

image

That's a factor of ~2.6 difference in time to completion, most of the difference being useless copying on the CPU.

Until this is improved in cupy, going via pytorch may be a valuable addition. We can also add torch<>cupy conversions, via the __cuda_array_interface__.

Using managed memory / unified memory / mapped arrays (or how you want to call it) is also an option - but transfers the array on each use. So it would only be a win for single-pass operations. Here implemented using numba.cuda.mapped_array:

image

Relevant cupy issues and comments:

@sk1p
Copy link
Member Author

sk1p commented Nov 3, 2023

Ongoing work in cupy/cupy#7939

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant