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

WIP: shorten compile time with nospecialize #76

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/LoopVectorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export LowDimArray, stridedpointer, vectorizable,

include("vectorizationbase_extensions.jl")
include("predicates.jl")
include("typeutils.jl")
include("map.jl")
include("filter.jl")
include("costs.jl")
Expand Down
18 changes: 12 additions & 6 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ the final operation.
# TODO: Need to make this handle A or B being (1 or 2)-D broadcast objects.
function add_broadcast!(
ls::LoopSet, mC::Symbol, bcname::Symbol, loopsyms::Vector{Symbol},
::Type{Product{A,B}}, elementbytes::Int
) where {A, B}
@nospecialize(AB::Type{<:Product}), elementbytes::Int
)
A, B = AB.parameters
K = gensym(:K)
mA = gensym(:Aₘₖ)
mB = gensym(:Bₖₙ)
Expand Down Expand Up @@ -126,8 +127,9 @@ function LowDimArray{D}(data::A) where {D,T,N,A <: AbstractArray{T,N}}
end
function add_broadcast!(
ls::LoopSet, destname::Symbol, bcname::Symbol, loopsyms::Vector{Symbol},
::Type{<:LowDimArray{D,T,N}}, elementbytes::Int
) where {D,T,N}
@nospecialize(LDA::Type{<:LowDimArray}), elementbytes::Int
)
D, T, N = LDA.parameters
fulldims = Symbol[loopsyms[n] for n ∈ 1:N if D[n]]
ref = ArrayReference(bcname, fulldims)
add_simple_load!(ls, destname, ref, elementbytes, true, false )::Operation
Expand Down Expand Up @@ -180,9 +182,13 @@ function add_broadcast!(
end
function add_broadcast!(
ls::LoopSet, destname::Symbol, bcname::Symbol, loopsyms::Vector{Symbol},
::Type{Broadcasted{S,Nothing,F,A}},
BT::Type{<:Broadcasted},
elementbytes::Int
) where {N,S<:Base.Broadcast.AbstractArrayStyle{N},F,A}
)
@nospecialize BT
S,_,F,A = BT.parameters
N = abstractparameters(S, Broadcast.AbstractArrayStyle)[1]

instr = get(FUNCTIONSYMBOLS, F) do
# f = gensym(:func)
# pushpreamble!(ls, Expr(:(=), f, Expr(:(.), bcname, QuoteNode(:f))))
Expand Down
5 changes: 3 additions & 2 deletions src/reconstruct_loopset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ function add_mref!(ls::LoopSet, ar::ArrayReferenceMeta, i::Int, ::Type{OffsetStr
end

function add_mref!(
ls::LoopSet, ar::ArrayReferenceMeta, i::Int, ::Type{S}
) where {T, X <: Tuple, S <: VectorizationBase.AbstractStaticStridedPointer{T,X}}
ls::LoopSet, ar::ArrayReferenceMeta, i::Int, @nospecialize(S::Type{<:VectorizationBase.AbstractStaticStridedPointer})
)
T, X = abstractparameters(S, VectorizationBase.AbstractStaticStridedPointer)
if last(X.parameters)::Int == 1
pushvarg′!(ls, ar, i)
else
Expand Down
21 changes: 21 additions & 0 deletions src/typeutils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# @nospecialize # don't specialize anything until @specialize

"""
params = abstractparameters(T::Type, AT::Type)

For a type `T` which is a subtype of `AT{params...}`, return `params`.
The purpose of this function is to allow one to use `@nospecialize` on type-arguments
and still extract the parameters of the corresponding abstract type.
"""
function abstractparameters(T::Type, AT::Type)
@nospecialize T AT
@assert T <: AT
Tst = supertype(T)
while Tst <: AT
T = Tst
Tst = supertype(T)
end
return T.parameters
end

# @specialize
2 changes: 2 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using LoopVectorization, LinearAlgebra, Test

@testset "broadcast" begin
M, N = 37, 47
# M = 77;
Expand Down