Skip to content

Commit 4dfacaf

Browse files
committed
Planning on changing how strides are handled; vectorizables will carry strides with them.
1 parent e3324d2 commit 4dfacaf

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

src/graphs.jl

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# using LightGraphs
21

32

43
isdense(::Type{<:DenseArray}) = true
@@ -83,10 +82,9 @@ struct Operation
8382
end
8483
end
8584

86-
87-
8885
function isreduction(op::Operation)
89-
(op.node_type == memstore) && (length(op.symbolic_metadata) < length(op.dependencies))# && issubset(op.symbolic_metadata, op.dependencies)
86+
length(op.reduced_deps) > 0
87+
# (op.node_type == memstore) && (length(op.symbolic_metadata) < length(op.dependencies))# && issubset(op.symbolic_metadata, op.dependencies)
9088
end
9189
isload(op::Operation) = op.node_type == memload
9290
iscompute(op::Operation) = op.node_type == compute
@@ -118,37 +116,6 @@ function stride(op::Operation, sym::Symbol)
118116
op.numerical_metadata[symposition(op,sym)]
119117
end
120118
# function
121-
function unitstride(op::Operation, sym::Symbol)
122-
(first(op.symbolic_metadata) === sym) && (first(op.numerical_metadata) == 1)
123-
end
124-
function mem_offset(op::Operation, incr::Int = 0)::Union{Symbol,Expr}
125-
@assert accesses_memory(op) "Computing memory offset only makes sense for operations that access memory."
126-
@unpack numerical_metadata, symbolic_metadata = op
127-
if incr == 0 && length(numerical_metadata) == 1
128-
firstsym = first(symbolic_metadata)
129-
if first(numerical_metadata) == 1
130-
return firstsym
131-
elseif first(numerical_metadata) == -1
132-
return Expr(:call, :*, Symbol(:stride_, op.variable, :_, firstsym), firstsym)
133-
else
134-
return Expr(:call, :*, first(numerical_metadata), firstsym)
135-
end
136-
end
137-
ret = Expr(:call, :+, )
138-
for i eachindex(numerical_metadata)
139-
sym = symbolic_metadata[i]; num = numerical_metadata[i]
140-
if num == 1
141-
push!(ret.args, sym)
142-
elseif num == -1
143-
push!(ret.args, Expr(:call, :*, Symbol(:stride_, op.variable, :_, firstsym), sym))
144-
else
145-
push!(ret.args, Expr(:call, :*, num, sym))
146-
end
147-
end
148-
incr == 0 || push!(ret.args, incr)
149-
ret
150-
end
151-
152119

153120
struct Loop
154121
itersymbol::Symbol
@@ -274,12 +241,14 @@ function add_loop!(ls::LoopSet, looprange::Expr)
274241
ls.loops[itersym] = loop
275242
nothing
276243
end
277-
function add_load!(ls::LoopSet, indexed::Symbol, indices::AbstractVector)
244+
function add_load!(
245+
ls::LoopSet, indexed::Symbol, indices::AbstractVector, nstrides::Vector{Int} = fill(-1, length(indices))
246+
)
278247
Ninds = length(indices)
279248
inds = ShortVector{Symbol}(indices)
280249
nsets = length(ls.stridesets)
281250
get!(ls.stridesets, inds) do
282-
strides = ShortVector{Symbol}(undef, Ninds - 1)
251+
sstrides = ShortVector{Symbol}(undef, Ninds)
283252
@inbounds for i 2:Ninds
284253
sᵢ = Symbol(:stride_, nsets, :_, inds[i])
285254
strides[i-1] = sᵢ

src/lowering.jl

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
1+
function unitstride(op::Operation, sym::Symbol)
2+
(first(op.symbolic_metadata) === sym) && (first(op.numerical_metadata) == 1)
3+
end
4+
function mem_offset(op::Operation, incr::Int = 0)::Union{Symbol,Expr}
5+
@assert accesses_memory(op) "Computing memory offset only makes sense for operations that access memory."
6+
@unpack numerical_metadata, symbolic_metadata = op
7+
if incr == 0 && length(numerical_metadata) == 1
8+
firstsym = first(symbolic_metadata)
9+
if first(numerical_metadata) == 1
10+
return firstsym
11+
elseif first(numerical_metadata) == -1
12+
return Expr(:call, :*, Symbol(:stride_, op.variable, :_, firstsym), firstsym)
13+
else
14+
return Expr(:call, :*, first(numerical_metadata), firstsym)
15+
end
16+
end
17+
ret = Expr(:call, :+, )
18+
for i eachindex(numerical_metadata)
19+
sym = symbolic_metadata[i]; num = numerical_metadata[i]
20+
if num == 1
21+
push!(ret.args, sym)
22+
elseif num == -1
23+
push!(ret.args, Expr(:call, :*, Symbol(:stride_, op.variable, :_, firstsym), sym))
24+
else
25+
push!(ret.args, Expr(:call, :*, num, sym))
26+
end
27+
end
28+
incr == 0 || push!(ret.args, incr)
29+
ret
30+
end
131

232
function add_expr(q, incr)
3-
q2 = copy(q)
4-
if q2.head === :call && q2.args[2] === :+
5-
push!(q2.args, incr)
33+
if q.head === :call && q.args[2] === :+
34+
qc = copy(q)
35+
push!(qc.args, incr)
36+
qc
637
else
7-
q2 = Expr(:call, :+, q2, incr)
38+
Expr(:call, :+, q, incr)
839
end
9-
q2
1040
end
1141
function lower_load_scalar!(
1242
q::Expr, op::Operation, W::Int, unrolled::Symbol, U::Int,
@@ -42,7 +72,7 @@ function lower_load_unrolled!(
4272
push!(q.args, Expr(:(=), var, Expr(:call,:vload,ptr,memoff)))
4373
else
4474
for u 0:U-1
45-
instrcall = Expr(:call,:vload, Val{W}(), ptr, u == 0 ? memoff : add_expr(memoff, W*u))
75+
instrcall = Expr(:call, :vload, Val{W}(), ptr, u == 0 ? memoff : add_expr(memoff, W*u))
4676
if mask !== nothing && u == U - 1
4777
push!(instrcall.args, mask)
4878
end

0 commit comments

Comments
 (0)