diff --git a/CHANGELOG.md b/CHANGELOG.md index b8f6e00b721..66525c60007 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Full documentation for MIGraphX is available at ### Added * Added `ArrayFeatureExtractor` ONNX operator support (#4742). +* Added support for building against ROCm 7.13 and newer using TheRock (#4952) * Added YOLO26 object detection example notebook. * Added `auto_pad` attribute support for the ONNX `ConvTranspose` operator, supporting `SAME_UPPER`, `SAME_LOWER`, and `VALID` padding modes for static shapes (#4638). * Added a dedicated logger for MIGraphX. diff --git a/CMakeLists.txt b/CMakeLists.txt index 6074bc01395..607f1c85462 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,6 +195,7 @@ endif() rocm_enable_clang_tidy( CHECKS bugprone-* + -bugprone-std-namespace-modification cert-* clang-analyzer-* clang-diagnostic-* @@ -212,11 +213,16 @@ rocm_enable_clang_tidy( -bugprone-crtp-constructor-accessibility -bugprone-derived-method-shadowing-base-method -bugprone-easily-swappable-parameters + -bugprone-exception-escape + -bugprone-fold-init-type -bugprone-implicit-widening-of-multiplication-result -bugprone-macro-parentheses -bugprone-nondeterministic-pointer-iteration-order + -bugprone-random-generator-seed -bugprone-return-const-ref-from-parameter + -bugprone-signed-bitwise -bugprone-signed-char-misuse + -bugprone-std-exception-baseclass -bugprone-unchecked-optional-access -bugprone-unintended-char-ostream-output # Disable the aliased reserved identifiers @@ -271,8 +277,11 @@ rocm_enable_clang_tidy( -misc-const-correctness -misc-include-cleaner -misc-macro-parentheses + -misc-multiple-inheritance -misc-no-recursion -misc-override-with-different-visibility + -misc-use-internal-linkage + -modernize-avoid-c-style-cast -modernize-concat-nested-namespaces -modernize-pass-by-value -modernize-type-traits @@ -280,12 +289,18 @@ rocm_enable_clang_tidy( -modernize-use-nodiscard -modernize-use-override -modernize-use-scoped-lock + -modernize-use-string-view + -modernize-use-structured-binding -modernize-use-trailing-return-type -modernize-use-transparent-functors -performance-avoid-endl + -performance-faster-string-find + -performance-prefer-single-char-overloads -performance-type-promotion-in-math-fn -performance-enum-size + -performance-use-std-move -readability-braces-around-statements + -readability-inconsistent-ifelse-braces -readability-container-size-empty -readability-avoid-nested-conditional-operator -readability-convert-member-functions-to-static @@ -294,10 +309,13 @@ rocm_enable_clang_tidy( -readability-identifier-length -readability-math-missing-parentheses -readability-named-parameter + -readability-redundant-lambda-parameter-list -readability-redundant-member-init -readability-redundant-parentheses + -readability-redundant-qualified-alias -readability-redundant-string-init -readability-suspicious-call-argument + -readability-trailing-comma -readability-uppercase-literal-suffix -readability-use-concise-preprocessor-directives -*-avoid-c-arrays diff --git a/Dockerfile b/Dockerfile index 367f60b6e99..56ccd5afd93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,42 @@ -FROM ubuntu:22.04 +# MIGraphX build environment with TheRock (amdrocm-*) deb packages. +# +# Build args: +# ROCM_VERSION ROCm release version for versioned package names (e.g. 7.13) +# GPU_ARCH GPU architecture family (e.g. gfx120x, gfx94x) +# USE_WHL Set to a non-empty value to install ROCm from Python +# wheels (pip) instead of system packages +# INDEX_URL pip --index-url used when installing ROCm from wheels +# (only effective together with USE_WHL) +# +# Build: +# docker build --build-arg GPU_ARCH= \ +# --build-arg ROCM_VERSION= \ +# -t migraphx-therock . +# +# Run: +# docker run -it --device=/dev/kfd --device=/dev/dri --group-add video \ +# -v $(pwd):/code/AMDMIGraphX migraphx-therock +# +# Build MIGraphX inside the container: +# cd /code/AMDMIGraphX +# rbuild build -d depend -B build +# + +FROM ubuntu:24.04 ARG PREFIX=/usr/local +# ROCm release version (used in versioned package names, e.g. amdrocm-developer-tools7.13) +ARG ROCM_VERSION="7.14" +# GPU architecture family (e.g. gfx942, gfx120x); leave empty for arch-independent packages +ARG GPU_ARCH="" +# Install location for the prebuilt MIGraphX dependencies. +ARG PREFIX=/usr/local +# Install the MIGraphX build prerequisites (system packages + ROCm components). +# Set USE_WHL to any non-empty value to install ROCm from Python wheels instead +# of system packages (passes --whl to the prereqs script). +ARG USE_WHL="" +# pip index URL for the wheel-based ROCm install (only used when USE_WHL is set). +ARG INDEX_URL="https://repo.amd.com/rocm/whl-multi-arch/" # Support multiarch RUN dpkg --add-architecture i386 @@ -8,20 +44,14 @@ RUN dpkg --add-architecture i386 # Install rocm key RUN apt-get update && apt-get install -y software-properties-common gnupg2 --no-install-recommends curl && \ mkdir -p /etc/apt/keyrings && \ - curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor -o /etc/apt/keyrings/rocm.gpg + curl -fsSL https://repo.amd.com/rocm/packages/gpg/rocm.gpg | gpg --dearmor -o /etc/apt/keyrings/amdrocm.gpg # Add rocm repository -RUN sh -c 'echo deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/7.2.3/ jammy main > /etc/apt/sources.list.d/rocm.list' - -# From docs.amd.com for installing rocm. Needed to install properly -RUN sh -c "echo 'Package: *\nPin: release o=repo.radeon.com\nPin-priority: 600' > /etc/apt/preferences.d/rocm-pin-600" - -# rocgdb doesn't work on 22.04, workaround by installing the older python packages that are in 20.04 -RUN add-apt-repository -y ppa:deadsnakes/ppa +RUN sh -c 'echo deb [arch=amd64 signed-by=/etc/apt/keyrings/amdrocm.gpg] https://repo.amd.com/rocm/packages-multi-arch/ubuntu2404 stable main > /etc/apt/sources.list.d/rocm.list' # Add LLVM repository for Clang 17 (ROCm 7.x ships with Clang 20 which has ODR false positives in ASAN) RUN curl -sL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ - add-apt-repository -y "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" + add-apt-repository -y "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-17 main" # Install dependencies RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ @@ -44,84 +74,69 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ python3-full \ libpython3.8 \ wget \ - rocm-device-libs \ - hip-dev \ libnuma-dev \ - miopen-hip \ libomp-17-dev \ - rocblas \ - hipfft \ - hipsolver \ - rocthrust \ - rocrand \ - rocprofiler-sdk \ - hipsparse \ - rccl \ - rocm-smi-lib \ - rocminfo \ - roctracer-dev \ - hipcub \ - hipblas \ - hipify-clang \ - hiprand-dev \ - hipsparselt \ - hsa-amd-aqlprofile \ - half \ libssl-dev \ zlib1g-dev && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* - -# Install pytorch -RUN pip3 install https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2.3/torch-2.8.0%2Brocm7.2.3.lw.git2742f6d1-cp310-cp310-linux_x86_64.whl \ - https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2.3/torchvision-0.24.0%2Brocm7.2.3.gitb919bd0c-cp310-cp310-linux_x86_64.whl \ - https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2.3/triton-3.4.0%2Brocm7.2.3.git0cace8d2-cp310-cp310-linux_x86_64.whl - -# add this for roctracer dependencies -RUN pip3 install CppHeaderParser - -# Workaround broken rocm packages -RUN ln -s /opt/rocm-* /opt/rocm -RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf -RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf -RUN ldconfig - -# ATT library -RUN wget -O /opt/rocm/lib/librocprof-trace-decoder.so https://github.com/ROCm/rocprof-trace-decoder/raw/7e58204a955e5787b9b38087f3ad502f07ff78ef/releases/linux_glibc_2_28_x86_64/librocprof-trace-decoder.so - -# Workaround broken miopen cmake files -RUN sed -i 's,;/usr/lib/x86_64-linux-gnu/librt.so,,g' /opt/rocm/lib/cmake/miopen/miopen-targets.cmake - -# Workaround for distributions running cmake < 3.25 -RUN sed -i -e 's/^block/if(COMMAND block)\nblock/g' -e 's/^endblock/endblock\(\)\nendif/g' /opt/rocm/lib/cmake/hipblaslt/hipblaslt-config.cmake - RUN locale-gen en_US.UTF-8 RUN update-locale LANG=en_US.UTF-8 ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 +ENV PIP_BREAK_SYSTEM_PACKAGES=1 + # Install dependencies ADD dev-requirements.txt /dev-requirements.txt ADD requirements.txt /requirements.txt ADD rbuild.ini /rbuild.ini -# Location where onnx unit tests models are cached -ENV ONNX_HOME=/.onnx -RUN mkdir -p $ONNX_HOME/models && chmod 777 $ONNX_HOME/models - COPY ./tools/install_prereqs.sh / COPY ./tools/requirements-py.txt /requirements-py.txt -RUN /install_prereqs.sh /usr/local / && rm /install_prereqs.sh && rm /requirements-py.txt +RUN ./install_prereqs.sh \ + --rocm-version ${ROCM_VERSION} \ + ${GPU_ARCH:+--gpu ${GPU_ARCH}} \ + --index-url ${INDEX_URL} \ + ${USE_WHL:+--whl} +RUN rm /install_prereqs.sh && rm /*.txt RUN test -f /usr/local/hash || exit 1 +# Workaround broken rocm packages +RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf +RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf +RUN ldconfig + +# Manually remove rocm-cmake, since it shouldnt be installed in the first place +RUN rm -rf /opt/rocm/share/rocmcmakebuildtools + +# Install pytorch +RUN pip3 install --index-url "${INDEX_URL}" \ + "torch==2.11.0+rocm${ROCM_VERSION}.0" \ + "torchvision==0.26.0+rocm${ROCM_VERSION}.0" \ + "torchaudio==2.11.0+rocm${ROCM_VERSION}.0" + +# Location where onnx unit tests models are cached +ENV ONNX_HOME=/.onnx +RUN mkdir -p $ONNX_HOME/models && chmod 777 $ONNX_HOME/models + # Install yapf -RUN pip3 install yapf==0.28.0 +RUN pipx install --global yapf==0.28.0 + +# Install clang format +RUN pipx install --global clang-format==22.1.5 # Install doc requirements ADD docs/sphinx/requirements.txt /doc-requirements.txt -RUN pip3 install -r /doc-requirements.txt +# pip rejects extras in a constraints file (the pip-compile output pins +# pyjwt[crypto]), and extras carry no meaning in a constraint, so strip them to +# pin the sphinx install. +RUN sed 's/\[[^][]*\]//' /doc-requirements.txt > /doc-constraints.txt && \ + pipx install --global sphinx --pip-args="-c /doc-constraints.txt" && \ + rm /doc-constraints.txt +RUN pipx inject --global sphinx -r /doc-requirements.txt # Install latest ccache version RUN cget -p $PREFIX install facebook/zstd@v1.4.5 -X subdir -DCMAKE_DIR=build/cmake @@ -139,3 +154,4 @@ ENV UBSAN_OPTIONS=print_stacktrace=1 # See: https://github.com/google/sanitizers/issues/1017 ENV ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 RUN ln -s /opt/rocm/llvm/bin/llvm-symbolizer /usr/bin/llvm-symbolizer + diff --git a/Jenkinsfile b/Jenkinsfile index ae4877ea2cd..ebed76d40bf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,7 @@ DOCKER_IMAGE = 'rocm/migraphx-ci-jenkins-ubuntu' DOCKER_IMAGE_ORT = 'rocm/migraphx-ci-jenkins-ubuntu-ort' def getgputargets() { - targets="gfx906;gfx908;gfx90a;gfx1030;gfx1100;gfx1101;gfx1201;gfx942" + targets="gfx908;gfx90a;gfx942;gfx950;gfx1030;gfx1100;gfx1101;gfx1201" return targets } @@ -26,9 +26,11 @@ def rocmnodename(name) { } else if(name == "navi21") { node_name = "${rocmtest_name} && navi21"; } else if(name == "mi100+") { - node_name = "${rocmtest_name} && (gfx908 || gfx90a) && !vm"; + node_name = "${rocmtest_name} && (gfx908 || gfx90a || gfx942 || gfx950) && !vm"; } else if(name == "mi200+") { - node_name = "${rocmtest_name} && (gfx90a || gfx942) && !vm"; + node_name = "${rocmtest_name} && (gfx90a || gfx942 || gfx950) && !vm"; + } else if(name == "mi300+") { + node_name = "${rocmtest_name} && (gfx942 || gfx950) && !vm"; } else if(name == "cdna") { node_name = "${rocmtest_name} && (gfx908 || gfx90a || vega20) && !vm"; } else if(name == "navi32") { @@ -81,7 +83,7 @@ def cmake_build = { bconf -> echo "leak:libtbb.so" >> suppressions.txt cat suppressions.txt export LSAN_OPTIONS="suppressions=\$(pwd)/suppressions.txt" - export ASAN_OPTIONS="detect_container_overflow=0" + export ASAN_OPTIONS="detect_container_overflow=0:detect_odr_violation=0" export MIGRAPHX_GPU_DEBUG=${gpu_debug} export CXX=${compiler} export CXXFLAGS='-Werror' @@ -90,7 +92,10 @@ def cmake_build = { bconf -> rm -rf build mkdir build cd build - cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_DEV=On -DCMAKE_EXECUTE_PROCESS_COMMAND_ECHO=STDOUT -DMIGRAPHX_DISABLE_VIRTUAL_ENV=ON ${flags} .. + # Pin the package's per-GPU dependency to the arch of the GPU in this node + # so the generated .deb is installable here (empty on nogpu -> device-all deps). + THEROCK_GPU_ARCH=\$(/opt/rocm/bin/rocminfo 2>/dev/null | grep -o -m1 'gfx[0-9a-z]*' || true) + cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_DEV=On -DCMAKE_EXECUTE_PROCESS_COMMAND_ECHO=STDOUT -DMIGRAPHX_DISABLE_VIRTUAL_ENV=ON -DMIGRAPHX_THEROCK_GPU_ARCH="\${THEROCK_GPU_ARCH}" ${flags} .. git diff git diff-index --quiet HEAD || (echo "Git repo is not clean after running cmake." && exit 1) make -j\$(nproc) generate VERBOSE=1 @@ -269,7 +274,11 @@ def rocmtest = { Map conf = [:], Closure body -> stage("build ${variant}") { withDockerContainer(image: "${image}:${imageTag}", args: docker_opts + docker_args) { timeout(time: 4, unit: 'HOURS') { - sh "mkdir -p '${ccache}' '${comgr_cache}'" + sh """ + mkdir -p ${ccache} ${comgr_cache} + ls -l /workspaces/ + ls -l /workspaces/.cache/ + """ body() } } @@ -349,7 +358,7 @@ pipeline { parallel { stage('All Targets Release') { agent { - label rocmnodename('mi100+') + label rocmnodename('mi300+') } steps { script { @@ -369,7 +378,7 @@ pipeline { rocmtest([:]) { def sanitizers = "undefined,address" def debug_flags = "-g -O2 -fno-omit-frame-pointer -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}" - cmake_build(flags: "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_C_API_TEST=Off -DMIGRAPHX_ENABLE_PYTHON=Off -DMIGRAPHX_ENABLE_GPU=Off -DMIGRAPHX_ENABLE_CPU=On -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'", compiler: '/usr/bin/clang++-17') + cmake_build(flags: "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_C_API_TEST=Off -DMIGRAPHX_ENABLE_PYTHON=Off -DMIGRAPHX_ENABLE_GPU=Off -DMIGRAPHX_ENABLE_CPU=On -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'") } } } @@ -384,7 +393,7 @@ pipeline { rocmtest([:]) { def sanitizers = "undefined" def debug_flags = "-g -O2 -fno-omit-frame-pointer -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers} -D_GLIBCXX_DEBUG" - cmake_build(flags: "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_C_API_TEST=Off -DMIGRAPHX_ENABLE_PYTHON=Off -DMIGRAPHX_ENABLE_GPU=Off -DMIGRAPHX_ENABLE_CPU=Off -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'", compiler: '/usr/bin/clang++-17') + cmake_build(flags: "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_C_API_TEST=Off -DMIGRAPHX_ENABLE_PYTHON=Off -DMIGRAPHX_ENABLE_GPU=Off -DMIGRAPHX_ENABLE_CPU=Off -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'") } } } @@ -392,7 +401,7 @@ pipeline { stage('HIP Clang Release') { agent { - label rocmnodename('mi100+') + label rocmnodename('mi300+') } steps { script { @@ -406,7 +415,7 @@ pipeline { stage('HIP Clang Static') { agent { - label rocmnodename('mi100+') + label rocmnodename('mi300+') } steps { script { @@ -445,17 +454,13 @@ pipeline { stage('HIP RTC Debug') { agent { - label "(rocmtest || migraphx) && gfx90a && !vm" - } - environment { - // Disable MLIR since it doesnt work with all ub sanitizers - MIGRAPHX_DISABLE_MLIR = '1' + label rocmnodename('mi300+') } steps { script { rocmtest([:]) { def sanitizers = "undefined" - def debug_flags = "-g -O2 -fsanitize=${sanitizers} -fno-sanitize=vptr,function -fno-sanitize-recover=${sanitizers}" + def debug_flags = "-g -O2 -Xarch_host -fsanitize=${sanitizers} -Xarch_host -fno-sanitize=vptr,function -Xarch_host -fno-sanitize-recover=${sanitizers}" cmake_build(flags: "-DCMAKE_C_COMPILER=/opt/rocm/llvm/bin/clang -DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_PYTHON=Off -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}' -DCMAKE_C_FLAGS_DEBUG='${debug_flags}' -DMIGRAPHX_USE_HIPRTC=On -DGPU_TARGETS='${getgputargets()}'", gpu_debug: '1') } } @@ -464,7 +469,7 @@ pipeline { stage('MLIR Debug') { agent { - label rocmnodename('mi100+') + label rocmnodename('mi300+') } environment { // Since the purpose of this run is to verify all things MLIR supports, @@ -483,7 +488,7 @@ pipeline { rocmtest([:]) { // Note: the -fno-sanitize= is copied from upstream LLVM_UBSAN_FLAGS. def sanitizers = "undefined" - def debug_flags = "-g -O2 -fsanitize=${sanitizers} -fno-sanitize=vptr,function -fno-sanitize-recover=${sanitizers}" + def debug_flags = "-g -O2 -Xarch_host -fsanitize=${sanitizers} -Xarch_host -fno-sanitize=vptr,function -Xarch_host -fno-sanitize-recover=${sanitizers}" cmake_build(flags: "-DCMAKE_C_COMPILER=/opt/rocm/llvm/bin/clang -DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_PYTHON=Off -DMIGRAPHX_ENABLE_MLIR=On -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}' -DCMAKE_C_FLAGS_DEBUG='${debug_flags}' -DGPU_TARGETS='${getgputargets()}'") } } @@ -547,8 +552,6 @@ pipeline { rocmtest(setup: setuppackage, docker_args: '-u root', image: DOCKER_IMAGE_ORT, imageTag: env.IMAGE_TAG_ORT) { sh ''' apt-get update - apt-get install -y half - #ls -lR md5sum ./build/*.deb apt-get install -y --allow-unauthenticated ./build/*.deb env diff --git a/README.md b/README.md index 8942c3cf3eb..0dfcb3a0d7c 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,12 @@ Once completed, all prerequisites are in the `depend` folder and MIGraphX is in ### Use Docker -The easiest way to set up the development environment is to use Docker. +The easiest way to set up the development environment is to use Docker. ROCm's +underlying drivers and libraries, known as "TheRock", now support multi-arch +packaging, meaning it only installs device-code packages for the GPU architecture +present on the system. Setting `GPU_ARCH` reduces the image size; leaving it +unset installs device code for all supported architectures, which is useful when +the same Docker image needs to run on different ROCm-supported GPUs. 1. With the Dockerfile, build a Docker image: @@ -166,6 +171,12 @@ The easiest way to set up the development environment is to use Docker. docker build -t migraphx . ``` + or + + ```bash + docker build -t migraphx --build-arg GPU_ARCH=$(rocminfo | grep -o -m1 'gfx.*') . + ``` + 2. Enter the development environment using `docker run`: ```bash @@ -214,8 +225,17 @@ Where `myApp` is the CMake target in your project. ## Other Dockerfiles +The default `Dockerfile` builds against ROCm 7.13 and newer using TheRock +(`amdrocm-*`) packages. To build against ROCm 7.2.x and older, use the legacy +dockerfile instead: + +```bash +docker build -t migraphx:legacy -f tools/docker/legacy.dockerfile . +``` + Alternative Dockerfiles are available under `tools/docker/`: +* `tools/docker/legacy.dockerfile` — ROCm 7.2.x and older (Ubuntu 22.04); use this when building against ROCm releases that predate TheRock packages * `tools/docker/ubuntu_2404.dockerfile` — Ubuntu 24.04 with ROCm 7.1.1 * `tools/docker/ubuntu_2204.dockerfile` — Ubuntu 22.04 with ROCm 6.4.2 diff --git a/cmake/DetectPackageBackend.cmake b/cmake/DetectPackageBackend.cmake index 486d8efc33a..489d5df88af 100644 --- a/cmake/DetectPackageBackend.cmake +++ b/cmake/DetectPackageBackend.cmake @@ -22,62 +22,135 @@ # THE SOFTWARE. ##################################################################################### -# Detect the packaging backend for MIGraphX. +# Detect the packaging backend for MIGraphX and auto-configure TheRock settings. # -# detect_package_backend() sets MIGRAPHX_PACKAGE_BACKEND as a cache variable: -# "therock" - TheRock environment (amdrocm-xxx deb/rpm packages) -# "default" - Traditional ROCm with deb/rpm packages +# detect_package_backend() probes the installed system packages and, when not +# overridden on the command line, fills in everything needed to build and +# package against TheRock so that a bare `rbuild package` (or +# `cmake --build build --target package`) works without extra -D flags. # -# Preferred usage (explicit): -# cmake -DMIGRAPHX_PACKAGE_BACKEND=therock -DMIGRAPHX_THEROCK_GPU_ARCH=gfx120x .. +# It sets these cache variables (each only when not already provided): +# MIGRAPHX_PACKAGE_BACKEND - "therock" if any installed package name +# starts with "amdrocm", else "default". +# MIGRAPHX_THEROCK_ROCM_VERSION - ROCm version suffix parsed from an installed +# amdrocm-blas- package (e.g. 7.13). +# MIGRAPHX_THEROCK_GPU_ARCH - the first detected per-GPU arch (e.g. gfx942), +# used to select the per-GPU package dependency. +# GPU_TARGETS - semicolon list of ALL detected arches +# (e.g. gfx942;gfx950), used for compilation. # -# If MIGRAPHX_PACKAGE_BACKEND is not set, falls back to auto-detection via -# dpkg/rpm to check for installed amdrocm-runtime packages. +# Precedence per variable: an explicit -D / already-set value wins, then the +# GPU_ARCH_FOR_THEROCK env fallback (GPU arch only), then the detected value. # -# When MIGRAPHX_PACKAGE_BACKEND=therock, MIGRAPHX_THEROCK_GPU_ARCH must be set -# to the target GPU architecture family that follows TheRock packaging requirements. +# Explicit usage still works and overrides detection, e.g.: +# cmake -DMIGRAPHX_PACKAGE_BACKEND=therock -DMIGRAPHX_THEROCK_GPU_ARCH=gfx942 \ +# -DMIGRAPHX_THEROCK_ROCM_VERSION=7.13 -DGPU_TARGETS="gfx942;gfx950" .. -function(_detect_therock_via_package_manager) - set(_found FALSE) +# Probe installed packages via dpkg/rpm. Returns (in PARENT_SCOPE): +# _AMDROCM_ANY - TRUE if any installed package name starts with amdrocm +# _THEROCK_VERSION - version suffix from the first amdrocm-blas[-] +# _THEROCK_FIRST_ARCH - arch suffix from the first amdrocm-blas- +# _THEROCK_ALL_ARCHS - deduped, sorted list of all detected arches +function(_probe_amdrocm_packages) + set(_names "") if(NOT WIN32) - find_program(_migraphx_dpkg_exe dpkg) - if(_migraphx_dpkg_exe) + find_program(_migraphx_dpkg_query_exe dpkg-query) + if(_migraphx_dpkg_query_exe) execute_process( - COMMAND ${_migraphx_dpkg_exe} -s amdrocm-runtime - RESULT_VARIABLE _result - OUTPUT_QUIET ERROR_QUIET + COMMAND ${_migraphx_dpkg_query_exe} + -W "-f=\${db:Status-Abbrev} \${Package}\n" amdrocm* + OUTPUT_VARIABLE _dpkg_out + RESULT_VARIABLE _dpkg_res + ERROR_QUIET ) - if(_result EQUAL 0) - set(_found TRUE) + if(_dpkg_res EQUAL 0 AND _dpkg_out) + string(REPLACE "\n" ";" _dpkg_lines "${_dpkg_out}") + foreach(_line IN LISTS _dpkg_lines) + # Keep only fully-installed packages (status starts with "ii"). + if(_line MATCHES "^ii[^ ]* +([A-Za-z0-9._+-]+)") + list(APPEND _names "${CMAKE_MATCH_1}") + endif() + endforeach() endif() endif() - if(NOT _found) + unset(_migraphx_dpkg_query_exe CACHE) + + if(NOT _names) find_program(_migraphx_rpm_exe rpm) if(_migraphx_rpm_exe) execute_process( - COMMAND ${_migraphx_rpm_exe} -q amdrocm-runtime - RESULT_VARIABLE _result - OUTPUT_QUIET ERROR_QUIET + COMMAND ${_migraphx_rpm_exe} -qa --qf "%{NAME}\n" amdrocm* + OUTPUT_VARIABLE _rpm_out + RESULT_VARIABLE _rpm_res + ERROR_QUIET ) - if(_result EQUAL 0) - set(_found TRUE) + if(_rpm_res EQUAL 0 AND _rpm_out) + string(REPLACE "\n" ";" _rpm_lines "${_rpm_out}") + foreach(_line IN LISTS _rpm_lines) + string(STRIP "${_line}" _line) + if(_line) + list(APPEND _names "${_line}") + endif() + endforeach() endif() endif() + unset(_migraphx_rpm_exe CACHE) endif() - unset(_migraphx_dpkg_exe CACHE) - unset(_migraphx_rpm_exe CACHE) endif() - set(_MIGRAPHX_THEROCK_DETECTED ${_found} PARENT_SCOPE) + + set(_any FALSE) + set(_version "") + set(_first_arch "") + set(_all_archs "") + set(_version_no_arch "") + if(_names) + list(SORT _names) + foreach(_name IN LISTS _names) + if(_name MATCHES "^amdrocm") + set(_any TRUE) + endif() + # Arch-suffixed blas package: amdrocm-blas- + if(_name MATCHES "^amdrocm-blas([0-9][0-9.]*)-(gfx[0-9a-z]+)$") + if(NOT _version) + set(_version "${CMAKE_MATCH_1}") + endif() + if(NOT _first_arch) + set(_first_arch "${CMAKE_MATCH_2}") + endif() + list(APPEND _all_archs "${CMAKE_MATCH_2}") + # Non-arch blas package: amdrocm-blas (version fallback only) + elseif(_name MATCHES "^amdrocm-blas([0-9][0-9.]*)$") + if(NOT _version_no_arch) + set(_version_no_arch "${CMAKE_MATCH_1}") + endif() + endif() + endforeach() + endif() + + # Fall back to the non-arch blas package version when no per-GPU blas is found. + if(NOT _version AND _version_no_arch) + set(_version "${_version_no_arch}") + endif() + + if(_all_archs) + list(REMOVE_DUPLICATES _all_archs) + list(SORT _all_archs) + endif() + + set(_AMDROCM_ANY ${_any} PARENT_SCOPE) + set(_THEROCK_VERSION "${_version}" PARENT_SCOPE) + set(_THEROCK_FIRST_ARCH "${_first_arch}" PARENT_SCOPE) + set(_THEROCK_ALL_ARCHS "${_all_archs}" PARENT_SCOPE) endfunction() function(detect_package_backend) + _probe_amdrocm_packages() + if(NOT DEFINED CACHE{MIGRAPHX_PACKAGE_BACKEND}) - # No explicit -D flag: auto-detect via package manager (fallback) - _detect_therock_via_package_manager() - if(_MIGRAPHX_THEROCK_DETECTED) + # No explicit -D flag: auto-detect from installed amdrocm* packages. + if(_AMDROCM_ANY) set(_default_backend "therock") - message(STATUS "MIGraphX package backend auto-detected: therock (amdrocm-runtime found)") - message(STATUS " Hint: prefer explicit -DMIGRAPHX_PACKAGE_BACKEND=therock -DMIGRAPHX_THEROCK_GPU_ARCH=") + message(STATUS "MIGraphX package backend auto-detected: therock (amdrocm-* packages found)") else() set(_default_backend "default") endif() @@ -95,16 +168,37 @@ function(detect_package_backend) endif() if(MIGRAPHX_PACKAGE_BACKEND STREQUAL "therock") - if(DEFINED ENV{GPU_ARCH_FOR_THEROCK}) - # Env name drops MIGRAPHX_ prefix to avoid the "unused MIGRAPHX_* env" warning. - set(_default_gpu_arch "$ENV{GPU_ARCH_FOR_THEROCK}") - else() - set(_default_gpu_arch "") + # ROCm version suffix used in all amdrocm-* dependency names. + if(NOT DEFINED CACHE{MIGRAPHX_THEROCK_ROCM_VERSION}) + set(MIGRAPHX_THEROCK_ROCM_VERSION "${_THEROCK_VERSION}" CACHE STRING + "TheRock ROCm major.minor version suffix for package dependencies (e.g. 7.13)") + endif() + + # Per-GPU arch used to select the per-GPU package dependency (first only). + if(NOT DEFINED CACHE{MIGRAPHX_THEROCK_GPU_ARCH}) + if(DEFINED ENV{GPU_ARCH_FOR_THEROCK}) + # Env name drops MIGRAPHX_ prefix to avoid the "unused MIGRAPHX_* env" warning. + set(_default_gpu_arch "$ENV{GPU_ARCH_FOR_THEROCK}") + else() + set(_default_gpu_arch "${_THEROCK_FIRST_ARCH}") + endif() + set(MIGRAPHX_THEROCK_GPU_ARCH "${_default_gpu_arch}" CACHE STRING + "TheRock GPU arch(es) for per-GPU package dependencies (e.g. gfx942). \ +Semicolon-separated list for per-GPU deps, or empty for device-all meta-package deps.") + endif() + + # GPU_TARGETS (what to compile) defaults to ALL detected arches. Only set + # when not already provided by -D, the HIP package, or env so we never + # clobber an explicit choice. + if(NOT GPU_TARGETS AND _THEROCK_ALL_ARCHS) + set(GPU_TARGETS "${_THEROCK_ALL_ARCHS}" CACHE STRING + "GPU architectures to compile for (auto-detected from TheRock amdrocm-blas packages)") endif() - set(MIGRAPHX_THEROCK_GPU_ARCH "${_default_gpu_arch}" CACHE STRING - "TheRock GPU architecture family suffix (e.g. gfx120x ..)") - message(STATUS "MIGraphX package backend: therock (GPU arch: ${MIGRAPHX_THEROCK_GPU_ARCH})") + message(STATUS "MIGraphX package backend: therock " + "(ROCm version: '${MIGRAPHX_THEROCK_ROCM_VERSION}', " + "package GPU arch: '${MIGRAPHX_THEROCK_GPU_ARCH}', " + "GPU_TARGETS: '${GPU_TARGETS}')") else() message(STATUS "MIGraphX package backend: default (traditional ROCm)") endif() diff --git a/hip-clang.docker b/hip-clang.docker index c74802dc21d..09457866e13 100644 --- a/hip-clang.docker +++ b/hip-clang.docker @@ -1,6 +1,18 @@ -FROM ubuntu:22.04 +FROM ubuntu:24.04 ARG PREFIX=/usr/local +# ROCm release version (used in versioned package names, e.g. amdrocm-developer-tools7.13) +ARG ROCM_VERSION="7.14" +# GPU architecture family (e.g. gfx942, gfx120x); leave empty for arch-independent packages +ARG GPU_ARCH="" +# Install location for the prebuilt MIGraphX dependencies. +ARG PREFIX=/usr/local +# Install the MIGraphX build prerequisites (system packages + ROCm components). +# Set USE_WHL to any non-empty value to install ROCm from Python wheels instead +# of system packages (passes --whl to the prereqs script). +ARG USE_WHL="" +# pip index URL for the wheel-based ROCm install (only used when USE_WHL is set). +ARG INDEX_URL="https://repo.amd.com/rocm/whl-multi-arch/" # Support multiarch RUN dpkg --add-architecture i386 @@ -8,16 +20,10 @@ RUN dpkg --add-architecture i386 # Install rocm key RUN apt-get update && apt-get install -y software-properties-common gnupg2 --no-install-recommends curl && \ mkdir -p /etc/apt/keyrings && \ - curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor -o /etc/apt/keyrings/rocm.gpg && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - + curl -fsSL https://repo.amd.com/rocm/packages/gpg/rocm.gpg | gpg --dearmor -o /etc/apt/keyrings/amdrocm.gpg # Add rocm repository -RUN sh -c 'echo deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/7.2.3/ jammy main > /etc/apt/sources.list.d/rocm.list' - -# From docs.amd.com for installing rocm. Needed to install properly -RUN sh -c "echo 'Package: *\nPin: release o=repo.radeon.com\nPin-priority: 600' > /etc/apt/preferences.d/rocm-pin-600" +RUN sh -c 'echo deb [arch=amd64 signed-by=/etc/apt/keyrings/amdrocm.gpg] https://repo.amd.com/rocm/packages-multi-arch/ubuntu2404 stable main > /etc/apt/sources.list.d/rocm.list' # Install dependencies RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ @@ -34,36 +40,14 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ python3-full \ software-properties-common \ wget \ - rocm-device-libs \ - hip-dev \ - libnuma-dev \ - miopen-hip \ - rocblas \ zlib1g-dev && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# Workaround broken rocm packages -RUN ln -s /opt/rocm-* /opt/rocm -RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf -RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf -RUN ldconfig - -# Workaround broken miopen cmake files -RUN sed -i 's,;/usr/lib/x86_64-linux-gnu/librt.so,,g' /opt/rocm/lib/cmake/miopen/miopen-targets.cmake - -# Workaround for distributions running cmake < 3.25 -RUN sed -i -e 's/^block/if(COMMAND block)\nblock/g' -e 's/^endblock/endblock\(\)\nendif/g' /opt/rocm/lib/cmake/hipblaslt/hipblaslt-config.cmake - ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 -# Install yapf -RUN pip3 install yapf==0.28.0 - -# Install doc requirements -ADD docs/sphinx/requirements.txt /doc-requirements.txt -RUN pip3 install -r /doc-requirements.txt +ENV PIP_BREAK_SYSTEM_PACKAGES=1 # Install dependencies ADD dev-requirements.txt /dev-requirements.txt @@ -71,6 +55,25 @@ ADD requirements.txt /requirements.txt ADD rbuild.ini /rbuild.ini COPY ./tools/install_prereqs.sh / -COPY ./tools/requirements-py.txt / -RUN /install_prereqs.sh /usr/local / && rm /install_prereqs.sh && rm /requirements-py.txt +COPY ./tools/requirements-py.txt /requirements-py.txt +RUN ./install_prereqs.sh \ + --rocm-version ${ROCM_VERSION} \ + ${GPU_ARCH:+--gpu ${GPU_ARCH}} \ + --index-url ${INDEX_URL} \ + ${USE_WHL:+--whl} +RUN rm /install_prereqs.sh && rm /*.txt +RUN test -f /usr/local/hash || exit 1 + +# Workaround broken rocm packages +RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf +RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf +RUN ldconfig + +# Manually remove rocm-cmake, since it shouldnt be installed in the first place +RUN rm -rf /opt/rocm/share/rocmcmakebuildtools + +# Install yapf +RUN pipx install --global yapf==0.28.0 +# Install clang format +RUN pipx install --global clang-format==22.1.5 diff --git a/test/gpu/gemm_tune.cpp b/test/gpu/gemm_tune.cpp index 277229d89fb..985b5b4698a 100644 --- a/test/gpu/gemm_tune.cpp +++ b/test/gpu/gemm_tune.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -185,6 +186,15 @@ TEST_CASE(gemm_tune_strided_lowered) TEST_CASE(gemm_tune_invalid_sol_index) { + // TODO: JIRA Ticket TBD - rocBLAS solution-index validation + // (rocblas_gemm_flags_check_solution_index) does not report invalid indices on + // gfx1201; it returns rocblas_status_success for any index, so an invalid index + // is never reset to the default. Skip on gfx1201 until rocBLAS is fixed. + if(migraphx::gpu::get_gfx_name(migraphx::gpu::get_device_name()) == "gfx1201") + { + test::skip("rocBLAS solution-index validation is broken on gfx1201 (JIRA Ticket TBD)"); + } + migraphx::program p; auto* mm = p.get_main_module(); diff --git a/tools/docker/hip-clang-legacy.docker b/tools/docker/hip-clang-legacy.docker new file mode 100644 index 00000000000..abdec9909c7 --- /dev/null +++ b/tools/docker/hip-clang-legacy.docker @@ -0,0 +1,76 @@ +FROM ubuntu:22.04 + +ARG PREFIX=/usr/local + +# Support multiarch +RUN dpkg --add-architecture i386 + +# Install rocm key +RUN apt-get update && apt-get install -y software-properties-common gnupg2 --no-install-recommends curl && \ + mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor -o /etc/apt/keyrings/rocm.gpg && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + + +# Add rocm repository +RUN sh -c 'echo deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/7.2.3/ jammy main > /etc/apt/sources.list.d/rocm.list' + +# From docs.amd.com for installing rocm. Needed to install properly +RUN sh -c "echo 'Package: *\nPin: release o=repo.radeon.com\nPin-priority: 600' > /etc/apt/preferences.d/rocm-pin-600" + +# Install dependencies +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + apt-utils \ + build-essential \ + cmake \ + gdb \ + git \ + lcov \ + pkg-config \ + python3 \ + python3-dev \ + python3-pip \ + python3-full \ + software-properties-common \ + wget \ + rocm-device-libs \ + hip-dev \ + libnuma-dev \ + miopen-hip \ + rocblas \ + zlib1g-dev && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Workaround broken rocm packages +RUN ln -s /opt/rocm-* /opt/rocm +RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf +RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf +RUN ldconfig + +# Workaround broken miopen cmake files +RUN sed -i 's,;/usr/lib/x86_64-linux-gnu/librt.so,,g' /opt/rocm/lib/cmake/miopen/miopen-targets.cmake + +# Workaround for distributions running cmake < 3.25 +RUN sed -i -e 's/^block/if(COMMAND block)\nblock/g' -e 's/^endblock/endblock\(\)\nendif/g' /opt/rocm/lib/cmake/hipblaslt/hipblaslt-config.cmake + +ENV LC_ALL=C.UTF-8 +ENV LANG=C.UTF-8 + +# Install yapf +RUN pip3 install yapf==0.28.0 + +# Install doc requirements +ADD docs/sphinx/requirements.txt /doc-requirements.txt +RUN pip3 install -r /doc-requirements.txt + +# Install dependencies +ADD dev-requirements.txt /dev-requirements.txt +ADD requirements.txt /requirements.txt +ADD rbuild.ini /rbuild.ini + +COPY ./tools/install_prereqs_legacy.sh / +COPY ./tools/requirements-py.txt / +RUN /install_prereqs_legacy.sh /usr/local / && rm /install_prereqs_legacy.sh && rm /requirements-py.txt + diff --git a/tools/docker/legacy.dockerfile b/tools/docker/legacy.dockerfile new file mode 100644 index 00000000000..2fd0672c2b7 --- /dev/null +++ b/tools/docker/legacy.dockerfile @@ -0,0 +1,140 @@ +FROM ubuntu:22.04 + +ARG PREFIX=/usr/local + +# Support multiarch +RUN dpkg --add-architecture i386 + +# Install rocm key +RUN apt-get update && apt-get install -y software-properties-common gnupg2 --no-install-recommends curl && \ + mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor -o /etc/apt/keyrings/rocm.gpg + +# Add rocm repository +RUN sh -c 'echo deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/7.2.3/ jammy main > /etc/apt/sources.list.d/rocm.list' + +# From docs.amd.com for installing rocm. Needed to install properly +RUN sh -c "echo 'Package: *\nPin: release o=repo.radeon.com\nPin-priority: 600' > /etc/apt/preferences.d/rocm-pin-600" + +# rocgdb doesn't work on 22.04, workaround by installing the older python packages that are in 20.04 +RUN add-apt-repository -y ppa:deadsnakes/ppa + +# Add LLVM repository for Clang 17 (ROCm 7.x ships with Clang 20 which has ODR false positives in ASAN) +RUN curl -sL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ + add-apt-repository -y "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" + +# Install dependencies +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + apt-utils \ + bison \ + build-essential \ + clang-17 \ + cmake \ + curl \ + flex \ + g++ \ + gdb \ + git \ + lcov \ + locales \ + pkg-config \ + python3 \ + python3-dev \ + python3-pip \ + python3-full \ + libpython3.8 \ + wget \ + rocm-device-libs \ + hip-dev \ + libnuma-dev \ + miopen-hip \ + libomp-17-dev \ + rocblas \ + hipfft \ + hipsolver \ + rocthrust \ + rocrand \ + rocprofiler-sdk \ + hipsparse \ + rccl \ + rocm-smi-lib \ + rocm-dev \ + roctracer-dev \ + hipcub \ + hipblas \ + hipify-clang \ + hiprand-dev \ + hipsparselt \ + half \ + libssl-dev \ + zlib1g-dev && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + + +# Install pytorch +RUN pip3 install https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2.3/torch-2.8.0%2Brocm7.2.3.lw.git2742f6d1-cp310-cp310-linux_x86_64.whl \ + https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2.3/torchvision-0.24.0%2Brocm7.2.3.gitb919bd0c-cp310-cp310-linux_x86_64.whl \ + https://repo.radeon.com/rocm/manylinux/rocm-rel-7.2.3/triton-3.4.0%2Brocm7.2.3.git0cace8d2-cp310-cp310-linux_x86_64.whl + +# add this for roctracer dependencies +RUN pip3 install CppHeaderParser + +# Workaround broken rocm packages +RUN ln -s /opt/rocm-* /opt/rocm +RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf +RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf +RUN ldconfig + +# ATT library +RUN wget -O /opt/rocm/lib/librocprof-trace-decoder.so https://github.com/ROCm/rocprof-trace-decoder/raw/7e58204a955e5787b9b38087f3ad502f07ff78ef/releases/linux_glibc_2_28_x86_64/librocprof-trace-decoder.so + +# Workaround broken miopen cmake files +RUN sed -i 's,;/usr/lib/x86_64-linux-gnu/librt.so,,g' /opt/rocm/lib/cmake/miopen/miopen-targets.cmake + +# Workaround for distributions running cmake < 3.25 +RUN sed -i -e 's/^block/if(COMMAND block)\nblock/g' -e 's/^endblock/endblock\(\)\nendif/g' /opt/rocm/lib/cmake/hipblaslt/hipblaslt-config.cmake + +RUN locale-gen en_US.UTF-8 +RUN update-locale LANG=en_US.UTF-8 + +ENV LC_ALL=C.UTF-8 +ENV LANG=C.UTF-8 + +# Install dependencies +ADD dev-requirements.txt /dev-requirements.txt +ADD requirements.txt /requirements.txt +ADD rbuild.ini /rbuild.ini + +# Location where onnx unit tests models are cached +ENV ONNX_HOME=/.onnx +RUN mkdir -p $ONNX_HOME/models && chmod 777 $ONNX_HOME/models + +COPY ./tools/install_prereqs_legacy.sh / +COPY ./tools/requirements-py.txt /requirements-py.txt +RUN /install_prereqs_legacy.sh /usr/local / && rm /install_prereqs_legacy.sh && rm /requirements-py.txt +RUN test -f /usr/local/hash || exit 1 + +# Install yapf +RUN pip3 install yapf==0.28.0 + +# Install doc requirements +ADD docs/sphinx/requirements.txt /doc-requirements.txt +RUN pip3 install -r /doc-requirements.txt + +# Install latest ccache version +RUN cget -p $PREFIX install facebook/zstd@v1.4.5 -X subdir -DCMAKE_DIR=build/cmake +RUN cget -p $PREFIX install ccache@v4.1 -DENABLE_TESTING=OFF +# Install a newer version of doxygen because the one that comes with ubuntu is broken +RUN cget -p $PREFIX install doxygen@Release_1_14_0 + +ENV MIOPEN_FIND_DB_PATH=/tmp/miopen/find-db +ENV MIOPEN_USER_DB_PATH=/tmp/miopen/user-db +ENV LD_LIBRARY_PATH=$PREFIX/lib + +# Setup ubsan environment to printstacktrace +ENV UBSAN_OPTIONS=print_stacktrace=1 +# Disable odr detection since its broken with shared libraries +# See: https://github.com/google/sanitizers/issues/1017 +ENV ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 +RUN ln -s /opt/rocm/llvm/bin/llvm-symbolizer /usr/bin/llvm-symbolizer diff --git a/tools/docker/ort.dockerfile b/tools/docker/ort.dockerfile index 12b337f2bac..172d22f51ea 100644 --- a/tools/docker/ort.dockerfile +++ b/tools/docker/ort.dockerfile @@ -1,15 +1,17 @@ -FROM ubuntu:22.04 +FROM ubuntu:24.04 + +ARG ROCM_VERSION=7.14 +ARG GPU_ARCH="" + +ENV PIP_BREAK_SYSTEM_PACKAGES=1 # Install rocm key RUN apt-get update && apt-get install -y software-properties-common gnupg2 --no-install-recommends curl && \ - curl -sL http://repo.radeon.com/rocm/rocm.gpg.key | apt-key add - + mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://repo.amd.com/rocm/packages/gpg/rocm.gpg | gpg --dearmor -o /etc/apt/keyrings/amdrocm.gpg # Add rocm repository -RUN sh -c 'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/7.2.3/ jammy main > /etc/apt/sources.list.d/rocm.list' - -# From docs.amd.com for installing rocm. Needed to install properly -RUN sh -c "echo 'Package: *\nPin: release o=repo.radeon.com\nPin-priority: 600' > /etc/apt/preferences.d/rocm-pin-600" - +RUN sh -c 'echo deb [arch=amd64 signed-by=/etc/apt/keyrings/amdrocm.gpg] https://repo.amd.com/rocm/packages-multi-arch/ubuntu2404 stable main > /etc/apt/sources.list.d/rocm.list' ARG ONNXRUNTIME_REPO=https://github.com/microsoft/onnxruntime ARG ONNXRUNTIME_BRANCH=main @@ -19,18 +21,37 @@ WORKDIR / # Pin onnxruntime commit from AMDMIGraphX repo (used by Check ORT image tag) COPY test/onnx/.onnxrt-commit /.onnxrt-commit -# Install half package and gdb required by the test stage +# Install gdb required by the test stage RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated \ gdb \ git \ - half \ libsqlite3-dev \ locales \ + python3 \ + python3-dev \ + python3-pip \ + python3-full \ pip && \ apt-get clean && rm -rf /var/lib/apt/lists/* +RUN pip3 install pipx + +RUN locale-gen en_US.UTF-8 +RUN update-locale LANG=en_US.UTF-8 + +ENV LC_ALL=C.UTF-8 +ENV LANG=C.UTF-8 + +COPY ./tools/install_prereqs.sh / +COPY ./tools/requirements-py.txt /requirements-py.txt +RUN ./install_prereqs.sh \ + --rocm-only \ + --rocm-version ${ROCM_VERSION} \ + ${GPU_ARCH:+--gpu ${GPU_ARCH}} \ + ${USE_WHL:+--whl} +RUN rm /install_prereqs.sh && rm /*.txt + # Workaround broken rocm packages -RUN ln -s /opt/rocm-* /opt/rocm RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf RUN ldconfig @@ -40,15 +61,9 @@ RUN git clone --single-branch --branch ${ONNXRUNTIME_BRANCH} --recursive ${ONNXR cd onnxruntime && git checkout $(cat /.onnxrt-commit) && \ /bin/sh /onnxruntime/dockerfiles/scripts/install_common_deps.sh -RUN locale-gen en_US.UTF-8 -RUN update-locale LANG=en_US.UTF-8 - -ENV LC_ALL=C.UTF-8 -ENV LANG=C.UTF-8 - # Add AMDMIGraphX CI test scripts (layout expected by build_and_test_onnxrt.sh) ADD tools/build_and_test_onnxrt.sh /onnxruntime/build_and_test_onnxrt.sh ADD tools/pai_test_launcher.sh /onnxruntime/tools/ci_build/github/pai/pai_test_launcher.sh ADD tools/pai_provider_test_launcher.sh /onnxruntime/tools/ci_build/github/pai/pai_provider_test_launcher.sh -RUN pip install cmake==4.3.1 +RUN pipx install --global cmake==4.3.1 diff --git a/tools/docker/sles.docker b/tools/docker/sles.docker index 239738a9743..31d5ecfd389 100644 --- a/tools/docker/sles.docker +++ b/tools/docker/sles.docker @@ -1,9 +1,14 @@ FROM registry.suse.com/suse/sle15:15.6 +ARG PREFIX=/usr/local +ARG ROCM_VERSION=7.14 +ARG GPU_ARCH="" + +# Register TheRock ROCm zypper repository (multi-arch amdrocm-* rpm packages). RUN sh -c 'echo -e "\ [rocm]\n\ name=rocm\n\ -baseurl=https://repo.radeon.com/rocm/zyp/7.2.3/main\n\ +baseurl=https://repo.amd.com/rocm/packages-multi-arch/sles15/x86_64\n\ enabled=1\n\ gpgcheck=0\n\ gpgkey=https://repo.radeon.com/rocm/rocm.gpg.key\n\ @@ -12,34 +17,29 @@ gpgkey=https://repo.radeon.com/rocm/rocm.gpg.key\n\ RUN cat /etc/zypp/repos.d/rocm.repo #addition of repos for packages -RUN zypper addrepo https://download.opensuse.org/repositories/devel:/languages:/perl/15.6/devel:languages:perl.repo  +RUN zypper addrepo https://download.opensuse.org/repositories/devel:/languages:/perl/15.6/devel:languages:perl.repo RUN zypper -n --gpg-auto-import-keys refresh RUN zypper --gpg-auto-import-keys install -y \ + cmake \ doxygen \ gcc-c++ \ gdb \ git \ - hip-devel \ + python3-devel \ python3-pip \ rpm-build -# Workaround broken rocm packages -RUN ln -s /opt/rocm-* /opt/rocm -RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf -RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf -RUN ldconfig - ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 -# Install yapf -RUN pip3 install yapf==0.28.0 +ENV PIP_BREAK_SYSTEM_PACKAGES=1 -# Install doc requirements -# ADD docs/sphinx/requirements.txt /doc-requirements.txt -# RUN pip3 install -r /doc-requirements.txt +# pipx 0.16 (the last version for python 3.6) has no --global flag; these env +# vars give the same global install locations. +ENV PIPX_HOME=/opt/pipx +ENV PIPX_BIN_DIR=/usr/local/bin # Install dependencies ADD dev-requirements.txt /dev-requirements.txt @@ -47,5 +47,24 @@ ADD requirements.txt /requirements.txt ADD rbuild.ini /rbuild.ini COPY ./tools/install_prereqs.sh / -COPY ./tools/requirements-py.txt / -RUN /install_prereqs.sh /usr/local / && rm /install_prereqs.sh && rm /requirements-py.txt +COPY ./tools/requirements-py.txt /requirements-py.txt +RUN ./install_prereqs.sh \ + --rocm-version ${ROCM_VERSION} \ + ${GPU_ARCH:+--gpu ${GPU_ARCH}} \ + ${USE_WHL:+--whl} +RUN rm /install_prereqs.sh && rm /*.txt +RUN test -f /usr/local/hash || exit 1 + +# Workaround broken rocm packages +RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf +RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf +RUN ldconfig + +# Manually remove rocm-cmake, since it shouldnt be installed in the first place +RUN rm -rf /opt/rocm/share/rocmcmakebuildtools + +# Install yapf +RUN pipx install yapf==0.28.0 + +# Install clang format +RUN pipx install clang-format==22.1.5 diff --git a/tools/docker/therock_deb.docker b/tools/docker/therock_deb.docker deleted file mode 100644 index 02cfa996979..00000000000 --- a/tools/docker/therock_deb.docker +++ /dev/null @@ -1,104 +0,0 @@ -# MIGraphX build environment with TheRock (amdrocm-*) deb packages. -# -# Build args: -# GPU_ARCH GPU architecture family (e.g. gfx120x, gfx94x) -# ROCM_RELEASE_URL TheRock ROCm apt repository URL -# -# Build: -# docker build --build-arg GPU_ARCH= \ -# --build-arg ROCM_RELEASE_URL= \ -# -f tools/docker/therock_deb.docker -t migraphx-therock . -# -# Run: -# docker run -it --device=/dev/kfd --device=/dev/dri --group-add video \ -# -v $(pwd):/code/AMDMIGraphX migraphx-therock -# -# Build MIGraphX inside the container: -# cd /code/AMDMIGraphX -# rbuild build -d depend -B build \ -# -DGPU_TARGETS=$(rocminfo | grep -o -m1 'gfx.*') - -FROM ubuntu:24.04 - -ARG GPU_ARCH=gfx120x -ARG ROCM_RELEASE_URL=https://rocm.nightlies.amd.com/deb/20260414-24379014014 - -# Support multiarch -RUN dpkg --add-architecture i386 - -# Install apt repository signing key for LLVM. -# ROCm nightlies do not serve a signed Release file yet, so we cannot use -# signed-by= for them and no ROCm key is imported here. -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates gnupg2 curl && \ - curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /usr/share/keyrings/llvm-archive-keyring.gpg - -# Add rocm repository. -# ROCm nightlies currently serve an unsigned Release (no InRelease / Release.gpg), -# so trusted=yes is required. Switch to signed-by= once upstream signs the repo. -RUN sh -c "echo deb [arch=amd64 trusted=yes] ${ROCM_RELEASE_URL} stable main > /etc/apt/sources.list.d/rocm.list" - -# From docs.amd.com for installing rocm. Needed to install properly -RUN sh -c "echo 'Package: *\nPin: release o=repo.radeon.com\nPin-priority: 600' > /etc/apt/preferences.d/rocm-pin-600" - -# Add LLVM repository for Clang 17 (ROCm 7.x ships with Clang 20 which has ODR false positives in ASAN) -RUN sh -c "echo deb [arch=amd64 signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] https://apt.llvm.org/noble/ llvm-toolchain-noble-17 main > /etc/apt/sources.list.d/llvm.list" - -# Install dependencies -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - apt-utils \ - bison \ - build-essential \ - clang-17 \ - cmake \ - curl \ - flex \ - g++ \ - gdb \ - git \ - lcov \ - locales \ - pkg-config \ - python3 \ - python3-dev \ - python3-pip \ - python3-full \ - wget \ - libnuma-dev \ - libomp-17-dev \ - libssl-dev \ - zlib1g-dev && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# Install rocm libraries -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - amdrocm-runtime \ - amdrocm-runtime-dev \ - amdrocm-llvm \ - amdrocm-core-${GPU_ARCH} \ - amdrocm-core-dev-${GPU_ARCH} \ - amdrocm-blas-${GPU_ARCH} \ - amdrocm-blas-dev-${GPU_ARCH} \ - amdrocm-hipblas-common-dev-${GPU_ARCH} \ - amdrocm-dnn-${GPU_ARCH} \ - amdrocm-dnn-dev-${GPU_ARCH} && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# Install rbuild -ENV PIP_BREAK_SYSTEM_PACKAGES=1 -RUN pip install https://github.com/RadeonOpenCompute/rbuild/archive/master.tar.gz - -# Add ROCm bin to PATH -ENV PATH=/opt/rocm/bin:$PATH - -# Expose GPU arch for CMake packaging, particularly for TheRock: -# Fallback for cache var MIGRAPHX_THEROCK_GPU_ARCH and avoid MIGRAPHX_ prefix "unused env" warning. -# cmake -DMIGRAPHX_PACKAGE_BACKEND=therock -DMIGRAPHX_THEROCK_GPU_ARCH=$GPU_ARCH_FOR_THEROCK -ENV GPU_ARCH_FOR_THEROCK=${GPU_ARCH} - -# Set locale -RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8 - -ENV LC_ALL=C.UTF-8 -ENV LANG=C.UTF-8 \ No newline at end of file diff --git a/tools/install_prereqs.sh b/tools/install_prereqs.sh index 388c08b3dbf..675eae0328c 100755 --- a/tools/install_prereqs.sh +++ b/tools/install_prereqs.sh @@ -24,69 +24,233 @@ # THE SOFTWARE. ##################################################################################### # -# Build MIGraphX prerequisites for docker container +# Install the minimal set of packages required to build MIGraphX from source. +# +# The host distribution is detected automatically and the matching package +# manager (apt, dnf/yum, or zypper) is used. The ROCm components come from +# TheRock "amdrocm-*" packages, either from the system package manager (default) +# or from Python wheels when --whl is supplied. +# +# Usage: +# install_prereqs.sh [--rocm-version ] [--gpu ] [--whl] [--index-url ] +# [--rocm-only] +# +# --rocm-version ROCm release version used in versioned package names, +# e.g. 7.13 -> amdrocm-developer-tools7.13 +# --gpu Specific GPU architecture, e.g. gfx942. When set, the +# smaller "skinny" per-gfx ROCm device code is installed. +# When unset, the "fat" (all-architecture) ROCm device +# code is installed, which is convenient for CI images +# that must run on any GPU. +# --whl Install the ROCm "amdrocm-*" components from Python +# wheels (pip) instead of the system package manager. +# --index-url Override the pip --index-url used with --whl. Common +# values to use would be +# https://repo.amd.com/rocm/whl-multi-arch +# https://rocm.prereleases.amd.com/whl-multi-arch +# https://rocm.nightlies.amd.com/whl-multi-arch/ +# --rocm-only Install only the ROCm components and skip everything +# else (pipx, rbuild, and the MIGraphX dependencies). -set -e +set -eo pipefail export LC_ALL=C.UTF-8 export LANG=C.UTF-8 +ROCM_VERSION="" +GPU_ARCH="" +USE_WHL=0 +ROCM_ONLY=0 +INDEX_URL="https://repo.amd.com/rocm/whl-multi-arch/" +PREFIX=/usr/local +REQ_FILE_DIR="$(dirname -- "$0")" + source /etc/os-release -# hipcc added as workaround for broken hip-dev package -if [[ ("${ID}" == "sles") ]]; then - zypper -n --gpg-auto-import-keys install -y \ - cmake \ - miopen-hip-devel \ - openmp-extras-devel \ - python3-devel \ - python3-pip \ - rocblas-devel \ - libgfortran5 \ - hipblas-devel \ - hipblaslt-devel +usage() +{ + grep '^#' "$0" | grep -v '!/bin/bash' | sed 's/^#//' +} + +# require_value errors out when a flag that needs an argument is missing one. +require_value() +{ + if [[ $# -lt 2 ]]; then + echo "Option $1 requires a value." >&2 + exit 1 + fi +} + +while [[ $# -gt 0 ]]; do + case "$1" in + --rocm-version) + require_value "$@" + ROCM_VERSION="$2" + shift 2 + ;; + --rocm-version=*) + ROCM_VERSION="${1#*=}" + shift + ;; + --gpu) + require_value "$@" + GPU_ARCH="$2" + shift 2 + ;; + --gpu=*) + GPU_ARCH="${1#*=}" + shift + ;; + --whl) + USE_WHL=1 + shift + ;; + --rocm-only) + ROCM_ONLY=1 + shift + ;; + --index-url) + require_value "$@" + INDEX_URL="$2" + shift 2 + ;; + --index-url=*) + INDEX_URL="${1#*=}" + shift + ;; + -h | --help) + usage + exit 0 + ;; + *) + echo "Unknown argument: $1" >&2 + usage >&2 + exit 1 + ;; + esac +done + +# Detect the available package manager. +PKG_MGR="" +if command -v apt-get > /dev/null 2>&1; then + PKG_MGR="apt" +elif command -v dnf > /dev/null 2>&1; then + PKG_MGR="dnf" +elif command -v yum > /dev/null 2>&1; then + PKG_MGR="yum" +elif command -v zypper > /dev/null 2>&1; then + PKG_MGR="zypper" else - # Need pip3 and Python headers to build dependencies - apt update && apt install -y \ - cmake \ - libnuma-dev \ - miopen-hip-dev \ - openmp-extras \ - python3-dev \ - python3-pip \ - python3-venv \ - rocblas-dev \ - libgfortran5 \ - hipblas-dev \ - hipblaslt-dev \ - hipcc \ - rocm-llvm-dev \ - libtbb-dev + echo "No supported package manager found (apt, dnf, yum, zypper)." >&2 + exit 1 fi +echo "Using package manager: ${PKG_MGR}" -# Needed for cmake to build various pip packages -pip3 install setuptools wheel +# pkg_refresh updates the package metadata for the detected manager. +pkg_refresh() +{ + case "$PKG_MGR" in + apt) apt-get update ;; + dnf) dnf makecache ;; + yum) yum makecache ;; + zypper) zypper -n --gpg-auto-import-keys refresh ;; + esac +} -# install rbuild to build dependencies -pip3 install https://github.com/RadeonOpenCompute/rbuild/archive/master.tar.gz +# pkg_install installs the given list of packages with the detected manager. +pkg_install() +{ + case "$PKG_MGR" in + apt) + DEBIAN_FRONTEND=noninteractive apt-get install -y "$@" + ;; + dnf) + dnf install -y "$@" + ;; + yum) + yum install -y "$@" + ;; + zypper) + zypper -n --gpg-auto-import-keys install -y "$@" + ;; + esac +} +case "$PKG_MGR" in + apt) + DEV_SUFFIX="-dev" + ;; + dnf | yum | zypper) + DEV_SUFFIX="-devel" + ;; +esac -PREFIX=/usr/local -REQ_FILE_DIR="$(dirname -- "$0")" -if [ "$#" -ge 2 ]; then - PREFIX=$1 - cd $2 -elif [ "$#" -eq 1 ]; then - PREFIX=$1 +# Install the ROCm packages, by WHL or by OS package +if [[ "$USE_WHL" -eq 1 ]]; then + # Install the ROCm components from Python wheels. + echo "Using pip index URL: ${INDEX_URL}" + python3 -m pip install --no-build-isolation --index-url "$INDEX_URL" \ + "rocm[libraries,devel,device-${GPU_ARCH:-all}]" + rocm-sdk init + +else + pkg_refresh + ROCM_PKGS=( + "amdrocm-runtime${DEV_SUFFIX}${ROCM_VERSION}" + "amdrocm-blas${DEV_SUFFIX}${ROCM_VERSION}" + "amdrocm-blas-host${ROCM_VERSION}" + "amdrocm-dnn${DEV_SUFFIX}${ROCM_VERSION}" + "amdrocm-dnn-host${ROCM_VERSION}" + "amdrocm-hipblas-common${DEV_SUFFIX}${ROCM_VERSION}" + ) + + # --gpu set -> add the small "skinny" per-gfx packages. + # amdrocm-dnn- pulls the matching rocBLAS and solver device + # code transitively. + if [[ -n "$GPU_ARCH" ]]; then + echo "Adding skinny device-code packages for ${GPU_ARCH}" + ROCM_PKGS+=( + "amdrocm-blas${ROCM_VERSION}-${GPU_ARCH}" + "amdrocm-dnn${ROCM_VERSION}-${GPU_ARCH}" + ) + else + echo "No GPU architecture specified or detected; installing fat (all-architecture) ROCm device code" + ROCM_PKGS+=("amdrocm-core${ROCM_VERSION}") + fi + pkg_install "${ROCM_PKGS[@]}" + mkdir -p /opt/rocm + for d in bin lib libexec include share llvm amdgcn; do + ln -snf core-${ROCM_VERSION}/$d /opt/rocm/$d; + done +fi + +if [[ "$ROCM_ONLY" -eq 1 ]]; then + echo "ROCm is installed; skipping the remaining MIGraphX prerequisites" + exit 0 fi +# Install pipx from pip rather than the distro package. The distro pipx depends +# on python3-packaging, and a dpkg-owned copy of packaging cannot be uninstalled +# by pip when requirements-py.txt pins a different version. +pip3 install setuptools wheel pipx + +# Install apps to the global location so any user can run them. On SLES pipx +# runs under python 3.6 where pipx 0.16 has no --global flag; there the global +# locations are set through PIPX_HOME/PIPX_BIN_DIR (see tools/docker/sles.docker). +PIPX_GLOBAL_FLAG="--global" +if [[ "${ID}" == "sles" ]]; then + PIPX_GLOBAL_FLAG="" +fi + +pipx install ${PIPX_GLOBAL_FLAG} https://github.com/RadeonOpenCompute/rbuild/archive/master.tar.gz --include-deps + echo "Dependencies are installed at $PREFIX" # Install deps with rbuild rbuild prepare -d $PREFIX -s develop if [[ ("${ID}" != "sles") ]]; then -export CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=ON" -pip3 install -r $REQ_FILE_DIR/requirements-py.txt + export CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=ON" + pip3 install -r $REQ_FILE_DIR/requirements-py.txt fi diff --git a/tools/install_prereqs_legacy.sh b/tools/install_prereqs_legacy.sh new file mode 100755 index 00000000000..00d4301c266 --- /dev/null +++ b/tools/install_prereqs_legacy.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +##################################################################################### +# The MIT License (MIT) +# +# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +##################################################################################### +# +# Build MIGraphX prerequisites for docker container + +set -e + +export LC_ALL=C.UTF-8 +export LANG=C.UTF-8 + +source /etc/os-release + +# hipcc added as workaround for broken hip-dev package +if [[ ("${ID}" == "sles") ]]; then + zypper -n --gpg-auto-import-keys install -y \ + cmake \ + miopen-hip-devel \ + openmp-extras-devel \ + python3-devel \ + python3-pip \ + rocblas-devel \ + rocm-cmake \ + libgfortran5 \ + hipblas-devel \ + hipblaslt-devel +else + # Need pip3 and Python headers to build dependencies + apt update && apt install -y \ + cmake \ + libnuma-dev \ + miopen-hip-dev \ + openmp-extras \ + python3-dev \ + python3-pip \ + python3-venv \ + rocblas-dev \ + libgfortran5 \ + hipblas-dev \ + hipblaslt-dev \ + hipcc \ + rocm-cmake \ + rocm-llvm-dev \ + libtbb-dev +fi + + +# Needed for cmake to build various pip packages +pip3 install setuptools wheel + +# install rbuild to build dependencies +pip3 install https://github.com/RadeonOpenCompute/rbuild/archive/master.tar.gz + + +PREFIX=/usr/local +REQ_FILE_DIR="$(dirname -- "$0")" +if [ "$#" -ge 2 ]; then + PREFIX=$1 + cd $2 +elif [ "$#" -eq 1 ]; then + PREFIX=$1 +fi + +echo "Dependencies are installed at $PREFIX" + +# Install deps with rbuild +rbuild prepare -d $PREFIX -s develop + +if [[ ("${ID}" != "sles") ]]; then +export CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=ON" +pip3 install -r $REQ_FILE_DIR/requirements-py.txt +fi