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
cupy raw kernel cannot handle view of cupy ndarray #7267
Comments
This is expected. When you only pass a raw pointer to a kernel, it's assumed that the array is contiguous in memory. If you want to handle views, you should also pass the array shape/strides and distribute the workload to each thread yourself. CuPy has the machinery for doing so, but I am not sure if they are considered public API. If it's simple Elementwise operation, it's better to just use ElementwiseKernel instead. |
Thank you @leofang for your comments! I didn't find the public API in cupy document so I will run deep copy before feeding my RawKernel. I want each thread work on a small patch of a big array. I didn't find the way to use ElementwiseKernel. If there are any smart way to achieve, please let me know! I appreciate it! |
It's unclear to me what you intended to do. If you can show us a version that you expect to work with contiguous arrays, we might be able to suggest alternative approaches. |
Thanks for your nice help! I finally find a way to implant it with elementwise kernel with the I wonder if there is any easier way to index a multidimensional array? For example, the element of the diagonal of a N*N matrix |
Glad to know it works for you! AFAIK you need to use 1D indexing with ElementwiseKernel. It has to do how the internal machinery is designed to handle array views. Moreover, 1D indexing should be familiar for most C/C++ programmers 🙂 |
Description
When feeding a view of cupy ndarray into a kernel, for example, a slice of a big ndarray, the result looks like the kernel read the original big ndarray not a slice of it.
To Reproduce
When call the kernel:
It will print:
But if feed a slice of
x
:It also print:
which is not as wanted.
However, if a copy is fed:
It print:
as expected.
Installation
Conda-Forge (
conda install ...
)Environment
Additional Information
No response
The text was updated successfully, but these errors were encountered: