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

MethodError: no method matching vload(::Ptr{Float64}, ::Int64, ::Mask{4,UInt8}) #116

Closed
baggepinnen opened this issue May 20, 2020 · 3 comments

Comments

@baggepinnen
Copy link
Contributor

baggepinnen commented May 20, 2020

Trying to produce a MWE for another problem, I stumbled into the following. If the length of x is changed to 12, the error goes away.

julia> function avx_problem(x::AbstractVector{T}, m) where T
           N = length(x)
           n = N-m+1
           ent = zeros(T, N)
           x isa AbstractVector && (x = x')
           @avx for i = 1:N
               for j = 1:size(x,1)
                   ent[i] += x[j,i]*log(x[j,i])
               end
           end
           ent
       end
avx_problem (generic function with 1 method)

julia> x = rand(10);

julia> e1 = avx_problem(x, 4);
ERROR: MethodError: no method matching vload(::Ptr{Float64}, ::Int64, ::VectorizationBase.Mask{4,UInt8})
Closest candidates are:
  vload(::Ptr{T}, ::I) where {T<:Union{Bool, Float16, Float32, Float64, Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}, I<:Integer} at /home/fredrikb/.julia/packages/VectorizationBase/WoChf/src/vectorizable.jl:58
  vload(::VectorizationBase.RangeWrapper, ::Any, ::Any) at /home/fredrikb/.julia/packages/VectorizationBase/WoChf/src/vectorizable.jl:565
  vload(::Ptr, ::VectorizationBase.SVec{W,I}, ::VectorizationBase.Mask{W,U} where U<:Unsigned, ::Val{Aligned}) where {W, I<:Integer, Aligned} at /home/fredrikb/.julia/packages/SIMDPirates/ShWZm/src/memory.jl:685
  ...
Stacktrace:
 [1] vload at /home/fredrikb/.julia/packages/VectorizationBase/WoChf/src/vectorizable.jl:217 [inlined]
 [2] macro expansion at /home/fredrikb/.julia/packages/LoopVectorization/WAJXF/src/reconstruct_loopset.jl:465 [inlined]
 [3] _avx_! at /home/fredrikb/.julia/packages/LoopVectorization/WAJXF/src/reconstruct_loopset.jl:465 [inlined]
 [4] avx_problem(::Array{Float64,1}, ::Int64) at ./none:6
 [5] top-level scope at none:0
@chriselrod
Copy link
Member

chriselrod commented May 20, 2020

Thanks for the report. I'm overhauling how indexing is handled on LoopVectorization master, so I'll add this as a test case for the 0.8 release and make sure it's resolved.

As a hotfix, I think the vload method at VectorizationBase.jl/src/vectorizable.jl L217 should be

@inline function vload(ptr::AbstractPointer, i::Tuple, u::Union{AbstractMask,Unsigned})
    vload(ptr.ptr, offset(ptr, staticm1(i)), extract_data(u))
end

instead of the current definition (shown in long form below for readability)

@inline function vload(ptr::AbstractPointer, i::Tuple, u::Union{AbstractMask,Unsigned})
    vload(ptr.ptr, offset(ptr, staticm1(i)), u)
end

but I'd have to make sure this doesn't break other code, since the call may be recursive and the method for OffsetStridedPtrs might not be generic enough.

@chriselrod
Copy link
Member

On my local versions...

julia> function avx_problem(x::AbstractVector{T}, m) where T
           N = length(x)
           n = N-m+1
           ent = zeros(T, N)
           x isa AbstractVector && (x = x')
           @avx for i = 1:N
               for j = 1:size(x,1)
                   ent[i] += x[j,i]*log(x[j,i])
               end
           end
           ent
       end
avx_problem (generic function with 1 method)

julia> x = rand(10);

julia> e1 = avx_problem(x, 4);

julia> e1
10-element Array{Float64,1}:
 -0.014324309330997381
 -0.3574754936802546
 -0.1615672896072288
 -0.3575533568057155
 -0.3080345204163032
 -0.28612490368920807
 -0.11497348037080715
 -0.08191664892303317
 -0.2838872967103637
 -0.3384879959637381

julia> function no_avx_problem(x::AbstractVector{T}, m) where T
           N = length(x)
           n = N-m+1
           ent = zeros(T, N)
           x isa AbstractVector && (x = x')
           for i = 1:N
               for j = 1:size(x,1)
                   ent[i] += x[j,i]*log(x[j,i])
               end
           end
           ent
       end
no_avx_problem (generic function with 1 method)

julia> e2 = no_avx_problem(x, 4);

julia> e2
10-element Array{Float64,1}:
 -0.014324309330997381
 -0.3574754936802546
 -0.1615672896072288
 -0.3575533568057155
 -0.30803452041630325
 -0.2861249036892081
 -0.11497348037080715
 -0.08191664892303317
 -0.2838872967103638
 -0.3384879959637381

@chriselrod
Copy link
Member

Finally merged the branch into master. I'll register shortly.

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