Skip to content

mapreduce over unit ranges on the GPU #33

@vchuravy

Description

@vchuravy

I was hoping that the following would work

julia> AcceleratedKernels.mapreduce(_->rand(), +, 1:n, ROCBackend(); init=0.0)/n

E.g. using a unit-range and the backend. (Note to self: define get_backend(1:N) = error("") to avoid a stack overflow.)

Of course, this works, but requires an allocation

julia> AcceleratedKernels.mapreduce(_->rand(), +, ROCArray(1:n), ROCBackend(); init=0.0)/n

The error is:

ERROR: GPU compilation of MethodInstance for AcceleratedKernels.gpu__mapreduce_block!(::KernelAbstractions.CompilerMetadata{…}, ::UnitRange{…}, ::SubArray{…}, ::var"#7#8", ::typeof(+), ::Int64) failed
KernelError: passing non-bitstype argument

Argument 4 to your kernel function is of type SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}, which is not a bitstype:
  .parent is of type Vector{Float64} which is not isbits.
    .ref is of type MemoryRef{Float64} which is not isbits.
      .mem is of type Memory{Float64} which is not isbits.


Only bitstypes, which are "plain data" types that are immutable
and contain no references to other values, can be used in GPU kernels.
For more information, see the `Base.isbitstype` function.

Stacktrace:
  [1] check_invocation(job::GPUCompiler.CompilerJob)
    @ GPUCompiler ~/.julia/packages/GPUCompiler/3QaEh/src/validation.jl:108
  [2] macro expansion
    @ ~/.julia/packages/GPUCompiler/3QaEh/src/driver.jl:87 [inlined]
  [3] macro expansion
    @ ~/.julia/packages/Tracy/GcShf/src/tracepoint.jl:158 [inlined]
  [4] compile_unhooked(output::Symbol, job::GPUCompiler.CompilerJob; kwargs::@Kwargs{})
    @ GPUCompiler ~/.julia/packages/GPUCompiler/3QaEh/src/driver.jl:85
  [5] compile_unhooked
    @ ~/.julia/packages/GPUCompiler/3QaEh/src/driver.jl:80 [inlined]
  [6] compile(target::Symbol, job::GPUCompiler.CompilerJob; kwargs::@Kwargs{})
    @ GPUCompiler ~/.julia/packages/GPUCompiler/3QaEh/src/driver.jl:67
  [7] compile
    @ ~/.julia/packages/GPUCompiler/3QaEh/src/driver.jl:55 [inlined]
  [8] #40
    @ ~/.julia/packages/AMDGPU/STpZC/src/compiler/codegen.jl:194 [inlined]
  [9] JuliaContext(f::AMDGPU.Compiler.var"#40#41"{GPUCompiler.CompilerJob{GPUCompiler.GCNCompilerTarget, AMDGPU.Compiler.HIPCompilerParams}}; kwargs::@Kwargs{})
    @ GPUCompiler ~/.julia/packages/GPUCompiler/3QaEh/src/driver.jl:34
 [10] JuliaContext(f::Function)
    @ GPUCompiler ~/.julia/packages/GPUCompiler/3QaEh/src/driver.jl:25
 [11] hipcompile(job::GPUCompiler.CompilerJob)
    @ AMDGPU.Compiler ~/.julia/packages/AMDGPU/STpZC/src/compiler/codegen.jl:193
 [12] actual_compilation(cache::Dict{…}, src::Core.MethodInstance, world::UInt64, cfg::GPUCompiler.CompilerConfig{…}, compiler::typeof(AMDGPU.Compiler.hipcompile), linker::typeof(AMDGPU.Compiler.hiplink))
    @ GPUCompiler ~/.julia/packages/GPUCompiler/3QaEh/src/execution.jl:245
 [13] cached_compilation(cache::Dict{…}, src::Core.MethodInstance, cfg::GPUCompiler.CompilerConfig{…}, compiler::Function, linker::Function)
    @ GPUCompiler ~/.julia/packages/GPUCompiler/3QaEh/src/execution.jl:159
 [14] macro expansion
    @ ~/.julia/packages/AMDGPU/STpZC/src/compiler/codegen.jl:161 [inlined]
 [15] macro expansion
    @ ./lock.jl:273 [inlined]
 [16] hipfunction(f::typeof(AcceleratedKernels.gpu__mapreduce_block!), tt::Type{Tuple{KernelAbstractions.CompilerMetadata{…}, UnitRange{…}, SubArray{…}, var"#7#8", typeof(+), Int64}}; kwargs::@Kwargs{})
    @ AMDGPU.Compiler ~/.julia/packages/AMDGPU/STpZC/src/compiler/codegen.jl:155
 [17] hipfunction(f::typeof(AcceleratedKernels.gpu__mapreduce_block!), tt::Type{Tuple{KernelAbstractions.CompilerMetadata{…}, UnitRange{…}, SubArray{…}, var"#7#8", typeof(+), Int64}})
    @ AMDGPU.Compiler ~/.julia/packages/AMDGPU/STpZC/src/compiler/codegen.jl:154
 [18] macro expansion
    @ ~/.julia/packages/AMDGPU/STpZC/src/highlevel.jl:155 [inlined]
 [19] (::KernelAbstractions.Kernel{…})(::UnitRange{…}, ::Vararg{…}; ndrange::Tuple{…}, workgroupsize::Nothing)
    @ AMDGPU.ROCKernels ~/.julia/packages/AMDGPU/STpZC/src/ROCKernels.jl:91
 [20] mapreduce_1d(f::var"#7#8", op::typeof(+), src::UnitRange{Int64}, backend::ROCBackend; init::Float64, neutral::Int64, block_size::Int64, temp::Nothing, switch_below::Int64)
    @ AcceleratedKernels ~/.julia/packages/AcceleratedKernels/Hf8B2/src/reduce/mapreduce_1d.jl:143
 [21] mapreduce_1d
    @ ~/.julia/packages/AcceleratedKernels/Hf8B2/src/reduce/mapreduce_1d.jl:102 [inlined]
 [22] #_mapreduce_impl#48
    @ ~/.julia/packages/AcceleratedKernels/Hf8B2/src/reduce/reduce.jl:252 [inlined]
 [23] _mapreduce_impl
    @ ~/.julia/packages/AcceleratedKernels/Hf8B2/src/reduce/reduce.jl:234 [inlined]
 [24] mapreduce(f::var"#7#8", op::typeof(+), src::UnitRange{…}, backend::ROCBackend; init::Float64, neutral::Int64, dims::Nothing, scheduler::Symbol, max_tasks::Int64, min_elems::Int64, block_size::Int64, temp::Nothing, switch_below::Int64)
    @ AcceleratedKernels ~/.julia/packages/AcceleratedKernels/Hf8B2/src/reduce/reduce.jl:219
 [25] top-level scope
    @ REPL[10]:1
Some type information was truncated. Use `show(err)` to see complete types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions