JuliaGPU / CUDAnative.jl

Julia support for native CUDA programming
https://juliagpu.org/cuda/
Other
392 stars 55 forks source link

Is there a `@cushow` macro? #633

Closed jw3126 closed 4 years ago

jw3126 commented 4 years ago

I am new to gpu programming and think that at least for me a gpu analog of @show macro would be convenient for debugging and understanding how simple gpu programs work. Does such a macro exist? If not would a PR be welcome?

maleadt commented 4 years ago

What do you expect that macro to do; print on the GPU? We have @cuprintln for that, which is much more restricted in the types it can print; a GPU-compatible version of @show would require show which is currently not possible (we can't use Base formatting functionality because we don't support String or IO).

jw3126 commented 4 years ago

I was imagining that it expands to something like this:

@cushow x
@cuprintln "x  = $x"

So same restrictions on types as @cuprintln.

maleadt commented 4 years ago

https://github.com/JuliaLang/julia/blob/b49d5ba3952bb1ce03ec55ab7ce0fa1cebd344fb/base/compiler/ssair/driver.jl#L8-L10 looks like a good implementation then :-) Want to create a PR with some tests?

jw3126 commented 4 years ago

Yes I want to do a PR.

jw3126 commented 4 years ago

I have trouble setting up dev version CUDAnative. If I do julia> using Pkg; pkg"dev CUDAnative"; using CUDAnative I get

...
[ Info: Precompiling CUDAnative [be33ccc6-a3ff-5ff2-a52e-74243cff1e17]
ERROR: LoadError: LoadError: UndefVarError: CompositeCompilerTarget not defined
jw3126 commented 4 years ago

The following works with the stable version of CUDAnative. Any hints on the problem with the dev version would be great.

macro cushow(ex)
    val = gensym("val")
    s = string(ex)
    quote
        $val = $(esc(ex))
        CUDAnative.@cuprintln($(Expr(:string, s, " = ", val)))
        $val
    end
end
maleadt commented 4 years ago

Any hints on the problem with the dev version would be great.

You also need to install GPUCompiler from the appropriate branch (generally master). The manifest encodes all this information.