Add test_amd_mi250 CI job including ROCm matmul tests. (#17293)

Progress on https://github.com/iree-org/iree/issues/17159
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index cc79e39..93616ee 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -390,6 +390,45 @@
                 ./build_tools/scripts/check_vulkan.sh
                 ./build_tools/cmake/ctest_all.sh ${BUILD_DIR}"
 
+  test_amd_mi250:
+    needs: [setup, build_all]
+    if: contains(fromJson(needs.setup.outputs.enabled-jobs), 'test_amd_mi250')
+    env:
+      BUILD_DIR: build-tests
+      INSTALL_DIR: ${{ needs.build_all.outputs.install-dir }}
+      INSTALL_DIR_ARCHIVE: ${{ needs.build_all.outputs.install-dir-archive }}
+      INSTALL_DIR_GCS_URL: ${{ needs.build_all.outputs.install-dir-gcs-url }}
+      IREE_CPU_DISABLE: 1
+      IREE_VULKAN_DISABLE: 1
+      IREE_CUDA_DISABLE: 1
+      IREE_HIP_DISABLE: 0
+      IREE_HIP_TEST_TARGET_CHIP: "gfx90a"
+    runs-on: nodai-amdgpu-mi250-x86-64
+    steps:
+      - name: "Checking out repository"
+        uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
+      - name: "Checking out runtime submodules"
+        run: ./build_tools/scripts/git/update_runtime_submodules.sh
+      - name: "Downloading install dir archive"
+        run: wget "${INSTALL_DIR_GCS_URL}" -O "${INSTALL_DIR_ARCHIVE}"
+      - name: "Extracting install directory"
+        run: tar -xf "${INSTALL_DIR_ARCHIVE}"
+      - name: "Building tests"
+        run: |
+          ./build_tools/pkgci/build_tests_using_package.sh ${INSTALL_DIR}
+      - name: "Running GPU tests"
+        env:
+          IREE_CTEST_LABEL_REGEX: ^requires-gpu|^driver=hip$
+          IREE_NVIDIA_SM80_TESTS_DISABLE: 1
+          IREE_MULTI_DEVICE_TESTS_DISABLE: 0
+          IREE_AMD_RDNA3_TESTS_DISABLE: 1
+          IREE_NVIDIA_GPU_TESTS_DISABLE: 0
+          IREE_CUDA_DISABLE: 1
+          IREE_CPU_DISABLE: 1
+          IREE_HIP_DISABLE: 0
+        run: |
+          ./build_tools/cmake/ctest_all.sh ${BUILD_DIR}
+
   ################################## Subsets ###################################
   # Jobs that build some subset of IREE
   ##############################################################################
@@ -1076,6 +1115,7 @@
       # Accelerators
       - test_nvidia_gpu
       - test_nvidia_a100
+      - test_amd_mi250
 
       # Subsets
       - build_test_runtime
diff --git a/build_tools/pkgci/build_tests_using_package.sh b/build_tools/pkgci/build_tests_using_package.sh
index cd5ad13..522c0c3 100755
--- a/build_tools/pkgci/build_tests_using_package.sh
+++ b/build_tools/pkgci/build_tests_using_package.sh
@@ -39,6 +39,7 @@
 export IREE_METAL_DISABLE="${IREE_METAL_DISABLE:-1}"
 export IREE_CUDA_DISABLE="${IREE_CUDA_DISABLE:-1}"
 export IREE_HIP_DISABLE="${IREE_HIP_DISABLE:-1}"
+export IREE_HIP_TEST_TARGET_CHIP="${IREE_HIP_TEST_TARGET_CHIP:-}"
 
 # Set cmake options based on disabled features.
 declare -a cmake_config_options=()
@@ -58,6 +59,9 @@
 if (( IREE_HIP_DISABLE == 1 )); then
   cmake_config_options+=("-DIREE_HAL_DRIVER_HIP=OFF")
 fi
+if [[ -n "${IREE_HIP_TEST_TARGET_CHIP}" ]]; then
+  cmake_config_options+=("-DIREE_HIP_TEST_TARGET_CHIP=${IREE_HIP_TEST_TARGET_CHIP}")
+fi
 
 ###############################################################################
 # Build the runtime and compile 'test deps'                                   #
diff --git a/runtime/src/iree/hal/drivers/hip/cts/CMakeLists.txt b/runtime/src/iree/hal/drivers/hip/cts/CMakeLists.txt
index e8cadc2..5d7c109 100644
--- a/runtime/src/iree/hal/drivers/hip/cts/CMakeLists.txt
+++ b/runtime/src/iree/hal/drivers/hip/cts/CMakeLists.txt
@@ -37,6 +37,7 @@
     "event"
   LABELS
     driver=hip
+    requires-gpu-amd
 )
 
 iree_hal_cts_test_suite(
@@ -59,6 +60,12 @@
   DEPS
     iree::hal::drivers::hip::registration
   EXCLUDED_TESTS
+  # These tests fail with:
+  #     UNAVAILABLE; missing hipDrvGraphAddMemcpyNode symbol;
+  #     cannot use graph-based command buffer
+  "command_buffer"
+  "command_buffer_dispatch"
+  "file"
     # HAL event is unimplemented for now.
     "event"
   LABELS
diff --git a/runtime/src/iree/hal/drivers/hip/registration/CMakeLists.txt b/runtime/src/iree/hal/drivers/hip/registration/CMakeLists.txt
index 318412e..cf51242 100644
--- a/runtime/src/iree/hal/drivers/hip/registration/CMakeLists.txt
+++ b/runtime/src/iree/hal/drivers/hip/registration/CMakeLists.txt
@@ -14,6 +14,7 @@
   DEPS
     iree::base
     iree::base::core_headers
+    iree::base::internal::flags
     iree::hal::drivers::hip
     iree::hal
   DEFINES
diff --git a/tests/e2e/matmul/BUILD.bazel b/tests/e2e/matmul/BUILD.bazel
index b6fe7b8..ef1948a 100644
--- a/tests/e2e/matmul/BUILD.bazel
+++ b/tests/e2e/matmul/BUILD.bazel
@@ -521,60 +521,6 @@
 ##
 ###########################################################################
 
-# Testing CDNA3 + matrix core path.
-iree_generated_e2e_runner_test(
-    name = "e2e_matmul_rocm_f16_large_cdna3_mfma",
-    compiler_flags = [
-        "--iree-rocm-target-chip=gfx942",
-    ],
-    generator = ":generate_e2e_matmul_tests",
-    generator_args = [
-        "--lhs_rhs_type=f16",
-        "--acc_type=f32",
-        "--shapes=gpu_large_aligned",
-        "--compilation_info=LLVMGPUVectorDistributeMFMA",
-    ],
-    tags = [
-        "noasan",
-        "nomsan",
-        "notsan",
-        "noubsan",
-        "requires-gpu-cdna3",
-    ],
-    target_backends_and_drivers = [
-        ("rocm", "hip"),
-    ],
-    test_runner = "//tools/testing/e2e:iree-e2e-matmul-test",
-    test_type = "matmul",
-)
-
-iree_generated_e2e_runner_test(
-    name = "e2e_matmul_rocm_f16_large_cdna3_mfma_tb",
-    compiler_flags = [
-        "--iree-rocm-target-chip=gfx942",
-    ],
-    generator = ":generate_e2e_matmul_tests",
-    generator_args = [
-        "--lhs_rhs_type=f16",
-        "--acc_type=f32",
-        "--transpose_rhs",
-        "--shapes=gpu_large_aligned",
-        "--compilation_info=LLVMGPUVectorDistributeMFMA",
-    ],
-    tags = [
-        "noasan",
-        "nomsan",
-        "notsan",
-        "noubsan",
-        "requires-gpu-cdna3",
-    ],
-    target_backends_and_drivers = [
-        ("rocm", "hip"),
-    ],
-    test_runner = "//tools/testing/e2e:iree-e2e-matmul-test",
-    test_type = "matmul",
-)
-
 # Testing RDNA3 + matrix core path.
 iree_generated_e2e_runner_test(
     name = "e2e_matmul_rocm_f16_large_rdna3_wmma",
diff --git a/tests/e2e/matmul/CMakeLists.txt b/tests/e2e/matmul/CMakeLists.txt
index cd4f225..f7a4fe9 100644
--- a/tests/e2e/matmul/CMakeLists.txt
+++ b/tests/e2e/matmul/CMakeLists.txt
@@ -1814,63 +1814,6 @@
 
 iree_generated_e2e_runner_test(
   NAME
-    e2e_matmul_rocm_f16_large_cdna3_mfma
-  TEST_TYPE
-    matmul
-  GENERATOR
-    "generate_e2e_matmul_tests.py"
-  GENERATOR_ARGS
-    "--lhs_rhs_type=f16"
-    "--acc_type=f32"
-    "--shapes=gpu_large_aligned"
-    "--compilation_info=LLVMGPUVectorDistributeMFMA"
-  TEST_RUNNER
-    iree_tools_testing_e2e_iree-e2e-matmul-test
-  TARGET_BACKENDS
-    "rocm"
-  DRIVERS
-    "hip"
-  COMPILER_FLAGS
-    "--iree-rocm-target-chip=gfx942"
-  LABELS
-    "noasan"
-    "nomsan"
-    "notsan"
-    "noubsan"
-    "requires-gpu-cdna3"
-)
-
-iree_generated_e2e_runner_test(
-  NAME
-    e2e_matmul_rocm_f16_large_cdna3_mfma_tb
-  TEST_TYPE
-    matmul
-  GENERATOR
-    "generate_e2e_matmul_tests.py"
-  GENERATOR_ARGS
-    "--lhs_rhs_type=f16"
-    "--acc_type=f32"
-    "--transpose_rhs"
-    "--shapes=gpu_large_aligned"
-    "--compilation_info=LLVMGPUVectorDistributeMFMA"
-  TEST_RUNNER
-    iree_tools_testing_e2e_iree-e2e-matmul-test
-  TARGET_BACKENDS
-    "rocm"
-  DRIVERS
-    "hip"
-  COMPILER_FLAGS
-    "--iree-rocm-target-chip=gfx942"
-  LABELS
-    "noasan"
-    "nomsan"
-    "notsan"
-    "noubsan"
-    "requires-gpu-cdna3"
-)
-
-iree_generated_e2e_runner_test(
-  NAME
     e2e_matmul_rocm_f16_large_rdna3_wmma
   TEST_TYPE
     matmul
@@ -2098,3 +2041,68 @@
 )
 
 ### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###
+
+if(IREE_HIP_TEST_TARGET_CHIP MATCHES "^gfx")
+
+unset(IREE_HIP_TEST_COMPILER_FLAGS)
+list(APPEND IREE_HIP_TEST_COMPILER_FLAGS
+  "--iree-rocm-target-chip=${IREE_HIP_TEST_TARGET_CHIP}"
+)
+
+iree_generated_e2e_runner_test(
+  NAME
+    e2e_matmul_rocm_f16_large_cdna3_mfma
+  TEST_TYPE
+    matmul
+  GENERATOR
+    "generate_e2e_matmul_tests.py"
+  GENERATOR_ARGS
+    "--lhs_rhs_type=f16"
+    "--acc_type=f32"
+    "--shapes=gpu_large_aligned"
+    "--compilation_info=LLVMGPUVectorDistributeMFMA"
+  TEST_RUNNER
+    iree_tools_testing_e2e_iree-e2e-matmul-test
+  TARGET_BACKENDS
+    "rocm"
+  DRIVERS
+    "hip"
+  COMPILER_FLAGS
+    ${IREE_HIP_TEST_COMPILER_FLAGS}
+  LABELS
+    "noasan"
+    "nomsan"
+    "notsan"
+    "noubsan"
+    "requires-gpu-cdna3"
+)
+
+iree_generated_e2e_runner_test(
+  NAME
+    e2e_matmul_rocm_f16_large_cdna3_mfma_tb
+  TEST_TYPE
+    matmul
+  GENERATOR
+    "generate_e2e_matmul_tests.py"
+  GENERATOR_ARGS
+    "--lhs_rhs_type=f16"
+    "--acc_type=f32"
+    "--transpose_rhs"
+    "--shapes=gpu_large_aligned"
+    "--compilation_info=LLVMGPUVectorDistributeMFMA"
+  TEST_RUNNER
+    iree_tools_testing_e2e_iree-e2e-matmul-test
+  TARGET_BACKENDS
+    "rocm"
+  DRIVERS
+    "hip"
+  COMPILER_FLAGS
+    ${IREE_HIP_TEST_COMPILER_FLAGS}
+  LABELS
+    "noasan"
+    "nomsan"
+    "notsan"
+    "noubsan"
+    "requires-gpu-cdna3"
+)
+endif(IREE_HIP_TEST_TARGET_CHIP MATCHES "^gfx")