GitHub - ROCm/rocm-examples: A collection of examples for the ROCm software stack (original) (raw)

ROCm Examples

This repository is a collection of examples to enable new users to start using ROCm, as well as provide more advanced examples for experienced users.

The examples are structured in several categories:

For a full overview over the examples see the section repository contents.

Prerequisites

Linux

Windows

Building the example suite

Linux

These instructions assume that the prerequisites for every example are installed on the system.

CMake

See CMake build options for an overview of build options.

Make

Beware that only a subset of the examples support building via Make.

Linux with Docker

Alternatively, instead of installing the prerequisites on the system, the Dockerfiles in this repository can be used to build images that provide all required prerequisites. Note, that the ROCm kernel GPU driver still needs to be installed on the host system.

The following instructions showcase building the Docker image and full example suite inside the container using CMake:

The built executables can be found and run in the build directory:

Windows

Visual Studio

The repository has Visual Studio project files for all examples and individually for each example.

CMake

First, clone the repository and go to the source directory.

git clone https://github.com/ROCm/rocm-examples.git cd rocm-examples

There are two ways to build the project using CMake: with the Visual Studio Developer Command Prompt (recommended) or with a standard Command Prompt. See CMake build options for an overview of build options.

Visual Studio Developer Command Prompt

Select Start, search for "x64 Native Tools Command Prompt for VS 2019", and the resulting Command Prompt. Ninja must be selected as generator, and Clang as C++ compiler.

cmake -S . -B build -G Ninja -D CMAKE_CXX_COMPILER=clang cmake --build build

Standard Command Prompt

Run the standard Command Prompt. When using the standard Command Prompt to build the project, the Resource Compiler (RC) path must be specified. The RC is a tool used to build Windows-based applications, its default path is C:/Program Files (x86)/Windows Kits/10/bin/<Windows version>/x64/rc.exe. Finally, the generator must be set to Ninja.

cmake -S . -B build -G Ninja -D CMAKE_RC_COMPILER="" cmake --build build

CMake build options

The following options are available when building with CMake.

Option Relevant to Default value Description
GPU_RUNTIME HIP / CUDA "HIP" GPU runtime to compile for. Set to "CUDA" to compile for NVIDIA GPUs and to "HIP" for AMD GPUs.
CMAKE_HIP_ARCHITECTURES HIP Compiler default HIP device architectures to target, e.g. "gfx908;gfx1030" to target architectures gfx908 and gfx1030.
CMAKE_CUDA_ARCHITECTURES CUDA Compiler default CUDA architecture to compile for e.g. "50;72" to target compute capibility 50 and 72.

Repository Contents