benchmarking: started tuning benchmarking results. found some errors that need fixing
Some checks are pending
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.10) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.6) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, pre) (push) Waiting to run

This commit is contained in:
Daniel
2025-05-09 19:19:53 +02:00
parent 327e4ebf1b
commit 7121329a17
5 changed files with 39 additions and 33 deletions

View File

@ -58,21 +58,34 @@ end
# Evaluate Expressions on the CPU
function interpret_cpu(exprs::Vector{Expr}, X::Matrix{Float32}, p::Vector{Vector{Float32}}; repetitions=1)::Matrix{Float32}
function interpret_cpu(exprs::Vector{Expr}, X::Matrix{Float32}, p::Vector{Vector{Float32}}; repetitions=1, parallel=false)::Matrix{Float32}
@assert axes(exprs) == axes(p)
nrows = size(X, 1)
# each column of the matrix has the result for an expr
res = Matrix{Float32}(undef, nrows, length(exprs))
for i in eachindex(exprs)
# The interpreter holds the postfix code and buffers for evaluation. It is costly to create
interpreter = CpuInterpreter.Interpreter{Float32}(exprs[i], length(p[i]))
# If an expression has to be evaluated multiple times (e.g. for different parameters),
# it is worthwhile to reuse the interpreter to reduce the number of allocations
for rep in 1:repetitions
CpuInterpreter.interpret!((@view res[:,i]), interpreter, X, p[i])
if parallel
Threads.@threads for i in eachindex(exprs)
# The interpreter holds the postfix code and buffers for evaluation. It is costly to create
interpreter = CpuInterpreter.Interpreter{Float32}(exprs[i], length(p[i]))
# If an expression has to be evaluated multiple times (e.g. for different parameters),
# it is worthwhile to reuse the interpreter to reduce the number of allocations
for rep in 1:repetitions
CpuInterpreter.interpret!((@view res[:,i]), interpreter, X, p[i])
end
end
else
for i in eachindex(exprs)
# The interpreter holds the postfix code and buffers for evaluation. It is costly to create
interpreter = CpuInterpreter.Interpreter{Float32}(exprs[i], length(p[i]))
# If an expression has to be evaluated multiple times (e.g. for different parameters),
# it is worthwhile to reuse the interpreter to reduce the number of allocations
for rep in 1:repetitions
CpuInterpreter.interpret!((@view res[:,i]), interpreter, X, p[i])
end
end
end

View File

@ -100,7 +100,7 @@ function get_operator(op::Symbol)::Operator
elseif op == :sqrt
return SQRT
else
throw("Operator unknown")
throw("Operator unknown. Operator was $op")
end
end