This tutorial shows how to use the GCC C++ Compiler on MacOS to build the HIP CPU Runtime. It does not delve into the details of HIP, the C++ language, the GCC toolset or the MacOS ecosystem.
If you encounter any difficulties, please create an issue for this tutorial.
To successfully complete this tutorial, the following steps are necessary:
-
Install Homebrew:
-
LLVM at the moment does not have parallel algorithm support. However, it is available in GNU G++. Homebrew provides a straightforward package manager for MacOS, which allows both the GNU G++ compiler, and Intel TBB on which HIP-CPU depends. One can also consider other package managers such as MacPorts, but we will focus on Homebrew here.
-
go to The Homebrew Site and follow the installation instructions there:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
You may or may not get messages about needing to install the XCode command line utilities if these are not yet installed. Follow the appropriate installation instructions on the Homebrew site.
-
-
Install [GNU G++][(https://gcc.gnu.org)
- Using Homebrew:
brew install gcc@10
- to avoid confusion with the system GCC (which is actually Clang), homebrew will name the executables as gcc-10 and g++-10
- Using Homebrew:
-
Install Intel TBB:
- At this time this is a pre-requisite for HIP-CPU(makefiles depend on it)
as it used to be a prerequisite for parallel algorithms for G++ on Linux.
Under MacOS, with the Homebrew installation, I successfully compiled a simple
parallel C++-17 parallel algorithm test from here
without TBB. However it is very easy to install using Homebrew:
brew install tbb
- At this time this is a pre-requisite for HIP-CPU(makefiles depend on it)
as it used to be a prerequisite for parallel algorithms for G++ on Linux.
Under MacOS, with the Homebrew installation, I successfully compiled a simple
parallel C++-17 parallel algorithm test from here
without TBB. However it is very easy to install using Homebrew:
-
Install latest CMake
-
Homebrew makes this super easy also:
brew install cmake
-
Alternatively, download and execute the installer.
-
-
Install Git
- This can be done from Homebrew:
brew install git
- alternatively a Git client can be installed from The Git Website`
- This can be done from Homebrew:
Ensure that /usr/local/bin
is on your PATH -- this is where Homebrew installs all its tools.
To verify whether GCC is installed and of a sufficiently recent version, open a Terminal window and enter the following command:
gcc-10 -v
git clone https://github.com/ROCm-Developer-Tools/HIP-CPU.git
cd HIP-CPU
mkdir build
cd build
cmake -DCMAKE_CXX_COMPILER=g++-10 ../
cmake --build ./
If you want to later install the HIP CPU Runtime in non standard folder you can
specify the install location to the cmake
command
cmake -DCMAKE_CXX_COMPILER=g++-10 -DCMAKE_INSTALL_PREFIX=<location to install the runtime>
# Assumes that you are in the build folder created in the build step.
cmake --build ./ --target install
# Assumes that you are in the build folder created in the build step.
ctest --output-on-failure
To use any of the HIP public interfaces include the hip/hip_runtime.h
header.
- If you are working with CMake, link against the convenience
INTERFACE
targethip_cpu_rt::hip_cpu_rt
, which is exported by the HIP CPU Runtime, which can be queried byfind_package(hip_cpu_rt)
; - If you are not working with CMake, add either
/path_where_you_cloned_the_hip_cpu_runtime/include
or, if you installed it,/path_where_you_installed_the_hip_cpu_runtime/include
to your include path.