Skip to content

v0.10: some LinearAlgebra functions can't be called anymore inside kernels #759

Closed

Description

@giordano

Another minimised reproducer of issues observed at CliMA/Oceananigans.jl#5799

using KernelAbstractions, LinearAlgebra

@kernel function dots!(out, a, b)
    i = @index(Global, Linear)
    @inbounds begin
        x = collect((a[i], a[i] + 1, a[i] + 2))   # Vector{Float64}
        y = collect((b[i], b[i] + 1, b[i] + 2))
        out[i] = dot(x, y)                        # BLAS.dot → cblas_ddot64_
    end
end

a = rand(8); b = rand(8); out = zeros(8)
dots!(CPU(), 4)(out, a, b; ndrange = 8)

This used to work in v0.9, but now we get

ERROR: LoadError: InvalidIRError: compiling MethodInstance for gpu_dots!(::KernelAbstractions.CompilerMetadata{KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.DynamicCheck, Nothing, CartesianIndices{1, Tuple{B
ase.OneTo{Int64}}}, KernelAbstractions.NDIteration.NDRange{1, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.StaticSize{(4,)}, CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, Nothing}}, ::KernelAbstractions.PO
CL.CLDeviceVector{Float64, 1}, ::KernelAbstractions.POCL.CLDeviceVector{Float64, 1}, ::KernelAbstractions.POCL.CLDeviceVector{Float64, 1}) resulted in invalid LLVM IR                                                                      
Reason: unsupported call to an external C function (call to cblas_ddot64_)                                                                                                                                                                  
Reason: unsupported call to a lazy-initialized function (call to cblas_ddot64_)                                                                                                                                                             

Interestingly, this gives different errors when the env var CI=true is set, and then an abort:

Call parameter type does not match function signature!
ptr addrspace(1) @ccalllib_libblastrampoline_so_59929
 ptr  %cblas_ddot64_.found = call ptr @ijl_load_and_lookup(ptr addrspacecast (ptr addrspace(1) @_j_str_libblastrampoline_so_5_3 to ptr), ptr addrspacecast (ptr addrspace(1) @_j_str_cblas_ddot64__2 to ptr), ptr addrspace(1) @ccalllib_lib
blastrampoline_so_59929)
LLVM ERROR: Broken module found, compilation aborted!

[93912] signal 6 (-6): Aborted                                                                                                                                                                                                              

Activity

  1. vchuravy commented on Sep 10, 2026

    @vchuravy
    Member

    How does any of this work on the GPU? If you want this x and y should be static arrays.

  2. added this to the 0.10.0 milestone on Sep 10, 2026
  3. giordano commented on Sep 10, 2026

    @giordano
    CollaboratorAuthor

    How does any of this work on the GPU?

    To quickly answer that question: the _calculate_metrics! kernel in Oceananigans is only ever called on CPU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions