diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index d1357cd36..c077c8890 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -100,6 +100,12 @@ jobs: platforms: linux/amd64 runner: [self-hosted, linux/amd64, rocm] build_args: "NUM_MAKE_JOBS=2" + - name: rocm7.2 + dockerfile: rocm7.2.x + tags: superbench/main:rocm7.2 + platforms: linux/amd64 + runner: [self-hosted, linux/amd64, rocm] + build_args: "NUM_MAKE_JOBS=8" steps: - name: Checkout uses: actions/checkout@0717577d45739eb3c851188b29f50ed6c0b2194e # v2.8.0 diff --git a/dockerfile/etc/hipblaslt-bench-standalone.cmake b/dockerfile/etc/hipblaslt-bench-standalone.cmake new file mode 100644 index 000000000..013b0e97f --- /dev/null +++ b/dockerfile/etc/hipblaslt-bench-standalone.cmake @@ -0,0 +1,129 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +# Standalone CMake for building hipblaslt-bench against system-installed +# hipBLASLt, bypassing the upstream build system. +# +# Used by dockerfile/rocm7.2.x.dockerfile because the upstream 7.2 source +# tree pulls in AMD-internal "origami" headers and a new tensilelite-host +# C++ library that conflict with the goal of building only the bench tool. +# +# Place this file at the root of an upstream hipBLASLt source tree as the +# top-level CMakeLists.txt and configure it as a normal CMake project, e.g.: +# +# cp /path/to/this/file /path/to/hipBLASLt/CMakeLists.txt +# cmake -S /path/to/hipBLASLt -B /path/to/hipBLASLt/build -DCMAKE_HIP_ARCHITECTURES="gfx942;gfx950" +# cmake --build /path/to/hipBLASLt/build --target hipblaslt-bench + +cmake_minimum_required(VERSION 3.21) +project(hipblaslt-bench-standalone LANGUAGES CXX HIP) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_HIP_STANDARD 17) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +if(NOT DEFINED ROCM_PATH) + if(DEFINED ENV{ROCM_PATH}) + set(ROCM_PATH "$ENV{ROCM_PATH}") + else() + set(ROCM_PATH "/opt/rocm") + endif() +endif() + +# The directory containing this build script is the hipBLASLt source root. +set(HIPBLASLT_SRC "${CMAKE_CURRENT_SOURCE_DIR}") + +# --- Dependencies (all from system / preinstalled) --- +find_package(hip REQUIRED) +find_package(hipblaslt CONFIG REQUIRED) +find_package(LAPACK REQUIRED) # also brings BLAS via implicit find_package(BLAS) +find_package(OpenMP REQUIRED) +find_package(rocm_smi) # optional + +# Locate cblas explicitly (not part of LAPACK's standard targets). +# cblas_interface.cpp uses cblas_sgemm/dgemm so we need the C BLAS library. +find_library(CBLAS_LIBRARY NAMES cblas PATHS /usr/local/lib /usr/lib REQUIRED) +message(STATUS "Found CBLAS: ${CBLAS_LIBRARY}") + +# --- The bench static helper library --- +# Mirrors the source list of upstream clients/common/src/CMakeLists.txt with +# rocRoller (mxDataGen.cpp) and BLIS (blis_interface.cpp) disabled. +set(HIPBLASLT_CLIENTS_COMMON_SOURCES + "${HIPBLASLT_SRC}/clients/common/src/singletons.cpp" + "${HIPBLASLT_SRC}/clients/common/src/utility.cpp" + "${HIPBLASLT_SRC}/clients/common/src/efficiency_monitor.cpp" + "${HIPBLASLT_SRC}/clients/common/src/cblas_interface.cpp" + "${HIPBLASLT_SRC}/clients/common/src/argument_model.cpp" + "${HIPBLASLT_SRC}/clients/common/src/hipblaslt_parse_data.cpp" + "${HIPBLASLT_SRC}/clients/common/src/hipblaslt_arguments.cpp" + "${HIPBLASLT_SRC}/clients/common/src/hipblaslt_random.cpp" + "${HIPBLASLT_SRC}/clients/common/src/hipblaslt_init_device.cpp" +) +add_library(hipblaslt-clients-common STATIC ${HIPBLASLT_CLIENTS_COMMON_SOURCES}) + +# These .cpp files are HIP code (use __device__/__host__, hip_runtime APIs, +# half/bfloat16 types). Compiling them as plain CXX with gcc fails. Force HIP. +set_source_files_properties(${HIPBLASLT_CLIENTS_COMMON_SOURCES} PROPERTIES LANGUAGE HIP) + +target_include_directories(hipblaslt-clients-common + PUBLIC + "${HIPBLASLT_SRC}/clients/common/include" + "${HIPBLASLT_SRC}/clients/bench/include" + # Source's library/include comes BEFORE system include so we get + # hipblaslt_xfloat32.h (not shipped in the system install). + "${HIPBLASLT_SRC}/library/include" + # Internal headers used by clients (rocblaslt/rocblaslt-types.h etc.) + "${HIPBLASLT_SRC}/library/src/amd_detail/include" + "${HIPBLASLT_SRC}/library/src/amd_detail/rocblaslt/include" + "${HIPBLASLT_SRC}/library/src/amd_detail/rocblaslt/src/include" + # tensilelite headers used by clients (e.g. client/include/Utility.hpp). + "${HIPBLASLT_SRC}/tensilelite/include" + "${HIPBLASLT_SRC}/tensilelite" +) + +target_compile_definitions(hipblaslt-clients-common + PUBLIC + # Critical: in 7.2 the upstream build sets ROCM_USE_FLOAT16 only + # via the in-tree hipblaslt target's INTERFACE_COMPILE_DEFINITIONS. + # The system find_package(hipblaslt) does not propagate it. Without + # this, hipblasLtHalf is the struct version with no operator float, + # which breaks hipblaslt_ostream.hpp. + ROCM_USE_FLOAT16 + __HIP_PLATFORM_AMD__ + HIPBLASLT_BENCH +) + +target_link_libraries(hipblaslt-clients-common + PUBLIC + hip::host + hip::device + # Order matters: cblas -> lapack -> blas -> gfortran (lapack needs blas + # which needs Fortran runtime). + ${CBLAS_LIBRARY} + ${LAPACK_LIBRARIES} + ${BLAS_LIBRARIES} + gfortran + OpenMP::OpenMP_CXX +) + +if(rocm_smi_FOUND) + target_link_libraries(hipblaslt-clients-common PRIVATE rocm_smi64) +endif() + +# Link against the system hipblaslt .so directly via library name to avoid +# inheriting INTERFACE_COMPILE_DEFINITIONS (HIPBLASLT_USE_ROCROLLER) from +# the imported roc::hipblaslt target. We only need linkage, not propagated +# defines. +target_link_directories(hipblaslt-clients-common PUBLIC "${ROCM_PATH}/lib") +target_link_libraries(hipblaslt-clients-common PUBLIC hipblaslt) + +# --- The bench executable --- +add_executable(hipblaslt-bench + "${HIPBLASLT_SRC}/clients/bench/src/client.cpp" +) +set_source_files_properties( + "${HIPBLASLT_SRC}/clients/bench/src/client.cpp" + PROPERTIES LANGUAGE HIP +) +target_link_libraries(hipblaslt-bench PRIVATE hipblaslt-clients-common) diff --git a/dockerfile/rocm7.2.x.dockerfile b/dockerfile/rocm7.2.x.dockerfile new file mode 100644 index 000000000..fc50ed01d --- /dev/null +++ b/dockerfile/rocm7.2.x.dockerfile @@ -0,0 +1,293 @@ +ARG BASE_IMAGE=rocm/pytorch:rocm7.2.4_ubuntu24.04_py3.12_pytorch_release_2.9.1 + +FROM ${BASE_IMAGE} + +# OS: +# - Ubuntu: 24.04 +# - Docker Client: 29.6.2 (client only) +# ROCm: +# - ROCm: 7.2 +# Lib: +# - torch: 2.9.1 +# - rccl: rocm-7.2.4 +# - hipblaslt: rocm-7.2.4 (hipblaslt-bench only, against system hipBLASLt) +# - rocblas: rocm-7.2.4 +# - transformer_engine: v2.10_rocm +# - openmpi: 4.1.x +# Intel: +# - mlc: v3.13 +# Network: +# - OFED: 25.10-3.1.8 user-space (via NVIDIA DOCA-Host 3.2.3, matches host) + +LABEL maintainer="SuperBench" + +# Target GPU architectures for ROCm builds (space-separated). Without an explicit +# target, hipcc defaults to gfx906 when no GPU is present at build time, producing +# kernels that run incorrectly on MI300X/MI355X. The default targets MI300X (gfx942) +# and MI355X (gfx950); other architectures can be selected with, e.g., +# --build-arg AMDGPU_TARGETS="gfx90a gfx942". +ARG AMDGPU_TARGETS="gfx942 gfx950" +ENV AMDGPU_TARGETS="${AMDGPU_TARGETS}" + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && \ + apt-get -q install -y --no-install-recommends \ + autoconf \ + automake \ + bc \ + build-essential \ + curl \ + dmidecode \ + flex \ + gfortran \ + git \ + hipify-clang \ + iproute2 \ + jq \ + libaio-dev \ + libboost-program-options-dev \ + libcap2 \ + libcurl4-openssl-dev \ + libnuma-dev \ + libpci-dev \ + libssl-dev \ + libtinfo6 \ + libtool \ + lshw \ + net-tools \ + numactl \ + openssh-client \ + openssh-server \ + pciutils \ + python3-mpi4py \ + rsync \ + sudo \ + util-linux \ + vim \ + wget \ + && \ + apt-get clean && \ + rm -rf /tmp/* + +ARG NUM_MAKE_JOBS=64 + +# Check if CMake is installed and its version +RUN cmake_version=$(cmake --version 2>/dev/null | awk 'NR == 1 { print $3 }') && \ + cmake_version=${cmake_version:-0.0.0} && \ + required_version="3.25.3" && \ + if [ "$(printf "%s\n" "$required_version" "$cmake_version" | sort -V | head -n 1)" != "$required_version" ]; then \ + echo "existing cmake version is ${cmake_version}" && \ + cd /tmp && \ + wget -q https://github.com/Kitware/CMake/releases/download/v${required_version}/cmake-${required_version}.tar.gz && \ + tar xzf cmake-${required_version}.tar.gz && \ + cd cmake-${required_version} && \ + ./bootstrap --prefix=/usr --no-system-curl --parallel=16 && \ + make -j ${NUM_MAKE_JOBS} && \ + make install && \ + rm -rf /tmp/cmake-${required_version}* ; \ + else \ + echo "CMake version ${cmake_version} is greater than or equal to ${required_version}"; \ + fi + +# Install the Docker CLI client only. SuperBench uses only the `docker` client (docker pull/run/rmi) +# against an external/host daemon; the bundled dockerd/containerd/runc/shims are never used in-container, +# so we extract just docker/docker to shrink the image and cut the CVE surface. Pinned to the latest static release. +ENV DOCKER_VERSION=29.6.2 +RUN cd /tmp && \ + wget -q https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz -O docker.tgz && \ + tar --extract --file docker.tgz --strip-components 1 --directory /usr/local/bin/ docker/docker && \ + rm docker.tgz + +# Update system config +RUN mkdir -p /root/.ssh && \ + touch /root/.ssh/authorized_keys && \ + mkdir -p /var/run/sshd && \ + sed -i "s/[# ]*PermitRootLogin prohibit-password/PermitRootLogin yes/" /etc/ssh/sshd_config && \ + sed -i "s/[# ]*PermitUserEnvironment no/PermitUserEnvironment yes/" /etc/ssh/sshd_config && \ + sed -i "s/[# ]*Port.*/Port 22/" /etc/ssh/sshd_config && \ + echo "* soft nofile 1048576\n* hard nofile 1048576" >> /etc/security/limits.conf && \ + echo "root soft nofile 1048576\nroot hard nofile 1048576" >> /etc/security/limits.conf + + +# Set Ubuntu version +ENV UBUNTU_VERSION=24.04 + +# Install OFED (user-space only) from the NVIDIA DOCA-Host repo to match the host stack. +ENV DOCA_VERSION=3.2.3 +# Check if ofed_info is present and has a version +RUN if ! command -v ofed_info >/dev/null 2>&1; then \ + echo "OFED not found. Installing DOCA-OFED user-space ${DOCA_VERSION}..."; \ + DOCA_REPO="https://linux.mellanox.com/public/repo/doca/${DOCA_VERSION}/ubuntu${UBUNTU_VERSION}/x86_64" && \ + curl -fsSL "${DOCA_REPO}/doca_keyring.gpg" -o /usr/share/keyrings/doca_keyring.gpg && \ + echo "deb [signed-by=/usr/share/keyrings/doca_keyring.gpg] ${DOCA_REPO}/ ./" > /etc/apt/sources.list.d/doca.list && \ + apt-get update && \ + apt-get install -y --no-install-recommends doca-ofed-userspace=${DOCA_VERSION}-019000 && \ + apt-get clean ; \ + fi + +ENV ROCM_PATH=/opt/rocm + +# Install OpenMPI +ENV OPENMPI_VERSION=4.1.x +ENV MPI_HOME=/usr/local/mpi +RUN cd /tmp && \ + git clone --recursive https://github.com/open-mpi/ompi.git -b v${OPENMPI_VERSION} && \ + cd ompi && \ + ./autogen.pl && \ + mkdir build && \ + cd build && \ + ../configure --prefix=/usr/local/mpi --enable-orterun-prefix-by-default --enable-mpirun-prefix-by-default --enable-prte-prefix-by-default --with-rocm=/opt/rocm && \ + make -j ${NUM_MAKE_JOBS} && \ + make -j ${NUM_MAKE_JOBS} install && \ + ldconfig && \ + cd / && \ + rm -rf /tmp/ompi + +# Install Intel MLC +RUN cd /tmp && \ + wget -q https://downloadmirror.intel.com/926327/mlc_v3.13.tgz -O mlc.tgz && \ + echo "a8537e8ff3fad626d75a383fabc224ccc4cc98a0111c9989f7fb26b639f12019 mlc.tgz" | sha256sum -c - && \ + tar xzf mlc.tgz Linux/mlc && \ + install -m 755 ./Linux/mlc /usr/local/bin/ && \ + rm -rf ./Linux mlc.tgz + +# Set CMAKE_POLICY_VERSION_MINIMUM globally so subprojects (RCCL's mscclpp, etc.) still configure +# with CMake 4.0+, which dropped compatibility for cmake_minimum_required < 3.5. +ENV CMAKE_POLICY_VERSION_MINIMUM=3.5 + +# Install RCCL. Pinned to the release tag matching the base image: /opt/rccl/build comes first on +# LD_LIBRARY_PATH, so this build replaces the base image's RCCL for rccl-tests and PyTorch. +RUN cd /opt/ && \ + git clone -b rocm-7.2.4 https://github.com/ROCmSoftwarePlatform/rccl.git && \ + cd rccl && \ + mkdir build && \ + cd build && \ + CXX=/opt/rocm/bin/hipcc cmake -DHIP_COMPILER=clang -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=1 \ + -DCMAKE_PREFIX_PATH="${ROCM_PATH}/hsa;${ROCM_PATH}/hip;${ROCM_PATH}/share/rocm/cmake/;${ROCM_PATH}" \ + .. && \ + make -j${NUM_MAKE_JOBS} + +# Install AMD SMI Python Library +RUN apt install amd-smi-lib -y && \ + cd /opt/rocm/share/amd_smi && \ + python3 -m pip install . + +# Do NOT LD_PRELOAD librccl.so - it causes segfaults on process exit due to HIP static +# object teardown order. The source-built RCCL is picked up through LD_LIBRARY_PATH instead. +# Do NOT put /usr/lib/x86_64-linux-gnu/ before /opt/rocm/lib - the OFED user-space stack can +# ship an older libhsa-runtime64.so there that conflicts with ROCm's version. +ENV PATH="/usr/local/mpi/bin:/opt/superbench/bin:/usr/local/bin/:/opt/rocm/hip/bin/:/opt/rocm/bin/:${PATH}" \ + LD_LIBRARY_PATH="/opt/rccl/build:/usr/local/mpi/lib:/opt/rocm/lib:/usr/local/lib/:${LD_LIBRARY_PATH}" \ + SB_HOME=/opt/superbench \ + SB_MICRO_PATH=/opt/superbench \ + ANSIBLE_DEPRECATION_WARNINGS=FALSE \ + ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections + +RUN echo PATH="$PATH" > /etc/environment && \ + echo LD_LIBRARY_PATH="$LD_LIBRARY_PATH" >> /etc/environment && \ + echo SB_MICRO_PATH="$SB_MICRO_PATH" >> /etc/environment + +RUN apt install rocm-cmake -y && \ + python3 -m pip install --upgrade pip wheel "setuptools>=69.0" + +WORKDIR ${SB_HOME} + +ADD third_party third_party +# RCCL is built from source above and referenced via RCCL_HOME. +# perftest_rocm6.patch changes are already upstream in the submodule version. +# rocm_hipblaslt: skipped - hipblaslt-bench is built separately below. +# rocm_megatron_lm: skipped (broken upstream - pretrain_deepseek.py missing in rocm_dev branch). +# apex_rocm: skipped - all apex imports in Megatron-DeepSpeed are guarded with try/except, +# superbench has zero direct apex usage, and PyTorch 2.9 has native fused optimizers/AMP. +# Refresh the apt index first: rocBLAS's install.sh --dependencies runs apt-get install, and the +# earlier apt-get update layer may come from a stale registry cache (404s on superseded packages). +RUN apt-get update && \ + make RCCL_HOME=/opt/rccl/build/ ROCBLAS_BRANCH=rocm-7.2.4 HIPBLASLT_BRANCH=rocm-7.2.4 ROCM_VER=rocm-5.5.0 -C third_party rocm -o cpu_hpl -o cpu_stream -o megatron_lm -o rocm_hipblaslt -o rocm_megatron_lm -o apex_rocm + +# Build hipblaslt-bench only (not the hipBLASLt library/Tensile kernels) and run it against the +# hipBLASLt shipped in the base image. This avoids the multi-hour, memory-hungry Tensile library +# generation that the ROCm 6.4 image needs. The upstream 7.2 build system pulls in AMD-internal +# "origami" headers and a new tensilelite-host C++ library even for client-only builds, so a +# minimal top-level CMakeLists.txt (dockerfile/etc/hipblaslt-bench-standalone.cmake) replaces it +# and compiles only the bench sources against the system hipBLASLt + LAPACK. +# The deps superbuild builds but does not install LAPACK; install it explicitly so the standalone +# build can find /usr/local/lib/{liblapack.a,libcblas.a,libblas.a}. The deps project's reserved +# "install" target is renamed so it also configures on CMake versions without CMP0037 OLD. +# The source is pinned to the release tag matching the base image, because the bench compiles +# against this checkout's (including internal) headers but links the installed libhipblaslt.so. +# CMAKE_HIP_ARCHITECTURES is only passed when AMDGPU_TARGETS is non-empty: a defined-but-empty +# value makes CMake fail at generate time, while leaving it undefined lets CMake auto-detect. +COPY dockerfile/etc/hipblaslt-bench-standalone.cmake /tmp/hipblaslt-bench-standalone.cmake +RUN cd third_party && \ + git clone --depth 1 -b rocm-7.2.4 https://github.com/ROCmSoftwarePlatform/hipBLASLt.git && \ + cp /tmp/hipblaslt-bench-standalone.cmake hipBLASLt/CMakeLists.txt && \ + cd hipBLASLt && \ + sed -i '/cmake_policy( SET CMP0037 OLD )/d; s/add_custom_target( install/add_custom_target( hipblaslt_deps_install/' deps/CMakeLists.txt && \ + mkdir -p deps/build && cd deps/build && \ + cmake .. && \ + cmake --build . -j${NUM_MAKE_JOBS} --target lapack && \ + cmake --build lapack/src/lapack-build -j${NUM_MAKE_JOBS} --target install && \ + cd ../.. && \ + hipblaslt_architectures=$(printf '%s' "${AMDGPU_TARGETS}" | tr -s '[:space:]' ';' | sed 's/^;//; s/;$//') && \ + set -- cmake \ + -DCMAKE_CXX_COMPILER="${ROCM_PATH}/llvm/bin/clang++" \ + -DCMAKE_HIP_COMPILER="${ROCM_PATH}/llvm/bin/clang++" && \ + if [ -n "${hipblaslt_architectures}" ]; then \ + set -- "$@" -DCMAKE_HIP_ARCHITECTURES="${hipblaslt_architectures}"; \ + fi && \ + set -- "$@" \ + -DCMAKE_PREFIX_PATH="${ROCM_PATH};/usr/local" \ + -DBLAS_LIBRARIES=/usr/local/lib/libblas.a \ + -DLAPACK_LIBRARIES=/usr/local/lib/liblapack.a \ + -DCMAKE_BUILD_TYPE=Release \ + .. && \ + mkdir -p build && cd build && \ + "$@" && \ + make -j${NUM_MAKE_JOBS} hipblaslt-bench && \ + cp -v hipblaslt-bench /opt/superbench/bin/ && \ + cd /opt/superbench/third_party && \ + rm -rf hipBLASLt /tmp/hipblaslt-bench-standalone.cmake +RUN cd third_party/Megatron/Megatron-DeepSpeed && \ + git apply ../megatron_deepspeed_rocm6.patch + +# Install TransformerEngine - pin to v2.10_rocm, a release line validated on ROCm 7.2 (it bundles +# AOTriton 0.11.2b GPU images for gfx942 and gfx950). CK fused attention stays disabled, as in the +# ROCm 6.4 image. AOTriton is enabled only when every requested target is gfx942 or gfx950, +# and disabled when any other architecture is requested. +# onnxscript/onnx are imported unconditionally by transformer_engine.pytorch; install them with +# pip up front rather than relying on `setup.py install` to resolve them. They are pinned to the +# versions validated with TE v2.10_rocm and torch 2.9.1 so rebuilds don't pull newer releases +# whose protobuf/numpy requirements conflict with the base image. +RUN transformer_engine_architectures=$(printf '%s' "${AMDGPU_TARGETS}" | tr -s '[:space:]' ';' | sed 's/^;//; s/;$//') && \ + nvte_fused_attn_aotriton=0 && \ + if [ -n "${transformer_engine_architectures}" ]; then \ + nvte_fused_attn_aotriton=1; \ + for arch in $(printf '%s' "${transformer_engine_architectures}" | tr ';' ' '); do \ + case "${arch}" in \ + gfx942|gfx950) ;; \ + *) nvte_fused_attn_aotriton=0 ;; \ + esac; \ + done; \ + fi && \ + python3 -m pip install onnxscript==0.7.2 onnx==1.23.0 && \ + git clone --recursive -b v2.10_rocm https://github.com/ROCm/TransformerEngine.git && \ + cd TransformerEngine && \ + MAX_JOBS="${NUM_MAKE_JOBS}" \ + NVTE_FRAMEWORK=pytorch \ + NVTE_FUSED_ATTN_CK=0 \ + NVTE_FUSED_ATTN_AOTRITON="${nvte_fused_attn_aotriton}" \ + NVTE_ROCM_ARCH="${transformer_engine_architectures}" \ + python3 setup.py install +RUN python3 -c "import transformer_engine.pytorch; print('TE installed successfully')" + +ADD . . +ENV USE_HIP_DATATYPE=1 +ENV USE_HIPBLAS_COMPUTETYPE=1 +RUN python3 -m pip install .[amdworker] && \ + CXX=/opt/rocm/bin/hipcc make cppbuild && \ + make postinstall && \ + rm -rf .git + +# Fix stale hypothesis plugin from base image (imports removed pkg_resources) +# and add test dependencies missing from the base image. +RUN python3 -m pip install --upgrade hypothesis setuptools pytest-timeout vcrpy diff --git a/tests/test_rocm72_dockerfile.py b/tests/test_rocm72_dockerfile.py new file mode 100644 index 000000000..0e910ef34 --- /dev/null +++ b/tests/test_rocm72_dockerfile.py @@ -0,0 +1,137 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +"""Tests for ROCm 7.2 Dockerfile build configuration.""" + +import os +import subprocess +import unittest +from pathlib import Path + + +class Rocm72DockerfileTestCase(unittest.TestCase): + """Test ROCm 7.2 architecture routing without building an image.""" + @classmethod + def setUpClass(cls): + """Load the Dockerfile and extract its architecture-routing shell blocks.""" + repo_root = Path(__file__).resolve().parents[1] + cls.dockerfile = (repo_root / 'dockerfile' / 'rocm7.2.x.dockerfile').read_text(encoding='utf-8') + cls.standalone_cmake_path = repo_root / 'dockerfile' / 'etc' / 'hipblaslt-bench-standalone.cmake' + cls.hipblaslt_script = cls._extract_script( + 'hipblaslt_architectures=$(printf', + ' mkdir -p build && cd build', + 'printf \'%s\\n\' "$@"\n', + ) + cls.transformer_engine_script = cls._extract_script( + 'transformer_engine_architectures=$(printf', + ' python3 -m pip install onnxscript==0.7.2 onnx==1.23.0', + 'printf \'%s\\n\' "$transformer_engine_architectures" "$nvte_fused_attn_aotriton"\n', + ) + + @classmethod + def _extract_script(cls, start_marker, end_marker, result_command): + """Extract an executable shell block between two Dockerfile markers.""" + start = cls.dockerfile.index(start_marker) + end = cls.dockerfile.index(end_marker, start) + return cls.dockerfile[start:end] + result_command + + def _run_script(self, script, targets): + """Run an extracted routing block for the requested targets.""" + env = os.environ.copy() + env.update({'AMDGPU_TARGETS': targets, 'NUM_MAKE_JOBS': '64', 'ROCM_PATH': '/opt/rocm'}) + result = subprocess.run( + ['/bin/sh', '-c', script], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + env=env, + ) + return result.stdout.splitlines() + + def _expected_hipblaslt_command(self, architectures): + """Return the expected standalone hipblaslt-bench CMake configure command.""" + architecture_flags = [f'-DCMAKE_HIP_ARCHITECTURES={architectures}'] if architectures else [] + return [ + 'cmake', + '-DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++', + '-DCMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++', + *architecture_flags, + '-DCMAKE_PREFIX_PATH=/opt/rocm;/usr/local', + '-DBLAS_LIBRARIES=/usr/local/lib/libblas.a', + '-DLAPACK_LIBRARIES=/usr/local/lib/liblapack.a', + '-DCMAKE_BUILD_TYPE=Release', + '..', + ] + + def test_architecture_routing(self): + """Test default, single, lower, mixed, whitespace-normalized, and empty target routing. + + An empty target list must omit -DCMAKE_HIP_ARCHITECTURES entirely, because CMake rejects a + defined-but-empty value and only auto-detects when the variable is undefined. + """ + configurations = ( + ('gfx942 gfx950', 'gfx942;gfx950', ['gfx942;gfx950', '1']), + ('gfx942', 'gfx942', ['gfx942', '1']), + ('gfx950', 'gfx950', ['gfx950', '1']), + ('gfx90a', 'gfx90a', ['gfx90a', '0']), + ('gfx90a gfx942 gfx950', 'gfx90a;gfx942;gfx950', ['gfx90a;gfx942;gfx950', '0']), + (' gfx942\t gfx950 ', 'gfx942;gfx950', ['gfx942;gfx950', '1']), + ('', '', ['', '0']), + ) + + for targets, expected_architectures, expected_transformer_engine in configurations: + with self.subTest(targets=targets): + self.assertEqual( + self._expected_hipblaslt_command(expected_architectures), + self._run_script(self.hipblaslt_script, targets), + ) + self.assertEqual( + expected_transformer_engine, + self._run_script(self.transformer_engine_script, targets), + ) + + def test_transformer_engine_receives_routed_configuration(self): + """Test that TransformerEngine receives the computed architecture settings.""" + self.assertIn('ARG AMDGPU_TARGETS="gfx942 gfx950"', self.dockerfile) + self.assertIn('NVTE_FUSED_ATTN_AOTRITON="${nvte_fused_attn_aotriton}"', self.dockerfile) + self.assertIn('NVTE_ROCM_ARCH="${transformer_engine_architectures}"', self.dockerfile) + + def test_standalone_hipblaslt_cmake_is_used(self): + """Test that the standalone hipblaslt-bench CMake script is shipped and copied into the build.""" + self.assertTrue(self.standalone_cmake_path.is_file()) + self.assertIn( + 'COPY dockerfile/etc/hipblaslt-bench-standalone.cmake /tmp/hipblaslt-bench-standalone.cmake', + self.dockerfile, + ) + self.assertIn('cp /tmp/hipblaslt-bench-standalone.cmake hipBLASLt/CMakeLists.txt', self.dockerfile) + + def test_rocm_sources_pinned_to_base_image_release(self): + """Test that ROCm library sources are pinned to the tag matching the base image.""" + self.assertIn('rocm/pytorch:rocm7.2.4_', self.dockerfile) + self.assertIn('git clone -b rocm-7.2.4 https://github.com/ROCmSoftwarePlatform/rccl.git', self.dockerfile) + self.assertIn( + 'git clone --depth 1 -b rocm-7.2.4 https://github.com/ROCmSoftwarePlatform/hipBLASLt.git', + self.dockerfile, + ) + self.assertIn('ROCBLAS_BRANCH=rocm-7.2.4', self.dockerfile) + self.assertNotIn('release/rocm-rel-7.2', self.dockerfile) + + def test_mlc_checksum_verification(self): + """Test MLC download is checksum-verified and installed as an executable.""" + self.assertIn('wget -q https://downloadmirror.intel.com/926327/mlc_v3.13.tgz -O mlc.tgz', self.dockerfile) + self.assertIn( + 'echo "a8537e8ff3fad626d75a383fabc224ccc4cc98a0111c9989f7fb26b639f12019 mlc.tgz" | sha256sum -c -', + self.dockerfile, + ) + self.assertIn('install -m 755 ./Linux/mlc /usr/local/bin/', self.dockerfile) + + def test_rocm_build_refreshes_package_index(self): + """Test APT metadata is refreshed before installing ROCm dependencies.""" + build_command = 'RUN apt-get update && \\\n make RCCL_HOME=/opt/rccl/build/ ' + self.assertIn(build_command, self.dockerfile) + self.assertEqual(self.dockerfile.count('make RCCL_HOME='), 1) + + +if __name__ == '__main__': + unittest.main() diff --git a/third_party/Makefile b/third_party/Makefile index 01516bb12..bb20379f7 100755 --- a/third_party/Makefile +++ b/third_party/Makefile @@ -201,9 +201,11 @@ rocm_hipblaslt: sb_micro_path # Build hipBusBandwidth. # HIP is released with rocm, like rocm-4.2.0 and so on. # The version we use is the released tag which is consistent with the rocm version in the environment or docker. - +# Inject include: newer clang (ROCm >= 7) rejects use of assert() without it. rocm_bandwidthTest: sb_micro_path git clone -b ${ROCM_VER} https://github.com/ROCm-Developer-Tools/HIP.git + grep -q '' ./HIP/samples/1_Utils/hipBusBandwidth/hipBusBandwidth.cpp || \ + sed -i '1i #include ' ./HIP/samples/1_Utils/hipBusBandwidth/hipBusBandwidth.cpp cd ./HIP/samples/1_Utils/hipBusBandwidth/ && mkdir -p build && cd build && cmake .. && make cp -v ./HIP/samples/1_Utils/hipBusBandwidth/build/hipBusBandwidth $(SB_MICRO_PATH)/bin/