The majority of the functionality for working with NVIDIA GPUs is contained in two Julia packages: CUDAnative and CuArrays. Both these packages can be installed using Julia's package manager. We also install the CUDAdrv package, which contains some tooling that we will use later, as shown in the following code:Â
julia> using Pkg
julia> Pkg.add("CUDAnative");
julia> Pkg.add("CuArrays");
julia> Pkg.add("CUDAdrv");
CUDAnative contains the basic building blocks of interfacing Julia code with the GPU. To see it in use, let's write the simplest possible function, printing a number, but executed on the GPU like so:
using CUDAnative
function cudaprint(n)
@cuprintf("Thread %ld prints: %ld\n",
threadIdx().x, n)
return
end
This is a regular Julia function, even though it uses some GPU...