Description
Hey all,
I am eager to switch from @inbounds @simd
to @turbo
in the evaluation loops of SymbolicRegression.jl, which is the backend for PySR. You can see my initial pull request here: MilesCranmer/SymbolicRegression.jl#132 which shows the loops I am attempting to speed up.
The way my package works is that the user can pass any binary or unary operator (e.g., +
, -
, *
, /
, cos
, exp
, or any function they define). These operators will be arranged into expressions by a genetic algorithm until a combination is found that matches a relationship in a dataset. The evaluation of each expression needs to be high-performance, and is performed by a loop over an array with the @inbounds @simd
macros. This loop is behind a function barrier so that the performance is the same as if I had hard-coded each operator the user passed.
I tried to switch to @turbo
; however, I ended up seeing StackOverflowError
when testing SpecialFunctions.gamma
as an operator. From my look through these issues: #233, #232, it seems like certain functions will raise this error if they do not have SIMD implemented.
Now, this is an issue for my package, since the user is allowed (and encouraged) to specify any Julia function they wish as the operator - even complex, branching functions (including any of SpecialFunctions
) - and those operators will be used inside these loops. Now, I understand that each operator would need to be implemented as a SIMD operation for @turbo
to give a speedup, but I would still like to get the speed for other more standard operators, like +
, -
, *
, /
, etc.
I am therefore wondering if it is possible to change @turbo
to be robust against StackOverflowErrors
, and fall back to a non-SIMD operations? Or, maybe a @safe_turbo
macro implemented that could do this? (This assumes I do not know what code the user would use inside each loop at runtime.)
Thanks!
Miles