You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am trying to write a matvec kernel with shared memory, it works for CUDA backend. However, it results in an error when switched to CPU backend:
ERROR: LoadError: UndefVarError: `j` not defined in `Main`
Stacktrace:
[1] cpu_matvec_kernel!
How to fix it? many thanks.
The julia script is shown below:
using KernelAbstractions
using CUDA
using Test
@kernelfunctionmatvec_kernel!(output, @Const(A), @Const(b))
I =@index(Global, Linear)
I =div(I-1, 32) +1
idx =@index(Local, Linear)
i = (idx -1) %32+1#local index within the wrap
cache_size =@uniform@groupsize()
cache =@localmemeltype(output) cache_size
N =size(A, 2)
sum =zero(eltype(output))
@inboundsbeginfor J = i:32:N
sum += A[I, J] * b[J]
end
cache[idx] = sum
end@synchronize
j::Int=16while j >0if i <= j
@inbounds cache[idx] += cache[idx + j] # can not find j for cpu backendend@synchronize
j = j ÷2endif i ==1@inbounds output[I] = cache[idx]
endendfunctionmatvec!(output, A, b)
backend = KernelAbstractions.get_backend(A)
kernel! =matvec_kernel!(backend, 256)
kernel!(output, A, b; ndrange=32*size(A, 1))
end
m, n =2^10, 2^10
A = CUDA.rand(Float32, m, n)
b = CUDA.rand(Float32, n)
output = CUDA.rand(Float32, m)
matvec!(output, A, b)
@testisapprox(output, A * b)
matvec!(Array(output), Array(A), Array(b))
Hi, I am trying to write a matvec kernel with shared memory, it works for CUDA backend. However, it results in an error when switched to CPU backend:
How to fix it? many thanks.
The julia script is shown below:
The versioninfo() gives:
The text was updated successfully, but these errors were encountered: