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

--check-bounds=no results in invalid IR with AMDGPU #387

Closed
pxl-th opened this issue Jan 23, 2023 · 3 comments
Closed

--check-bounds=no results in invalid IR with AMDGPU #387

pxl-th opened this issue Jan 23, 2023 · 3 comments

Comments

@pxl-th
Copy link
Contributor

pxl-th commented Jan 23, 2023

On Julia 1.9-beta3 setting --check-bounds=no results in invalid IR.
Note, that @inbounds works.

Launch below MWE with --check-bounds=no:

using AMDGPU

function memset_kerr!(x, v::Float32)
    i = workitemIdx().x + (workgroupIdx().x - 0x1) * workgroupDim().x
    x[i] = v
    return nothing
end

function main()
    x = ROCArray{Float32}(undef, 1024 * 1024)
    wait(@roc groupsize=256 gridsize=length(x) memset_kerr!(x, 1f0))
    return nothing
end
main()

Error:

ERROR: LoadError: InvalidIRError: compiling kernel #memset_kerr!(AMDGPU.Device.ROCDeviceVector{Float32, 1}, Float32) resulted in invalid LLVM IR
Reason: unsupported call to an unknown function (call to jl_f_apply_type)
Stacktrace:
 [1] Val
   @ ./essentials.jl:801
 [2] #setindex!
   @ ~/.julia/dev/AMDGPU/src/device/gcn/array.jl:85
 [3] memset_kerr!
   @ ~/.julia/dev/gcn_test.jl:5
Reason: unsupported call to an unknown function (call to ijl_new_structv)
Stacktrace:
 [1] Val
   @ ./essentials.jl:799
 [2] Val
   @ ./essentials.jl:801
 [3] #setindex!
   @ ~/.julia/dev/AMDGPU/src/device/gcn/array.jl:85
 [4] memset_kerr!
   @ ~/.julia/dev/gcn_test.jl:5
Reason: unsupported dynamic function invocation (call to unsafe_store!)
Stacktrace:
 [1] #setindex!
   @ ~/.julia/dev/AMDGPU/src/device/gcn/array.jl:85
 [2] memset_kerr!
   @ ~/.julia/dev/gcn_test.jl:5
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.ROCCompilerParams, GPUCompiler.FunctionSpec{typeof(memset_kerr!), Tuple{AMDGPU.Device.ROCDeviceVector{Float32, 1}, Float32}}}, args::LLVM.Module)
    @ GPUCompiler ~/.julia/packages/GPUCompiler/qdoh1/src/validation.jl:141
  [2] macro expansion
    @ ~/.julia/packages/GPUCompiler/qdoh1/src/driver.jl:418 [inlined]
  [3] macro expansion
    @ ~/.julia/packages/TimerOutputs/LHjFw/src/TimerOutput.jl:253 [inlined]
  [4] macro expansion
    @ ~/.julia/packages/GPUCompiler/qdoh1/src/driver.jl:416 [inlined]
  [5] emit_asm(job::GPUCompiler.CompilerJob, ir::LLVM.Module; strip::Bool, validate::Bool, format::LLVM.API.LLVMCodeGenFileType)
    @ GPUCompiler ~/.julia/packages/GPUCompiler/qdoh1/src/utils.jl:83
  [6] (::AMDGPU.Compiler.var"#33#36"{GPUCompiler.CompilerJob{GPUCompiler.GCNCompilerTarget, AMDGPU.Compiler.ROCCompilerParams, GPUCompiler.FunctionSpec{typeof(memset_kerr!), Tuple{AMDGPU.Device.ROCDeviceVector{Float32, 1}, Float32}}}, Core.MethodInstance})(ctx::LLVM.ThreadSafeContext)
    @ AMDGPU.Compiler ~/.julia/dev/AMDGPU/src/compiler.jl:182
  [7] LLVM.ThreadSafeContext(f::AMDGPU.Compiler.var"#33#36"{GPUCompiler.CompilerJob{GPUCompiler.GCNCompilerTarget, AMDGPU.Compiler.ROCCompilerParams, GPUCompiler.FunctionSpec{typeof(memset_kerr!), Tuple{AMDGPU.Device.ROCDeviceVector{Float32, 1}, Float32}}}, Core.MethodInstance})
    @ LLVM ~/.julia/packages/LLVM/qc3sa/src/executionengine/ts_module.jl:14
  [8] JuliaContext(f::AMDGPU.Compiler.var"#33#36"{GPUCompiler.CompilerJob{GPUCompiler.GCNCompilerTarget, AMDGPU.Compiler.ROCCompilerParams, GPUCompiler.FunctionSpec{typeof(memset_kerr!), Tuple{AMDGPU.Device.ROCDeviceVector{Float32, 1}, Float32}}}, Core.MethodInstance})
    @ GPUCompiler ~/.julia/packages/GPUCompiler/qdoh1/src/driver.jl:74
  [9] rocfunction_compile(job::GPUCompiler.CompilerJob)
    @ AMDGPU.Compiler ~/.julia/dev/AMDGPU/src/compiler.jl:178
 [10] cached_compilation(cache::Dict{UInt64, Any}, job::GPUCompiler.CompilerJob, compiler::typeof(AMDGPU.Compiler.rocfunction_compile), linker::typeof(AMDGPU.Compiler.rocfunction_link))
    @ GPUCompiler ~/.julia/packages/GPUCompiler/qdoh1/src/cache.jl:90
 [11] rocfunction(f::typeof(memset_kerr!), tt::Type; name::Nothing, device::ROCDevice, global_hooks::NamedTuple{(), Tuple{}})
    @ AMDGPU.Compiler ~/.julia/dev/AMDGPU/src/compiler.jl:164
 [12] rocfunction
    @ ~/.julia/dev/AMDGPU/src/compiler.jl:154 [inlined]
 [13] macro expansion
    @ ~/.julia/dev/AMDGPU/src/highlevel.jl:430 [inlined]
 [14] memset!(x::ROCVector{Float32}, v::Float32)
    @ Main ~/.julia/dev/gcn_test.jl:10
 [15] main()
    @ Main ~/.julia/dev/gcn_test.jl:25
 [16] top-level scope
    @ ~/.julia/dev/gcn_test.jl:35
@pxl-th
Copy link
Contributor Author

pxl-th commented Jan 23, 2023

Turns out, this is probably AMDGPU's issue, as it passes alignment argument to Base.unsafe_store!:
https://github.com/JuliaGPU/AMDGPU.jl/blob/09cf06ca16012887e7f6b19635936189994fdadc/src/device/gcn/array.jl#L85

I'll close it here.

@pxl-th pxl-th closed this as completed Jan 23, 2023
@maleadt
Copy link
Member

maleadt commented Jan 23, 2023

LLVM.jl has versions of these functions taking a Val argument: https://github.com/maleadt/LLVM.jl/blob/9f9d2faee81f907343ddf2d27eab12fa836e5cd4/src/interop/pointer.jl#L84-L85

That said, an in valid IR error is unlikely to be a compiler issue, or at least not straight away. It's more likely that the const-prop of align failed, for whatever reason.

@maleadt
Copy link
Member

maleadt commented Jan 23, 2023

It's more likely that the const-prop of align failed, for whatever reason.

The reason is of course --check-bounds=no, see JuliaLang/julia#48245. TL;DR: don't use --check-bounds=no, as it pessimizes codegen leading issues to the const-prop failure here.

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

2 participants