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 two 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 installing the prerequisites, configuring cmake, and building the source code.

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, and rocblas 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.

Also note that you may meet the error of rbuild: command not found. It is because rbuild is installed at $HOME/.local/bin, which is not in PATH. You can either export PATH as export PATH=$HOME/.local/bin:$PATH to add the folder to PATH or add the option --prefix /usr/local in the pip3 command when installing rbuild.

Use cmake to build MIGraphX source

Install prerequistes

The prerequisites required to build MIGraphX source are the same as that in ROCm3.7 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. After running the rbuild command, all the prerequisites are in the folder depend.

  1. Use a script install_prereqs_rocm3.3.sh

You can download a 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.)

  1. Use a docker container

We provide a docker file hcc.docker that can be used to build a docker image with all the prerequisites installed.

You can download this docker file and copy it to the project folder, then run the following command to build a docker image.

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

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 next section to build MIGraphX source.

Build MIGraphX source

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

  1. Go to the project 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

Finally, MIGraphX libs can be installed as:

make install