Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,17 @@ function _mapreduce_kernel_expr(f, op, initop, N::Int, M::Int)
outerreturnstrideex[i] = returnex
end

# Unit-stride fast path for the innermost (vectorized) loop dimension.
# We special-case for contiguous loads/stores to avoid SIMD gather/scatter
# in favor of SIMD load/store, which streams memory more efficiently.
unitstep1ex = :($(Ivars[1]) += 1)
unitstep2ex = Expr(:block)
for j in 2:M
push!(unitstep2ex.args, :($(Ivars[j]) += 1))
end
firststrides = Expr(:tuple, (stridevars[1, j] for j in 1:M)...)
unitstridecond = :(all(==(1), $firststrides))

if op == Nothing
ex = Expr(:(=), lhsex, fcallex)
exa = Expr(:(=), :a, fcallex)
Expand All @@ -358,6 +369,14 @@ function _mapreduce_kernel_expr(f, op, initop, N::Int, M::Int)
end
$lhsex = a
$(returnstride2ex[i])
elseif $unitstridecond
@simd for $(innerloopvars[i]) in Base.OneTo($(blockdimvars[i]))
$ex
$unitstep1ex
$unitstep2ex
end
$(returnstride1ex[i])
$(returnstride2ex[i])
else
@simd for $(innerloopvars[i]) in Base.OneTo($(blockdimvars[i]))
$ex
Expand Down
Loading