LoopVectorization.jl icon indicating copy to clipboard operation
LoopVectorization.jl copied to clipboard

KeyError: key NumType not found

Open JeffreySarnoff opened this issue 5 years ago • 3 comments
trafficstars

This is a powerful and welcome tool. I would like to apply it to more packages. I have run into a limitation on supported types that seems more narrow than necessary.

running e.g. myselfdotavx(xs::T) where T is a Float64 compatible primitive type (or most other numeric bitstype, including Int64 compatibles) except for T = Union{Float64, Float32, Int64, Int32} results in a KeyError.

ERROR: KeyError: key XFloat32 not found
Stacktrace:
 [1] getindex at .\dict.jl:477 [inlined]
 [2] llvmtype(::Type{T} where T) at C:\Users\jas\.julia\packages\VectorizationBase\rPD9W\src\vectorizable.jl:22
 [3] #s13#2(::Any, ::Any, ::Any, ::Any) at C:\Users\jas\.julia\packages\VectorizationBase\rPD9W\src\VectorizationBase.jl:50
 [4] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at .\boot.jl:526
 [5] vzero at C:\Users\jas\.julia\packages\VectorizationBase\rPD9W\src\VectorizationBase.jl:74 [inlined]
 [6] macro expansion at C:\Users\jas\.julia\packages\LoopVectorization\8wcli\src\reconstruct_loopset.jl:248 [inlined]
 [7] _avx_! at C:\Users\jas\.julia\packages\LoopVectorization\8wcli\src\reconstruct_loopset.jl:248 [inlined]
 [8] myselfdotavx(::Array{XFloat32,1}) at .\REPL[39]:3
 [9] ##core#495() at C:\Users\jas\.julia\packages\BenchmarkTools\7aqwe\src\execution.jl:297
 [10] ##sample#496(::BenchmarkTools.Parameters) at C:\Users\jas\.julia\packages\BenchmarkTools\7aqwe\src\execution.jl:303
 [11] _run(::BenchmarkTools.Benchmark{Symbol("##benchmark#494")}, ::BenchmarkTools.Parameters; verbose::Bool, pad::String, kwargs::Base.Iterators.Pairs{Symbol,Integer,NTuple{4,Symbol},NamedTuple{(:samples, :evals, :gctrial, :gcsample),Tuple{Int64,Int64,Bool,Bool}}}) at C:\Users\jas\.julia\packages\BenchmarkTools\7aqwe\src\execution.jl:331
 [12] (::Base.var"#inner#2"{Base.Iterators.Pairs{Symbol,Integer,NTuple{5,Symbol},NamedTuple{(:verbose, :samples, :evals, :gctrial, :gcsample),Tuple{Bool,Int64,Int64,Bool,Bool}}},typeof(BenchmarkTools._run),Tuple{BenchmarkTools.Benchmark{Symbol("##benchmark#494")},BenchmarkTools.Parameters}})() at .\essentials.jl:715
 [13] #invokelatest#1 at .\essentials.jl:716 [inlined]
 [14] #run_result#37 at C:\Users\jas\.julia\packages\BenchmarkTools\7aqwe\src\execution.jl:32 [inlined]
 [15] run(::BenchmarkTools.Benchmark{Symbol("##benchmark#494")}, ::BenchmarkTools.Parameters; kwargs::Base.Iterators.Pairs{Symbol,Integer,NTuple{5,Symbol},NamedTuple{(:verbose, :samples, :evals, :gctrial, :gcsample),Tuple{Bool,Int64,Int64,Bool,Bool}}}) at C:\Users\jas\.julia\packages\BenchmarkTools\7aqwe\src\execution.jl:46
 [16] #warmup#42 at C:\Users\jas\.julia\packages\BenchmarkTools\7aqwe\src\execution.jl:79 [inlined]
 [17] warmup(::BenchmarkTools.Benchmark{Symbol("##benchmark#494")}) at C:\Users\jas\.julia\packages\BenchmarkTools\7aqwe\src\execution.jl:79
 [18] top-level scope at C:\Users\jas\.julia\packages\BenchmarkTools\7aqwe\src\execution.jl:390

or Using Int128 results in

ERROR: error compiling myselfdotavx: Failed to parse LLVM Assembly:
julia: llvmcall:3:5: error: value doesn't match function result type '[2 x i128]'
ret <2 x i128> zeroinitializer
    ^

JeffreySarnoff avatar Feb 06 '20 07:02 JeffreySarnoff

If, on the other hand, by providing some specified function using a signature with the variant type would allow this to work -- please let me know the details.

JeffreySarnoff avatar Feb 06 '20 07:02 JeffreySarnoff

This library uses a lot of llvmcall under the hood, therefore it needs the types it uses to map to LLVM. For some reason Julia doesn't map NTuple{N,Core.VecElement{Int128}} to LLVM vectors, even though i128 is a supported type. Maybe one of us can file an issue with Julia to have this changed or find out the reasoning behind that choice.

It would be great to come up with a way to let it work in cases where there shouldn't be anything stopping it. Presumably XFloat32 is like a Float32? Same goes for packages like UnitFul.

At some point I'll do an overhaul on how it handles types, but I'm waiting until I have a clearer vision of how and what it'll do. I'd like to be able to handle composite structs like StructOfArrays does, creating structs of llvm vectors.

chriselrod avatar Feb 06 '20 13:02 chriselrod

For some reason Julia doesn't map NTuple{N,Core.VecElement{Int128}} to LLVM vectors, even though i128 is a supported type. Maybe one of us can file an issue with Julia to have this changed or find out the reasoning behind that choice.

I will pursue this.

@chriselrod and I are wondering if it is easily remediable that "Julia does not map NTuple{N,Core.VecElement{Int128}} to LLVM vectors, even though i128 is a supported type." (https://github.com/chriselrod/LoopVectorization.jl/issues/46)

posted in Slack #codegen (https://julialang.slack.com/archives/CGMPNPNFK/p1581008475002100)

JeffreySarnoff avatar Feb 06 '20 16:02 JeffreySarnoff