Skip to content

Commit bf2a0a6

Browse files
committed
Change handling of vector reductions
1 parent ed0c5c4 commit bf2a0a6

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LoopVectorization"
22
uuid = "bdcacae8-1622-11e9-2a5c-532679323890"
33
authors = ["Chris Elrod <[email protected]>"]
4-
version = "0.12.35"
4+
version = "0.12.36"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/codegen/lower_compute.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,18 +363,31 @@ function getu₁forreduct(ls::LoopSet, op::Operation, u₁::Int)
363363
end
364364
isidentityop(op::Operation) = iscompute(op) && (instruction(op).instr === :identity) && (length(parents(op)) == 1)
365365
function reduce_parent!(q::Expr, ls::LoopSet, op::Operation, opp::Operation, parent::Symbol)
366+
# if instruction(op).instr === :log_fast
367+
# @show op opp isvectorized(op) isvectorized(opp) dependent_outer_reducts(ls, op)
368+
# end
366369
isvectorized(op) && return parent
367-
dependent_outer_reducts(ls, op) && return parent
370+
# if dependent_outer_reducts(ls, op)
371+
372+
# return parent
373+
# end
374+
# @show op opp isvectorized(opp)
368375
if isvectorized(opp)
369376
oppt = opp
370377
elseif isidentityop(opp)
371378
oppt = only(parents(opp))
379+
# @show oppt
372380
isvectorized(oppt) || return parent
373381
else
374382
return parent
375383
end
384+
reduct_class = reduction_instruction_class(oppt.instruction)
385+
if (instruction(op).instr === :mul_fast) & (reduct_class == ADDITIVE_IN_REDUCTIONS)
386+
op.vectorized = true
387+
return parent
388+
end
376389
newp = gensym(parent)
377-
push!(q.args, Expr(:(=), newp, Expr(:call, lv(reduction_to_scalar(oppt.instruction)), parent)))
390+
push!(q.args, Expr(:(=), newp, Expr(:call, lv(reduction_to_scalar(reduct_class)), parent)))
378391
newp
379392
end
380393
function lower_compute!(
@@ -528,7 +541,7 @@ function lower_compute!(
528541
# elseif parents_u₂syms[n] & (!u₂unrolledsym)
529542
#&& (isouterreduction(ls, opp) != -1)
530543
# this checks if the parent is u₂ unrolled but this operation is not, in which case we need to reduce it.
531-
reduced_u₂ = reduce_expr_u₂(mangledvar(opp), instruction(opp), u₂max, Symbol("__", u₁))#ureduct(ls))
544+
reduced_u₂ = reduce_expr_u₂(mangledvar(opp), instruction(opp), u₂max, Symbol("__", u₁))#ureduct(ls))
532545
reducedparentname = gensym!(ls, "reducedop")
533546
push!(q.args, Expr(:(=), reducedparentname, reduced_u₂))
534547
reduced_u₂ = reduce_parent!(q, ls, op, opp, reducedparentname)

src/codegen/lower_store.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function storeinstr_preprend(op::Operation, vloopsym::Symbol)
66
# vectorized is not a loopdep, but is a reduced dep
77
opp = first(parents(op))
88
# while vectorized ∉ loopdependencies(opp)
9-
while !isvectorized(opp)
9+
while ((!isvectorized(opp)) || (any(rdep -> rdep loopdependencies(opp), reduceddependencies(opp))))
1010
oppold = opp
1111
for oppp parents(opp)
1212
if vloopsym reduceddependencies(oppp)

src/codegen/operation_evaluation_order.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,28 @@
1616

1717
# end
1818

19-
function dependent_outer_reducts(ls::LoopSet, op)
20-
for i ls.outer_reductions
21-
search_tree(parents(operations(ls)[i]), name(op)) && return true
22-
end
23-
false
24-
end
19+
# function dependent_outer_reducts(ls::LoopSet, op)
20+
# for i ∈ ls.outer_reductions
21+
# search_tree(parents(operations(ls)[i]), name(op)) && return true
22+
# end
23+
# false
24+
# end
2525

2626
function isnopidentity(ls::LoopSet, op::Operation, u₁loop::Symbol, u₂loop::Symbol, vectorized::Symbol, u₂max::Int)
27-
parents_op = parents(op)
27+
parents_op = parents(op)
2828
if iscompute(op) && instruction(op).instr === :identity && isone(length(parents_op)) && name(first(parents_op)) === name(op)
29-
loopistiled = u₂max -1
29+
# loopistiled = u₂max ≠ -1
3030
# parents_u₁syms, parents_u₂syms = parent_unroll_status(op, u₁loop, u₂loop, u₂max)
31-
# @show (u₁unrolledsym, first(parents_u₁syms)), (isu₂unrolled(op), parents_u₂syms[1])
32-
# @show op parents(op) isu₁unrolled(op), isu₁unrolled(only(parents(op)))
3331
# if (u₁unrolledsym == first(parents_u₁syms)) && (isu₂unrolled(op) == parents_u₂syms[1])
3432
opp = only(parents_op)
33+
# @show op opp isu₁unrolled(op), isu₁unrolled(opp), isu₂unrolled(op), isu₂unrolled(opp)
3534
if (isu₁unrolled(op) == isu₁unrolled(opp)) & (isu₂unrolled(op) == isu₂unrolled(opp))
3635
true
3736
else
38-
if isvectorized(opp) & (!isvectorized(op))
39-
op.instruction = reduction_to_scalar(instruction(opp))
40-
op.mangledvariable = gensym(op.mangledvariable)
41-
end
37+
# if isvectorized(opp) & (!isvectorized(op))
38+
# op.instruction = reduction_to_scalar(instruction(opp))
39+
# op.mangledvariable = gensym(op.mangledvariable)
40+
# end
4241
false
4342
end
4443
else

test/outer_reductions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function test_awmean(::Type{T}) where {T}
5050
wxlv, wσlv, mswdlv = awmean_lv(x, σ)
5151
isfinite(wx) && @test wx wxlv
5252
isfinite(wσ) && @test wσlv
53-
isfinite(mswd) && @test mswd mswdlv atol=1e-16 rtol=sqrt(eps(typeof(mswdlv)))
53+
isfinite(mswd) && @test mswd mswdlv atol=eps(typeof(mswdlv)) rtol=sqrt(eps(typeof(mswdlv)))
5454
end
5555
end
5656

0 commit comments

Comments
 (0)