plugin.onnxruntime — Run ONNX models in Solar2D (iOS, Android, macOS, Windows)

Hi everyone,

I’ve released plugin.onnxruntime, a native C plugin that brings https://onnxruntime.ai/ inference to Solar2D. Load and run any ONNX model directly in your app — style transfer, image classification, text-to-speech, or any other ML model exported to ONNX format.

GitHub: GitHub - labolado/solar2d-plugin-onnxruntime · GitHub

Features

  • Cross-platform: iOS (with CoreML acceleration), Android, macOS Simulator, Windows Simulator*
  • Simple API: ort.load(path) → session:run(inputs) → done
  • Flexible I/O: Lua tables or binary strings for tensor data, supports float32 and int64

*Windows Simulator build is included but has not been tested on a real Windows machine. Feedback welcome.

Quick Example

  local ort = require("plugin.onnxruntime")

  local session = ort.load(system.pathForFile("model.onnx",
  system.ResourceDirectory))
  local output = session:run({
      input = { dims = {1, 3, 224, 224}, data = imagePixels }
  })
  print(output.output1.data[1])
  session:close()

Demo App

The included example demonstrates:

  • Style Transfer (Candy / Mosaic) — transform photos using neural style models
  • Text-to-Speech — synthesize speech from phoneme tokens

Tested on iPhone 17 Pro Max (iOS), Huawei ANA-AN00 (Android), and
macOS Simulator.

4 Likes

Thank you for the plugin. I test run the “main.lua” in your “example” folder on my Windows PC Simulator. It results in an error below,

error loading module 'plugin_onnxruntime' from file 'C:\Users\xxx\AppData\Roaming\Corona Labs\Corona Simulator\Plugins\plugin_onnxruntime.dll':
%1 is not a valid Win32 application.

What should be my next step? Thank you.

PS> Verified that both “onnxruntime.dll” and “plugin_onnxruntime.dll” are indeed in my plugins folder.

Regarding this issue, I think these dlls are x64 instead of the x86 architecture that Solar2D currently only supports, that is, win32, and then found the earliest ONNX Runtime v0.3.0 mentions that there is a Windows x86 version, referring to solar2d-plugin-onnxruntime/win32/download_ort.ps1 at master · labolado/solar2d-plugin-onnxruntime · GitHub and x86 · Release · microsoft/onnxruntime · GitHub

Thanks for reporting this! @clang is correct — the DLLs in v6 were x64, but Solar2D Windows Simulator is 32-bit (x86).

Fixed in v6 (updated):

  • Both plugin_onnxruntime.dll and onnxruntime.dll are now x86 (32-bit)
  • Uses ONNX Runtime v1.16.3 (last version with x86 support)

Please re-download the plugin (clear the Simulator Plugins cache if needed, usually at %APPDATA%\Corona Labs\Corona Simulator\Plugins\) and try again.

The download_ort.ps1 and build.bat scripts have also been updated for anyone building from source.

2 Likes

Thank you @laboladoapp and @clang.

I have tried the 3 released versions of 32-bit DLLs. The first 32-bit gave “Runtime error” of “The specified module could not be found.”. The later 2 versions of 32-bit DLLs crashed my Windows Simulator right away.

What is it that I have missed? Thank you again.

PS> I am running the latest example main.lua on “OnnxDemo-Win32-Example.zip”. Also, verified that all the DLLs in my plugin folders are 32-bit.

Thank you very much @laboladoapp.

It now works in my Windows Simulator with the latest update of 32-bit win-32 DLLs.

A question on the “Text-to-Speech” portion of the demo, it give a “Load failed” message on my PC windows simulator. Is it meant for Android only, and would not work in windows? Thank you.

PS> I have not yet build and test run it on Android.

I have built Android app from my windows simulator. It immediately encountered a “Runtime Error” after launch on an Android physical device,

error loading module ‘plugin.onnxruntime’ from file '/data/app/xxx-xxx/lib/arm64/libplugin.onnxruntime.so:
dlopen failed: cannot locate symbol “luaL_newmetatable” referenced by '/data/app/xxx-xxx/lib/arm64/libplugin.onnxruntime.so" …

What do you think where the cause of the problem is? Thank you again.

PS> I have verified that both “libplugin.onnxruntime.so” and “libonnxruntime.so” files are present in “arm64-v8a” and “armeabi-v7a” folders on the built Android app.

Glad it’s working!

TTS Load failed fix:
The TTS model requires ONNX opset 20, but the previous Windows DLL used ORT v1.16.3 (opset 19 only). This is now fixed in v7 — please update:

Clear your Plugins cache before updating:
%APPDATA%\Corona Labs\Corona Simulator\Plugins\

Important note on Windows performance: Solar2D Windows is x86 (32-bit), which means no AVX/SSE
optimizations. Both the Simulator and packaged EXE have the same performance limitation.
Style transfer takes several seconds, and TTS may take even longer. For production ML
inference, target iOS (CoreML acceleration) or Android.

Fixed in v7 (just updated). The Android .so was missing liblua.so linkage. Please re-download from:

Release v7 · labolado/solar2d-plugin-onnxruntime · GitHub

This should resolve the cannot locate symbol “luaL_newmetatable” error on Android.

Thank you. I have updated “built.settings” to use v7. However, it encountered “Runtime error” running on windows simulator,

error loading module ‘plugin_onnxruntime’ from file ‘C:\Users\xxx\AppData\Roaming\Corona Labs\Corona Simulator\Plugins\plugin_onnxruntime.dll’:
A dynamic link library (DLL) initialization routine failed.

Thank you again.

PS1> I have confirmed that all the DLLs have been updated to v7 in my plugin folder.
PS2> When I revert the plugins to the latest v6, it was working as before. However, the error above appear again when I update them to v7.

manually copy plugin_onnxruntime.dll to the folder where the exe file is located. I don’t have a Windows runtime environment here. Besides, Windows has a lot of issues due to x86 compatibility problems.

Yes, windows can be a pain at times. I am not sure about which “exe” file or folder you are refering to, in the windows simulator environment,

In order to reproduce the problem running in the windows simulator environment, (1) I revert them to the v6 working version in my plugin folder, run the simulator to show it is working, and (2) put the v7 version back and run the simulator to see if the problem is repeatable. (3) I also try mix and match the various pairs from v6 versions and v7. (4) The cycle above is repeated 3 times.

The problem with v7 is repeatable (in the windows simulator). Sorry about the troubles caused. Thank you.

PS> I have kept all versions of win32 plugins from v6 (noting the results of each versions), and the one from v7.