Install ONNX Runtime for Radeon GPUs#
Refer to this section to install ONNX via the PIP installation method.
Overview#
Ensure that the following prerequisite installations are successful before proceeding to install ONNX Runtime for use with ROCm™ on Radeon™ GPUs.
Prerequisites#
Radeon Software for Linux (with ROCm) is installed.
MIGraphX is installed. This enables ONNX Runtime to build the correct MIGraphX EP.
The half library is installed.
NOTE The half library is installed with MIGraphX. If the half library install is not verified, use the following install command:
$ sudo apt install half
If the prerequisite installations are successful, proceed to install ONNX Runtime.
NOTE Unless adding custom features, use the pre-built Python wheel files provided in the PIP installation method.
Install ONNX Runtime#
Important!
Use the provided pre-built Python wheel files from the PIP installation method, unless adding custom features.
The wheel file contains the MIGraphX and ROCm Execution Providers (EP). Refer to Install MIGraphX for ONNX RT for more information.
Refer to ONNX Runtime Documentation for additional information on ONNX Runtime topics.
See ONNX Runtime Tutorials to try out real applications and tutorials on how to get started.
Option A: ONNX Runtime install via PIP installation method (Recommended)
AMD recommends the PIP install method to create an ONNX Runtime environment when working with ROCm for machine learning development.
To install via PIP,
Enter this command to download and install the ONNX Runtime wheel.
pip3 install https://repo.radeon.com/rocm/manylinux/rocm-rel-6.0.2/onnxruntime_rocm-inference-1.17.0-cp310-cp310-linux_x86_64.whl
Option B: Build from source for your environment, followed by local wheel file installation (Advanced)
Use this method for advanced customization usecases. This requires the user install the desired ROCm and MIGraphX versions, and creation of softlink prior to starting the build.
NOTE The build time typically takes ~45 minutes.
Prerequisites to build ONNX from source
Radeon Software for Linux (with ROCm) is installed
MigraphX is installed
Softlink is created
To create a softlink for
/opt/rocm, enter the following command:language = bash linenumbers = true ln -s /opt/rocm* /opt/rocm
To build from source,
Verify that MIGraphX is installed with the half library.
$ dpkg -l | grep migraphx $ dpkg -l | grep half
Expected result:
root@aus-navi3x-02:/workspace/AMDMIGraphX# dpkg -l | grep migraphx ii migraphx 2.9.0 amd64 AMD's graph optimizer ii migraphx-dev 2.9.0 amd64 AMD's graph optimizer ii migraphx-tests 2.9.0 amd64 AMD's graph opt $ dpkg -l | grep half ii half 1.12.0.60000-91~20.04 amd64 HALF-PRECISION FLOATING POINT LIBRARY
NOTE Versions may vary between ROCm builds and installed versions of MIGraphX, but the desired result is the same.
Enter the following install command if the half library is not installed with MIGraphX:
$ dpkg -l | grep migraphx $ dpkg -l | grep half
Run
rocm-smito ensure there’s an Onnxruntime supported GPU in the system.$ rocm-smi
Expected result:
======================================= ROCm System Management Interface ======================================= ================================================= Concise Info ================================================= Device [Model : Revision] Temp Power Partitions SCLK MCLK Fan Perf PwrCap VRAM% GPU% Name (20 chars) (Edge) (Avg) (Mem, Compute) ================================================================================================================ 0 [0x0e0d : 0x00] 32.0°C 73.0W N/A, N/A 1526Mhz 96Mhz 31.76% auto 241.0W 0% 50% 0x7448 ================================================================================================================ ============================================= End of ROCm SMI Log ==============================================
Clone the Onnxruntime repository into the root directory.
cd / git clone https://github.com/microsoft/onnxruntime.git
Run the build and install script from the MIGraphX project root directory.
cd ~ git clone https://github.com/ROCm/AMDMIGraphX.git cd AMDMIGraphX sudo tools/build_and_test_onnxrt.sh
This builds Onnxruntime and adds ROCm and MIGraphX EP support to the Onnxruntime interface.
Install ONNX Runtime once the build is completed and unit tests have run on the binary.
$ pip3 install /onnxruntime/build/Linux/Release/dist/*.whl
Verify ONNX Runtime installation#
Confirm if ONNX Runtime is correctly installed.
$ python3
$ import onnxruntime as ort
ort.get_available_providers()
Expected result: The following EPs are displayed.
>>> ort.get_available_providers()
['MIGraphXExecutionProvider', 'ROCMExecutionProvider', 'CPUExecutionProvider']
Environment set-up is complete, and the system is ready for use with ONNX Runtime to work with machine learning models, and algorithms.