Hi there,
I hope this is not a duplicate. If so, please fill free to shit this post.
I’m relatively new to Julia. I currently working on a numerical project which I want to implement on the GPU. Therefore I’m using the Julia CUDA libraries.
I want to create some initial date using my Nvidia-GPU , so I execute the following lines of code:
using CuArrays
using CUDAnative
using CUDAdrv
using AbstractFFTs, FFTW
using LinearAlgebra
#custom kernels for GPU---------------------------------------------------------
function kernel_initial_psi(a,N,k)
j = (blockIdx().x - 1) * blockDim().x + threadIdx().x
k = (blockIdx().y - 1) * blockDim().y + threadIdx().y
l = (blockIdx().z - 1) * blockDim().z + threadIdx().z
if j <= size(a,1)
f(x) = CUDAnative.exp(x)
a[j , k, l]= f(-im*((j-N/2)*k[1]+ (k-N/2)*k[2]+(l-N/2)*k[3]))
end
return nothing
end
#Paramters----------------------------------------------------------------------
N=4 # size of spatial grid
k=[1.0,1.0,1.0] #inital wave direction
psi_int=CuArrays.cuzeros(ComplexF64, (N,N,N))
#Threads and Blocks-------------------------------------------------------------
dev = CuDevice(0)
max_threads = attribute(dev, CUDAdrv.MAX_THREADS_PER_BLOCK)
max = min(N, max_threads)
threads_x = min(max_threads, size(psi_int,3))
blocks = ceil.(Int, (size(psi_int,3), size(psi_int,4)) ./ threads)
#initial data-------------------------------------------------------------------
@cuda blocks=blocks threads=threads_x kernel_initial_psi(psi_int, N, k)
and obtain the following error message:
ERROR: LoadError: InvalidIRError: compiling kernel_initial_psi(CuDeviceArray{Complex{Float64},3,CUDAnative.AS.Global}, Int64, Array{Float64,1}) resulted in invalid LLVM IR
Reason: unsupported call to the Julia runtime (call to jl_apply_generic)
Stacktrace:
[1] f at C:\Users\Noobie\Documents\TESTJULIAGPU\inital_data.jl:14
[2] kernel_initial_psi at C:\Users\Noobie\Documents\TESTJULIAGPU\inital_data.jl:15
Stacktrace:
[1] check_ir(::CUDAnative.CompilerContext, ::LLVM.Module) at C:\Users\Noobie\.julia\packages\CUDAnative\Mdd3w\src\compiler\validation.jl:77
[2] compile(::CUDAnative.CompilerContext) at C:\Users\Noobie\.julia\packages\CUDAnative\Mdd3w\src\compiler\driver.jl:90
[3] #cufunction#110(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(cufunction), ::typeof(kernel_initial_psi), ::Type{Tuple{CuDeviceArray{Complex{Float64},3,CUDAnative.AS.Global},Int64,Array{Float64,1}}}) at C:\Users\Noobie\.julia\packages\CUDAnative\Mdd3w\src\compiler\driver.jl:38
[4] cufunction(::Function, ::Type) at C:\Users\Noobie\.julia\packages\CUDAnative\Mdd3w\src\execution.jl:237
[5] top-level scope at C:\Users\Noobie\.julia\packages\CUDAnative\Mdd3w\src\execution.jl:205
[6] top-level scope at gcutils.jl:87
[7] top-level scope at C:\Users\Noobie\.julia\packages\CUDAnative\Mdd3w\src\execution.jl:202
in expression starting at C:\Users\Noobie\Documents\TESTJULIAGPU\inital_data.jl:41
As I search through the community posts I found that the was a problem with calling Base. functions in CUDA kernels in the past. So I tried out to use the following workaround by defining “f(x) = CUDAnative.exp(x)” but it didn’t work either. My question is if I missed something during my coding or there is some other way to get this working.
Thanks