:selector-toc2: Installation environment
:selector-toc2-icon: fa-solid fa-computer

.. meta::
  :description: Installing MIGraphX for ROCm
  :keywords: install, pip, package manager, tarball, build, MIGraphX, AMD, ROCm, development, contributing

****************
Install MIGraphX
****************

Installing MIGraphX using prebuilt packages is sufficient for most users
who want to use the MIGraphX API. If you plan to develop for MIGraphX or
contribute to the source code, see `Developing for MIGraphX <../dev/contributing-to-migraphx.html>`_.

.. selector:: Installation method
   :key: i

   .. selector-option:: Package manager
      :value: pkgman
      :width: 4

   .. selector-option:: pip
      :value: pip
      :width: 4

   .. selector-option:: Tarball
      :value: tar
      :width: 4

Prerequisites
=============

MIGraphX |MIGRAPHX_VERSION| is currently supported on:

* ``gfx950`` AMD Instinct MI355X, MI350X, and MI350P

* ``gfx942`` AMD Instinct MI325X, MI300X, and MI300A

* ``gfx90a`` AMD Instinct MI250X, MI250, and MI210

* ``gfx1200``, ``gfx1201``, ``gfx1100``, ``gfx1101``, ``gfx1102``, and ``gfx1103`` Radeon GPUs.

* ``gfx1153``, ``gfx1152``, ``gfx1151``, and ``gfx1150`` Ryzen AI processors.

See the |ROCM_COMPAT_DOC| for more information.

.. _migraphx-package-install:

Install MIGraphX on Linux
=========================

MIGraphX requires ROCm to be installed on your system first.

Install ROCm
------------

For instructions, see |ROCM_INSTALL_DOC|. Use the selector
panel on that page to view instructions appropriate for your system
environment.

.. selected:: i=pkgman

   .. note::

      Installing MIGraphX using a package manager requires a ROCm
      |ROCM_VERSION| installation using the same method. When selecting
      the ROCm installation method, choose your Linux distribution's
      package manager (``apt``, ``dnf``, or ``zypper``).

.. selected:: i=pip

   .. note::

      Installing MIGraphX using pip requires a ROCm |ROCM_VERSION|
      installation using pip in the same virtual environment. When
      selecting the ROCm installation method, choose **pip** as the ROCm
      installation method and install ROCm |ROCM_VERSION| into a Python
      virtual environment.

.. selected:: i=tar

   .. note::

      Installing MIGraphX using a tarball requires a ROCm |ROCM_VERSION|
      installation using a tarball or your Linux distribution's package
      manager. When selecting the ROCm installation method, choose
      **Tarball** or your Linux distribution's package manager as the
      ROCm installation method.

.. selected:: i=pkgman
   :heading: Install MIGraphX via package manager
   :heading-level: 3

   Use the following steps to install MIGraphX system-wide using your
   distribution's package manager on top of ROCm core libraries.

   .. selector:: Linux distribution
      :key: os

      .. selector-option:: Ubuntu
         :value: ubuntu
         :width: 4

      .. selector-option:: Debian
         :value: debian
         :width: 4

      .. selector-option:: RHEL
         :value: rhel
         :width: 4

      .. selector-option:: Oracle Linux
         :value: oracle-linux
         :width: 4

      .. selector-option:: Rocky Linux
         :value: rocky-linux
         :width: 4

      .. selector-option:: SLES
         :value: sles
         :width: 4

   .. selected:: os=ubuntu

      .. selector:: Ubuntu version
         :key: ubuntu-ver

         .. selector-option:: 26.04.1
            :width: 4

         .. selector-option:: 24.04.5
            :width: 4

         .. selector-option:: 22.04.5
            :width: 4

   .. selected:: os=debian

      .. selector:: Debian version
         :key: debian-ver

         .. selector-option:: 13
            :width: 6

         .. selector-option:: 12
            :width: 6

   .. selected:: os=rhel

      .. selector:: RHEL version
         :key: rhel-ver

         .. selector-option:: 10.3
            :width: 3

         .. selector-option:: 10.2
            :width: 3

         .. selector-option:: 10.0
            :width: 3

         .. selector-option:: 9.9
            :width: 3

         .. selector-option:: 9.8
            :width: 3

         .. selector-option:: 9.6
            :width: 3

         .. selector-option:: 9.4
            :width: 3

         .. selector-option:: 8.10
            :width: 3

   .. selected:: os=oracle-linux

      .. selector:: Oracle Linux version
         :key: oracle-linux-ver

         .. selector-option:: 10
            :width: 4

         .. selector-option:: 9
            :width: 4

         .. selector-option:: 8
            :width: 4

   .. selected:: os=rocky-linux

      .. selector:: Rocky Linux version
         :key: rocky-linux-ver

         .. selector-option:: 9
            :width: 12

   .. selected:: os=sles

      .. selector:: SLES version
         :key: sles-ver

         .. selector-option:: 16.1
            :width: 4

         .. selector-option:: 16.0
            :width: 4

         .. selector-option:: 15.7
            :width: 4

   .. raw:: html

      <br>

   1. Register the ROCm MIGraphX repository.

      .. selected:: os=ubuntu

         .. selected:: ubuntu-ver=26.04.1

            .. code-block:: bash

               sudo mkdir --parents --mode=0755 /etc/apt/keyrings
               wget https://stable.repo.amd.com/rocm/gpg/packages.gpg -O - | \
                   gpg --dearmor | sudo tee /etc/apt/keyrings/amdrocm.gpg > /dev/null
               sudo tee /etc/apt/sources.list.d/amdrocm-migraphx.sources << 'EOF'
               X-Repo-Id: amdrocm-migraphx
               Types: deb
               URIs: https://stable.repo.amd.com/rocm/migraphx/packages/ubuntu2604/
               Suites: stable
               Components: main
               Architectures: amd64
               Signed-By: /etc/apt/keyrings/amdrocm.gpg
               Enabled: yes
               EOF

               sudo apt update

         .. selected:: ubuntu-ver=24.04.5

            .. code-block:: bash

               sudo mkdir --parents --mode=0755 /etc/apt/keyrings
               wget https://stable.repo.amd.com/rocm/gpg/packages.gpg -O - | \
                   gpg --dearmor | sudo tee /etc/apt/keyrings/amdrocm.gpg > /dev/null
               sudo tee /etc/apt/sources.list.d/amdrocm-migraphx.sources << 'EOF'
               X-Repo-Id: amdrocm-migraphx
               Types: deb
               URIs: https://stable.repo.amd.com/rocm/migraphx/packages/ubuntu2404/
               Suites: stable
               Components: main
               Architectures: amd64
               Signed-By: /etc/apt/keyrings/amdrocm.gpg
               Enabled: yes
               EOF

               sudo apt update

         .. selected:: ubuntu-ver=22.04.5

            .. code-block:: bash

               sudo mkdir --parents --mode=0755 /etc/apt/keyrings
               wget https://stable.repo.amd.com/rocm/gpg/packages.gpg -O - | \
                   gpg --dearmor | sudo tee /etc/apt/keyrings/amdrocm.gpg > /dev/null
               sudo tee /etc/apt/sources.list.d/amdrocm-migraphx.sources << 'EOF'
               X-Repo-Id: amdrocm-migraphx
               Types: deb
               URIs: https://stable.repo.amd.com/rocm/migraphx/packages/ubuntu2204/
               Suites: stable
               Components: main
               Architectures: amd64
               Signed-By: /etc/apt/keyrings/amdrocm.gpg
               Enabled: yes
               EOF

               sudo apt update

      .. selected:: os=debian

         .. selected:: debian-ver=13

            .. code-block:: bash

               sudo mkdir --parents --mode=0755 /etc/apt/keyrings
               wget https://stable.repo.amd.com/rocm/gpg/packages.gpg -O - | \
                   gpg --dearmor | sudo tee /etc/apt/keyrings/amdrocm.gpg > /dev/null
               sudo tee /etc/apt/sources.list.d/amdrocm-migraphx.sources << 'EOF'
               X-Repo-Id: amdrocm-migraphx
               Types: deb
               URIs: https://stable.repo.amd.com/rocm/migraphx/packages/debian13/
               Suites: stable
               Components: main
               Architectures: amd64
               Signed-By: /etc/apt/keyrings/amdrocm.gpg
               Enabled: yes
               EOF

               sudo apt update

         .. selected:: debian-ver=12

            .. code-block:: bash

               sudo mkdir --parents --mode=0755 /etc/apt/keyrings
               wget https://stable.repo.amd.com/rocm/gpg/packages.gpg -O - | \
                   gpg --dearmor | sudo tee /etc/apt/keyrings/amdrocm.gpg > /dev/null
               sudo tee /etc/apt/sources.list.d/amdrocm-migraphx.sources << 'EOF'
               X-Repo-Id: amdrocm-migraphx
               Types: deb
               URIs: https://stable.repo.amd.com/rocm/migraphx/packages/debian12/
               Suites: stable
               Components: main
               Architectures: amd64
               Signed-By: /etc/apt/keyrings/amdrocm.gpg
               Enabled: yes
               EOF

               sudo apt update

      .. selected:: os=rhel

         .. selected:: rhel-ver=10.3 rhel-ver=10.2 rhel-ver=10.0

            .. code-block:: bash

               sudo tee /etc/yum.repos.d/amdrocm-migraphx.repo <<EOF
               [amdrocm-migraphx]
               name=AMD ROCm MIGraphX
               baseurl=https://stable.repo.amd.com/rocm/migraphx/packages/rhel10/x86_64
               enabled=1
               gpgcheck=1
               gpgkey=https://stable.repo.amd.com/rocm/gpg/packages.gpg
               priority=50
               EOF
               sudo dnf clean all

         .. selected:: rhel-ver=9.9 rhel-ver=9.8 rhel-ver=9.6 rhel-ver=9.4

            .. code-block:: bash

               sudo tee /etc/yum.repos.d/amdrocm-migraphx.repo <<EOF
               [amdrocm-migraphx]
               name=AMD ROCm MIGraphX
               baseurl=https://stable.repo.amd.com/rocm/migraphx/packages/rhel9/x86_64
               enabled=1
               gpgcheck=1
               gpgkey=https://stable.repo.amd.com/rocm/gpg/packages.gpg
               priority=50
               EOF
               sudo dnf clean all

         .. selected:: rhel-ver=8.10

            .. code-block:: bash

               sudo tee /etc/yum.repos.d/amdrocm-migraphx.repo <<EOF
               [amdrocm-migraphx]
               name=AMD ROCm MIGraphX
               baseurl=https://stable.repo.amd.com/rocm/migraphx/packages/rhel8/x86_64
               enabled=1
               gpgcheck=1
               gpgkey=https://stable.repo.amd.com/rocm/gpg/packages.gpg
               priority=50
               EOF
               sudo dnf clean all

      .. selected:: os=oracle-linux

         .. selected:: oracle-linux-ver=10

            .. code-block:: bash

               sudo tee /etc/yum.repos.d/amdrocm-migraphx.repo <<EOF
               [amdrocm-migraphx]
               name=AMD ROCm MIGraphX
               baseurl=https://stable.repo.amd.com/rocm/migraphx/packages/rhel10/x86_64
               enabled=1
               gpgcheck=1
               gpgkey=https://stable.repo.amd.com/rocm/gpg/packages.gpg
               priority=50
               EOF
               sudo dnf clean all

         .. selected:: oracle-linux-ver=9

            .. code-block:: bash

               sudo tee /etc/yum.repos.d/amdrocm-migraphx.repo <<EOF
               [amdrocm-migraphx]
               name=AMD ROCm MIGraphX
               baseurl=https://stable.repo.amd.com/rocm/migraphx/packages/rhel9/x86_64
               enabled=1
               gpgcheck=1
               gpgkey=https://stable.repo.amd.com/rocm/gpg/packages.gpg
               priority=50
               EOF
               sudo dnf clean all

         .. selected:: oracle-linux-ver=8

            .. code-block:: bash

               sudo tee /etc/yum.repos.d/amdrocm-migraphx.repo <<EOF
               [amdrocm-migraphx]
               name=AMD ROCm MIGraphX
               baseurl=https://stable.repo.amd.com/rocm/migraphx/packages/rhel8/x86_64
               enabled=1
               gpgcheck=1
               gpgkey=https://stable.repo.amd.com/rocm/gpg/packages.gpg
               priority=50
               EOF
               sudo dnf clean all

      .. selected:: os=rocky-linux

         .. code-block:: bash

            sudo tee /etc/yum.repos.d/amdrocm-migraphx.repo <<EOF
            [amdrocm-migraphx]
            name=AMD ROCm MIGraphX
            baseurl=https://stable.repo.amd.com/rocm/migraphx/packages/rhel9/x86_64
            enabled=1
            gpgcheck=1
            gpgkey=https://stable.repo.amd.com/rocm/gpg/packages.gpg
            priority=50
            EOF
            sudo dnf clean all

      .. selected:: os=sles

         .. selected:: sles-ver=16.1 sles-ver=16.0

            .. code-block:: bash

               sudo tee /etc/zypp/repos.d/amdrocm-migraphx.repo <<EOF
               [amdrocm-migraphx]
               name=AMD ROCm MIGraphX
               baseurl=https://stable.repo.amd.com/rocm/migraphx/packages/sles16/x86_64
               enabled=1
               gpgcheck=1
               gpgkey=https://stable.repo.amd.com/rocm/gpg/packages.gpg
               priority=50
               EOF

               sudo zypper --gpg-auto-import-keys refresh

         .. selected:: sles-ver=15.7

            .. code-block:: bash

               sudo tee /etc/zypp/repos.d/amdrocm-migraphx.repo <<EOF
               [amdrocm-migraphx]
               name=AMD ROCm MIGraphX
               baseurl=https://stable.repo.amd.com/rocm/migraphx/packages/sles15/x86_64
               enabled=1
               gpgcheck=1
               gpgkey=https://stable.repo.amd.com/rocm/gpg/packages.gpg
               priority=50
               EOF

               sudo zypper --gpg-auto-import-keys refresh

   2. Install the MIGraphX packages and ROCm dependencies.

      .. selected:: os=ubuntu os=debian

         .. code-block:: bash
            :substitutions:

            sudo apt install amdrocm|ROCM_MAJOR|-migraphx amdrocm|ROCM_MAJOR|-migraphx-dev

      .. selected:: os=rhel os=oracle-linux os=rocky-linux

         .. code-block:: bash
            :substitutions:

            sudo dnf install amdrocm|ROCM_MAJOR|-migraphx amdrocm|ROCM_MAJOR|-migraphx-devel

      .. selected:: os=sles

         .. code-block:: bash
            :substitutions:

            sudo zypper install amdrocm|ROCM_MAJOR|-migraphx amdrocm|ROCM_MAJOR|-migraphx-devel

   3. Complete the following post-installation steps.

      Configure environment variables so that MIGraphX is added to the
      ``PATH`` and ``LD_LIBRARY_PATH``.

      .. tab-set::

         .. tab-item:: Active session
            :sync: active

            Set the MIGraphX environment variables for the current shell
            session only. To keep these settings across sessions, use
            System-wide setup or User setup.

            .. code-block:: bash
               :substitutions:

               # MIGraphX Environment Setup
               export ROCM_PATH=/opt/rocm/core-|ROCM_VERSION_PKG_SUFFIX|
               export MIGRAPHX_PATH=/opt/rocm/extras-|ROCM_MAJOR|
               export PATH=$MIGRAPHX_PATH/bin:$PATH
               export LD_LIBRARY_PATH=$MIGRAPHX_PATH/lib:$ROCM_PATH/lib:$LD_LIBRARY_PATH

         .. tab-item:: System-wide setup
            :sync: system

            Create a profile script so that all users inherit the
            MIGraphX environment variables when they start a shell
            session.

            .. code-block:: bash
               :substitutions:

               # MIGraphX Environment Setup
               sudo tee /etc/profile.d/set-migraphx-env.sh << 'EOF'
               export ROCM_PATH=/opt/rocm/core-|ROCM_VERSION_PKG_SUFFIX|
               export MIGRAPHX_PATH=/opt/rocm/extras-|ROCM_MAJOR|
               export PATH=$MIGRAPHX_PATH/bin:$PATH
               export LD_LIBRARY_PATH=$MIGRAPHX_PATH/lib:$ROCM_PATH/lib:$LD_LIBRARY_PATH
               EOF

               sudo chmod +x /etc/profile.d/set-migraphx-env.sh
               source /etc/profile.d/set-migraphx-env.sh

         .. tab-item:: User setup
            :sync: user

            Configure the MIGraphX environment for your user by updating
            your shell startup configuration file.

            .. tab-set::

               .. tab-item:: .bashrc
                  :sync: bashrc

                  .. code-block:: bash
                     :substitutions:

                     # MIGraphX Environment Setup
                     tee --append ~/.bashrc << 'EOF'
                     # BEGIN MIGraphX environment configuration
                     export ROCM_PATH=/opt/rocm/core-|ROCM_VERSION_PKG_SUFFIX|
                     export MIGRAPHX_PATH=/opt/rocm/extras-|ROCM_MAJOR|
                     export PATH=$MIGRAPHX_PATH/bin:$PATH
                     export LD_LIBRARY_PATH=$MIGRAPHX_PATH/lib:$ROCM_PATH/lib:$LD_LIBRARY_PATH
                     # END MIGraphX environment configuration
                     EOF

                     source ~/.bashrc

               .. tab-item:: .profile
                  :sync: profile

                  .. code-block:: bash
                     :substitutions:

                     # MIGraphX Environment Setup
                     tee --append ~/.profile << 'EOF'
                     # BEGIN MIGraphX environment configuration
                     export ROCM_PATH=/opt/rocm/core-|ROCM_VERSION_PKG_SUFFIX|
                     export MIGRAPHX_PATH=/opt/rocm/extras-|ROCM_MAJOR|
                     export PATH=$MIGRAPHX_PATH/bin:$PATH
                     export LD_LIBRARY_PATH=$MIGRAPHX_PATH/lib:$ROCM_PATH/lib:$LD_LIBRARY_PATH
                     # END MIGraphX environment configuration
                     EOF

                     source ~/.profile

   4. Verify your installation.

      Confirm that ``migraphx-driver`` is on your ``PATH`` and reports the
      expected version.

      .. code-block:: bash

         migraphx-driver --version

      You should see MIGraphX |MIGRAPHX_VERSION| in the output:

      .. code-block:: text
         :substitutions:

         MIGraphX Version: |MIGRAPHX_VERSION|

      .. tip::

         If the command isn't found, the environment variables from the
         previous step aren't set in your current shell. Re-run the
         ``source`` command or open a new shell session.

.. selected:: i=pkgman
   :heading: Uninstall MIGraphX
   :heading-level: 3

   1. Use your package manager to remove the installed packages.

      .. selected:: os=ubuntu os=debian

         .. code-block:: bash
            :substitutions:

            sudo apt remove amdrocm|ROCM_MAJOR|-migraphx amdrocm|ROCM_MAJOR|-migraphx-dev

      .. selected:: os=rhel os=oracle-linux os=rocky-linux

         .. code-block:: bash
            :substitutions:

            sudo dnf remove amdrocm|ROCM_MAJOR|-migraphx amdrocm|ROCM_MAJOR|-migraphx-devel

      .. selected:: os=sles

         .. code-block:: bash
            :substitutions:

            sudo zypper remove --clean-deps amdrocm|ROCM_MAJOR|-migraphx amdrocm|ROCM_MAJOR|-migraphx-devel

   2. Remove the MIGraphX repository.

      .. selected:: os=ubuntu os=debian

         .. code-block:: bash

            # Remove MIGraphX repository
            sudo rm /etc/apt/sources.list.d/amdrocm-migraphx.sources

            # Clear the cache and clean the system
            sudo apt clean
            sudo apt update

      .. selected:: os=rhel os=oracle-linux os=rocky-linux

         .. code-block:: bash

            # Remove MIGraphX repository
            sudo rm /etc/yum.repos.d/amdrocm-migraphx.repo

            # Clear the cache and clean the system
            sudo dnf clean all

      .. selected:: os=sles

         .. code-block:: bash

            # Remove MIGraphX repository
            sudo zypper removerepo "amdrocm-migraphx"

            # Clear the cache and clean the system
            sudo zypper clean --all
            sudo zypper refresh

   3. Remove the MIGraphX environment configuration.

      .. tab-set::

         .. tab-item:: System-wide setup
            :sync: system

            If you opted for a system-wide setup during the installation
            process, remove the MIGraphX environment variables.

            .. code-block:: bash

               sudo rm -f /etc/profile.d/set-migraphx-env.sh

         .. tab-item:: User setup
            :sync: user

            .. tab-set::

               .. tab-item:: .bashrc
                  :sync: bashrc

                  If you opted for a user-specific setup during the installation
                  process, remove the MIGraphX environment configuration block --
                  the lines between the ``BEGIN`` and ``END`` markers -- from
                  ``~/.bashrc``.

               .. tab-item:: .profile
                  :sync: profile

                  If you opted for a user-specific setup during the installation
                  process, remove the MIGraphX environment configuration block --
                  the lines between the ``BEGIN`` and ``END`` markers -- from
                  ``~/.profile``.

.. selected:: i=pip
   :heading: Install MIGraphX using pip
   :heading-level: 3

   After installing ROCm, install MIGraphX. This method installs MIGraphX |MIGRAPHX_VERSION| into
   a Python virtual environment.

   1. Activate the ROCm |ROCM_VERSION| virtual environment you created
      while installing ROCm using pip.

      .. code-block:: bash

         source .venv/bin/activate

      .. note::

         Substitute ``.venv`` with the path to your virtual environment if
         you used a different name or location.

   2. Install the MIGraphX and ``migraphx-libs`` wheels.

      .. code-block:: bash
         :substitutions:

         python -m pip install --index-url |WHL_PKG_REPO| \
             "migraphx==|MIGRAPHX_VERSION|+rocm|ROCM_VERSION|" \
             "migraphx-libs==|MIGRAPHX_VERSION|+rocm|ROCM_VERSION|"

   3. Verify your installation.

      Confirm that ``migraphx-driver`` and the ``migraphx`` Python module are
      available in your virtual environment and report the expected version.

      .. code-block:: bash

         migraphx-driver --version
         python -c "import migraphx; print(migraphx.__version__)"

      You should see MIGraphX |MIGRAPHX_VERSION| in the output:

      .. code-block:: text
         :substitutions:

         MIGraphX Version: |MIGRAPHX_VERSION|
         |MIGRAPHX_VERSION|+rocm|ROCM_VERSION|

   .. seealso::

      ONNX Runtime with ``onnxruntime-ep-migraphx`` accelerates machine
      learning inference using the MIGraphX execution provider on
      ROCm-supported GPUs. See the `ONNX Runtime installation guide`_.

.. _ONNX Runtime installation guide: https://rocm.docs.amd.com/projects/ai-ecosystem/en/latest/inference/onnxruntime.html

.. selected:: i=pip
   :heading: Uninstall MIGraphX
   :heading-level: 3

   1. Remove the virtual environment containing MIGraphX.

      .. code-block:: bash

         deactivate
         rm -rf .venv

.. selected:: i=tar
   :heading: Install MIGraphX via tarball
   :heading-level: 3

   After installing ROCm, install MIGraphX using the tarball method.

   1. Download the MIGraphX tarball.

      .. code-block:: bash
         :substitutions:

         wget |TARBALL_REPO||TARBALL_NAME|

   2. Extract the tarball.

      MIGraphX is part of the ROCm Extras set of tools that work with the
      ROCm Core SDK and requires configuring the location of a ROCm
      installation. Set the ``ROCM_INSTALL_PATH`` variable to the install
      directory of ROCm. For example, if you installed the ROCm Core SDK
      using your Linux distribution's package manager, set it to
      :substitution-code:`/opt/rocm/core-|ROCM_VERSION_PKG_SUFFIX|`. If ROCm
      was installed via tarball to a custom location, set
      ``ROCM_INSTALL_PATH`` to that location, for example
      ``$HOME/therock-tarball/install``.

      ``MIGRAPHX_INSTALL_PATH`` is set to the installation of MIGraphX to an
      extras location within the ROCm installation.

      .. code-block:: bash
         :substitutions:

         # Set installation paths
         ROCM_INSTALL_PATH="$HOME/therock-tarball/install"
         MIGRAPHX_INSTALL_PATH="$HOME/therock-tarball/install/extras-|ROCM_MAJOR|"

         # Extract to the MIGraphX directory
         mkdir -p $MIGRAPHX_INSTALL_PATH
         tar -xzf |TARBALL_NAME| -C $MIGRAPHX_INSTALL_PATH

      .. note::

         The installation path for MIGraphX above assumes ROCm was installed
         to ``$HOME/therock-tarball/install``.

   3. Complete the following post-installation steps.

      Configure environment variables so that MIGraphX is added to the
      ``PATH`` and ``LD_LIBRARY_PATH``. ``MIGRAPHX_PATH`` and ``ROCM_PATH``
      are set to the values used during extraction.

      .. tab-set::

         .. tab-item:: Active session
            :sync: active

            Set the MIGraphX environment variables for the current shell
            session only. To keep these settings across sessions, use
            System-wide setup or User setup.

            .. code-block:: bash

               # MIGraphX Environment Setup
               export ROCM_PATH=$ROCM_INSTALL_PATH
               export MIGRAPHX_PATH=$MIGRAPHX_INSTALL_PATH
               export PATH=$MIGRAPHX_PATH/bin:$PATH
               export LD_LIBRARY_PATH=$MIGRAPHX_PATH/lib:$ROCM_PATH/lib:$LD_LIBRARY_PATH

         .. tab-item:: System-wide setup
            :sync: system

            Create a profile script so that all users inherit the
            MIGraphX environment variables when they start a shell
            session.

            .. code-block:: bash

               # MIGraphX Environment Setup
               sudo tee /etc/profile.d/set-migraphx-env.sh << EOF
               export ROCM_PATH=$ROCM_INSTALL_PATH
               export MIGRAPHX_PATH=$MIGRAPHX_INSTALL_PATH
               export PATH=\$MIGRAPHX_PATH/bin:\$PATH
               export LD_LIBRARY_PATH=\$MIGRAPHX_PATH/lib:\$ROCM_PATH/lib:\$LD_LIBRARY_PATH
               EOF

               sudo chmod +x /etc/profile.d/set-migraphx-env.sh
               source /etc/profile.d/set-migraphx-env.sh

         .. tab-item:: User setup
            :sync: user

            Configure the MIGraphX environment for your user by updating
            your shell startup configuration file.

            .. tab-set::

               .. tab-item:: .bashrc
                  :sync: bashrc

                  .. code-block:: bash

                     # MIGraphX Environment Setup
                     tee --append ~/.bashrc << EOF
                     # BEGIN MIGraphX environment configuration
                     export ROCM_PATH=$ROCM_INSTALL_PATH
                     export MIGRAPHX_PATH=$MIGRAPHX_INSTALL_PATH
                     export PATH=\$MIGRAPHX_PATH/bin:\$PATH
                     export LD_LIBRARY_PATH=\$MIGRAPHX_PATH/lib:\$ROCM_PATH/lib:\$LD_LIBRARY_PATH
                     # END MIGraphX environment configuration
                     EOF

                     source ~/.bashrc

               .. tab-item:: .profile
                  :sync: profile

                  .. code-block:: bash

                     # MIGraphX Environment Setup
                     tee --append ~/.profile << EOF
                     # BEGIN MIGraphX environment configuration
                     export ROCM_PATH=$ROCM_INSTALL_PATH
                     export MIGRAPHX_PATH=$MIGRAPHX_INSTALL_PATH
                     export PATH=\$MIGRAPHX_PATH/bin:\$PATH
                     export LD_LIBRARY_PATH=\$MIGRAPHX_PATH/lib:\$ROCM_PATH/lib:\$LD_LIBRARY_PATH
                     # END MIGraphX environment configuration
                     EOF

                     source ~/.profile

   4. Verify your installation.

      Confirm that ``migraphx-driver`` is on your ``PATH`` and reports the
      expected version.

      .. code-block:: bash

         migraphx-driver --version

      You should see MIGraphX |MIGRAPHX_VERSION| in the output:

      .. code-block:: text
         :substitutions:

         MIGraphX Version: |MIGRAPHX_VERSION|

      .. tip::

         If the command isn't found, the environment variables from the
         previous step aren't set in your current shell. Re-run the
         ``source`` command or open a new shell session.

.. selected:: i=tar
   :heading: Uninstall MIGraphX
   :heading-level: 3

   1. Remove the installation directory.

      To uninstall MIGraphX, remove your MIGraphX installation directory.

      .. important::

         The following command assumes you're working with the
         ``MIGRAPHX_INSTALL_PATH`` directory set to
         :substitution-code:`$HOME/therock-tarball/install/extras-|ROCM_MAJOR|`.
         If you chose a different directory when installing MIGraphX, adjust
         the command accordingly.

      .. code-block:: bash
         :substitutions:

         rm -rf "$HOME/therock-tarball/install/extras-|ROCM_MAJOR|"

   2. Remove the MIGraphX environment configuration.

      .. tab-set::

         .. tab-item:: System-wide setup
            :sync: system

            If you opted for a system-wide setup during the installation
            process, remove the MIGraphX environment variables.

            .. code-block:: bash

               sudo rm -f /etc/profile.d/set-migraphx-env.sh

         .. tab-item:: User setup
            :sync: user

            .. tab-set::

               .. tab-item:: .bashrc
                  :sync: bashrc

                  If you opted for a user-specific setup during the installation
                  process, remove the MIGraphX environment configuration block --
                  the lines between the ``BEGIN`` and ``END`` markers -- from
                  ``~/.bashrc``.

               .. tab-item:: .profile
                  :sync: profile

                  If you opted for a user-specific setup during the installation
                  process, remove the MIGraphX environment configuration block --
                  the lines between the ``BEGIN`` and ``END`` markers -- from
                  ``~/.profile``.


.. _build-from-source:

Build MIGraphX from source
==========================

.. note::

   For reproducibility, we recommend using the provided Docker environment
   with MIGraphX build prerequisites preinstalled. See
   :doc:`./build-migraphx-docker`.

See the `MIGraphX README <https://github.com/ROCm/AMDMIGraphX>`__ for more
information.

1. Complete the appropriate :doc:`ROCm installation prerequisites
   <rocm:install/rocm>` for your system environment
   and register AMD package repositories.

2. Install required ROCm development packages:

   .. tab-set::

      .. tab-item:: Debian-based distros
         :sync: deb

         .. code-block:: shell
            :substitutions:

            sudo apt install amdrocm-runtime-dev|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-blas-dev|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-blas-host|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-dnn-dev|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-dnn-host|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-hipblas-common-dev|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-core|ROCM_VERSION_PKG_SUFFIX|

      .. tab-item:: RHEL-based distros
         :sync: rhel

         .. code-block:: shell
            :substitutions:

            sudo dnf install amdrocm-runtime-devel|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-blas-devel|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-blas-host|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-dnn-devel|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-dnn-host|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-hipblas-common-devel|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-core|ROCM_VERSION_PKG_SUFFIX|

      .. tab-item:: SLES
         :sync: zypper

         .. code-block:: shell
            :substitutions:

            sudo zypper install amdrocm-runtime-devel|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-blas-devel|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-blas-host|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-dnn-devel|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-dnn-host|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-hipblas-common-devel|ROCM_VERSION_PKG_SUFFIX| \
                amdrocm-core|ROCM_VERSION_PKG_SUFFIX|

   ``amdrocm-core`` provides the GPU device code and links ``/opt/rocm/bin``,
   ``/opt/rocm/llvm``, and the other ``/opt/rocm`` entry points to this
   release, so the paths used in the remaining steps resolve.

   .. note::

      :substitution-code:`amdrocm-core|ROCM_VERSION_PKG_SUFFIX|` installs the device code for
      every supported architecture. Append your GPU's architecture to install
      only the device code that architecture needs, which is a much smaller
      download:

      .. code-block:: shell
         :substitutions:

         sudo apt install amdrocm-core|ROCM_VERSION_PKG_SUFFIX|-gfx942

      Run ``rocminfo | grep -o -m1 'gfx.*'`` to find the architecture of an
      installed GPU. The suffixed package sets up the same ``/opt/rocm`` links.

3. Install the host build tools. The ROCm packages don't provide CMake, Git, or
   the Python headers and ``venv`` module that the following steps need.

   .. tab-set::

      .. tab-item:: Debian-based distros
         :sync: deb

         .. code-block:: shell

            sudo apt install build-essential cmake git pkg-config \
                python3-dev python3-pip python3-venv

      .. tab-item:: RHEL-based distros
         :sync: rhel

         .. code-block:: shell

            sudo dnf install gcc-c++ make cmake git \
                python3-devel python3-pip

      .. tab-item:: SLES
         :sync: zypper

         .. code-block:: shell

            sudo zypper install gcc-c++ make cmake git \
                python3-devel python3-pip

4. Clone the MIGraphX source code:

   .. code-block:: shell

      git clone https://github.com/ROCm/AMDMIGraphX.git
      cd AMDMIGraphX

5. Install `rbuild <https://github.com/RadeonOpenCompute/rbuild>`__ into a Python
   virtual environment.

   On Python 3.14 or newer, install ``cget`` from source.

   .. code-block:: shell

      python3 -m venv venv_rbuild
      source venv_rbuild/bin/activate

      pip install https://github.com/pfultz2/cget/archive/master.tar.gz
      pip install https://github.com/ROCm/rbuild/archive/master.tar.gz

6. Build MIGraphX source code. Run this from the root of the checkout, because
   ``rbuild`` builds the source directory you invoke it from:

   .. code-block:: shell

      rbuild build -d depend -B build -DGPU_TARGETS=$(/opt/rocm/bin/rocminfo | grep -o -m1 'gfx.*')

Once completed, all prerequisites are in the ``depend`` folder and MIGraphX is in
the ``build`` directory.

If you plan to develop for MIGraphX or contribute to the source code, see
:doc:`Developing for MIGraphX <../dev/contributing-to-migraphx>`.
