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

StrideArraysCore not able to SIMD #121

Open
jwscook opened this issue Apr 10, 2024 · 3 comments
Open

StrideArraysCore not able to SIMD #121

jwscook opened this issue Apr 10, 2024 · 3 comments

Comments

@jwscook
Copy link

jwscook commented Apr 10, 2024

I was using Polyester.jl to thread an outer loop and wanted to SIMD the inner loop but got an error. Apparently Polyester converts vectors into StrideArraysCore.PtrArray which does not dispatch on SIMD._pointer. Below is the MWE example of the error and a fix. I'd be happy to provide the fix here but StrideArraysCore.jl is not a dependency, so thought I'd raise the issue here.

julia> using StrideArraysCore, SIMD

julia> x = StrideArraysCore.PtrArray(rand(4))
4-element PtrArray{Float64, 1, (1,), Tuple{Int64}, Tuple{Nothing}, Tuple{StaticInt{1}}}:
 0.5349256395906962
 0.17431749301270416
 0.8864181731419128
 0.30373397033508265

julia> lane = VecRange{4}(0)
VecRange{4}(0)

julia> x[1 + lane]
ERROR: MethodError: no method matching _pointer(::PtrArray{Float64, 1, (1,), Tuple{Int64}, Tuple{Nothing}, Tuple{StaticInt{1}}}, ::Int64, ::Tuple{})

Closest candidates are:
  _pointer(::SubArray{T, N, P, I, true} where {T, N, P, I<:Union{Tuple{Vararg{Real}}, Tuple{AbstractUnitRange, Vararg{Any}}}}, ::Any, ::Tuple{})
   @ SIMD ~/.julia/packages/SIMD/2fAdM/src/arrayops.jl:290
  _pointer(::SubArray{T, N, P, I, true} where {T, N, P, I<:Union{Tuple{Vararg{Real}}, Tuple{AbstractUnitRange, Vararg{Any}}}}, ::Any, ::Any)
   @ SIMD ~/.julia/packages/SIMD/2fAdM/src/arrayops.jl:288
  _pointer(::SubArray, ::Any, ::Any)
   @ SIMD ~/.julia/packages/SIMD/2fAdM/src/arrayops.jl:295
  ...

Stacktrace:
 [1] getindex(::PtrArray{Float64, 1, (1,), Tuple{Int64}, Tuple{Nothing}, Tuple{StaticInt{1}}}, ::VecRange{4})
   @ SIMD ~/.julia/packages/SIMD/2fAdM/src/arrayops.jl:302
 [2] top-level scope
   @ REPL[4]:1

The obvious fix is

Base.@propagate_inbounds SIMD._pointer(arr::StrideArraysCore.PtrArray, i, I) =
    pointer(Base.unsafe_view(arr, 1, I...), i)
@KristofferC
Copy link
Collaborator

I would have thought that maybe

SIMD.jl/src/arrayops.jl

Lines 288 to 289 in ecf1f4a

Base.@propagate_inbounds _pointer(arr::Base.FastContiguousSubArray, i, I) =
pointer(arr, (i, I...))
would match this but perhaps this is the difference between "FastContiguousArray" and "ContiguousArray". I don't fully understand all the typealiases in that file...

@KristofferC
Copy link
Collaborator

I'd be happy to provide the fix here but StrideArraysCore.jl is not a dependency, so thought I'd raise the issue here.

In theory we could add an extension for StrideArraysCore and provide it there but if it can be done generically, that would be better.

@jwscook
Copy link
Author

jwscook commented Apr 11, 2024

Yep, extending it treats the symptom but a cure would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants