4 ms·
>Writing a fast CUDA kernel requires quite a bit of low level GPU knowledge False. Not in Julia: https://juliagpu.gitlab.io/KernelAbstractions.jl/ https://juli
by amkkma 6y ago
>Writing a fast CUDA kernel requires quite a bit of low level GPU knowledge
False. Not in Julia: https://juliagpu.gitlab.io/KernelAbstractions.jl/ https://juliagpu.gitlab.io/KernelAbstractions.jl/
https://github.com/mcabbott/Tullio.jl https://github.com/mcabbott/Tullio.jl
- ChrisRackauckas 6y agoTo share the details, here's a post demonstrating Tullio.jl, a Julia-based higher order tensor library, is faster than OpenBLAS for gemm kernels: https://discourse.julialang.org/t/realistically-how-close-is-gaius-jl-to-becoming-a-full-replacement-for-blas-in-julia/42780/5 https://discourse.julialang.org/t/realistically-how-close-is... And PaddedMatrices.jl is another example: https://discourse.julialang.org/t/ann-paddedmatrices-jl-julia-blas-and-partially-sized-arrays/38215 https://discourse.julialang.org/t/ann-paddedmatrices-jl-juli... So there isn't just one example but multiples at this point. RecursiveFactorization's `lu` tends to perform better than MKL for small matrices and this is what we use in the differential equation solvers when there are <100 ODEs. That's all on CPUs though. KernelAbstractions.jl is the GPU version and that's still being constructed but moving strong.
- amkkma 6y agoFor the person who downvoted me, care to refute my examples?
- p1esk 6y agoI haven't downvoted you, but from KernelAbstractions.jl docs it's not clear you will be able to write a fast kernel (emphasis on fast) without having as much GPU/CUDA knowledge as what's required to write the same fast kernel in CUDA. I might be wrong, and if so that would be great. Here's an example: not long ago I needed a fast GPU implementation of numpy.unpackbits. I can do it in Pytorch, but it's slow and it wastes a ton of memory. So, my question is: can I write it in Julia as efficiently as I can do it in CUDA? If yes, will it be easier to do so?
- snicker7 6y agoKernelAbstractions.jl has some simple examples in its repo [^0]. The API looks simple and elegant. Code looks like regular Julia code. Documentation well behind CUDA, of course. [^0]: https://github.com/JuliaGPU/KernelAbstractions.jl/blob/master/examples/naive_transpose.jl https://github.com/JuliaGPU/KernelAbstractions.jl/blob/maste...
- ChrisRackauckas 6y agoThe code is essentially just Julia code: https://juliagpu.gitlab.io/KernelAbstractions.jl/examples/naive_transpose/ https://juliagpu.gitlab.io/KernelAbstractions.jl/examples/na... and you get ~60% of the best known CUDA implementation on that test: https://juliagpu.gitlab.io/KernelAbstractions.jl/examples/performance/ https://juliagpu.gitlab.io/KernelAbstractions.jl/examples/pe... Not perfect but not awful.
- p1esk 6y agoI’m sorry, what does it have to do with my question? I gave a specific example where I couldn’t get what I needed from Pytorch. Would Julia be any different in this situation?
- dklend122 6y agoIt answers your question because it's a specific case of KA's compile structured loops with annotations to low level CUDA code. If you could express the problem in generalized index notation, tullio.jl is an even higher level abstraction that uses KA I don't know about the numpy function you mentioned, but here's a KA matmul. Definitely doesn't look like it has any CUDA specific things. Just a regular loop with some restrictions @kernel function matmul_kernel!(a, b, c) i, j = @index(Global, NTuple) # creating a temporary sum variable for matrix multiplication tmp_sum = zero(eltype(c)) for k = 1:size(a)[2] tmp_sum += a[i,k] * b[k, j] end c[i,j] = tmp_sum end Wish I had time to write the code and compare to pytorch for you though
- 6y ago