Can I use Julia to program my GPU & CPU?

4.1k views Asked by At

My system has graphics card. I do not play games.

I want to program some high performance computing stuff for fun.

Can I use JULIA lang to leverage my hardware?

3

There are 3 answers

1
suryakrupa On

YES!

Enter OpenCL.jl

*how to install?

Pkg.add("OpenCL"); 
Pkg.update()
  • Use the following link to check the various OPENCL compute platforms on your hardware

https://github.com/JuliaGPU/OpenCL.jl/blob/master/examples/performance.jl

1
James D On

CUDA is propietary for NVIDIA but is widely used in scientific computing. Julia has several CUDA related packages, but I've been using CUDArt which has been working quite well for me.

https://github.com/JuliaGPU/CUDArt.jl

Usually you have to manually free memory you allocate on the GPU, but this package has CudaArray classes that are registered with the Julia GC, so you don't have to worry about memory leaks. When your memory needs are more demanding you can of course manage the memory manually.

When you start writing your own kernels, it's also a snap to call them from Julia directly if you compile them to PTX (not to shared objects/dll's). You can actually live reload them within an existing Julia session if you approach it this way.

1
Matthias Winkelmann On

I'm successfully using the ArrayFire library using the Julia wrapper. It supports both CUDA and OpenCL (and CPU).

It's pretty easy to understand and use:

#Random number generation
a = rand(AFArray{Float64}, 100, 100) 
#Basic arithmetic operations
c = sin(a) + 0.5
d = a * 5

Here's a benchmark run:

julia> benchmark()
INFO: Warmup done!
INFO: Matmul
Time (CPU): 0.042887455
Time (GPU): 0.0417952754
INFO: FFT
Time (CPU): 0.074640831
Time (GPU): 0.009890463
INFO: Rand
Time (CPU): 0.089245094
Time (GPU): 0.0097255858
INFO: Vec sort
Time (CPU): 0.11730852
Time (GPU): 0.0384733068