Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/auxiliary/mock_turbo.jl
2055 views
1
# Copies some of the LoopVectorization functionality,
2
# but solely using Julia base functionality. It is equivalent to `@simd`
3
# at every loop level
4
macro turbo(exprs...)
5
# Find the outermost for loop
6
body = nothing
7
for expr in exprs
8
if Meta.isexpr(expr, :for)
9
body = expr
10
end
11
end
12
@assert body !== nothing
13
14
# We want to visit each nested for loop and insert a `Loopinfo` expression at every level.
15
function insert_loopinfo!(expr)
16
recurse = Meta.isexpr(expr, :for) || Meta.isexpr(expr, :block) ||
17
Meta.isexpr(expr, :let)
18
if recurse
19
foreach(insert_loopinfo!, expr.args)
20
end
21
if Meta.isexpr(expr, :for)
22
# We could insert additional LLVM loopinfo or `julia.ivdep`.
23
# For now we just encourage vectorization.
24
# `Expr(:loopinfo)` corresponds to https://llvm.org/docs/LangRef.html#llvm-loop with two additional nodes
25
# `julia.simdloop` & `julia.ivdep`
26
# x-ref: https://github.com/JuliaLang/julia/pull/31376
27
push!(expr.args, Expr(:loopinfo, Symbol("julia.simdloop")))
28
end
29
end
30
insert_loopinfo!(body)
31
32
body = Expr(:block,
33
Expr(:inbounds, true),
34
body,
35
Expr(:inbounds, :pop))
36
return esc(body)
37
end
38
39