Skip to content

Commit 4d29e79

Browse files
committed
Add prefetch statements, minor cost updates.
1 parent 0842b02 commit 4d29e79

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/costs.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,20 @@ const COST = Dict{Instruction,InstructionCost}(
197197
Instruction(:identity) => InstructionCost(0,0.0,0.0,0),
198198
Instruction(:adjoint) => InstructionCost(0,0.0,0.0,0),
199199
Instruction(:transpose) => InstructionCost(0,0.0,0.0,0),
200-
Instruction(:prefetch) => InstructionCost(0,0.0,0.0,0)
200+
Instruction(:prefetch) => InstructionCost(0,0.0,0.0,0),
201+
Instruction(:prefetch1) => InstructionCost(0,0.0,0.0,0),
202+
Instruction(:prefetch2) => InstructionCost(0,0.0,0.0,0),
203+
Instruction(:prefetch3) => InstructionCost(0,0.0,0.0,0)
201204
)
205+
@inline prefetch0(x, i) = SIMDPirates.prefetch(gep(stridedpointer(x), (extract_data(i) - 1,)), Val{3}(), Val{0}())
206+
@inline prefetch0(x, i, j) = SIMDPirates.prefetch(gep(stridedpointer(x), (extract_data(i) - 1, extract_data(j) - 1)), Val{3}(), Val{0}())
207+
# @inline prefetch0(x, i, j, oi, oj) = SIMDPirates.prefetch(gep(stridedpointer(x), (extract_data(i) + extract_data(oi) - 1, extract_data(j) + extract_data(oj) - 1)), Val{3}(), Val{0}())
208+
@inline prefetch1(x, i) = SIMDPirates.prefetch(gep(stridedpointer(x), (extract_data(i) - 1,)), Val{2}(), Val{0}())
209+
@inline prefetch1(x, i, j) = SIMDPirates.prefetch(gep(stridedpointer(x), (extract_data(i) - 1, VectorizationBase.extract_data(j) - 1)), Val{2}(), Val{0}())
210+
# @inline prefetch1(x, i, j, oi, oj) = SIMDPirates.prefetch(gep(stridedpointer(x), (extract_data(i) + extract_data(oi) - 1, extract_data(j) + extract_data(oj) - 1)), Val{2}(), Val{0}())
211+
@inline prefetch2(x, i) = SIMDPirates.prefetch(gep(stridedpointer(x), (extract_data(i) - 1,)), Val{1}(), Val{0}())
212+
@inline prefetch2(x, i, j) = SIMDPirates.prefetch(gep(stridedpointer(x), (VectorizationBase.extract_data(i) - 1, VectorizationBase.extract_data(j) - 1)), Val{1}(), Val{0}())
213+
# @inline prefetch2(x, i, j, oi, oj) = SIMDPirates.prefetch(gep(stridedpointer(x), (extract_data(i) + extract_data(oi) - 1, extract_data(j) + extract_data(oj) - 1)), Val{1}(), Val{0}())
202214

203215
# const KNOWNINSTRUCTIONS = keys(COST)
204216
# instruction(f, m) = f ∈ KNOWNINSTRUCTIONS ? Instruction(:LoopVectorization, f) : Instruction(m, f)

src/determinestrategy.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ function register_pressure(op::Operation)
5050
end
5151
end
5252
function cost(ls::LoopSet, op::Operation, vectorized::Symbol, Wshift::Int, size_T::Int = op.elementbytes)
53-
isconstant(op) && return 0.0, 0, 1
53+
isconstant(op) && return 0.0, 0, Int(length(loopdependencies(op)) > 0)
5454
isloopvalue(op) && return 0.0, 0, 0
5555
# Wshift == dependson(op, vectorized) ? Wshift : 0
5656
# c = first(cost(instruction(op), Wshift, size_T))::Int
5757
instr = Instruction(:LoopVectorization, instruction(op).instr)
5858
# instr = instruction(op)
5959
if length(parents(op)) == 1
6060
if instr == Instruction(:-) || instr === Instruction(:vsub) || instr == Instruction(:+) || instr == Instruction(:vadd)
61-
return 0.0, 0, 1
61+
return 0.0, 0, 0
6262
end
63-
elseif iscompute(op) && all(isloopvalue, parents(op))
64-
return 0.0, 0, 1
63+
elseif iscompute(op) && all(opp -> (isloopvalue(opp) | isconstant(opp)), parents(op))
64+
return 0.0, 0, 0
6565
end
6666
opisvectorized = dependson(op, vectorized)
6767
srt, sl, srp = opisvectorized ? vector_cost(instr, Wshift, size_T) : scalar_cost(instr)
@@ -524,6 +524,7 @@ function evaluate_cost_tile(
524524
isunrolled = unrolledtiled[1,id]
525525
istiled = unrolledtiled[2,id]
526526
rt, lat, rp = cost(ls, op, vectorized, Wshift, size_T)
527+
# @show op rt, lat, rp
527528
if isload(op)
528529
factor1, factor2 = convolution_cost_factor(ls, op, unrolled, tiled, vectorized)
529530
rt *= factor1; rp *= factor2;

0 commit comments

Comments
 (0)