From 8fb547c3404cd444f7d71138bc9755937b1e4390 Mon Sep 17 00:00:00 2001
From: blorange-amd <bo.li2@amd.com>
Date: Fri, 9 Dec 2022 00:28:45 +0000
Subject: [PATCH 1/6] Upgrade nightly wheels to rocm5.4

---
 .github/workflows/build-libtorch-images.yml  | 2 +-
 .github/workflows/build-manywheel-images.yml | 2 +-
 libtorch/Dockerfile                          | 8 ++++----
 libtorch/build_all_docker.sh                 | 2 +-
 manywheel/build_all_docker.sh                | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/build-libtorch-images.yml b/.github/workflows/build-libtorch-images.yml
index 9df52050d..7400ef101 100644
--- a/.github/workflows/build-libtorch-images.yml
+++ b/.github/workflows/build-libtorch-images.yml
@@ -47,7 +47,7 @@ jobs:
     runs-on: ubuntu-18.04
     strategy:
       matrix:
-        rocm_version: ["5.2", "5.3"]
+        rocm_version: ["5.3", "5.4"]
     env:
       GPU_ARCH_TYPE: rocm
       GPU_ARCH_VERSION: ${{ matrix.rocm_version }}
diff --git a/.github/workflows/build-manywheel-images.yml b/.github/workflows/build-manywheel-images.yml
index 811f3fc53..3b9f4fc4e 100644
--- a/.github/workflows/build-manywheel-images.yml
+++ b/.github/workflows/build-manywheel-images.yml
@@ -49,7 +49,7 @@ jobs:
     runs-on: ubuntu-18.04
     strategy:
       matrix:
-        rocm_version: ["5.2", "5.3"]
+        rocm_version: ["5.3", "5.4"]
     env:
       GPU_ARCH_TYPE: rocm
       GPU_ARCH_VERSION: ${{ matrix.rocm_version }}
diff --git a/libtorch/Dockerfile b/libtorch/Dockerfile
index 04342fa63..9e429e9ad 100644
--- a/libtorch/Dockerfile
+++ b/libtorch/Dockerfile
@@ -69,13 +69,13 @@ RUN apt-get update -y && \
     apt-get install python -y && \
     apt-get clean
 
-FROM rocm as rocm5.2
-RUN ROCM_VERSION=5.2 bash ./install_rocm.sh && rm install_rocm.sh
+FROM rocm as rocm5.3
+RUN ROCM_VERSION=5.3 bash ./install_rocm.sh && rm install_rocm.sh
 RUN bash ./install_rocm_drm.sh && rm install_rocm_drm.sh
 RUN bash ./install_rocm_magma.sh && rm install_rocm_magma.sh
 
-FROM rocm as rocm5.3
-RUN ROCM_VERSION=5.3 bash ./install_rocm.sh && rm install_rocm.sh
+FROM rocm as rocm5.4
+RUN ROCM_VERSION=5.4 bash ./install_rocm.sh && rm install_rocm.sh
 RUN bash ./install_rocm_drm.sh && rm install_rocm_drm.sh
 RUN bash ./install_rocm_magma.sh && rm install_rocm_magma.sh
 
diff --git a/libtorch/build_all_docker.sh b/libtorch/build_all_docker.sh
index a6fae3f82..c1103017f 100755
--- a/libtorch/build_all_docker.sh
+++ b/libtorch/build_all_docker.sh
@@ -8,6 +8,6 @@ for cuda_version in 11.8 11.7 11.6; do
     GPU_ARCH_TYPE=cuda GPU_ARCH_VERSION="${cuda_version}" "${TOPDIR}/libtorch/build_docker.sh"
 done
 
-for rocm_version in 5.2 5.3; do
+for rocm_version in 5.3 5.4; do
     GPU_ARCH_TYPE=rocm GPU_ARCH_VERSION="${rocm_version}" "${TOPDIR}/libtorch/build_docker.sh"
 done
diff --git a/manywheel/build_all_docker.sh b/manywheel/build_all_docker.sh
index d202bd641..4b61948fb 100644
--- a/manywheel/build_all_docker.sh
+++ b/manywheel/build_all_docker.sh
@@ -14,7 +14,7 @@ for cuda_version in 11.7 11.6; do
     MANYLINUX_VERSION=2014 GPU_ARCH_TYPE=cuda GPU_ARCH_VERSION="${cuda_version}" "${TOPDIR}/manywheel/build_docker.sh"
 done
 
-for rocm_version in 5.2 5.3; do
+for rocm_version in 5.3 5.4; do
     GPU_ARCH_TYPE=rocm GPU_ARCH_VERSION="${rocm_version}" "${TOPDIR}/manywheel/build_docker.sh"
     MANYLINUX_VERSION=2014 GPU_ARCH_TYPE=rocm GPU_ARCH_VERSION="${rocm_version}" "${TOPDIR}/manywheel/build_docker.sh"
 done

From a794cecc7eb5b26f42cc6665ec7c0fe7b1d2f58a Mon Sep 17 00:00:00 2001
From: blorange-amd <bo.li2@amd.com>
Date: Wed, 14 Dec 2022 00:59:02 +0000
Subject: [PATCH 2/6] Adding graphic architectures for ROCm 5.4

---
 common/install_miopen.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/install_miopen.sh b/common/install_miopen.sh
index b526cbe20..5fbd8911c 100644
--- a/common/install_miopen.sh
+++ b/common/install_miopen.sh
@@ -60,7 +60,10 @@ MIOPEN_CMAKE_COMMON_FLAGS="
 -DMIOPEN_BUILD_DRIVER=OFF
 "
 # Pull MIOpen repo and set DMIOPEN_EMBED_DB based on ROCm version
-if [[ $ROCM_INT -ge 50300 ]] && [[ $ROCM_INT -lt 50400 ]]; then
+if [[ $ROCM_INT -ge 50400 ]] && [[ $ROCM_INT -lt 50500 ]]; then
+    MIOPEN_CMAKE_DB_FLAGS="-DMIOPEN_EMBED_DB=gfx900_56;gfx906_60;gfx90878;gfx90a6e;gfx1030_36 -DMIOPEN_USE_MLIR=Off"
+    MIOPEN_BRANCH="release/rocm-rel-5.4-staging"
+else if [[ $ROCM_INT -ge 50300 ]] && [[ $ROCM_INT -lt 50400 ]]; then
     MIOPEN_CMAKE_DB_FLAGS="-DMIOPEN_EMBED_DB=gfx900_56;gfx906_60;gfx90878;gfx90a6e;gfx1030_36 -DMIOPEN_USE_MLIR=Off"
     MIOPEN_BRANCH="release/rocm-rel-5.3-staging"
 elif [[ $ROCM_INT -ge 50200 ]] && [[ $ROCM_INT -lt 50300 ]]; then

From 69d11a633c93637cea38c044b1968107a15c9fd3 Mon Sep 17 00:00:00 2001
From: blorange-amd <bo.li2@amd.com>
Date: Tue, 24 Jan 2023 23:43:08 -0600
Subject: [PATCH 3/6] Updated to use ROCm5.4.1

---
 .github/workflows/build-libtorch-images.yml  | 2 +-
 .github/workflows/build-manywheel-images.yml | 2 +-
 libtorch/Dockerfile                          | 4 ++--
 libtorch/build_all_docker.sh                 | 2 +-
 manywheel/build_all_docker.sh                | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/build-libtorch-images.yml b/.github/workflows/build-libtorch-images.yml
index 7400ef101..00d040850 100644
--- a/.github/workflows/build-libtorch-images.yml
+++ b/.github/workflows/build-libtorch-images.yml
@@ -47,7 +47,7 @@ jobs:
     runs-on: ubuntu-18.04
     strategy:
       matrix:
-        rocm_version: ["5.3", "5.4"]
+        rocm_version: ["5.3", "5.4.1"]
     env:
       GPU_ARCH_TYPE: rocm
       GPU_ARCH_VERSION: ${{ matrix.rocm_version }}
diff --git a/.github/workflows/build-manywheel-images.yml b/.github/workflows/build-manywheel-images.yml
index 3b9f4fc4e..254f49fc1 100644
--- a/.github/workflows/build-manywheel-images.yml
+++ b/.github/workflows/build-manywheel-images.yml
@@ -49,7 +49,7 @@ jobs:
     runs-on: ubuntu-18.04
     strategy:
       matrix:
-        rocm_version: ["5.3", "5.4"]
+        rocm_version: ["5.3", "5.4.1"]
     env:
       GPU_ARCH_TYPE: rocm
       GPU_ARCH_VERSION: ${{ matrix.rocm_version }}
