Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mofeing opened this issue Jan 29, 2025 · 1 comment
Open
Labels
good first issue Good for newcomers tracing

Comments

@mofeing
Copy link
Collaborator

mofeing commented Jan 29, 2025

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)
@wsmoses
Copy link
Member

wsmoses commented Jan 30, 2025

I think we just need an overload for LinearAlgebra.dot. We have one for broadcast and sum so that makes sense

@mofeing mofeing added good first issue Good for newcomers tracing labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers tracing
Projects
None yet
Development

No branches or pull requests

2 participants