-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
unnable to wrap function with da.as_gufunc for cupy array #275
Comments
Can you provide the full error traceback (i.e. everything else that gets printed above that Also, just to check, can you run your gpu function on a single cupy input array? |
executing:
results
Execution the same function without dask annotation
on a single image cupy array works without problem. But I noticed interesting thing. Function wrapped with
gives the following output: |
Did a bit of digging here, and I think it's possible the two I tried a quick test to check this theory, replacing |
I think we should transfer this issue to the main dask repository, for two reasons:
@jakirkham can you transfer this issue across to dask/dask? (Apparently you have to have write access to transfer issues, and I have "triage" level access instead) |
Issue summaryDask generalized ufuncs do not work correctly when given Dask arrays containing cupy chunks. Minimal reproducible exampleYou can run this quick test on Google Colab, if you don't have a GPU on your local machine.
I used this docstring example to make a minimal, reproducible test. It works as expected with a numpy backed dask array: import dask.array as da
import numpy as np
def outer_product(x, y):
return np.einsum("i,j->ij", x, y)
a = da.random.normal(size=(20,30), chunks=(10, 30))
b = da.random.normal(size=(10, 1,40), chunks=(5, 1, 40))
c = da.apply_gufunc(outer_product, "(i),(j)->(i,j)", a, b, vectorize=True)
c.compute().shape
# Expected output: (10, 20, 30, 40)
# Works as expected Fails with a cupy backed dask array: import dask.array as da
import cupy as cp
def outer_product(x, y):
return cp.einsum("i,j->ij", x, y)
data_a = cp.random.normal(size=(20,30))
a = da.from_array(data_a, chunks=(10, 30))
data_b = cp.random.normal(size=(10, 1,40))
b = da.from_array(data_b, chunks=(5, 1, 40))
c = da.apply_gufunc(outer_product, "(i),(j)->(i,j)", a, b, vectorize=True)
c.compute().shape
# Expected output: (10, 20, 30, 40)
# TypeError: Implicit conversion to a NumPy array is not allowed. Please use `.get()` to construct a NumPy array explicitly. Notably, this other docstring example does work with a dask array containing cupy chunks. This example does not use the HypothesisThere are several lines in dask/array/gufunc.py that have numpy specific functions What we've tried so farTo test this idea, I tried switching out the Unfortunately, cupy gives me this error:
See here in the cupy source code. What to do next?We could make a feature request issue in the cupy repository, for supporting the If that was implemented, Dask could then consider replacing the three numpy-specific lines in dask/array/gufunc.py with some sort of dispatching solution, so that In the meantime, @lrlunin might investigate if there's a way to avoid using |
If I understand your problem correctly, one possible workaround might be to use da.map_blocks (possibly in combination with the |
Created issue at dask/dask#9714 (I know this is only 4 days since my last comment and two of them were the weekend. But I figured I might forget to check back in on this, so it might be best if I did it now while I remember) |
Describe the issue:
I was happy to use
dask-image
with processing many images with CPU. Now I want to look whether this task can be rather accelerated with GPU. Previously I defined my custom function in this way:and applied it to images loaded with
dask_image.imread.imread("...", arraytype="numpy" )
and it was perfekt.Now I loading my images with
cp_images = dask_image.imread.imread("...", arraytype="cupy" )
and have a python function which doing some sort of complex things inside using GPU-only functions inside.When now I try to execute the following code:
or either apply more functions at the end, for example:
I will get an error:
TypeError: Implicit conversion to a NumPy array is not allowed. Please use `.get()` to construct a NumPy array explicitly.
It seems like dask inside tries to handle the array as numpy array despite it is cupy array. I would also ask whether my approach is correct in a sense of CUDA architecture. When I executing a cupy function it will work only in a "single core mode" on the GPU, right? I mean that GPU doesn't parallelize it itself and I need to run more instances to get this kind of "GPU multicore supremacy" with all these 2000+ CUDA cores on my GPU. I would be very thankful if you correct me and tell what the right way would be.
Thank you so much for your beautiful project and nice code!
Environment:
The text was updated successfully, but these errors were encountered: