Skip to content

Build MIGraphX Source in ROCm3.3

Shucai Xiao edited this page Feb 23, 2021 · 15 revisions

Build MIGraphX source in ROCm3.3 is very similar as that in ROCm3.7 as described in the MIGraphX repository webpage. The only difference is that the compiler in ROCm3.3 is hcc rather than the clang++ in ROCm3.7 or later releases.

They are three ways to build MIGraphX source in ROCm3.3, the first one is using the ROCm build tool rbuild with only one command. The second approach is building the prerequisites, configuring cmake, and building the source code, and the last approach is using a docker image to set up the development environment, then build MIGraphX source code inside the docker container.

Use the ROCm build tool rbuild.

In this approach, we use the rbuild build tool to build MIGraphX. The specific steps are as follows:

  1. Install rocm-cmake, pip3, rocblas, and with the command
sudo apt update && sudo apt install -y rocm-cmake python3-pip rocblas

Note that we do not install the miopen-hip package since the MIOpen contained in ROCm3.3 is out of date. We will install MIOpen through the rbuild command in step 3).

  1. Install rbuild (sudo may be required here.)
pip3 install https://github.com/RadeonOpenCompute/rbuild/archive/master.tar.gz
  1. Build MIGraphX source code
rbuild build -d depend -B build --cxx=/opt/rocm/bin/hcc

then all the prerequisites are in the folder depend, and MIGraphX is built in the build directory. Again, the difference is the compiler used here.

Use cmake to build MIGraphX source

The prerequisites required to build MIGraphX source are the same as that in ROCm3.6 and are listed here. They can be installed with three approaches (you can choose anyone from them):

  1. Use the rbuild command

The steps here is the same as in the previous [section](

  1. Use a script install_prereqs_rocm3.3.sh

Specifically, you can download this script install_prereqs_rocm3.3.sh and copy it to the location as $migraphx_dir/tools/install_prereqs_rocm3.3.sh, then run the command ./tools/install_prereqs_rocm3.3.sh.

By default, all prerequisites are installed at the default location /usr/local and are accessible by all users. For the default location, sudo is required to run the script. You can also specify a location at which the prerequisites are installed using the command ./tools/install_prereqs_rocm3.3.sh $your_loc.)

downloaded and installed one by one manually or through a script install_prereqs_rocm3.3.sh. To install them one by one manually, you can refer to the corresponding websites for the build and installation instructions. To use the script to install them, you can download this script install_prereqs_rocm3.3.sh and copy it to the location as $migraphx_dir/tools/install_prereqs_rocm3.3.sh, then run the command ./tools/install_prereqs_rocm3.3.sh.

By default, all prerequisites are installed at the default location /usr/local and are accessible by all users. For the default location, sudo is required to run the script. You can also specify a location at which the prerequisites are installed using the command ./tools/install_prereqs_rocm3.3.sh $your_loc.)

With the prerequisites installed successfully, MIGraphX source code can be built as:

  1. Go to the preject folder and create a build directory:
mkdir build
cd build
  1. Configure the cmake. If the prerequisites are installed at the default location /usr/local, the command is:
CXX=/opt/rocm/bin/hcc cmake ..

Otherwise, you need to set -DCMAKE_PREFIX_PATH=$your_loc to configure the cmake as:

CXX=/opt/rocm/bin/hcc cmake -DCMAKE_PREFIX_PATH=$your_loc ..
  1. Build MIGraphX source code
make -j$(nproc)

Correctness can be verified as:

make -j$(nproc) check

MIGraphX libs can be installed as:

make install

Note that the only different from building the source in ROCm3.7 is that the compiler is hcc here.

Build use the docker file.

We provide a docker file hcc.docker to build a docker container that includes all the prerequisites. You can download this docker file to the project folder, use the following commands to build and create a container.

docker build -t migraphx:rocm3.3 -f hcc.docker .

Then to enter the developement environment use docker run:

docker run --device='/dev/kfd' --device='/dev/dri' -v=`pwd`:/code/AMDMIGraphX -w /code/AMDMIGraphX --group-add video -it migraphx:rocm3.3

In the docker container, all the required prerequisites are already installed, so users can just go to the folder /code/AMDMIGraphX and follow the steps in the above Use cmake to build MIGraphX section to build MIGraphX source.