main
CodeQL Advanced / Analyze (swift) (push) Has been cancelled
Wraps the C API's SetInterOpNumThreads, mirroring the existing setIntraOpNumThreads binding. Automated-By: Claude Fable 5
Swift Package Manager for ONNX Runtime
Swift-native ONNX Runtime bindings derived from the public Objective-C wrapper surface, but implemented without the Objective-C bridge so the package can build on Linux.
Status
- Public API covers inference, session/run options, tensor values, checkpoint state, and training session entry points.
- Backend is wired to the ONNX Runtime C API and training C API through a Swift system library target.
- The package expects
libonnxruntimeand headers to be available on the host, typically viapkg-config.
Requirements
- Swift 6.1+
- ONNX Runtime installed on the system with:
libonnxruntimeonnxruntime_c_api.honnxruntime_training_c_api.hpkg-configmetadata forlibonnxruntime
Usage
import OnnxRuntimeBindings
let environment = try ORTEnv(loggingLevel: .warning)
let sessionOptions = try ORTSessionOptions()
let session = try ORTSession(
env: environment,
modelPath: "/path/to/model.onnx",
sessionOptions: sessionOptions
)
let inputTensor = try ORTValue(
tensorData: NSMutableData(data: inputData),
elementType: .float,
shape: [1, 224, 224, 3]
)
let outputs = try session.run(
inputs: ["input": inputTensor],
outputNames: ["output"]
)
Notes
- The
objectivec/directory remains in the repo as the reference contract surface from upstream ONNX Runtime. - The shipped Swift package target is the pure Swift
OnnxRuntimeBindingsimplementation underswift/OnnxRuntimeBindings.
Languages
Objective-C++
42.1%
Swift
32.4%
Objective-C
24.1%
C
1.3%