Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce(f, A) fails to compile if Julia is started with --check-bounds=no #581

Open
Keluaa opened this issue Jan 18, 2024 · 0 comments
Open

Comments

@Keluaa
Copy link

Keluaa commented Jan 18, 2024

Reproductible on AMDGPU version 0.8.4, I initially saw this issue in version 0.5.
Currently using Julia 1.9.1 on a MI100 GPU with system ROCm (version 5.6.0).

Starting Julia with julia --check-bounds=no:

julia> using AMDGPU

julia> A = ROCArray{Float64}(undef, 10);

julia> reduce(+, A)
ERROR: InvalidIRError: ...
Full stacktrace
julia> reduce(+, A)
ERROR: InvalidIRError: compiling MethodInstance for AMDGPU.partial_mapreduce_device(::typeof(identity), ::typeof(+), ::Float64, ::CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, ::CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, ::AMDGPU.Device.ROCDeviceMatrix{Float64, 1}, ::Base.Broadcast.Broadcasted{AMDGPU.ROCArrayStyle{1, AMDGPU.Runtime.Mem.HIPBuffer}, Tuple{Base.OneTo{Int64}}, typeof(identity), Tuple{AMDGPU.Device.ROCDeviceVector{Float64, 1}}}) resulted in invalid LLVM IR
Reason: unsupported call through a literal pointer
Stacktrace:
 [1] typeintersect
   @ ./reflection.jl:689
 [2] convert
   @ ./essentials.jl:415
 [3] CartesianIndex
   @ ./multidimensional.jl:67
 [4] CartesianIndex
   @ ./multidimensional.jl:70
 [5] CartesianIndex
   @ ./multidimensional.jl:71
 [6] partial_mapreduce_device
   @ /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/kernels/mapreduce.jl:60
Reason: unsupported dynamic function invocation (call to _tuple_error(T::Type, x) @ Base essentials.jl:409)
Stacktrace:
 [1] convert
   @ ./essentials.jl:416
 [2] CartesianIndex
   @ ./multidimensional.jl:67
 [3] CartesianIndex
   @ ./multidimensional.jl:70
 [4] CartesianIndex
   @ ./multidimensional.jl:71
 [5] partial_mapreduce_device
   @ /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/kernels/mapreduce.jl:60
