Skip to content
Siu Chi Chan edited this page May 2, 2017 · 48 revisions

HCC is an Open Source, Optimizing C++ Compiler for Heterogeneous Compute

HCC supports heterogeneous offload to AMD APUs and discrete GPUs via HSA enabled runtimes and drivers. It is an ISO compliant C++ 11/14 compiler. It is based on Clang, the LLVM Compiler Infrastructure and the “libc++” C++ standard library.

Accelerator Modes Supported

Inspired by C++ AMP and C++14, this is the default C++ compute API for the HCC compiler. HC has some important differences from C++ AMP including removing the “restrict” keyword, supporting additional data types in kernels, providing more control over synchronization and data movement, and providing pointer-based memory allocation. It is designed to expose cutting edge compute capabilities on Boltzmann and HSA devices to developers while offering the productivity and usability of C++.

HIP provides a set of tools and API for converting CUDA applications into a portable C++ API. An application using the HIP API could be compiled by hcc to target AMD GPUs. Please refer to HIP's repository for more information.

Microsoft C++ AMP is a C++ accelerator API with support for GPU offload. This mode is compatible with Version 1.2 of the C++ AMP specification.

HCC provides an initial implementation of the parallel algorithms described in the ISO C++ Extensions for Parallelism, which enables parallel acceleration for certain STL algorithms.

OpenMP

HCC supports OpenMP 3.1 on CPU. The support for OpenMP 4.x accelerator offloading is currently in development.

Platform Requirements

Accelerated applications could be run on Radeon discrete GPUs from the Fiji family (AMD R9 Nano, R9 Fury, R9 Fury X, FirePro S9300 x2, Polaris 10, Polaris 11) paired with an Intel Haswell CPU or newer. HCC would work with AMD HSA APUs (Kaveri, Carrizo); however, they are not our main support platform and some of the more advanced compute capabilities may not be available on the APUs.

HCC currently only works on Linux and with the open source ROCK kernel driver and the ROCR runtime (see Installation for details). It will not work with the closed source AMD graphics driver.

Compiler Backends

This backend compiles GPU kernels into native GCN ISA, which could be directly execute on the GPU hardware. It's being actively developed by the Radeon Technology Group in LLVM.

Installation

Prerequisites

Before continuing with the installation, please make sure any previously installed hcc compiler has been removed from on your system.
Install ROCm and make sure it works correctly.

Ubuntu

Ubuntu 14.04

Follow the instruction here to setup the ROCm apt repository and install the rocm or the rocm-dev meta-package.

Ubuntu 16.04

Ubuntu 16.04 is also supported but currently it has to be built from source.

Fedora

HCC compiler has been tested on Fedora 23 but currently it has to be built from source.

Building HCC from Source

First, install the build dependencies:

# Ubuntu 14.04
sudo apt-get install git cmake make g++  g++-multilib gcc-multilib libc++-dev libc++1 libc++abi-dev libc++abi1 python findutils libelf1 libpci3 file debianutils 
# Ubuntu 16.04
sudo apt-get install git cmake make g++  g++-multilib gcc-multilib python findutils libelf1 libpci3 file debianutils
# Fedora 23
sudo dnf install git cmake make gcc-c++ python findutils elfutils-libelf pciutils-libs file pth rpm-build 

Clone the HCC source tree:

# automatically fetches all submodules
git clone --recursive -b clang_tot_upgrade https://github.com/RadeonOpenCompute/hcc.git

Create a build directory and run cmake to configure the build:

mkdir build; cd build
cmake ../hcc

Compile HCC:

make -j

Run the unit tests:

make test

Create an installer package (DEB or RPM file)

make package

How to use HCC

Here's a simple saxpy example written with the hc API.

Compiling Your First HCC Program

To compile and link in a single step:

# Assume HCC is installed and added to PATH
# Notice the the hcc-config command is between two backticks 
hcc `hcc-config --cxxflags --ldflags` saxpy.cpp -o saxpy

To build with separate compile and link steps:

# Assume HCC is installed and added to PATH
# Notice the the hcc-config command is between two backticks 
hcc `hcc-config --cxxflags` saxpy.cpp -c -o saxpy.cpp.o
hcc `hcc-config --ldflags` saxpy.cpp.o -o saxpy

Compiling for Different GPU Architectures

The --amdgpu-target=<GCN Version> option specifies the version of GCN ISA generated by the compiler. The following table shows the different versions currently supported by HCC. If no GCN ISA is specified, the HCC compiler generates the gfx803 GCN ISA by default.

Another option is to set the environment variable HCC_AMDGPU_TARGET to override the default GPU architecture globally for HCC; however, this is not recommended.

Note that older version of HCC only support the long form of the GCN version strings with the prefix "AMD::AMDGPU:". The long form is being deprecated in newer versions of HCC in favor of the more compact form.

GCN Version GCN ISA Version (Deprecated) GPU/APU Family Examples of Radeon GPU
gfx701 AMD:AMDGPU:7:0:1 GFX7 FirePro W8100, FirePro W9100, Radeon R9 290, Radeon R9 390
gfx801 AMD:AMDGPU:8:0:1 Carrizo APU FX-8800P
gfx803 (Default) AMD:AMDGPU:8:0:3 GFX8 R9 Fury, R9 Fury X, R9 Nano, FirePro S9300 x2, Radeon RX 480, Radeon RX 470, Radeon RX 460

API documentation

API reference of HCC