ROCm/rocm-examples

A collection of examples for the ROCm software stack

What is ROCm/rocm-examples?

A collection of example programs for ROCm, AMD's GPU computing platform. It's designed to help two kinds of people: newcomers who want to learn the basics, and experienced users who want to see more advanced techniques.

Main categories

The repository is organized into several folders, each with a different purpose:

  • HIP-Basic — Self-contained examples of core HIP (AMD's GPU programming language) features, with no extra dependencies. Covers things like memory management, streams, shared memory, matrix multiplication, and GPU-to-GPU data transfer.
  • HIP-Doc — The exact example codes that appear in the official HIP documentation. Mostly used for testing the docs, but also useful as standalone examples.
  • Libraries — Examples showing how to use ROCm's higher-level libraries (like rocRAND for random numbers, rocDecode for video, etc.).
  • Applications — Complete, practical programs accelerated with HIP, such as bitonic sort, convolution, Floyd-Warshall shortest paths, histogram, Monte Carlo estimation of π, optical flow, and prefix sum.
  • Systems — Examples for ROCm system-level features, like hipFile for GPU-direct storage I/O.
  • AI — Instructions on using ROCm for AI workloads.
  • Tutorials — Code that accompanies the HIP tutorials in the documentation.
  • Common — Shared utility code used across the other examples.

Prerequisites

  • Linux: CMake (≥ 3.21), optionally GNU Make, and ROCm (≥ 7.x). Some examples need extra libraries (FFmpeg, OpenCV, GLFW3, Vulkan) — the build script detects which are available and skips examples with missing dependencies.
  • Windows: Visual Studio 2019 or 2022 with the C++ workload, the HIP SDK for Windows, and optionally CMake, Ninja, and Perl (for hipify scripts).

How to build

There are several ways:

  • CMake (Linux or Windows): cmake -S . -B build, then cmake --build build. Works on both AMD and NVIDIA GPUs — set ROCM_EXAMPLES_GPU_LANGUAGE=CUDA to target NVIDIA.
  • Make (Linux): Run ./configure.sh first to detect available dependencies, then make. The make test command runs every example as a smoke test.
  • Docker (Linux): Pre-made Dockerfiles build an image with all prerequisites. The GPU driver still needs to be installed on the host.
  • Visual Studio (Windows): Project files with _vs2019 or _vs2022 suffixes are provided.

Notable details

  • The same code can be compiled for AMD GPUs (HIP) or NVIDIA GPUs (CUDA) by changing one CMake option.
  • The make test feature lets you pass custom arguments to each test, e.g. pointing a video-decoding test at your own video file.
  • Some examples are Windows-only (like the Vulkan mipmap interop example).

In short: it's a well-organized, multi-platform set of working code samples that demonstrate everything from "hello world" on a GPU to full applications, with build instructions for Linux, Windows, and Docker.

Related

  • Project
  • Project
  • Dispatch
  • Project
  • Project