SUMMARY
ONNX Runtime Raku Bindings - Summary
What Works
Standalone Scripts (ā WORKING)
onnx-working.raku- Basic functionality demonstrationmnist-final.raku- Complete MNIST inference exampleBoth scripts work perfectly and can load models and run inference
Why Modules Don't Work
Raku's module precompilation system has a bug when:
Modules use NativeCall to load native libraries
Function pointers are obtained at runtime (not direct exports)
These function pointers are called during module initialization
This causes the precompilation process to hang indefinitely.
Attempted Solutions
1. Traditional Module Approach (ā FAILED)
Created various module architectures (Simple, Direct, Lazy, etc.)
All hang during precompilation when trying to initialize ONNX Runtime
2. Server-Client Approach (ā ļø PARTIAL)
Created
onnx-runtime-server.raku- A standalone server that handles ONNX operationsCreated wrapper modules (
ONNX::Wrapper,ONNX::Runtime) to communicate with serverWorks in principle but has complexity issues with process management
3. Script Generation Approach (ā ļø PARTIAL)
Created
ONNX::ScriptWrapperthat generates temporary scriptsAvoids precompilation by running standalone scripts
Works but has overhead and complexity
Recommendations
For production use:
Use the standalone scripts directly - They work perfectly
Wait for Raku to fix the precompilation bug - This needs to be reported upstream
Consider creating a C wrapper library - With direct function exports instead of function pointers
Key Learning
The ONNX Runtime C API's design (function pointer table via OrtGetApiBase()) is fundamentally incompatible with Raku's current module precompilation system. This is a Raku bug, not an issue with our implementation.
Files Overview
Working Scripts:
āāā onnx-working.raku # Basic ONNX Runtime demo
āāā mnist-final.raku # Complete MNIST inference
āāā onnx-runtime-server.raku # Server for wrapper approach
Module Attempts:
āāā lib/
ā āāā ONNX/
ā ā āāā Simple.rakumod # Minimal module (exports types only)
ā ā āāā Wrapper.rakumod # Async server wrapper
ā ā āāā Runtime.rakumod # Sync server wrapper
ā ā āāā ScriptWrapper.rakumod # Script generation wrapper
ā āāā ONNX/Runtime/
ā āāā API/Simple.rakumod # Various architecture attempts
ā āāā Direct.rakumod
ā āāā Lazy.rakumod
ā āāā ... (many more attempts)
Documentation:
āāā README-ONNX-Runtime.md # User documentation
āāā README-precompilation-issue.md # Technical details of the bug
āāā SUMMARY.md # This fileNext Steps
Report the bug to Raku developers with our minimal test cases
Use the working scripts for any immediate needs
Consider alternative approaches like creating a simplified C wrapper library