Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.
This repository was archived by the owner on May 27, 2021. It is now read-only.

Scalar static vector multiplication triggers unsupported call to the Julia runtime #291

@mohamed82008

Description

@mohamed82008

The following code triggers unsupported call to the Julia runtime (call to jl_invoke).

using CUDAnative, CUDAdrv, CuArrays, StaticArrays

k = 3
n = 10

Ks = [SMatrix{k, k, Float64}(rand(k,k)) for i in 1:n] |> CuArrays.CuArray
fs = [SVector{k, Float64}(rand(k)) for i in 1:n] |> CuArrays.CuArray
newfs = similar(fs)

dev = CUDAdrv.device()
ctx = CUDAdrv.CuContext(dev)
MAX_THREADS_PER_BLOCK = CUDAdrv.attribute(dev, CUDAdrv.MAX_THREADS_PER_BLOCK)
threads = min(n, MAX_THREADS_PER_BLOCK)
blocks = ceil.(Int, n / threads)

function kernel(newfs, Ks, fs::AbstractVector{TV}, n) where {N, T, TV<:SVector{N,T}}
    i = (blockIdx().x-1) * blockDim().x + threadIdx().x
    m = 2.0
    if i <= n
	    newfs[i] = m * (Ks[i] * fs[i])
	    #newfs[i] = SVector{1,T}((m,)) .* (Ks[i] * fs[i])
    end
    return
end

@cuda blocks=blocks threads=threads kernel(newfs,  Ks, fs, n)

Replacing the multiplication line with the commented one works fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions