Skip to content

Latest commit

 

History

History
114 lines (89 loc) · 4 KB

gcc_macos.md

File metadata and controls

114 lines (89 loc) · 4 KB

Building the HIP CPU Runtime and Client Applications GCC C++

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.

Prerequisites

To successfully complete this tutorial, the following steps are necessary:

  1. 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.

  2. 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
  3. 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
  4. Install latest CMake

  5. Install Git

    • This can be done from Homebrew:
      brew install git
    • alternatively a Git client can be installed from The Git Website`

Ensure that /usr/local/bin is on your PATH -- this is where Homebrew installs all its tools.

Ensure GCC is Installed

To verify whether GCC is installed and of a sufficiently recent version, open a Terminal window and enter the following command:

gcc-10 -v

Clone and build the HIP CPU Runtime

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> 

OPTIONAL Install the HIP CPU Runtime

# Assumes that you are in the build folder created in the build step.
cmake --build ./ --target install

Verify the build by running the unit tests

# Assumes that you are in the build folder created in the build step.
ctest --output-on-failure

Use the HIP CPU Runtime in your code

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 target hip_cpu_rt::hip_cpu_rt, which is exported by the HIP CPU Runtime, which can be queried by find_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.