@@ -5,51 +5,55 @@ function opisreduced(op::Operation)
5
5
false
6
6
end
7
7
function storeinstr_preprend (op:: Operation , vloopsym:: Symbol )
8
- # defaultstoreop = :vstore!
9
- # defaultstoreop = :vnoaliasstore!
10
- isvectorized (op) && return Symbol (" " )
11
- vloopsym ∉ reduceddependencies (op) && return Symbol (" " )
12
- # vectorized is not a loopdep, but is a reduced dep
13
- opp:: Operation = first (parents (op))
14
- # while vectorized ∉ loopdependencies(opp)
15
- while ((! isvectorized (opp)) || opisreduced (opp))
16
- oppold = opp
17
- for oppp ∈ parents (opp)
18
- if vloopsym ∈ reduceddependencies (oppp)
19
- @assert opp != = oppp " More than one parent is a reduction over the vectorized variable."
20
- opp = oppp
21
- end
22
- end
23
- @assert opp != = oppold " Failed to find any parents "
8
+ # defaultstoreop = :vstore!
9
+ # defaultstoreop = :vnoaliasstore!
10
+ isvectorized (op) && return Symbol (" " )
11
+ vloopsym ∉ reduceddependencies (op) && return Symbol (" " )
12
+ # vectorized is not a loopdep, but is a reduced dep
13
+ opp:: Operation = first (parents (op))
14
+ # while vectorized ∉ loopdependencies(opp)
15
+ while ((! isvectorized (opp)) || opisreduced (opp))
16
+ oppold = opp
17
+ for oppp ∈ parents (opp)
18
+ if vloopsym ∈ reduceddependencies (oppp)
19
+ @assert opp != = oppp " More than one parent is a reduction over the vectorized variable."
20
+ opp = oppp
21
+ end
24
22
end
25
- reduction_to_scalar (reduction_instruction_class (instruction (opp)))
23
+ @assert opp != = oppold " Failed to find any parents "
24
+ end
25
+ instr = instruction (opp). instr
26
+ instr === :ifelse && return Symbol (" " ) # throw(LoopError("ifelse not yet supported for inner reductions"))
27
+ return reduction_to_scalar (instr)
28
+ # if instr ≢ :ifelse
29
+ # Expr(:(.), LoopVectorization, QuoteNode(reduction_to_scalar(instr))) # :IfElseReducer
30
+ # else
31
+ # ifelse_reduction(:IfElseReducer,opp) do opv
32
+ # throw(LoopError("Does not support storing mirrored ifelse-reductions yet"))
33
+ # end
34
+ # end
26
35
end
27
36
28
- function reduce_expr_u₂ (toreduct:: Symbol , instr :: Instruction , u₂:: Int , suffix:: Symbol )
29
- t = Expr (:tuple )
30
- for u ∈ 0 : u₂- 1
31
- push! (t. args, Symbol (toreduct, u, suffix))
32
- end
33
- Expr (:call , lv (:reduce_tup ), reduce_to_onevecunroll (instr ), t)
37
+ function reduce_expr_u₂ (toreduct:: Symbol , op :: Operation , u₂:: Int , suffix:: Symbol )
38
+ t = Expr (:tuple )
39
+ for u ∈ 0 : u₂- 1
40
+ push! (t. args, Symbol (toreduct, u, suffix))
41
+ end
42
+ Expr (:call , lv (:reduce_tup ), reduce_to_onevecunroll (op ), t)
34
43
end
35
- function reduce_expr! (q:: Expr , toreduct:: Symbol , instr:: Instruction , u₁:: Int , u₂:: Int , isu₁unrolled:: Bool , isu₂unrolled:: Bool )
36
- if isu₂unrolled# u₂ != -1
37
- _toreduct = Symbol (toreduct, 0 )
38
- push! (q. args, Expr (:(= ), _toreduct, reduce_expr_u₂ (toreduct, instr, u₂, Symbol (" " ))))
39
- else # if u₂ == -1
40
- _toreduct = Symbol (toreduct, ' _' , u₁)
41
- # else
42
- # _toreduct = Symbol(toreduct, 0)
43
- end
44
- # @show toreduct, _toreduct, u₁, u₂, isu₁unrolled, isu₂unrolled
45
- if (u₁ == 1 ) | (~ isu₁unrolled)
46
- push! (q. args, Expr (:(= ), Symbol (toreduct, " ##onevec##" ), _toreduct))
47
- else
48
- push! (q. args, Expr (:(= ), Symbol (toreduct, " ##onevec##" ), Expr (:call , lv (reduction_to_single_vector (instr)), _toreduct)))
49
- # push!(q.args, :(@show $_toreduct))
50
- # push!(q.args, Expr(:(=), Symbol(toreduct, "##onevec##"), :(@show $(Expr(:call, lv(reduction_to_single_vector(instr)), _toreduct)))))
51
- end
52
- nothing
44
+ function reduce_expr! (q:: Expr , toreduct:: Symbol , op:: Operation , u₁:: Int , u₂:: Int , isu₁unrolled:: Bool , isu₂unrolled:: Bool )
45
+ if isu₂unrolled# u₂ != -1
46
+ _toreduct = Symbol (toreduct, 0 )
47
+ push! (q. args, Expr (:(= ), _toreduct, reduce_expr_u₂ (toreduct, op, u₂, Symbol (" " ))))
48
+ else # if u₂ == -1
49
+ _toreduct = Symbol (toreduct, ' _' , u₁)
50
+ end
51
+ if (u₁ == 1 ) | (~ isu₁unrolled)
52
+ push! (q. args, Expr (:(= ), Symbol (toreduct, " ##onevec##" ), _toreduct))
53
+ else
54
+ push! (q. args, Expr (:(= ), Symbol (toreduct, " ##onevec##" ), Expr (:call , reduction_to_single_vector (op), _toreduct)))
55
+ end
56
+ nothing
53
57
end
54
58
55
59
function lower_store_collection! (
@@ -278,7 +282,7 @@ function lower_tiled_store!(blockq::Expr, op::Operation, ls::LoopSet, ua::Unroll
278
282
end
279
283
opp = first (parents (op))
280
284
if (opp. instruction. instr === reductfunc) && isone (length (parents (opp)))
281
- throw (" Operation $opp 's instruction is $reductfunc , shouldn't be able to reach here." )
285
+ throw (LoopError ( " Operation $opp 's instruction is $reductfunc , shouldn't be able to reach here." ) )
282
286
# opp = only(parents(opp))
283
287
end
284
288
isu₁, isu₂ = isunrolled_sym (opp, u₁loopsym, u₂loopsym, vloopsym, ls)# , u₂)
0 commit comments