{"slug": "building-a-high-performance-video-inference-pipeline-with-rocm-libraries-using-c", "title": "Building a High-Performance Video Inference Pipeline with ROCm Libraries Using C/C++", "summary": "AMD ROCm software provides an open-source stack for programming AMD GPUs, enabling high-performance video inference pipelines. A tutorial demonstrates building a pipeline using rocDecode for hardware-accelerated video decoding, HIP for custom kernels, and MIGraphX for model inference on a HEVC stream with ResNet-18, requiring an AMD GPU and ROCm version 7.2.1 on Ubuntu 24.04.", "body_md": "# Building a High-Performance Video Inference Pipeline with ROCm Libraries Using C/C++[#](#building-a-high-performance-video-inference-pipeline-with-rocm-libraries-using-c-c)\n\n[AMD ROCm™ software](https://rocm.docs.amd.com/en/latest/what-is-rocm.html) is an\nopen-source software stack designed for programming AMD GPUs, spanning\neverything from low-level kernel development to high-level applications.\nIt provides developers with direct access to the full capabilities of\nAMD hardware, enabling high-performance and power-efficient computing.\n\nTo fully benefit from ROCm, it is important to design applications that take advantage of GPU acceleration wherever possible. Offloading compute-intensive tasks to the GPU is often essential for achieving optimal performance and energy efficiency, especially given ROCm’s support for AMD RDNA™ and CDNA™ architectures, including RDNA 3.5 integrated graphics found in desktop and laptop systems.\n\nIn this tutorial, we will show how to build a pipeline which includes three different ROCm libraries:\n\nrocDecode for hardware-accelerated video decoding\n\nHIP for custom kernels\n\nMIGraphX for efficient model inference.\n\nWe will walk through the process of ingesting a HEVC stream, decoding it, performing the necessary manipulations on the decoded frames, and running inference on each frame.\n\n## Environment[#](#environment)\n\n### Hardware Requirements[#](#hardware-requirements)\n\nAs mentioned earlier, you will need an AMD GPU in your system to use ROCm libraries. While the latest RDNA 4 or CDNA 4 GPUs provide the best experience, RDNA 3.5 integrated graphics in a desktop or laptop system are also sufficient for following this tutorial. It is also important to develop and validate your application on the hardware available to you and scale it later to more powerful devices, such as a dedicated GPU or even datacenter Instinct accelerators.\n\nYou can consult the [GPU hardware\nspecifications](https://rocm.docs.amd.com/en/latest/reference/gpu-arch-specs.html)\nto determine which hardware is available to you or identify a better alternative.\n\n### Software Requirements[#](#software-requirements)\n\nThis tutorial focuses on Ubuntu 24.04. Historically, ROCm\nwas developed primarily for Linux, so you will generally get the best experience by using Linux for both development and deployment.\nYou may check the [list of supported operating\nsystems](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html)\non the corresponding page.\n\nNext, install the following components:\n\nInstall AMD GPU drivers\n\nFollow the[ROCm documentation](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/install/quick-start.html)rather than standalone driver instructions. Be cautious if Secure Boot is enabled, as it may complicate installation.Install ROCm (version 7.2.1 is used in this tutorial)\n\nNewer versions should also work, but consistency helps avoid compatibility issues.Use Docker (recommended)\n\nDocker simplifies setup and allows multiple ROCm versions to coexist on the same system. If you prefer a bare-metal setup, you’ll need to manually replicate the environment referenced in the[Dockerfile](../../_downloads/648e9afe7f807ad17b9d69df8530b801/Dockerfile).\n\n## Problem Statement[#](#problem-statement)\n\nIn this tutorial, we will show how to build an efficient pipeline for decoding a HEVC stream, performing the necessary conversions on the GPU, and running inference using ResNet-18 on each frame.\n\nWe will review the following components of the implementation:\n\nThe decoder component will be implemented using the rocDecode library which enables hardware-accelerated video decoding on the GPU. Learn more about rocDecode (\n\n[https://rocm.docs.amd.com/projects/rocDecode/en/latest/what-is-rocDecode.html](https://rocm.docs.amd.com/projects/rocDecode/en/latest/what-is-rocDecode.html)). You can also find information about[supported hardware and available codecs](https://rocm.docs.amd.com/projects/rocDecode/en/latest/reference/rocDecode-formats-and-architectures.html)in the documentation. Information about consumer GPUs is available on the specification pages for each product. For example, see the page for the[RX 9070 XT](https://www.amd.com/en/products/graphics/desktops/radeon/9000-series/amd-radeon-rx-9070xt.html)(section: Supported Rendering Format).Color Space Conversion (CSC), resizing, and normalization will be implemented as a separate kernel in the application which uses HIP.\n\nLearn more about HIP (\n\n[https://rocm.docs.amd.com/projects/HIP/en/latest/what_is_hip.html](https://rocm.docs.amd.com/projects/HIP/en/latest/what_is_hip.html)). Understanding HIP also helps explain why ROCm-based applications require a customized LLVM toolchain. ROCm applications use specialized kernel declarations in the source code. These declarations are not supported by standard compilers.Finally, the most important part is running inference on each frame. To do that, we will use a ROCm library named MIGraphX which provides efficient inference for ONNX models on AMD GPUs. Learn more about MIGraphX (\n\n[https://rocm.docs.amd.com/projects/AMDMIGraphX/en/latest/index.html](https://rocm.docs.amd.com/projects/AMDMIGraphX/en/latest/index.html)).\n\nThis tutorial demonstrates how applications can combine multiple ROCm libraries to build an effective pipeline which does most manipulations on the GPU without offloading data to system memory until the end.\n\n## Building and Running the Pipeline[#](#building-and-running-the-pipeline)\n\nThis tutorial uses the following Docker image as its build environment: rocm7.2.1_ubuntu24.04_py3.12_pytorch_release_2.7.1 which you can pull using the following command:\n\n```\ndocker pull rocm/pytorch:rocm7.2.1_ubuntu24.04_py3.12_pytorch_release_2.7.1\n```\n\nDocker also allows multiple ROCm versions to coexist on the same system.\n\nNext, you need to set up a specific build environment for building the example [code](../../_downloads/cf5504d1752438e6ff304c5e2e0f0a96/main.cpp). This\ntutorial is based on the usage of a custom LLVM version by AMD, which is\navailable inside the Docker image mentioned above, but you will also need to\ncompile the rocDecode and MIGraphX libraries used in the tutorial. It is\nimportant to build them on the target system to avoid compatibility issues that may arise\nwhen using packages from standard Linux repositories.\n\nThe [Dockerfile](../../_downloads/648e9afe7f807ad17b9d69df8530b801/Dockerfile) used to build the image is included in the source files.\n\nLet’s highlight a few non-obvious details.\n\nThe MIGraphX build configuration includes an important parameter\n-DGPU_TARGETS=$GPU_TARGETS. You may adjust this argument according to the GPU architecture available\non your system (available in [the GPU\nspecifications](https://rocm.docs.amd.com/en/latest/reference/gpu-arch-specs.html)).\nIt also requires providing paths to LLVM compilers explicitly.\n\nMIGraphX also requires a custom build system that can be installed using:\n\n```\npip install https://github.com/RadeonOpenCompute/rbuild/archive/master.tar.gz\n```\n\nrocDecode also uses a Python-based script to set up the build environment:\n\n```\npython3 rocDecode-setup.py --developer=ON\n```\n\nOne final workaround appears at the end of the [Dockerfile](../../_downloads/648e9afe7f807ad17b9d69df8530b801/Dockerfile): It rebuilds\nMIGraphX a second time. This is not strictly required, but it works around\nan issue when your application cannot run due to conflicts between multiple LLVM instances inside\nyour application.\n\nYou can download [Dockerfile](../../_downloads/648e9afe7f807ad17b9d69df8530b801/Dockerfile) and build it using the following command:\n\n```\nsudo docker image build . -t videopipe\n```\n\nThis command creates a new Docker image tagged as videopipe[:latest].\n\nPut the source files in a directory of your choice (for example, ~/tutorial).\n\nYou can then run the container using the following command:\n\n```\nsudo docker container run -it --device=/dev/kfd --device=/dev/dri --mount type=bind,src=.,dst=/workspace/videopipe --rm videopipe\n```\n\nIt will run a Docker container in interactive mode (–it) and will remove it after exit (–rm). It also mounts the current directory as /workspace/videopipe inside the container.\n\nImportant arguments are “–device=/dev/kfd –device=/dev/dri”,\nwhich expose the GPU inside the container. Without these options, the GPU will not be available\ninside the container. More information about accessing a GPU in a container\ncan be found in the “[Running ROCm Docker\ncontainers](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/how-to/docker.html)” documentation.\nEspecially, if you are planning to run it on Instinct GPUs.\n\nThe [CMakeLists.txt](../../_downloads/a9e4a70f67d868073e2d6409923a0602/CMakeLists.txt) is relatively simple and just configures the use of a\ncustom compiler (allows HIP blocks to be compiled) and locates the required\nlibraries (HIP, rocDecode, MIGraphX).\n\nAt this point, the videopipe directory should contain [CMakeLists.txt](../../_downloads/a9e4a70f67d868073e2d6409923a0602/CMakeLists.txt) and\n[main.cpp](../../_downloads/cf5504d1752438e6ff304c5e2e0f0a96/main.cpp). To build the application, run the following\ncommands in the running container:\n\n```\ncd /workspace/videopipe\nmkdir build\ncd build\ncmake ..\ncmake --build .\n```\n\nAfter that, you should have a binary executable in /workspace/videopipe/build named “videopipe”.\n\nTo use it, you need to place a prepared video.h265 with resolution 1920x1080 in 420 format.\n\nYou must also provide a model.onnx file based on a ResNet-18 implementation. This\ncan be done by converting a [PyTorch\nmodel](https://huggingface.co/microsoft/resnet-18).\n\nFor example:\n\n``` python\nimport torch\nimport torchvision.models as models\nimport onnx\nimport onnxruntime as ort\nimport numpy as np\n\n# 1. Load the pre-trained ResNet-18 model and switch it to evaluation mode\nmodel = models.resnet18(pretrained=True)\nmodel.eval()\n\n# 2. Create a dummy input tensor [1, 3, 224, 224]\ndummy_input = torch.randn(1, 3, 224, 224)\n\n# 3. Export to ONNX\ntorch.onnx.export(\n  model,\n  dummy_input,\n  \"model.onnx\",\n  export_params=True,\n  opset_version=19,\n  do_constant_folding=True,\n  input_names=['input'],\n  output_names=['output'],\n  external_data=False\n)\n\n# 4. Verify with ONNX Runtime\nort_session = ort.InferenceSession(\"model.onnx\")\nort_inputs = {ort_session.get_inputs()[0].name: dummy_input.numpy()}\nort_outs = ort_session.run(None, ort_inputs)\n```\n\nYou can now place all required files (videopipe, video.h265, model.onnx[, model.onnx.data]) in one folder and just execute ./videopipe to process the video and display classification results for each frame.\n\nAfter running the application you should see lines like:\n\n```\nFrame detected class: 975 confidence: 9.05893\nFrame detected class: 975 confidence: 9.05893\nFrame detected class: 975 confidence: 9.05893\nFrame detected class: 975 confidence: 9.05893\n```\n\nThe exact number of output lines depends on how quickly the scene changes\nin the source video stream. In the example above, the video contains a\nframe showing a shoreline, so the detected class is 975, which corresponds to\n“lakeside, lakeshore”. A mapping between class IDs and labels can be found in\n[config.json](https://huggingface.co/microsoft/resnet-18/blob/main/config.json)\nof the original ResNet-18 model.\n\n## Summary[#](#summary)\n\nThis tutorial demonstrates how to build a fully GPU-accelerated video processing pipeline using ROCm. By combining rocDecode, HIP, and MIGraphX, you can efficiently decode video, preprocess frames, and run deep learning inference, all while keeping the data resident on the GPU.\n\nThis approach minimizes data movement, improves performance, and reduces power consumption. From here, you can extend the pipeline by:\n\nReplacing classification models with object detection or segmentation models\n\nStreaming video from a camera or network source\n\nScaling to more powerful AMD GPUs or datacenter accelerators\n\nROCm provides the flexibility and performance needed to build production-grade, GPU-first applications. The pipeline provides a strong foundation for further development.\n\n## Example Source[#](#example-source)\n\n## Disclaimers[#](#disclaimers)\n\nThird-party content is licensed to you directly by the third party that owns the content and is not licensed to you by AMD. ALL LINKED THIRD-PARTY CONTENT IS PROVIDED “AS IS” WITHOUT A WARRANTY OF ANY KIND. USE OF SUCH THIRD-PARTY CONTENT IS DONE AT YOUR SOLE DISCRETION AND UNDER NO CIRCUMSTANCES WILL AMD BE LIABLE TO YOU FOR ANY THIRD-PARTY CONTENT. YOU ASSUME ALL RISK AND ARE SOLELY RESPONSIBLE FOR ANY DAMAGES THAT MAY ARISE FROM YOUR USE OF THIRD-PARTY CONTENT.", "url": "https://wpnews.pro/news/building-a-high-performance-video-inference-pipeline-with-rocm-libraries-using-c", "canonical_source": "https://rocm.blogs.amd.com/artificial-intelligence/rocm-videopipe-cpp/README.html", "published_at": "2026-07-21 00:00:00+00:00", "updated_at": "2026-07-21 16:18:15.526315+00:00", "lang": "en", "topics": ["machine-learning", "computer-vision", "developer-tools", "ai-infrastructure"], "entities": ["AMD ROCm", "rocDecode", "HIP", "MIGraphX", "ResNet-18", "AMD RDNA", "AMD CDNA", "Ubuntu 24.04"], "alternates": {"html": "https://wpnews.pro/news/building-a-high-performance-video-inference-pipeline-with-rocm-libraries-using-c", "markdown": "https://wpnews.pro/news/building-a-high-performance-video-inference-pipeline-with-rocm-libraries-using-c.md", "text": "https://wpnews.pro/news/building-a-high-performance-video-inference-pipeline-with-rocm-libraries-using-c.txt", "jsonld": "https://wpnews.pro/news/building-a-high-performance-video-inference-pipeline-with-rocm-libraries-using-c.jsonld"}}