From 383a20e05ab871f8951fb1a5867e5a8b7ddaacee Mon Sep 17 00:00:00 2001 From: Jithun Nair Date: Wed, 9 Oct 2024 05:22:48 +0000 Subject: [PATCH 1/2] Update aotriton.cmake for release/2.4 --- cmake/External/aotriton.cmake | 80 +++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/cmake/External/aotriton.cmake b/cmake/External/aotriton.cmake index 8c2984ae9e9c1..8714f449f5653 100644 --- a/cmake/External/aotriton.cmake +++ b/cmake/External/aotriton.cmake @@ -1,38 +1,74 @@ if(NOT __AOTRITON_INCLUDED) set(__AOTRITON_INCLUDED TRUE) - set(__AOTRITON_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/aotriton/src") - set(__AOTRITON_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/aotriton/build") + set(__AOTRITON_EXTERN_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/aotriton") set(__AOTRITON_INSTALL_DIR "${PROJECT_SOURCE_DIR}/torch") add_library(__caffe2_aotriton INTERFACE) + + # AOTriton package information from GitHub Release Pages + # Replaces .ci/docker/aotriton_version.txt + set(__AOTRITON_VER "0.7.1b") + set(__AOTRITON_MANYLINUX_LIST + "manylinux_2_17" # rocm6.2 + "manylinux_2_28" # rocm6.3 + ) + set(__AOTRITON_ROCM_LIST + "rocm6.2" + "rocm6.3" + ) + message("JN: ${__AOTRITON_ROCM_LIST}") + set(__AOTRITON_CI_COMMIT "99f540a954e80f446ec6980f108e8c25408f1823") + set(__AOTRITON_SHA256_LIST + "df00412ae36fe5732d0a4601802bd3622b5dec12df7ec86027c5147adeb54c25" # rocm6.2 + "e4e3b06d2431e68e0096fcc8d3668cd5034ca0fd6fe236fb3b96774427d934b8" # rocm6.3 + ) + set(__AOTRITON_Z "gz") + # Note it is INSTALL"ED" if(DEFINED ENV{AOTRITON_INSTALLED_PREFIX}) + install(DIRECTORY + $ENV{AOTRITON_INSTALLED_PREFIX}/lib + $ENV{AOTRITON_INSTALLED_PREFIX}/include + DESTINATION ${__AOTRITON_INSTALL_DIR}) set(__AOTRITON_INSTALL_DIR "$ENV{AOTRITON_INSTALLED_PREFIX}") message(STATUS "Using Preinstalled AOTriton at ${__AOTRITON_INSTALL_DIR}") else() - file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/.ci/docker/aotriton_version.txt" __AOTRITON_CI_INFO) - list(GET __AOTRITON_CI_INFO 3 __AOTRITON_CI_COMMIT) + list(GET __AOTRITON_ROCM_LIST 0 __AOTRITON_ROCM_LOW_STR) + list(GET __AOTRITON_ROCM_LIST -1 __AOTRITON_ROCM_HIGH_STR) + # len("rocm") == 4 + string(SUBSTRING ${__AOTRITON_ROCM_LOW_STR} 4 -1 __AOTRITON_ROCM_LOW) + string(SUBSTRING ${__AOTRITON_ROCM_HIGH_STR} 4 -1 __AOTRITON_ROCM_HIGH) + set(__AOTRITON_SYSTEM_ROCM "${ROCM_VERSION_DEV_MAJOR}.${ROCM_VERSION_DEV_MINOR}") + if(__AOTRITON_SYSTEM_ROCM VERSION_LESS __AOTRITON_ROCM_LOW) + set(__AOTRITON_ROCM ${__AOTRITON_ROCM_LOW}) + elseif(__AOTRITON_SYSTEM_ROCM VERSION_GREATER __AOTRITON_ROCM_HIGH) + set(__AOTRITON_ROCM ${__AOTRITON_ROCM_HIGH}) + else() + set(__AOTRITON_ROCM ${__AOTRITON_SYSTEM_ROCM}) + endif() + list(FIND __AOTRITON_ROCM_LIST "rocm${__AOTRITON_ROCM}" __AOTRITON_ROCM_INDEX) + list(GET __AOTRITON_SHA256_LIST ${__AOTRITON_ROCM_INDEX} __AOTRITON_SHA256) + list(GET __AOTRITON_MANYLINUX_LIST ${__AOTRITON_ROCM_INDEX} __AOTRITON_MANYLINUX) + set(__AOTRITON_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR}) + string(CONCAT __AOTRITON_FILE "aotriton-" + "${__AOTRITON_VER}-${__AOTRITON_MANYLINUX}" + "_${__AOTRITON_ARCH}-rocm${__AOTRITON_ROCM}" + "-shared.tar.${__AOTRITON_Z}") + string(CONCAT __AOTRITON_URL "https://github.com/ROCm/aotriton/releases/download/" + "${__AOTRITON_VER}/${__AOTRITON_FILE}") ExternalProject_Add(aotriton_external - GIT_REPOSITORY https://github.com/ROCm/aotriton.git - GIT_TAG ${__AOTRITON_CI_COMMIT} - SOURCE_DIR ${__AOTRITON_SOURCE_DIR} - BINARY_DIR ${__AOTRITON_BUILD_DIR} - PREFIX ${__AOTRITON_INSTALL_DIR} - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${__AOTRITON_INSTALL_DIR} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DAOTRITON_NO_PYTHON=ON - -DAOTRITON_NO_SHARED=OFF - # CONFIGURE_COMMAND "" - BUILD_COMMAND "" # No build, install command will repeat the build process due to problems in the build system. + URL "${__AOTRITON_URL}" + URL_HASH SHA256=${__AOTRITON_SHA256} + SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/aotriton_tarball + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_BINARY_DIR}/aotriton_tarball" + "${__AOTRITON_INSTALL_DIR}" BUILD_BYPRODUCTS "${__AOTRITON_INSTALL_DIR}/lib/libaotriton_v2.so" - USES_TERMINAL_DOWNLOAD TRUE - USES_TERMINAL_CONFIGURE TRUE - USES_TERMINAL_BUILD TRUE - USES_TERMINAL_INSTALL TRUE - # INSTALL_COMMAND ${MAKE_COMMAND} install - ) + ) add_dependencies(__caffe2_aotriton aotriton_external) - message(STATUS "Using AOTriton compiled from source directory ${__AOTRITON_SOURCE_DIR}") + message(STATUS "Using AOTriton from pre-compiled binary ${__AOTRITON_URL}") endif() target_link_libraries(__caffe2_aotriton INTERFACE ${__AOTRITON_INSTALL_DIR}/lib/libaotriton_v2.so) target_include_directories(__caffe2_aotriton INTERFACE ${__AOTRITON_INSTALL_DIR}/include) From c30d565bdde8592331f374c3bc9de3fffc157f97 Mon Sep 17 00:00:00 2001 From: Jithun Nair Date: Tue, 8 Oct 2024 05:44:46 +0000 Subject: [PATCH 2/2] AOTriton: download binary from github, NO BUILD FROM SOURCE option Fix tarball's suffix Read rocm version from variables set by LoadHIP.cmake Copy AOTRITON_INSTALLED_PREFIX/* to torch/ Otherwise bdist_wheel will miss libaotriton_v2.so Fix problems in aotriton.cmake Guard against new ROCM environment This also updates aotriton_version.txt's format Supply ROCM versions and SHA256 checksums as lists. Let install_aotriton.sh parse the new format of aotriton_version.txt Do not hardcode __AOTRITON_ARCH Updates to aotriton build steps and Dockerfiles (#1599) Changes cherry-picked from pytorch#137443 --- .ci/docker/aotriton_version.txt | 5 ----- .ci/docker/centos-rocm/Dockerfile | 7 ------- .ci/docker/common/install_aotriton.sh | 21 --------------------- .ci/docker/ubuntu-rocm/Dockerfile | 7 ------- 4 files changed, 40 deletions(-) delete mode 100644 .ci/docker/aotriton_version.txt delete mode 100755 .ci/docker/common/install_aotriton.sh diff --git a/.ci/docker/aotriton_version.txt b/.ci/docker/aotriton_version.txt deleted file mode 100644 index 1869c01146123..0000000000000 --- a/.ci/docker/aotriton_version.txt +++ /dev/null @@ -1,5 +0,0 @@ -0.7.1b -manylinux_2_17 -rocm6.2 -f6b28a9b7265b69e3df54ea6ba0237e8a8d6f736 -df00412ae36fe5732d0a4601802bd3622b5dec12df7ec86027c5147adeb54c25 diff --git a/.ci/docker/centos-rocm/Dockerfile b/.ci/docker/centos-rocm/Dockerfile index 9ef063e7e851e..e5a23c0509689 100644 --- a/.ci/docker/centos-rocm/Dockerfile +++ b/.ci/docker/centos-rocm/Dockerfile @@ -115,13 +115,6 @@ COPY triton_version.txt triton_version.txt RUN if [ -n "${TRITON}" ]; then bash ./install_triton.sh; fi RUN rm install_triton.sh common_utils.sh triton-rocm.txt triton_version.txt -# Install AOTriton (Early fail) -COPY ./aotriton_version.txt aotriton_version.txt -COPY ./common/common_utils.sh common_utils.sh -COPY ./common/install_aotriton.sh install_aotriton.sh -RUN ["/bin/bash", "-c", "./install_aotriton.sh /opt/rocm && rm -rf install_aotriton.sh aotriton_version.txt common_utils.sh"] -ENV AOTRITON_INSTALLED_PREFIX /opt/rocm/aotriton - # Install ccache/sccache (do this last, so we get priority in PATH) COPY ./common/install_cache.sh install_cache.sh ENV PATH /opt/cache/bin:$PATH diff --git a/.ci/docker/common/install_aotriton.sh b/.ci/docker/common/install_aotriton.sh deleted file mode 100755 index ebf09e1e74608..0000000000000 --- a/.ci/docker/common/install_aotriton.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -set -ex - -TARBALL='aotriton.tar.gz' -# This read command alwasy returns with exit code 1 -read -d "\n" VER MANYLINUX ROCMBASE PINNED_COMMIT SHA256 < aotriton_version.txt || true -ARCH=$(uname -m) -AOTRITON_INSTALL_PREFIX="$1" -AOTRITON_URL="https://github.com/ROCm/aotriton/releases/download/${VER}/aotriton-${VER}-${MANYLINUX}_${ARCH}-${ROCMBASE}-shared.tar.gz" - -cd "${AOTRITON_INSTALL_PREFIX}" -# Must use -L to follow redirects -curl -L --retry 3 -o "${TARBALL}" "${AOTRITON_URL}" -ACTUAL_SHA256=$(sha256sum "${TARBALL}" | cut -d " " -f 1) -if [ "${SHA256}" != "${ACTUAL_SHA256}" ]; then - echo -n "Error: The SHA256 of downloaded tarball is ${ACTUAL_SHA256}," - echo " which does not match the expected value ${SHA256}." - exit -fi -tar xf "${TARBALL}" && rm -rf "${TARBALL}" diff --git a/.ci/docker/ubuntu-rocm/Dockerfile b/.ci/docker/ubuntu-rocm/Dockerfile index ee9ede8ba611b..cc43d9ec24142 100644 --- a/.ci/docker/ubuntu-rocm/Dockerfile +++ b/.ci/docker/ubuntu-rocm/Dockerfile @@ -105,13 +105,6 @@ COPY triton_version.txt triton_version.txt RUN if [ -n "${TRITON}" ]; then bash ./install_triton.sh; fi RUN rm install_triton.sh common_utils.sh triton-rocm.txt triton_version.txt -# Install AOTriton -COPY ./aotriton_version.txt aotriton_version.txt -COPY ./common/common_utils.sh common_utils.sh -COPY ./common/install_aotriton.sh install_aotriton.sh -RUN ["/bin/bash", "-c", "./install_aotriton.sh /opt/rocm && rm -rf install_aotriton.sh aotriton_version.txt common_utils.sh"] -ENV AOTRITON_INSTALLED_PREFIX /opt/rocm/aotriton - # Install ccache/sccache (do this last, so we get priority in PATH) COPY ./common/install_cache.sh install_cache.sh ENV PATH /opt/cache/bin:$PATH