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

Operations with loop variables #83

Closed
kose-y opened this issue Apr 2, 2020 · 2 comments
Closed

Operations with loop variables #83

kose-y opened this issue Apr 2, 2020 · 2 comments

Comments

@kose-y
Copy link
Contributor

kose-y commented Apr 2, 2020

I have been playing around with this package, and it looks like there are many unimplemented corner cases involving operations with loop variables.

With version 0.6.27:

using LoopVectorization
function rshift_i!(out)
    n = length(out)
    @avx for i in 1:n
        out[i] = out[i] << i
    end
end
n = 512
out = Array{Int}(undef, n)
rshift_i!(out)
MethodError: no method matching <<(::VectorizationBase._MM{4,Int64}, ::VectorizationBase.SVec{4,Int64})
Closest candidates are:
  <<(!Matched::VectorizationBase.Static{N}, ::Any) where N at /home/kose/.julia/packages/VectorizationBase/OOwYB/src/static.jl:89
  <<(!Matched::VectorizationBase.Mask{W,U} where U<:Unsigned, ::Any) where W at /home/kose/.julia/packages/VectorizationBase/OOwYB/src/masks.jl:34
  <<(!Matched::VectorizationBase.SVec{W,T}, ::VectorizationBase.SVec{W,T}) where {W, T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8, Ptr}} at /home/kose/.julia/packages/SIMDPirates/thWlM/src/SIMDPirates.jl:80
  ...

Stacktrace:
 [1] macro expansion at ./gcutils.jl:91 [inlined]
 [2] rshift_i!(::Array{Int64,1}) at ./In[78]:3
 [3] top-level scope at In[80]:3
function one_plus_i!(out)
    n = length(out)
    @avx for i in 1:n
        out[i] = 1 + i
    end
end
n = 512
out = Array{Int}(undef, n)
one_plus_i!(out)
MethodError: no method matching vstore!(::Ptr{Int64}, ::VectorizationBase._MM{4,Int64}, ::VectorizationBase._MM{4,Int64})
Closest candidates are:
  vstore!(::Ptr{T}, !Matched::Tuple{Vararg{VecElement{T},W}}, ::I, !Matched::Val{Aligned}, !Matched::Val{Nontemporal}) where {W, T, I, Aligned, Nontemporal} at /home/kose/.julia/packages/SIMDPirates/thWlM/src/memory.jl:329
  vstore!(::Ptr{T}, !Matched::Union{Tuple{Vararg{VecElement{T},W}}, VectorizationBase.AbstractStructVec{W,T}}, ::VectorizationBase._MM{W,I} where I<:Number) where {W, T} at /home/kose/.julia/packages/SIMDPirates/thWlM/src/memory.jl:474
  vstore!(::Ptr{T}, !Matched::Union{Tuple{Vararg{VecElement{T},W}}, VectorizationBase.AbstractStructVec{W,T}}, ::VectorizationBase._MM{W,I} where I<:Number, !Matched::Unsigned) where {W, T} at /home/kose/.julia/packages/SIMDPirates/thWlM/src/memory.jl:474
  ...

Stacktrace:
 [1] vstore! at /home/kose/.julia/packages/VectorizationBase/OOwYB/src/vectorizable.jl:197 [inlined]
 [2] macro expansion at ./gcutils.jl:91 [inlined]
 [3] one_plus_i!(::Array{Int64,1}) at ./In[72]:3
 [4] top-level scope at In[74]:3
@chriselrod
Copy link
Member

I added these examples to the test suite.

Please file new issues as they come up!
PRs are welcome too.

For reference, the actual fixes were in SIMDPirates.jl.
Eventually, it'll need a refactoring with a focus on better type promotion behavior.

@chriselrod
Copy link
Member

chriselrod commented Apr 3, 2020

I cannot reproduce the test failures on Macs on travis.
I have neither a Mac, nor a CPU without AVX2. The latter is probably the problem. AVX2 added the SIMD shift operations. Travis's Macs do not have them.

The problem is probably that shifts are sometimes undefined when they exceed the number of bits of the element,

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