Skip to content

LinearAlgebra.dot and x' * y require @allowscalar but sum(x .* y) doesn't #649

@mofeing

Description

@mofeing
julia> a = rand(2)
2-element Vector{Float64}:
 0.41323466569127665
 0.4525169547907606

julia> b = rand(2)
2-element Vector{Float64}:
 0.37009493514138525
 0.818796709700481

julia> a_re = adapt(ConcreteRArray, a)
2-element ConcreteRArray{Float64, 1}:
 0.41323466569127665
 0.4525169547907606

julia> b_re = adapt(ConcreteRArray, b)
2-element ConcreteRArray{Float64, 1}:
 0.37009493514138525
 0.818796709700481

julia> f(x,y) = LinearAlgebra.dot(x,y)
f (generic function with 1 method)

julia> @jit f(a_re, b_re)
ERROR: Scalar indexing is disallowed.
Invocation of getindex(::TracedRArray, ::Vararg{Int, N}) resulted in scalar indexing of a GPU array.
This is typically caused by calling an iterating implementation of a method.
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore should be avoided.

If you want to allow scalar iteration, use `allowscalar` or `@allowscalar`
to enable scalar iteration globally or for the operations in question.
Stacktrace:
...

julia> f(x,y) = x' * y
f (generic function with 1 method)

julia> @jit f(a_re, b_re)
ERROR: Scalar indexing is disallowed.
Invocation of getindex(::TracedRArray, ::Vararg{Int, N}) resulted in scalar indexing of a GPU array.
This is typically caused by calling an iterating implementation of a method.
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore should be avoided.

If you want to allow scalar iteration, use `allowscalar` or `@allowscalar`
to enable scalar iteration globally or for the operations in question.
Stacktrace:
...

julia> f(x,y) = sum(x .* y)
f (generic function with 1 method)

julia> @jit f(a_re, b_re)
ConcreteRNumber{Float64}(0.5234554504635411)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions