Clone this wiki locally
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.
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.
A compiler backend is responsible for compiling intermediate representation of your program into a lower level, target dependent instruction set. Currently, HCC supports two backends:
- Native GCN ISA Backend
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 ToT. This is the recommended compiler backend for the Fiji family GPUs.
- HSAIL Backend (Deprecated)
This backend compiles GPU kernels into HSAIL defined by the HSA Foundation. HSAIL is a virtual machine instruction set and it gets jitted into machine specific instruction during the execution time of a program. Support for this backend has been deprecated. Newer or future hcc features may not work with this compiler backend.
Before continuing with the installation, please make sure any previously installed hcc compiler has been removed from on your system.
Follow the instruction here to setup the ROCm apt repository and install the rocm or the rocm-dev meta-package.
We currently distribute two hcc packages (hcc_lc and hcc_hsail).
The hcc_lc package provides an HCC compiler that makes use of the native GCN ISA backend that supports GPUs that are in the Hawaii familty and the Fiji family. This is the recommended compiler package for Fiji GPUs. By default, this compiler is installed to
The hcc_hsail package contains an HCC compiler with the legacy HSAIL backend. This compiler is being deprecated and it should be used only for debugging. By default, this compiler is installed to
It is possible to install both compilers on the same system. A
/opt/rocm/hcc symlink is created during the compiler package installation and it links to hcc_lc by default. It is recommended to update this symlink if a user decides to switch to another HCC with a different backend.
HCC compiler has only been tested on Fedora 23. The same instructions would probably work on other versions of Fedora.
HCC has a dependency on libc++; however, the current libc++ package from Fedora has an unmet dependency on libc++abi, which is unavailable in Fedora. Users will have to install libc++ and libc++abi from source.
It is recommended to install the
release_36 release of libc++ and libc++abi and here are the instructions:
git clone --branch release_36 https://github.com/llvm-mirror/llvm.git llvm git clone --branch release_36 https://github.com/llvm-mirror/libcxx.git llvm/projects/libcxx git clone --branch release_36 https://github.com/llvm-mirror/libcxxabi.git llvm/projects/libcxxabi mkdir -p llvm/build cd llvm/build cmake -DCMAKE_BUILD_TYPE=Release .. make cd projects/libcxx; make install cd ../libcxxabi; make install
Add the libc++ and libc++abi installation path to the library search paths
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib )
After installing libc++ and libc++abi, then follow the instructions from ROCm to install the rpm packages.
CentOS 7/RHEL 7.1
Support on CentOS and RHEL is currently experimental and developers using these distros will have to compile the HCC compiler from source (see next section).
Install from Source
The build instruction could be found here
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
--amdgpu-target=<GCN ISA 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
AMD:AMDGPU:8:0:3 GCN ISA by default.
|GCN ISA Version||GPU/APU Family||Examples of Radeon GPU|
|AMD:AMDGPU:7:0:1||GFX7||FirePro W8100, FirePro W9100, Radeon R9 290, Radeon R9 390|
|AMD:AMDGPU:8:0:3 (Default)||GFX8||R9 Fury, R9 Fury X, R9 Nano, FirePro S9300 x2, Radeon RX 480, Radeon RX 470, Radeon RX 460|