From 1453a50c947e0855a6b0eb4dc2997f03938e9e25 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 25 Feb 2025 13:34:16 +0100 Subject: [PATCH] handle inbounds and insert `julia.simdloop` to every loop --- src/Trixi.jl | 14 +------------- src/auxiliary/mock_turbo.jl | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 src/auxiliary/mock_turbo.jl diff --git a/src/Trixi.jl b/src/Trixi.jl index 725ede2eb6..7178243c1a 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -63,19 +63,7 @@ if _PREFERENCE_LOOPVECTORIZATION using LoopVectorization: LoopVectorization, @turbo, indices else using LoopVectorization: LoopVectorization, indices - macro turbo(exprs...) - body = nothing - for expr in exprs - if expr.head == :for - body = expr - end - end - @assert body !== nothing - # TODO: We should insert !loopinfo !julia.ivdep !julia.simd - # but SimdLoop.compile doesn't deal with nested for loops. - # esc(Base.SimdLoop.compile(body, Symbol("julia.ivdep"))) - return esc(body) - end + include("auxiliary/mock_turbo.jl") end using StaticArrayInterface: static_length # used by LoopVectorization diff --git a/src/auxiliary/mock_turbo.jl b/src/auxiliary/mock_turbo.jl new file mode 100644 index 0000000000..dcf1a892ed --- /dev/null +++ b/src/auxiliary/mock_turbo.jl @@ -0,0 +1,28 @@ +macro turbo(exprs...) + body = nothing + for expr in exprs + if Meta.isexpr(expr, :for) + body = expr + end + end + @assert body !== nothing + + function insert_loopinfo!(expr) + recurse = Meta.isexpr(expr, :for) || Meta.isexpr(expr, :block) || + Meta.isexpr(expr, :let) + if recurse + foreach(insert_loopinfo!, expr.args) + end + if Meta.isexpr(expr, :for) + # TODO: Should we insert LLVM loopinfo or `julia.ivdep`? + push!(expr.args, Expr(:loopinfo, Symbol("julia.simdloop"))) + end + end + insert_loopinfo!(body) + + body = Expr(:block, + Expr(:inbounds, true), + body, + Expr(:inbounds, :pop)) + return esc(body) +end