JuliaGPU / JuliaGPU/GPUCompiler.jl
Validator does not catch global host loads
- Dominant language
- Julia
- Stars
- 187
- Forks
- 68
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 28
Description
```
julia> using CUDA
julia> const foo = [1, 2]
2-element Vector{Int64}:
1
2
julia> a = CUDA.zeros(Int, 1)
1-element CuArray{Int64, 1, CUDA.Mem.DeviceBuffer}:
0
julia> function kernel(a, i)
@inbounds a[i] = foo[i]
return
end
kernel (generic function with 1 method)
julia> @device_code_llvm @cuda kernel(a, 1)
; PTX CompilerJob of kernel kernel(CuDeviceVector{Int64, 1}, Int64) for sm_75
; @ REPL[5]:1 within `kernel`
define ptx_kernel void @_Z17julia_kernel_295113CuDeviceArrayI5Int64Li1ELi1EES0_({ i8 addrspace(1)*, i64, [1 x i64] } %0, i64 signext %1) local_unnamed_addr #0 {
entry:
%.fca.0.extract = extractvalue { i8 addrspace(1)*, i64, [1 x i64] } %0, 0
; @ REPL[5]:2 within `kernel`
; ┌ @ array.jl:835 within `getindex`
%2 = add i64 %1, -1
%3 = load i64*, i64** inttoptr (i64 139929053628784 to i64**), align 16
%4 = getelementptr inbounds i64, i64* %3, i64 %2
%5 = load i64, i64* %4, align 8
; └
; ┌ @ /home/tim/Julia/pkg/CUDA/src/device/array.jl:192 within `setindex!`
; │┌ @ /home/tim/Julia/pkg/CUDA/src/device/array.jl:153 within `arrayset`
; ││┌ @ /home/tim/Julia/pkg/CUDA/src/device/array.jl:162 within `arrayset_bits`
; │││┌ @ /home/tim/Julia/pkg/LLVM/src/interop/pointer.jl:84 within `unsafe_store!`
; ││││┌ @ /home/tim/Julia/pkg/LLVM/src/interop/pointer.jl:44 within `pointerset`
; │││││┌ @ /home/tim/Julia/pkg/LLVM/src/interop/pointer.jl:44 within `macro expansion` @ /home/tim/Julia/pkg/LLVM/src/interop/base.jl:39
%6 = bitcast i8 addrspace(1)* %.fca.0.extract to i64 addrspace(1)*
%7 = getelementptr inbounds i64, i64 addrspace(1)* %6, i64 %2
store i64 %5, i64 addrspace(1)* %7, align 8
ret void
; └└└└└└
}
ERROR: CUDA error: an illegal memory access was encountered (code 700, ERROR_ILLEGAL_ADDRESS)
Stacktrace:
[1] throw_api_error(res::CUDA.cudaError_enum)
@ CUDA ~/Julia/pkg/CUDA/lib/cudadrv/error.jl:105
[2] query
@ ~/Julia/pkg/CUDA/lib/cudadrv/stream.jl:102 [inlined]
[3] synchronize(stream::CuStream; blocking::Bool)
@ CUDA ~/Julia/pkg/CUDA/lib/cudadrv/stream.jl:130
[4] synchronize (repeats 2 times)
@ ~/Julia/pkg/CUDA/lib/cudadrv/stream.jl:117 [inlined]
[5] top-level scope
@ ~/Julia/pkg/CUDA/src/initialization.jl:67
```
Ref https://github.com/JuliaGPU/CUDA.jl/issues/1085
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the reproduced `@cuda` kernel and the `@device_code_llvm` output, then trace how the validator handles the global load shown in the generated LLVM. Done means the validator detects and reports this global host load instead of allowing the kernel to reach the illegal memory access.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100