diff --git a/libtorch/Dockerfile b/libtorch/Dockerfile
index 9e429e9ad..98d362752 100644
--- a/libtorch/Dockerfile
+++ b/libtorch/Dockerfile
@@ -74,8 +74,8 @@ RUN ROCM_VERSION=5.3 bash ./install_rocm.sh && rm install_rocm.sh
 RUN bash ./install_rocm_drm.sh && rm install_rocm_drm.sh
 RUN bash ./install_rocm_magma.sh && rm install_rocm_magma.sh
 
-FROM rocm as rocm5.4
-RUN ROCM_VERSION=5.4 bash ./install_rocm.sh && rm install_rocm.sh
+FROM rocm as rocm5.4.1
+RUN ROCM_VERSION=5.4.1 bash ./install_rocm.sh && rm install_rocm.sh
 RUN bash ./install_rocm_drm.sh && rm install_rocm_drm.sh
 RUN bash ./install_rocm_magma.sh && rm install_rocm_magma.sh
 
diff --git a/libtorch/build_all_docker.sh b/libtorch/build_all_docker.sh
index c1103017f..5b41f80ed 100755
--- a/libtorch/build_all_docker.sh
+++ b/libtorch/build_all_docker.sh
@@ -8,6 +8,6 @@ for cuda_version in 11.8 11.7 11.6; do
     GPU_ARCH_TYPE=cuda GPU_ARCH_VERSION="${cuda_version}" "${TOPDIR}/libtorch/build_docker.sh"
 done
 
-for rocm_version in 5.3 5.4; do
+for rocm_version in 5.3 5.4.1; do
     GPU_ARCH_TYPE=rocm GPU_ARCH_VERSION="${rocm_version}" "${TOPDIR}/libtorch/build_docker.sh"
 done
diff --git a/manywheel/build_all_docker.sh b/manywheel/build_all_docker.sh
index 4b61948fb..95e7ae716 100644
--- a/manywheel/build_all_docker.sh
+++ b/manywheel/build_all_docker.sh
@@ -14,7 +14,7 @@ for cuda_version in 11.7 11.6; do
     MANYLINUX_VERSION=2014 GPU_ARCH_TYPE=cuda GPU_ARCH_VERSION="${cuda_version}" "${TOPDIR}/manywheel/build_docker.sh"
 done
 
-for rocm_version in 5.3 5.4; do
+for rocm_version in 5.3 5.4.1; do
     GPU_ARCH_TYPE=rocm GPU_ARCH_VERSION="${rocm_version}" "${TOPDIR}/manywheel/build_docker.sh"
     MANYLINUX_VERSION=2014 GPU_ARCH_TYPE=rocm GPU_ARCH_VERSION="${rocm_version}" "${TOPDIR}/manywheel/build_docker.sh"
 done

From 3daa37e17a81afdc56a0a902f999186446e2317f Mon Sep 17 00:00:00 2001
From: blorange-amd <bo.li2@amd.com>
Date: Wed, 25 Jan 2023 12:45:08 -0600
Subject: [PATCH 4/6] Updated to use ROCm5.4.2

---
 .github/workflows/build-libtorch-images.yml  | 2 +-
 .github/workflows/build-manywheel-images.yml | 2 +-
 libtorch/Dockerfile                          | 4 ++--
 libtorch/build_all_docker.sh                 | 2 +-
 manywheel/build_all_docker.sh                | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/build-libtorch-images.yml b/.github/workflows/build-libtorch-images.yml
index 00d040850..d32b6e4b0 100644
--- a/.github/workflows/build-libtorch-images.yml
+++ b/.github/workflows/build-libtorch-images.yml
@@ -47,7 +47,7 @@ jobs:
     runs-on: ubuntu-18.04
     strategy:
       matrix:
-        rocm_version: ["5.3", "5.4.1"]
+        rocm_version: ["5.3", "5.4.2"]
     env:
       GPU_ARCH_TYPE: rocm
       GPU_ARCH_VERSION: ${{ matrix.rocm_version }}
diff --git a/.github/workflows/build-manywheel-images.yml b/.github/workflows/build-manywheel-images.yml
index 254f49fc1..bbd221989 100644
--- a/.github/workflows/build-manywheel-images.yml
+++ b/.github/workflows/build-manywheel-images.yml
@@ -49,7 +49,7 @@ jobs:
     runs-on: ubuntu-18.04
     strategy:
       matrix:
-        rocm_version: ["5.3", "5.4.1"]
+        rocm_version: ["5.3", "5.4.2"]
     env:
       GPU_ARCH_TYPE: rocm
       GPU_ARCH_VERSION: ${{ matrix.rocm_version }}
diff --git a/libtorch/Dockerfile b/libtorch/Dockerfile
index 98d362752..38f3da9d8 100644
--- a/libtorch/Dockerfile
+++ b/libtorch/Dockerfile
@@ -74,8 +74,8 @@ RUN ROCM_VERSION=5.3 bash ./install_rocm.sh && rm install_rocm.sh
 RUN bash ./install_rocm_drm.sh && rm install_rocm_drm.sh
 RUN bash ./install_rocm_magma.sh && rm install_rocm_magma.sh
 
-FROM rocm as rocm5.4.1
-RUN ROCM_VERSION=5.4.1 bash ./install_rocm.sh && rm install_rocm.sh
+FROM rocm as rocm5.4.2
+RUN ROCM_VERSION=5.4.2 bash ./install_rocm.sh && rm install_rocm.sh
 RUN bash ./install_rocm_drm.sh && rm install_rocm_drm.sh
 RUN bash ./install_rocm_magma.sh && rm install_rocm_magma.sh
 
diff --git a/libtorch/build_all_docker.sh b/libtorch/build_all_docker.sh
index 5b41f80ed..8d25da9bc 100755
--- a/libtorch/build_all_docker.sh
+++ b/libtorch/build_all_docker.sh
@@ -8,6 +8,6 @@ for cuda_version in 11.8 11.7 11.6; do
     GPU_ARCH_TYPE=cuda GPU_ARCH_VERSION="${cuda_version}" "${TOPDIR}/libtorch/build_docker.sh"
 done
 
-for rocm_version in 5.3 5.4.1; do
+for rocm_version in 5.3 5.4.2; do
     GPU_ARCH_TYPE=rocm GPU_ARCH_VERSION="${rocm_version}" "${TOPDIR}/libtorch/build_docker.sh"
 done
diff --git a/manywheel/build_all_docker.sh b/manywheel/build_all_docker.sh
index 95e7ae716..395f71be3 100644
--- a/manywheel/build_all_docker.sh
+++ b/manywheel/build_all_docker.sh
@@ -14,7 +14,7 @@ for cuda_version in 11.7 11.6; do
     MANYLINUX_VERSION=2014 GPU_ARCH_TYPE=cuda GPU_ARCH_VERSION="${cuda_version}" "${TOPDIR}/manywheel/build_docker.sh"
 done
 
-for rocm_version in 5.3 5.4.1; do
+for rocm_version in 5.3 5.4.2; do
     GPU_ARCH_TYPE=rocm GPU_ARCH_VERSION="${rocm_version}" "${TOPDIR}/manywheel/build_docker.sh"
     MANYLINUX_VERSION=2014 GPU_ARCH_TYPE=rocm GPU_ARCH_VERSION="${rocm_version}" "${TOPDIR}/manywheel/build_docker.sh"
 done

From 9e377be80141146855478b869d5793712390c21d Mon Sep 17 00:00:00 2001
From: blorange-amd <bo.li2@amd.com>
Date: Tue, 31 Jan 2023 22:00:22 -0600
Subject: [PATCH 5/6] Fixed syntax error

---
 common/install_miopen.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/install_miopen.sh b/common/install_miopen.sh
index 5fbd8911c..a5166c097 100644
--- a/common/install_miopen.sh
+++ b/common/install_miopen.sh
@@ -63,7 +63,7 @@ MIOPEN_CMAKE_COMMON_FLAGS="
 if [[ $ROCM_INT -ge 50400 ]] && [[ $ROCM_INT -lt 50500 ]]; then
     MIOPEN_CMAKE_DB_FLAGS="-DMIOPEN_EMBED_DB=gfx900_56;gfx906_60;gfx90878;gfx90a6e;gfx1030_36 -DMIOPEN_USE_MLIR=Off"
     MIOPEN_BRANCH="release/rocm-rel-5.4-staging"
-else if [[ $ROCM_INT -ge 50300 ]] && [[ $ROCM_INT -lt 50400 ]]; then
+elif [[ $ROCM_INT -ge 50300 ]] && [[ $ROCM_INT -lt 50400 ]]; then
     MIOPEN_CMAKE_DB_FLAGS="-DMIOPEN_EMBED_DB=gfx900_56;gfx906_60;gfx90878;gfx90a6e;gfx1030_36 -DMIOPEN_USE_MLIR=Off"
     MIOPEN_BRANCH="release/rocm-rel-5.3-staging"
 elif [[ $ROCM_INT -ge 50200 ]] && [[ $ROCM_INT -lt 50300 ]]; then

From 80cd7104228e20b6ffd7282656a77de2cfd3236f Mon Sep 17 00:00:00 2001
From: blorange-amd <bo.li2@amd.com>
Date: Tue, 7 Feb 2023 11:53:55 -0600
Subject: [PATCH 6/6] Perform build on image with magma and miopen preinstalled

---
 manywheel/Dockerfile      | 23 ++++++++++++-----------
 manywheel/build_docker.sh |  2 +-
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/manywheel/Dockerfile b/manywheel/Dockerfile
index 26aa69bf4..7dc20257b 100644
--- a/manywheel/Dockerfile
+++ b/manywheel/Dockerfile
@@ -160,14 +160,15 @@ ADD ./common/install_rocm.sh install_rocm.sh
 RUN ROCM_VERSION=${ROCM_VERSION} bash ./install_rocm.sh && rm install_rocm.sh
 ADD ./common/install_rocm_drm.sh install_rocm_drm.sh
 RUN bash ./install_rocm_drm.sh && rm install_rocm_drm.sh
-ADD ./common/install_rocm_magma.sh install_rocm_magma.sh
-RUN bash ./install_rocm_magma.sh && rm install_rocm_magma.sh
-# cmake is already installed inside the rocm base image, but both 2 and 3 exist
-# cmake3 is needed for the later MIOpen custom build, so that step is last.
-RUN rpm -e cmake && \
-    pip3 install cmake==3.18.4 && \
-    ln -sf /usr/local/bin/cmake /usr/bin/cmake && \
-    ln -sf /usr/local/bin/cmake /usr/bin/cmake3
-
-ADD ./common/install_miopen.sh install_miopen.sh
-RUN bash ./install_miopen.sh ${ROCM_VERSION} && rm install_miopen.sh
+### The following is now performed beforehand in a new GPU_IMAGE with magma and miopen preinstalled
+#ADD ./common/install_rocm_magma.sh install_rocm_magma.sh
+#RUN bash ./install_rocm_magma.sh && rm install_rocm_magma.sh
+## cmake is already installed inside the rocm base image, but both 2 and 3 exist
+## cmake3 is needed for the later MIOpen custom build, so that step is last.
+#RUN rpm -e cmake && \
+#    pip3 install cmake==3.18.4 && \
+#    ln -sf /usr/local/bin/cmake /usr/bin/cmake && \
+#    ln -sf /usr/local/bin/cmake /usr/bin/cmake3
+#
+#ADD ./common/install_miopen.sh install_miopen.sh
+#RUN bash ./install_miopen.sh ${ROCM_VERSION} && rm install_miopen.sh
diff --git a/manywheel/build_docker.sh b/manywheel/build_docker.sh
index 1b8b04e70..87b27af04 100755
--- a/manywheel/build_docker.sh
+++ b/manywheel/build_docker.sh
@@ -44,7 +44,7 @@ case ${GPU_ARCH_TYPE} in
         TARGET=rocm_final
         DOCKER_TAG=rocm${GPU_ARCH_VERSION}
         LEGACY_DOCKER_IMAGE=${DOCKER_REGISTRY}/pytorch/manylinux-rocm:${GPU_ARCH_VERSION}
-        GPU_IMAGE=rocm/dev-centos-7:${GPU_ARCH_VERSION}
+        GPU_IMAGE=rocm/dev-centos-7:${GPU_ARCH_VERSION}-magma-miopen-staging
         PYTORCH_ROCM_ARCH="gfx900;gfx906;gfx908"
         ROCM_REGEX="([0-9]+)\.([0-9]+)[\.]?([0-9]*)"
         if [[ $GPU_ARCH_VERSION =~ $ROCM_REGEX ]]; then