Hint: catch this exception as `err` and call `code_typed(err; interactive = true)` to introspect the erronous code with Cthulhu.jl
Stacktrace:
  [1] check_ir(job::GPUCompiler.CompilerJob{GPUCompiler.GCNCompilerTarget, AMDGPU.Compiler.HIPCompilerParams}, args::LLVM.Module)
    @ GPUCompiler /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/validation.jl:147
  [2] macro expansion
    @ /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/driver.jl:440 [inlined]
  [3] macro expansion
    @ /home/briandl/.julia/packages/TimerOutputs/RsWnF/src/TimerOutput.jl:253 [inlined]
  [4] macro expansion
    @ /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/driver.jl:439 [inlined]
  [5] emit_llvm(job::GPUCompiler.CompilerJob; libraries::Bool, toplevel::Bool, optimize::Bool, cleanup::Bool, only_entry::Bool, validate::Bool)
    @ GPUCompiler /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/utils.jl:92
  [6] emit_llvm
    @ /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/utils.jl:86 [inlined]
  [7] codegen(output::Symbol, job::GPUCompiler.CompilerJob; libraries::Bool, toplevel::Bool, optimize::Bool, cleanup::Bool, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing)
    @ GPUCompiler /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/driver.jl:129
  [8] codegen
    @ /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/driver.jl:110 [inlined]
  [9] compile(target::Symbol, job::GPUCompiler.CompilerJob; libraries::Bool, toplevel::Bool, optimize::Bool, cleanup::Bool, strip::Bool, validate::Bool, only_entry::Bool)
    @ GPUCompiler /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/driver.jl:106
 [10] compile
    @ /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/driver.jl:98 [inlined]
 [11] #40
    @ /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/compiler/codegen.jl:140 [inlined]
 [12] JuliaContext(f::AMDGPU.Compiler.var"#40#41"{GPUCompiler.CompilerJob{GPUCompiler.GCNCompilerTarget, AMDGPU.Compiler.HIPCompilerParams}})
    @ GPUCompiler /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/driver.jl:47
 [13] hipcompile(job::GPUCompiler.CompilerJob)
    @ AMDGPU.Compiler /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/compiler/codegen.jl:139
 [14] actual_compilation(cache::Dict{Any, AMDGPU.HIP.HIPFunction}, src::Core.MethodInstance, world::UInt64, cfg::GPUCompiler.CompilerConfig{GPUCompiler.GCNCompilerTarget, AMDGPU.Compiler.HIPCompilerParams}, compiler::typeof(AMDGPU.Compiler.hipcompile), linker::typeof(AMDGPU.Compiler.hiplink))
    @ GPUCompiler /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/execution.jl:125
 [15] cached_compilation(cache::Dict{Any, AMDGPU.HIP.HIPFunction}, src::Core.MethodInstance, cfg::GPUCompiler.CompilerConfig{GPUCompiler.GCNCompilerTarget, AMDGPU.Compiler.HIPCompilerParams}, compiler::Function, linker::Function)
    @ GPUCompiler /home/briandl/.julia/packages/GPUCompiler/U36Ed/src/execution.jl:103
 [16] macro expansion
    @ /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/compiler/codegen.jl:107 [inlined]
 [17] macro expansion
    @ ./lock.jl:267 [inlined]
 [18] hipfunction(f::typeof(AMDGPU.partial_mapreduce_device), tt::Type{Tuple{typeof(identity), typeof(+), Float64, CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, AMDGPU.Device.ROCDeviceMatrix{Float64, 1}, Base.Broadcast.Broadcasted{AMDGPU.ROCArrayStyle{1, AMDGPU.Runtime.Mem.HIPBuffer}, Tuple{Base.OneTo{Int64}}, typeof(identity), Tuple{AMDGPU.Device.ROCDeviceVector{Float64, 1}}}}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ AMDGPU.Compiler /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/compiler/codegen.jl:101
 [19] hipfunction
    @ /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/compiler/codegen.jl:100 [inlined]
 [20] macro expansion
    @ /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/highlevel.jl:157 [inlined]
 [21] mapreducedim!(f::typeof(identity), op::typeof(+), R::ROCArray{Float64, 1, AMDGPU.Runtime.Mem.HIPBuffer}, A::Base.Broadcast.Broadcasted{AMDGPU.ROCArrayStyle{1, AMDGPU.Runtime.Mem.HIPBuffer}, Tuple{Base.OneTo{Int64}}, typeof(identity), Tuple{ROCArray{Float64, 1, AMDGPU.Runtime.Mem.HIPBuffer}}}; init::Float64)
    @ AMDGPU /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/kernels/mapreduce.jl:136
 [22] mapreducedim!
    @ /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/kernels/mapreduce.jl:88 [inlined]
 [23] _mapreduce(f::typeof(identity), op::typeof(+), As::ROCArray{Float64, 1, AMDGPU.Runtime.Mem.HIPBuffer}; dims::Colon, init::Nothing)
    @ GPUArrays /home/briandl/.julia/packages/GPUArrays/Hd5Sk/src/host/mapreduce.jl:67
 [24] mapreduce(::Function, ::Function, ::ROCArray{Float64, 1, AMDGPU.Runtime.Mem.HIPBuffer}; dims::Function, init::Nothing)
    @ GPUArrays /home/briandl/.julia/packages/GPUArrays/Hd5Sk/src/host/mapreduce.jl:29
 [25] mapreduce
    @ /home/briandl/.julia/packages/GPUArrays/Hd5Sk/src/host/mapreduce.jl:29 [inlined]
 [26] #reduce#802
    @ ./reducedim.jl:406 [inlined]
 [27] reduce(op::Function, A::ROCArray{Float64, 1, AMDGPU.Runtime.Mem.HIPBuffer})
    @ Base ./reducedim.jl:406
 [28] top-level scope
    @ REPL[3]:1
 [29] top-level scope
    @ /home/briandl/.julia/packages/AMDGPU/k7TXJ/src/tls.jl:200

The error seems to be unrelated to the + reduction, since it also occurs with min or max.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant