Skip to content

About

For NET applications provide complete low-level binding of MIGraphX official C API, as well as high-level hosted APIs for ONNX model parsing, AMD GPU compilation, parameter management, and synchronous/asynchronous inference.

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

240 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MIGraphX CSharp API โ€” AMD GPU inference for C# and .NET

MIGraphX CSharp API

Run ONNX models on AMD GPUs from C#, with MIGraphX inference and HIP image processing.

Apache-2.0 license NuGet version NuGet downloads GitHub Release GitHub stars .NET 4.6 to 10.0 ROCm 7.2.1

English | ็ฎ€ไฝ“ไธญๆ–‡

๐Ÿ“– Introduction

AMD MIGraphX is a graph inference engine in the ROCm ecosystem. It compiles deep learning models into GPU programs and optimizes their execution for AMD hardware.

MIGraphX CSharp API is a .NET wrapper for AMD MIGraphX. It lets C# developers load ONNX models, compile GPU programs, work with tensors and run inference directly from their applications. The optional HIP adapter connects GPU preprocessing, model execution and postprocessing on the same stream.

The repository includes complete YOLO26 and PP-OCRv4/v5/v6 examples. All three OCR generations use one PaddleOcr project. Image processing, inference, result decoding and timing are written in C# and HIP; running the examples requires no Python or OpenCV.

Core advantage What it means for your application
๐Ÿš€ AMD GPU inference Use MIGraphX model compilation and execution through a managed C# API
โšก GPU image pipelines Keep numerical preprocessing and postprocessing on the GPU with HIP streams and device buffers
๐Ÿงฉ .NET integration 15 target frameworks from .NET Framework 4.6 to .NET 10, with Chinese/English XML API comments
๐Ÿ“š Complete examples YOLO26 five tasks and PP-OCRv4/v5/v6 detection/recognition, including OCR batching and multiple recognition instances

๐Ÿ“ข 0.0.2 Update Summary

  • Adds RunDeviceIntoAsync for device output buffers and subsequent HIP processing.
  • Moves numerical preprocessing and postprocessing in both vision examples to HIP.
  • Adds OCR recognition batching and multiple instances; full-image recognition defaults to batch 4 with 2 instances.

Complete 0.0.2 release notes ยท All releases ยท Download v0.0.2

๐Ÿš€ Quick Start

1. Install the NuGet package

Install ROCm 7.2.1 and MIGraphX 2.15.0 on a compatible Linux host first; see the runtime deployment guide. Then create your application:

dotnet new console -n MigraphxDemo
cd MigraphxDemo
dotnet add package JYPPX.ROCm.MIGraphX.CSharp.API --version 0.0.2

2. Write inference code

This example uses a static float32 ONNX model whose input is named input and contains four elements. Replace the model path, input name and data with those required by your model.

using JYPPX.ROCm.MIGraphXSharp;

const string nativePath = "/opt/rocm/lib/libmigraphx_c.so.3";

// Parse the model and read its input shapes.
using var options = new MIGraphXOnnxOptions(nativePath);
using var program = MIGraphXProgram.ParseOnnxFile("/models/model.onnx", options);
var inputShapes = program.GetParameterShapes();

// Compile once, then reuse the program for subsequent inputs.
using var target = new MIGraphXTarget(nativePath, "gpu");
using var compileOptions = new MIGraphXCompileOptions(nativePath, offloadCopy: true);
program.Compile(target, compileOptions);

// Supply the model input and execute inference.
using var input = MIGraphXArgument.Create(
    nativePath, inputShapes["input"], new[] { 1f, 2f, 3f, 4f });
using var parameters = new MIGraphXParameterMap(nativePath);
parameters.Add("input", input);

using var outputs = program.Run(parameters);
float[] result = outputs[0].ToArray<float>();
Console.WriteLine(string.Join(", ", result));

3. Run the application

dotnet run -c Release

Start with the YOLO26 example or PaddleOCR example for image models. The getting started guide covers installation and native-library diagnostics.

โœจ Features

Feature Description
ONNX inference Parse models from files or memory, compile for GPU and execute with multiple inputs/outputs
Typed tensors Inspect shapes, types and strides; create typed host inputs and copy results into C# arrays
Dynamic shapes Configure fixed input overrides or dimension ranges before parsing
Program reuse Save/load compiled programs and use an explicit model cache
HIP integration Host/device-input asynchronous submission, stream synchronization and caller-owned device output buffers
Graph APIs Program-owned modules, parameters, literals, instructions and typed operation attributes
Advanced APIs TensorFlow parsing, FP16/BF16/INT8/FP8 quantization and experimental custom-operation callbacks
Resource management Deterministic Dispose, native loading diagnostics and resource leases for pending HIP work

See the API guides and platform support for the applicable runtime and experimental feature boundaries.

๐Ÿ“ฆ NuGet Packages

Package Purpose Version
JYPPX.ROCm.MIGraphX.CSharp.API Core model, tensor, compilation and inference API NuGet
JYPPX.ROCm.MIGraphX.CSharp.API.HIP.Interop Optional HIP stream/device-buffer adapter NuGet
JYPPX.ROCm.HIP.CSharp.API HipSharp runtime, memory, stream and kernel APIs; adapter dependency NuGet

Install the adapter only when you need HIP integration:

dotnet add package JYPPX.ROCm.MIGraphX.CSharp.API.HIP.Interop --version 0.0.2

The adapter requires core 0.0.2 and HipSharp 0.10.0; NuGet restores these dependencies. The core namespace is JYPPX.ROCm.MIGraphXSharp. AMD native libraries are installed separately. GitHub Releases also provide packages, source and offline HTML documentation.

๐Ÿงช Examples

Example Tasks Included functionality
YOLO26 Detection, classification, instance segmentation, pose and oriented boxes HIP resize/normalization, output decoding, masks, keypoints and annotated results
PP-OCRv4/v5/v6 v4/v5 mobile and server; v6 tiny, small and medium; full images or recognition only HIP text-box extraction, perspective crops, batched recognition, multiple instances and CTC decoding
CLIP Image/text matching and retrieval ViT-B/32 GPU dual encoders, English BPE, image batching and HTML results
PP-Structure Document orientation, layout, OCR and tables MIGraphX GPU document/table models and HIP OCR; optional, explicitly selected ORT CPU formula recognition

All four projects are self-contained and target .NET 10. YOLO26 and PaddleOcr include a CPU preprocessing/postprocessing option; both options use MIGraphX GPU model execution. CLIP uses CPU image processing with GPU encoders. PP-Structure's formula recognition is an explicit ORT CPU option. Supply models and inputs separately; each example documents its processing and timing scope.

The unified PaddleOcr entry point, v4/v5 support, CLIP and PP-Structure are available in the current main source. The published v0.0.2 tag retains the original PaddleOcrV6 example.

On the documented gfx1100 FP32 baseline, whole-image HIP processing averages 2.75 ms for YOLO26n detection and 10.97 ms for PP-OCRv6 tiny with 16 text lines. These timings exclude file decode, compilation, drawing and export. The 0.0.2 notes contain the complete results and measurement conditions; the vision guide explains the options.

๐Ÿ“– Documentation

Resource Contents
Getting started Install packages and run the first inference
Managed objects Models, tensors, inputs/outputs and resource ownership
Dynamic shapes and cache Input overrides, program persistence and cache reuse
HIP integration Asynchronous execution and GPU buffers
Advanced APIs Graphs, TensorFlow and quantization
API reference API documentation and offline reference
Release history Changes, compatibility and upgrade instructions by version
Technical blog Chinese project and application articles

๐Ÿš€ More Usage Examples

Override an input shape

Set your model's input dimensions before parsing; compile and run it using the same object API shown above.

