con-kitty / categorifier-c

Haskell to C compiler via Categorifier
BSD 3-Clause "New" or "Revised" License
29 stars 3 forks source link

Staged compilation for unsafePerformIO #58

Open zliu41 opened 2 years ago

zliu41 commented 2 years ago

When external functions (such as ad) uses unsafePerformIO, 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:

wavewave commented 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).