Skip to content

raise=true: cannot raise llvm.mlir.addressof of a Julia scalar constant global (@_j_const_N) #3043

Description

@masonlee277

Summary

A KA kernel that writes a compile-time float literal into an MArray slot at a runtime index lowers to llvm.mlir.addressof @_j_const_*, which raise rejects. Reproduced on Reactant 0.2.271 (2026-07-09).

Environment

Julia 1.12.5 · Reactant 0.2.271 · Enzyme 0.13.173 · CUDA 6.2.0 · KernelAbstractions 0.9.42 · StaticArrays 1.9.18 · CPU backend (CUDA loaded for ReactantCUDAExt)

Reproducer

using Reactant
using CUDA
using KernelAbstractions
import KernelAbstractions as KA
import KernelAbstractions.StaticArrays: MArray

Reactant.set_default_backend("cpu")
@assert Reactant.is_extension_loaded(Val(:CUDA))

@kernel function const_into_marray_kernel!(out, input, ::Val{N}) where {N}
    column = @index(Global)
    n = Int(@inbounds input[column])
    scratch = MArray{Tuple{N}, Float64}(undef)
    @inbounds for i in 1:n
        scratch[i] = 1.0e-10
    end
    @inbounds for i in 1:n
        v = input[column] * Float64(i) - 3.0
        if v < 0.0
            scratch[i] = 0.99999899999999997
        else
            scratch[i] = v
        end
    end
    acc = 0.0
    @inbounds for i in 1:n
        acc += scratch[i]
    end
    @inbounds out[column] = acc
end

function const_into_marray!(out, input)
    kernel = const_into_marray_kernel!(KA.get_backend(out))
    kernel(out, input, Val(4); ndrange = length(out))
    return nothing
end

out = Reactant.to_rarray(fill(-9.0, 2))
input = Reactant.to_rarray([4.0, 4.0])
compiled = Reactant.@compile raise=true raise_first=true sync=true const_into_marray!(out, input)
compiled(out, input)

Expected behavior

The scalar constant should lower without leaving an unsupported LLVM global reference; the compiled kernel should return [28.0, 28.0].

Actual behavior

ERROR: LoadError: CompilationError: MLIR pass pipeline "all" failed
error: cannot raise op to stablehlo%14 = "llvm.mlir.addressof"() <{global_name = @_j_const_1}> : () -> !llvm.ptr
  note: see current operation: %14 = "llvm.mlir.addressof"() <{global_name = @_j_const_1}> : () -> !llvm.ptr
caused by: "failed to run pass manager on module"

Related issues

This is distinct from the Complex aggregate llvm.alloca raising failure in Reactant.jl #3044: this report concerns llvm.mlir.addressof of a named Julia scalar-constant global. Reactant.jl #3003 concerned SLP-vectorized vector constants rather than a scalar global.

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