by unfamiliar · 11y ago · 0 comments
using CUDA
# define a kernel
@kernel function kernel_vadd(a, b, c)
i = blockId_x() + (threadId_x()-1) * numBlocks_x()
c[i] = a[i] + b[i]
end
# create some data
dims = (3, 4)
a = round(rand(Float32, dims) * 100)
b = round(rand(Float32, dims) * 100)
c = Array(Float32, dims)
# execute!
@cuda kernel_vadd(CuIn(a), CuIn(b), CuOut(c))
# verify
@show a+b == c
i.e. no set up, no "cuda context" (whatever that is), and no tear down afterwards. I understand that manual memory management is almost necessary with this application, but it seems that most of it could be automated in the most common case of "I have a couple of large arrays and a few operations I want to perform."Currently supports both including multithreading. Its just he unified interface that is in the works.
More involved example using a neural network: http://code.cogbits.com/wiki/doku.php?id=tutorial_cuda
https://github.com/takagi/cl-cuda/blob/master/examples/vecto...
I though that Julia had macros, so I don't understand why what you propose is not possible (note to self: find time to learn Julia).
For single GPU stuff, I find myself writing the performance critical kernels in cuda, and using thrust for nearly all the easy stuff.