Skip to content

CUDA: reinterpret results in dynamic function invocation #1312

Description

@pxl-th

Ref: JuliaGPU/AMDGPU.jl#808
MWE (fails on Julia 1.10, works on 1.11+):

using CUDA, StaticArrays

@inline function add!(a::MMatrix{NC,NC,Complex{T},NC2}) where {NC,NC2,T}
    ar = reinterpret(reshape, T, a)
    @inbounds ar[1] += 1.0
    return a
end

function kernel!(a)
    i = threadIdx().x
    @inbounds a[i] = SMatrix(add!(MMatrix(a[i])))
    return
end

a = CUDA.zeros(SMatrix{3,3,ComplexF64,9}, 1)
@cuda threads=1 kernel!(a)

Error:

ERROR: LoadError: InvalidIRError: compiling MethodInstance for kernel!(::CuDeviceVector{SMatrix{3, 3, ComplexF64, 9}, 1}) resulted in invalid LLVM IR
Reason: unsupported dynamic function invocation (call to padding(T::DataType, baseoffset::Int64) @ Base reinterpretarray.jl:706)
Stacktrace:
 [1] padding
   @ ./reinterpretarray.jl:707
 [2] CyclePadding
   @ ./reinterpretarray.jl:727
 [3] array_subpadding
   @ ./reinterpretarray.jl:736
 [4] reinterpret
   @ ./reinterpretarray.jl:115
 [5] add!
   @ ~/code/t.jl:4
 [6] kernel!
   @ ~/code/t.jl:11
Reason: unsupported call to an unknown function (call to jl_f__svec_ref)
Stacktrace:
 [1] getindex
   @ ./essentials.jl:769
 [2] iterate (repeats 2 times)
   @ ./essentials.jl:779
 [3] iterate
   @ ./reinterpretarray.jl:693
 [4] array_subpadding
   @ ./reinterpretarray.jl:740
 [5] reinterpret
   @ ./reinterpretarray.jl:115
 [6] add!
   @ ~/code/t.jl:4
 [7] kernel!
   @ ~/code/t.jl:11
Hint: catch this exception as `err` and call `code_typed(err; interactive = true)` to introspect the erroneous code with Cthulhu.jl
Stacktrace:
  [1] check_ir(job::GPUCompiler.CompilerJob{GPUCompiler.PTXCompilerTarget, CUDA.CUDACompilerParams}, args::LLVM.Module)
    @ GPUCompiler ~/.julia/packages/GPUCompiler/3QaEh/src/validation.jl:167
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions