DaggerGPU.jl icon indicating copy to clipboard operation
DaggerGPU.jl copied to clipboard

Usage example

Open RomeoV opened this issue 1 year ago • 2 comments

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 avatar Dec 13 '23 20:12 RomeoV

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 avatar Dec 13 '23 20:12 RomeoV

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 avatar Dec 13 '23 20:12 RomeoV