JuliaGPU / KernelAbstractions.jl

Heterogeneous programming in Julia
MIT License
384 stars 67 forks source link

Stencil example #49

Open vchuravy opened 4 years ago

vchuravy commented 4 years ago

@dpsanders

using KernelAbstractions
using OffsetArrays

@kernel function update!(A, @Const(B))
  i, j = @index(Global, NTuple)

  acc = zero(eltype(A))
  for m in -1:1
    for n in -1:1
      acc += B[i+m, j+n]
    end
  end
  A[i, j] = acc
end

N = 64
B = OffsetArray(ones(N+2, N+2), 0:N+1, 0:N+1)
A = OffsetArray(ones(N+2, N+2), 0:N+1, 0:N+1)

kernel = update!(CPU(), (4,4), (N,N))
wait(kernel(A, B))
dpsanders commented 4 years ago

I'm getting the following error:

julia> wait(kernel(A, B))
ERROR: TaskFailedException:
TaskFailedException:
MethodError: no method matching __index_Global_Cartesian(::CartesianIndex{2})
Stacktrace:
 [1] __index_Global_NTuple at /Users/dpsanders/.julia/dev/KernelAbstractions/src/KernelAbstractions.jl:214 [inlined]
 [2] cpu_update! at /Users/dpsanders/.julia/dev/KernelAbstractions/src/macros.jl:212 [inlined]
 [3] (::KernelAbstractions.var"#25#28"{Cassette.Context{nametype(CPUCtx),KernelAbstractions.CompilerMetadata{KernelAbstractions.NDIteration.StaticSize{(64, 64)},true,CartesianIndex{2},Nothing,KernelAbstractions.NDIteration.NDRange{2,KernelAbstractions.NDIteration.StaticSize{(16, 16)},KernelAbstractions.NDIteration.StaticSize{(4, 4)},Nothing,Nothing}},Nothing,KernelAbstractions.var"##PassType#253",Nothing,Cassette.DisableHooks},KernelAbstractions.Kernel{CPU,KernelAbstractions.NDIteration.StaticSize{(4, 4)},KernelAbstractions.NDIteration.StaticSize{(64, 64)},typeof(cpu_update!)},Tuple{OffsetArray{Float64,2,Array{Float64,2}},OffsetArray{Float64,2,Array{Float64,2}}}})() at ./threadingconstructs.jl:126

...and 255 more exception(s).

Stacktrace:
 [1] sync_end(::Array{Any,1}) at ./task.jl:316
 [2] macro expansion at ./task.jl:335 [inlined]
 [3] macro expansion at /Users/dpsanders/.julia/dev/KernelAbstractions/src/backends/cpu.jl:57 [inlined]
 [4] (::KernelAbstractions.var"#23#26"{KernelAbstractions.Kernel{CPU,KernelAbstractions.NDIteration.StaticSize{(4, 4)},KernelAbstractions.NDIteration.StaticSize{(64, 64)},typeof(cpu_update!)},Nothing,KernelAbstractions.NDIteration.NDRange{2,KernelAbstractions.NDIteration.StaticSize{(16, 16)},KernelAbstractions.NDIteration.StaticSize{(4, 4)},Nothing,Nothing},Tuple{OffsetArray{Float64,2,Array{Float64,2}},OffsetArray{Float64,2,Array{Float64,2}}},Nothing})() at ./threadingconstructs.jl:126
Stacktrace:
 [1] wait at ./task.jl:267 [inlined]
 [2] wait at /Users/dpsanders/.julia/dev/KernelAbstractions/src/backends/cpu.jl:7 [inlined]
 [3] wait(::KernelAbstractions.CPUEvent) at /Users/dpsanders/.julia/dev/KernelAbstractions/src/backends/cpu.jl:6
 [4] top-level scope at REPL[8]:1

julia> versioninfo()
Julia Version 1.4.0-rc2.0
Commit b99ed72c95 (2020-02-24 16:51 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.0.0)
  CPU: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
dpsanders commented 4 years ago
julia> kernel(A, B)
KernelAbstractions.CPUEvent(Task (failed) @0x0000000123bc9690)
vchuravy commented 4 years ago

Since you are on Julia 1.4 this is #43