4 ms·
Since I only have one GPU usually, I'm still waiting for the day I can do this: using CUDA # define a kernel @kernel function kernel_vadd(a, b, c)
by unfamiliar 12y ago
Since I only have one GPU usually, I'm still waiting for the day I can do this:
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."
- th0ma5 12y agoI have seen a couple of Clojure based GPU compilers, although they seemed to be sort of proof-of-concepts, and I'm not sure how general purpose they were. It would be nice to possibly get out of the mode of it being a whole other computer and compiler, but maybe that distinction is for the best for the time being.
- Lofkin 12y agoWriting backend agnostic code (CPU and GPU) jitted to fast LLVM is on the roadmap for python's Numba: https://github.com/numba/numba/issues/545 https://github.com/numba/numba/issues/545 Currently supports both including multithreading. Its just he unified interface that is in the works.
- jtth 12y agoYou can do that in Mathematica. http://www.wolfram.com/products/cuda-opencl-programming-mathematica.html http://www.wolfram.com/products/cuda-opencl-programming-math...
- zevets 12y agoHave you tried thrust? For a limited but very useful set of operations, it is nearly that painless, as long as you don't mind a generous helping of C++ template boilerplate. http://thrust.github.io/ http://thrust.github.io/ For single GPU stuff, I find myself writing the performance critical kernels in cuda, and using thrust for nearly all the easy stuff.
- tabacof 12y agoTorch7 has amazing GPU support. If you wanna send a tensor (array) to the GPU, you just type array:cuda(). All operations you do from now on will be on the GPU. More involved example using a neural network: http://code.cogbits.com/wiki/doku.php?id=tutorial_cuda http://code.cogbits.com/wiki/doku.php?id=tutorial_cuda
- deleted 12y ago[deleted]
- ICWiener 12y agoInstead of @kernel and @cuda, you might want to use defkernel and with-cuda... See the example files for cl-cuda: https://github.com/takagi/cl-cuda/blob/master/examples/vector-add.lisp 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).
- maleadt 12y agoIt is definitely possible to do that in Julia. The reason a didn't yet is purely a manner of priorities, I first focused on wrapping the basic primitives (calling a kernel, marshalling arguments, etc) in a user-friendly way.