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

Usage example #28

Open
RomeoV opened this issue Dec 13, 2023 · 2 comments · May be fixed by #29
Open

Usage example #28

RomeoV opened this issue Dec 13, 2023 · 2 comments · May be fixed by #29

Comments

@RomeoV
Copy link

RomeoV commented Dec 13, 2023

Hello, would it be possible to add a usage example? I couldn't find one here, nor in the Dagger.jl docs.

For example, let's say I have the following task:

# two large matrices
A = rand(1000, 1000)
B = rand(1000, 1000)
# move them to gpu and multiply there
A_gpu = CUDA.Matrix(A) 
B_gpu = CUDA.Matrix(B)
C_gpu = A_gpu*B_gpu
# move back to cpu to use there.
C = Matrix(C_gpu) 

Intuitively, with Dagger, I'd just try to write it like this:

# two large matrices
A = rand(1000, 1000)
B = rand(1000, 1000)
# move them to gpu and multiply there
A_gpu = Dagger.@spawn CUDA.Matrix(A) 
B_gpu = Dagger.@spawn CUDA.Matrix(B)
C_gpu = Dagger.@spawn A_gpu*B_gpu
# move back to cpu to use there.
C = Dagger.@spawn Matrix(C_gpu) 

What role does DaggerGPU.jl play here? It seems I could even do this with just Dagger.jl?

@RomeoV
Copy link
Author

RomeoV commented Dec 13, 2023

Trying out this code yields an error

julia> A_gpu = Dagger.@spawn CUDA.Matrix(A)
Error in eager scheduler:
MethodError: no method matching get_parent(::CUDAExt.CuArrayDeviceProc)

The Readme in this repo points in that direction

add DaggerGPU.CuArrayDeviceProc/DaggerGPU.ROCArrayProc/DaggerGPU.MtlArrayDeviceProc to your scheduler or thunk options (see Dagger.jl documentation for details on how to do this).

but it's not clear to me what to do, as the Dagger.jl docs have no mention of DaggerGPU arrays...

@RomeoV
Copy link
Author

RomeoV commented Dec 13, 2023

Actually, it seems DaggerGPU.CuArrayDeviceProc isn't even defined anymore...

However, I did find the following line in the tests:

https://github.com/JuliaGPU/DaggerGPU.jl/blob/319a71e44587dc0983dc4cd5c64f18d672a3e44d/test/runtests.jl#L83C1-L86C12

        c = Dagger.with_options(;scope=Dagger.scope(cuda_gpu=1)) do
            @test fetch(Dagger.@spawn isongpu(b))
            Dagger.@spawn sum(b)
        end

and indeed wrapping my code in this scope seems to do the trick.

RomeoV added a commit to RomeoV/DaggerGPU.jl that referenced this issue Dec 13, 2023
@RomeoV RomeoV linked a pull request Dec 13, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant