Skip to content

About

Community-maintained Nim bindings for the OpenVINO Runtime C API. An idiomatic managed layer over a header-faithful raw layer. Not an official Intel or OpenVINO project.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

47 Commits

Folders and files

OpenVINO Nim API

CI License Nim OpenVINO Status

English | 简体中文

Nim bindings for the OpenVINO Runtime and GenAI C APIs.

OpenVINO Nim API provides two layers. The managed API is idiomatic Nim with private native handles, Nim exceptions and documented ownership rules. The raw layer is a header-faithful binding to the OpenVINO C ABI for callers who need it.

This is a community-maintained project. It is not an official Intel or OpenVINO project, and it is not endorsed by or affiliated with Intel Corporation. OpenVINO is a trademark of Intel Corporation.

Status

Version 0.2.2 adds the optional OpenVINO GenAI C API for text/chat, visual language and Whisper workloads, and fixes remaining correctness issues. See the release notes and GenAI guide. GenAI uses separately installed matching native libraries; only Linux x86_64 CPU LLM and Whisper execution has been verified so far.

Version 0.2.1 was released on 2026-11-15 with correctness and memory safety fixes. See the GitHub Release and release notes.

Version 0.2.0 was released on 2026-10-18 and adds asynchronous inference, dynamic and partial shapes with reshape, and declarative layout and preprocessing. Download the source archives from the GitHub Release. Its development record is OPENVINO_NIM_0.2_DEVELOPMENT_PLAN.md, and the design decisions are ADRs 0003, 0004 and 0005.

Version 0.1.1 was released on 2026-10-18 targeting OpenVINO 2026.4.1 (and verified against 2026.4.0). Download the source archives from the GitHub Release. The foundational design and initial release work are tracked in OPENVINO_NIM_0.1_DEVELOPMENT_PLAN.md.

Synchronous and asynchronous inference work across CPU, GPU and NPU. Core, Model, CompiledModel, InferRequest, Tensor, partial shapes, reshape, CompletionQueue, preprocessing plans, properties, profiling and explicit blob export/import are implemented and covered by tests that run real inference on CPU (nimble testIntegration) and on GPU and NPU hardware (nimble testHardware), including multi-hundred and thousand-iteration lifetime loops under both --mm:orc and --mm:arc.

Verified on two hosts:

  • Windows 11 x86_64 with Nim 2.2.12 against OpenVINO 2026.4.1 (build 22982) and 2026.4.0 (build 22959) across CPU (Intel(R) Core(TM) Ultra 7 270K Plus), GPU.0 (Intel(R) Graphics (iGPU)), GPU.1 (NVIDIA GeForce RTX 5080 (dGPU) via OpenCL) and NPU (Intel(R) AI Boost).
  • Ubuntu 26.04 x86_64 with Nim 2.2.4 against OpenVINO 2026.4.0 on CPU, plus GitHub Actions Linux and Windows runners against OpenVINO 2026.4.1.

No claim is made for macOS. See compatibility for what was and was not run, including measured plugin differences between CPU, GPU and NPU. Nothing in this README should be read as a claim that a feature already works unless it says so.

Feature overview

Capability 0.2.2 status Notes
Managed Nim API Available Core, Model, CompiledModel, InferRequest, Tensor, shapes and properties
Raw C ABI layers Available Import openvino/raw for Runtime 2026.4.1 or openvino/raw/genai for GenAI 2026.4.1.0 headers
Synchronous CPU inference Available Windows and Linux x86_64 are verified in CI and on clean hosts
Synchronous GPU & NPU inference Available (Windows x86_64) Verified on Intel iGPU (GPU.0), NVIDIA dGPU (GPU.1) and Intel AI Boost (NPU) via nimble testHardware
Runtime discovery and diagnostics Available Version, device listing, symbol checks and actionable loader errors
Profiling and explicit blob I/O Available Verified on CPU, GPU and NPU; no implicit cache directory or device policy is added
Asynchronous inference Available (new in 0.2.0) startAsync, wait, waitFor, cancel and CompletionQueue; no Nim code runs on OpenVINO threads, so user callbacks are deliberately not offered
Dynamic shapes and reshape Available (new in 0.2.0) PartialShape, Port.partialShape and Model.reshape; the NPU plugin needs bounded or static shapes
Layout and preprocessing Available (new in 0.2.0) Layout and a declarative PreprocessPlan applied in one call
Optional OpenVINO GenAI C API Available (new in 0.2.2) All 153 pinned C symbols represented by 150 raw declarations and a C adapter for three variadic constructors; managed LLM/chat, VLM and Whisper APIs; real-model CPU checks cover LLM and Whisper on Linux x86_64
Request pools, remote contexts Roadmap See the roadmap

The roadmap is deliberately explicit about what is not implemented. See the API overview and the roadmap before designing an application around a future feature.

Quick start

  1. Install OpenVINO Runtime 2026.4.x. On Windows, run setupvars.bat in Command Prompt (CMD); on Linux, source setupvars.sh in Bash. Keep using that shell for the remaining commands.

  2. Install the Nim package via Nimble (or from a local checkout to run the bundled examples and test suites):

    # From the official Nimble index (nim-lang/packages #3578):
    nimble refresh
    nimble install openvino
    
    # Or directly from GitHub before refreshing / while the index PR is open:
    nimble install https://github.com/AbyssGG/OpenVINO-Nim-API
    
    # Or from a local checkout:
    git clone https://github.com/AbyssGG/OpenVINO-Nim-API.git
    cd OpenVINO-Nim-API
    nimble install
  3. From a local checkout, run the verified examples against the included four-value ReLU fixture:

    nimble examples

The getting started guide has platform-specific loader checks and troubleshooting. The complete inference snippet is kept below and is compiled from the same source as examples/minimal.nim.

Release artifacts

The v0.2.0 Release follows the packaging contract in the development plan and contains exactly four canonical assets with one shared base name:

openvino-nim-{version}-{date}-ov{openvino-version}.zip
openvino-nim-{version}-{date}-ov{openvino-version}.tar.gz
openvino-nim-{version}-{date}-ov{openvino-version}.zip.sha256
openvino-nim-{version}-{date}-ov{openvino-version}.tar.gz.sha256

Both archives contain one top-level directory named after the base name and were checked for reproducibility and forbidden runtime/model files. See RELEASE_NOTES.md for the published asset names and the consumer-side checksum command.

Six naming roles

These names are deliberately different. Mixing them up is the most common source of confusion when installing the package.

Name Where it is used Why
OpenVINO Nim API Project title, prose, repository description The human-readable display name
OpenVINO-Nim-API GitHub repository name The exact public repository name requested by the project owner
openvino-nim Release archive prefix and distribution references Lowercase because file systems and package indexes disagree about case
openvino Nimble package identifier Nimble package identifiers may not contain a hyphen
openvino.nimble Manifest file name Nimble requires the manifest name to match the package identifier
import openvino Nim source code The stable import root, kept identical to the package identifier

The GitHub repository is the hyphenated form of the human-readable project title. Package and archive tooling use their lowercase identifiers: openvino-nim for release assets and openvino for Nimble and imports. A Git tag remains a SemVer tag such as v0.1.1; it is not derived from any of these names.

nimble releaseCheck asserts that this README mentions the repository, display and distribution names, that the repository is the hyphenated display name, and that the distribution name stays lowercase, so none can quietly drift from src/openvino/version.nim.

Release archives use the base name openvino-nim-{version}-{date}-ov{openvino-version} with dots replaced by hyphens. For version 0.1.1 released against OpenVINO 2026.4.1, the archive base name is generated by the release tooling rather than written by hand, so that the Git tag, release title, archive name and checksums cannot drift apart.

Requirements

Component Requirement
Nim 2.0.0 or newer; CI pins the exact versions that are verified
OpenVINO Runtime 2026.4.x, verified against 2026.4.1 and 2026.4.0
Tier 1 platforms Windows x86_64, Linux x86_64
Verified devices CPU (Windows & Linux), GPU and NPU (Windows x86_64)

The 2026.4 requirement is not arbitrary. This package uses the non-variadic properties API (ov_property_t, ov_core_compile_model_props, ov_compiled_model_set_properties and friends) that avoids passing property pairs through C varargs. The package does not silently fall back to older runtimes.

GPU and NPU devices are discovered dynamically when the corresponding OpenVINO plugins and hardware drivers are installed. Standard CI runners have CPU only and run nimble testIntegration; on a host with GPU or NPU hardware, run nimble testHardware to exercise compilation, synchronous inference, external buffers, non-ASCII model paths, profiling and blob export/import on every discovered GPU and NPU device. Note one measured plugin difference: when a model is compiled without enableProfiling(), request.profilingInfo() returns zero-time entries on CPU, an empty list on NPU, and raises OpenVinoError on GPU; when compiled with [enableProfiling()], all three plugins return timed execution entries.

Installing the OpenVINO runtime

The package binds to the OpenVINO runtime at run time and never ships it. Install OpenVINO 2026.4.x separately, then make sure the C API library is visible to the dynamic loader:

Platform Library Loader notes
Windows openvino_c.dll Must be on the DLL search path
Linux libopenvino_c.so, libopenvino_c.so.2641, or libopenvino_c.so.2640 Must be on the loader search path. A pip installation ships only the versioned name; all verified 2026.4.x SONAMEs are tried

Loading openvino_c alone is not enough to run inference. Core also needs plugins.xml, the device plugins and the model frontends from the same official runtime layout. Copying a single library out of an OpenVINO installation can load successfully and still fail when creating a Core or reading a model.

Run setupvars.bat in CMD on Windows, or source setupvars.sh in Bash on Linux. Run installation and inference in that same session; environment changes made by a batch file launched from PowerShell do not propagate back to its parent shell. See Getting started for the commands and pip-specific loader setup.

Installing the package

The package is registered under the Nimble identifier openvino (nim-lang/packages #3578). Install it from the Nimble index, directly by repository URL, or from a local checkout:

# From the official Nimble package index:
nimble refresh
nimble install openvino

# Or directly from the GitHub repository URL:
nimble install https://github.com/AbyssGG/OpenVINO-Nim-API

# Or from the root of a local checkout:
nimble install

The installed package is named openvino; import it with import openvino.

Minimal synchronous inference

import openvino

const modelPath = "tests/fixtures/relu_1x4_f32.xml"

proc main() =
  let core = newCore()
  defer: core.close()

  let compiled = core.compileModel(modelPath, "CPU")
  defer: compiled.close()

  let request = compiled.createInferRequest()
  defer: request.close()

  let input = tensorFrom(etF32, initShape(1, 4),
                         [float32(-1.5), 2.0, -0.25, 4.0])
  defer: input.close()

  request.setInputTensor(0, input)
  request.infer()

  let output = request.outputTensor(0)
  defer: output.close()
  echo output.toSeq(float32)

main()

Run the example from the repository root:

nim c -r --path:src examples/minimal.nim

It prints @[0.0, 2.0, 0.0, 4.0]: the model is a ReLU, so the two negative inputs become zero and the two positive ones pass through.

The code matches examples/minimal.nim, which nimble examples compiles and runs. nimble lint checks that the README example stays in sync. Each owned object is closed in the scope that creates it.

To adapt it to another model, update the input count, element type, shape, data preparation and output validation. The bundled fixture has no weights; an IR model with weights also needs its .bin file.

More examples, all using the public API only:

Example What it shows
examples/list_devices.nim Runtime version and device discovery, useful first when a deployment misbehaves
examples/minimal.nim The block above
examples/sync_infer.nim Model metadata and the four-value ReLU loop, with model path and device arguments
examples/tensor_basics.nim Shapes, element types, and the difference between the safe data paths and the unsafe one
examples/profiling.nim Per-node timings, and what the numbers do and do not mean

Error diagnosis

Failures surface as distinguishable Nim exceptions rather than status codes:

Exception Meaning
OpenVinoError An OpenVINO C call returned a non-OK status
OpenVinoLibraryError The dynamic library or a required symbol is missing
OpenVinoVersionError The detected runtime major/minor is unsupported
OpenVinoArgumentError An argument or handle state is invalid before the C call

OpenVinoError carries the operation name, the numeric status, the stable status description and the native detail captured at the moment of failure. Argument errors such as a negative index, an invalid shape or a call on a closed object are raised before entering the C layer.

Call requireSupportedRuntime() if your application should fail early on a runtime outside the 2026.4 baseline. This check is explicit; package import and newCore() do not call it automatically.

Lifetime and zero-copy rules

Two rules cover most of what you need to know:

  1. Each managed handle owns one native handle and offers an idempotent close(). Calling close() twice is harmless. Using an object after close() raises a Nim error instead of crashing in native code. Destructors are a backstop, not a replacement for close(). Assigning a managed value shares the handle and its closed state; closing either alias closes both. Shape and Property are Nim-owned values and do not need close().
  2. Tensors allocated by OpenVINO or copied from Nim data are the safe default. Any entry point that borrows caller memory without owning it is named with unsafe and documents exactly what the caller must guarantee about address stability, alignment, capacity and lifetime.

Documentation

The documentation hub groups the English guides and the generated API reference.

Start with whichever question you have:

Question Document
How is this put together, and why? Architecture
What has actually been tested? Compatibility
Something does not work Troubleshooting
Who releases what? Ownership rules
Which C entry points are bound? C API coverage
What is the public API shape? API overview
How do I install and verify it? Getting started
What is planned after 0.2.0? Roadmap
I have Resonance code Migration guide
Why was it done this way? Symbol loading, handle model, async completion, partial shapes, preprocessing

Project documents: notice and provenance, 0.1 development plan, 0.2 development plan, development log in English and Chinese, style guide, contributing, changelog, prototype audit.

Project layout

Path Purpose
src/openvino.nim Stable managed import root
src/openvino/ Managed handles, conversions and user-facing errors
src/openvino/raw/ Explicit, header-faithful C ABI declarations
examples/ Small runnable programs using only the public API
tests/ Unit, ABI, lifecycle, integration and packaging checks
docs/ Architecture, compatibility, API coverage and decisions
.github/workflows/ Static, runtime, documentation and release checks

Community and support

Bug reports should include the OpenVINO runtime version, Nim version, target device and the smallest reproducible example. Start with Troubleshooting, then open a GitHub issue if the problem is reproducible with the supported matrix. Security reports belong in SECURITY.md, not in a public issue.

Pull requests are welcome. Read CONTRIBUTING.md, keep the managed/raw boundary intact, and update tests and documentation with any public API change. The project is community maintained and is not an Intel product.

License

Apache-2.0. See LICENSE, and NOTICE for how this package relates to the OpenVINO C headers, why no upstream text is copied, and what is and is not bundled.

About

Community-maintained Nim bindings for the OpenVINO Runtime C API. An idiomatic managed layer over a header-faithful raw layer. Not an official Intel or OpenVINO project.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages