Open zliu41 opened 2 years ago
Comment: Independently from this unsafePerformIO
issue, in practice, the use of the ad
library in categorifer-c generated code should be passed through autointerpret. The reason is because to have differentiated function at compile time and use it in already-compiled form at use sites enormously saves computations.
If we use only inlining for H&G-like function, then the differentiation will be invoked at run time at every call site.
Note that this was essentially what we observed when comparing the performance difference between generated C and using autodiff C++ library (the former was few hundred times faster than the latter).
When external functions (such as
ad
) usesunsafePerformIO
, currently one viable way to circumvent the blocking categorization situation is to wrap the function and inline the result of the function before categorization. This can be only applicable for functions that generates expression, not values, but in old code generation,unsafePerformIO
is also only available only for generating phase functions, so this should be compatible with our approach.Acceptance Criteria:
(Extricated from https://kitty-hawk.atlassian.net/browse/SW-3432)