Julia CUDA: UndefVarError: parameters not defined

Viewed 292

I have a program for doing Fourier series and I wanted to switch to CuArrays to make it faster. The code is as follows (extract):

#Arrays I want to use
coord = CuArray{ComplexF64,1}(complex.(a[:,1],a[:,2]))
t=CuArray{Float64,1}(-L:(2L/(N-1)):L)

#Array of indexes in the form [0,1,-1,2,-2,...]
n=[((-1)^i)div(i,2) for i in 1:grado]

#Array of functions I need for calculations
base= [x -> exp(π * im * i * x / L) / L for i in n]


base[i](1.)                       #This line is OK
base[i](-1:.1:1)                  #This line is OK
base[i].(t)                       #This line gives error!
base[i].(CuArray{Float64,1}(t))   #This line gives error!

And the error is:

GPU broadcast resulted in non-concrete element type Any.
This probably means that the function you are broadcasting contains an error or type instability.

If I change it like this

base= [(x::Float64) -> (exp(π * im * i * x / L) / L)::ComplexF64 for i in n]

the same lines still give error, but the error now is:

UndefVarError: parameters not defined

Any idea how I could fix this? Thank you in advance!

Package information:

(@v1.6) pkg> st CUDA
      Status `C:\Users\marce\.julia\environments\v1.6\Project.toml`
  [052768ef] CUDA v2.6.2

P.S.: This other function has the same problem:

function integra(inizio, fine, arr)
    N=size(arr,1)
    h=(fine-inizio)/N
    integrale=sum(arr)
    integrale -= (first(arr)+last(arr))/2
    integrale *= h
end

L=2
integra(-L,L,coord)
1 Answers

The first and easier problem is that you should take care to declare global variables to be constant so that the compiler can assume a constant type: const L = 2. A mere L = 2 allows you to do something like L = SomeOtherType(), and if that type can be Anything, so must the return type of your functions. On the CPU that's only a performance hit, but it's a no-no for the GPU. If you actually want L to vary in value, pass it in as an argument so the compiler can still infer types within a function.

Your ::ComplexF64 assertion did actually force a concrete return type, though the middle of the function is still type unstable (check with @code_warntype). The second problem you ran into after that patch was probably caused by this recently patched conflict between ExprTools.jl and LLVM.jl. Seems like you just need to update the packages or maybe reinstall them.

Related