Skip to content

Commit 5a5ce54

Browse files
committed
Add a few many loop reduction tests.
1 parent 90038c8 commit 5a5ce54

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

src/codegen/lower_store.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ function lower_store!(
149149
reductfunc::Symbol = storeinstr_preprend(op, ua.vloop.itersymbol), inds_calc_by_ptr_offset = indices_calculated_by_pointer_offsets(ls, op.ref)
150150
)
151151
@unpack u₁, u₁loopsym, u₂loopsym, vloopsym, vloop, u₂max, suffix = ua
152-
153152
omop = offsetloadcollection(ls)
154153
batchid, opind = omop.batchedcollectionmap[identifier(op)]
155154
if ((batchid 0) && isvectorized(op)) && (!rejectinterleave(op))
@@ -161,10 +160,13 @@ function lower_store!(
161160
# trueexpr = Expr(:call, lv(:True));
162161
rs = staticexpr(reg_size(ls));
163162
opp = first(parents(op))
164-
if ((opp.instruction.instr === reductfunc) || (opp.instruction.instr === :identity)) && isone(length(parents(opp)))
165-
opp = only(parents(opp))
163+
if (((opp.instruction.instr === reductfunc) || (opp.instruction.instr === :identity)) && isone(length(parents(opp))))
164+
oppp = only(parents(opp))
165+
if isu₂unrolled(op) == isu₂unrolled(oppp)
166+
opp = oppp
167+
end
166168
end
167-
# __u₂max = ls.unrollspecification.u₂
169+
# __u₂max = ls.unrollspecification.u₂
168170
isu₁, isu₂ = isunrolled_sym(opp, u₁loopsym, u₂loopsym, vloopsym, ls)#, __u₂max)
169171
# @show isu₁, isu₂, u₁loopsym, u₂loopsym
170172
# @show isu₁, isu₂, opp, u₁loopsym, u₂loopsym, vloopsym

test/grouptests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const START_TIME = time()
4949
@time include("multiassignments.jl")
5050

5151
@time include("reduction_untangling.jl")
52+
53+
@time include("manyloopreductions.jl")
5254
end
5355

5456
@time if LOOPVECTORIZATION_TEST == "all" || LOOPVECTORIZATION_TEST == "part2"

test/manyloopreductions.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
@testset "Many Loop Reductions" begin
3+
A = rand((2:6)...);
4+
N = ndims(A)
5+
T = eltype(A)
6+
let dims = (3,5)
7+
8+
sᵢ = size(A)
9+
sₒ = ntuple(Val(N)) do d
10+
ifelse(d dims, 1, sᵢ[d])
11+
end
12+
Tₒ = Base.promote_op(+, T, Int)
13+
B = similar(A, Tₒ, sₒ);
14+
15+
Bᵥ = view(B, Colon(), Colon(), firstindex(B, 3), Colon(), firstindex(B, 5))
16+
@turbo for i_1 = indices((A, B), 1)
17+
for i_2 = indices((A, B), 2)
18+
for i_4 = indices((A, B), 4)
19+
Σ = zero(eltype(Bᵥ))
20+
for i_3 = axes(A, 3)
21+
for i_5 = axes(A, 5)
22+
Σ += A[i_1, i_2, i_3, i_4, i_5]
23+
end
24+
end
25+
Bᵥ[i_1, i_2, i_4] = Σ
26+
end
27+
end
28+
end
29+
@test B sum(A, dims = dims)
30+
end
31+
let dims = (1,2,5)
32+
33+
sᵢ = size(A)
34+
sₒ = ntuple(Val(N)) do d
35+
ifelse(d dims, 1, sᵢ[d])
36+
end
37+
Tₒ = Base.promote_op(+, T, Int)
38+
B = similar(A, Tₒ, sₒ);
39+
40+
Bᵥ = view(B, firstindex(B, 1), firstindex(B, 2), Colon(), Colon(), firstindex(B, 5))
41+
@turbo for i_3 = indices((A, B), 3)
42+
for i_4 = indices((A, B), 4)
43+
Σ = zero(eltype(Bᵥ))
44+
for i_1 = axes(A, 1)
45+
for i_2 = axes(A, 2)
46+
for i_5 = axes(A, 5)
47+
Σ += A[i_1, i_2, i_3, i_4, i_5]
48+
end
49+
end
50+
end
51+
Bᵥ[i_3, i_4] = Σ
52+
end
53+
end
54+
@test B sum(A, dims = dims)
55+
end
56+
end
57+

0 commit comments

Comments
 (0)