using var options = new MIGraphXOnnxOptions(nativePath);
options.SetInputParameterShape("images", new long[] { 1, 3, 640, 640 });
using var program = MIGraphXProgram.ParseOnnxFile("/models/yolo26n.onnx", options);

Save a compiled program

using var fileOptions = new MIGraphXFileOptions(nativePath, "msgpack");
program.Save("/models/compiled.msgpack", fileOptions);
using var restored = MIGraphXProgram.Load("/models/compiled.msgpack", fileOptions);

Use a compatible native runtime and compilation target when reusing a saved program. Device output and GPU postprocessing are covered in the HIP guide.

๐Ÿ’ป System Requirements

Component Requirements
Managed library .NET Framework 4.6โ€“4.8.1, .NET Core 3.1, .NET 5โ€“10; 15 target frameworks
Validated native platform Ubuntu 24.04 x86-64, ROCm 7.2.1, MIGraphX 2.15.0, gfx1100
Native library /opt/rocm/lib/libmigraphx_c.so.3, or the absolute path in your ROCm installation
Vision examples .NET 10; HIPRTC with the matching GPU architecture, or a precompiled HIP module

Managed framework compatibility does not provide a Windows/macOS MIGraphX runtime. Use the AMD installation instructions and deployment guide to prepare the target host. Other GPU/runtime combinations are described in platform support.

๐Ÿ—๏ธ Project Structure

MIGraphXSharp/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ JYPPX.ROCm.MIGraphX.CSharp.API/              # Core library
โ”‚   โ””โ”€โ”€ JYPPX.ROCm.MIGraphX.CSharp.API.HIP.Interop/  # HIP adapter
โ”œโ”€โ”€ samples/
โ”‚   โ”œโ”€โ”€ Yolo26/                                    # Five vision tasks
โ”‚   โ””โ”€โ”€ PaddleOcr/                                 # Text detection and recognition
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ guides/                                    # Installation and usage
โ”‚   โ”œโ”€โ”€ release-notes/                             # Version history
โ”‚   โ””โ”€โ”€ blog/                                      # Technical articles
โ”œโ”€โ”€ eng/                                           # Build and packaging scripts
โ””โ”€โ”€ MIGraphXSharp.sln

๐Ÿ”ง Build from Source

Install the SDK selected by global.json, PowerShell 7 and the HipSharp source dependency. Run from the repository root:

./eng/build.ps1 -Configuration Release -Version 0.0.2
./eng/pack.ps1 -Configuration Release -Version 0.0.2 -NoBuild

Builds without an explicit version use 0.0.0. Outputs go to the sibling MIGraphXSharp.Workspace/ directory. See CONTRIBUTING.md for the full build setup.

๐Ÿค Contributing

Issues and pull requests are welcome. Include package versions, ROCm/MIGraphX versions, operating system, GPU and a minimal reproduction when reporting an issue.

๐Ÿ“„ License and Acknowledgments

The project is licensed under Apache-2.0; see NOTICE. Thanks to AMD MIGraphX and ROCm for the native inference and GPU computing stack. Third-party libraries and model assets retain their own licenses.

Related projects: OpenVINO C# API ยท TensorRT C# API ยท HIP C# API.

๐Ÿ“ฎ Contact and Sponsorship

Developer contacts, community links and sponsorship QR codes

โš–๏ธ Software and Usage Notice

This project uses AI-assisted development. Feedback, issue reports and contributions help improve the library. The software is provided under the Apache-2.0 license without warranties; evaluate your application's models, native runtime and deployment requirements before production use. Refer to platform support for known limitations and experimental APIs.

Copyright ยฉ 2026 Guojin Yan.

About

For NET applications provide complete low-level binding of MIGraphX official C API, as well as high-level hosted APIs for ONNX model parsing, AMD GPU compilation, parameter management, and synchronous/asynchronous inference.

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages