4 ms·
Am I missing something? I was excited about other languages doing the same as Julia, but the first example for ClojureCUDA has (def kernel-source
by KenoFischer 8y ago
Am I missing something? I was excited about other languages doing the same as Julia, but the first example for ClojureCUDA has
(def kernel-source
"extern \"C\"
__global__ void increment (int n, float *a) {
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < n) {
a[i] = a[i] + 1.0f;
}
};")
Is there an example where the kernel is written in Clojure?
- dragandj 8y agoYou can of course create Clojure/lisp code that would generate kernel code, but I am strongly against it as the default option, since I find plain C much better suited to small kernels close to hardware (which are only a small proportion of the overall code) than either lisp or Julia. Please note that there is no need for out-of process compilation step. You compile this by calling a Clojure function, interactively from the REPL.
- KenoFischer 8y agoSure, but that's a completely separate thing from what Julia is doing here. The whole point of the GPU backend is that you get almost the full flexibility of the Julia language at your disposal, without having to fall back to C code. As a result, not only is your code more familiar to Julia programmers, but you also get to share large amounts of code between CPU/GPU/TPU. If all you're doing is super small kernels that may not matter much, but GPUs are so powerful these days that it's perfectly sensible to offload rather large programs that you may not want to write in C anymore.
- byt143 8y agoAlso that exact C example can be written almost verbatim in Julia, so C isn't "better suited" for even these small kernels, because one can drop to low level with even clearer syntax in julia
- 3rdAccount 8y agoIt's not just easier to read for Julia programmers. Any pythonista can mostly read Julia without significant issue. They're both high level and syntactically similar enough. I know Python is a lot more OO, but when you're just writing a short script it looks a lot like Julia if Julia didn't need you to specify types.