diff --git a/.jenkins/pytorch/build.sh b/.jenkins/pytorch/build.sh index 18538697f134..4e105821daeb 100755 --- a/.jenkins/pytorch/build.sh +++ b/.jenkins/pytorch/build.sh @@ -42,7 +42,7 @@ if [[ "$BUILD_ENVIRONMENT" == *rocm* ]]; then # This environment variable enabled HCC Optimizations that speed up the linking stage. # https://github.com/RadeonOpenCompute/hcc#hcc-with-thinlto-linking - # export KMTHINLTO=1 + export KMTHINLTO=1 sudo chown -R jenkins:jenkins /usr/local rm -rf "$(dirname "${BASH_SOURCE[0]}")/../../../pytorch_amd/" || true diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index 0518c089235a..ff096660945e 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt @@ -261,13 +261,24 @@ endif() # ---[ Caffe2 HIP sources. if(USE_ROCM) # Call again since Caffe2_HIP_INCLUDES is extended with ATen include dirs. - IF(BUILD_ATEN) - HIP_INCLUDE_DIRECTORIES(${Caffe2_HIP_INCLUDES}) - ENDIF() + if(BUILD_ATEN) + # Get Compile Definitions from the directory (FindHIP.CMake bug) + get_directory_property(MY_DEFINITIONS COMPILE_DEFINITIONS) + if(MY_DEFINITIONS) + foreach(_item ${MY_DEFINITIONS}) + LIST(APPEND HIP_HCC_FLAGS "-D${_item}") + endforeach() + endif() + + # Call again since Caffe2_HIP_INCLUDES is extended with ATen include dirs. + hip_include_directories(${Caffe2_HIP_INCLUDES}) + endif() IF(BUILD_CAFFE2) set_source_files_properties(${Caffe2_HIP_SRCS} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1) ENDIF() - hip_add_library(caffe2_hip ${Caffe2_HIP_SRCS}) + + # FindHIP.CMake checks if the SHARED flag is set and adds extra logic accordingly. + hip_add_library(caffe2_hip SHARED ${Caffe2_HIP_SRCS}) # Since PyTorch files contain HIP headers, these flags are required for the necessary definitions to be added. set_target_properties(caffe2_hip PROPERTIES COMPILE_FLAGS ${HIP_HIPCC_FLAGS}) diff --git a/cmake/public/LoadHIP.cmake b/cmake/public/LoadHIP.cmake index b3ee2ae9e72c..481f812852af 100644 --- a/cmake/public/LoadHIP.cmake +++ b/cmake/public/LoadHIP.cmake @@ -111,6 +111,8 @@ IF(HIP_FOUND) set(CMAKE_HIP_ARCHIVE_CREATE ${CMAKE_CXX_ARCHIVE_CREATE}) set(CMAKE_HIP_ARCHIVE_APPEND ${CMAKE_CXX_ARCHIVE_APPEND}) set(CMAKE_HIP_ARCHIVE_FINISH ${CMAKE_CXX_ARCHIVE_FINISH}) + SET(CMAKE_HCC_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) + SET(CMAKE_HCC_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) ### Remove setting of Flags when FindHIP.CMake PR #558 is accepted.### set(rocrand_DIR ${ROCRAND_PATH}/lib/cmake/rocrand) diff --git a/tools/amd_build/build_pytorch_amd.py b/tools/amd_build/build_pytorch_amd.py index ed7206f0bf6d..e9daea644e9c 100644 --- a/tools/amd_build/build_pytorch_amd.py +++ b/tools/amd_build/build_pytorch_amd.py @@ -1,4 +1,3 @@ -"""Requires the hipify-python.py script (https://github.com/ROCm-Developer-Tools/pyHIPIFY).""" import shutil import subprocess import os @@ -8,6 +7,7 @@ amd_build_dir = os.path.dirname(os.path.realpath(__file__)) proj_dir = os.path.dirname(os.path.dirname(amd_build_dir)) + includes = [ "aten/*", "torch/*" @@ -16,7 +16,7 @@ # List of operators currently disabled yaml_file = os.path.join(amd_build_dir, "disabled_features.yaml") -# Apply patch files. +# Apply patch files in place. patch_folder = os.path.join(amd_build_dir, "patches") for filename in os.listdir(os.path.join(amd_build_dir, "patches")): subprocess.Popen(["git", "apply", os.path.join(patch_folder, filename)], cwd=proj_dir) diff --git a/tools/setup_helpers/rocm.py b/tools/setup_helpers/rocm.py index 4aea4e5cdf18..8a049a05c2e7 100644 --- a/tools/setup_helpers/rocm.py +++ b/tools/setup_helpers/rocm.py @@ -1,5 +1,15 @@ -from .env import check_env_flag -# Check if ROCM is enabled -USE_ROCM = check_env_flag('USE_ROCM') -ROCM_HOME = "/opt/rocm" +import os +from .env import check_env_flag, check_negative_env_flag + +# Get ROCm Home Path +ROCM_HOME = os.getenv("ROCM_HOME", "/opt/rocm") ROCM_VERSION = "" +USE_ROCM = False + +# Check if ROCm disabled. +if check_negative_env_flag("USE_ROCM"): + USE_ROCM = False +else: + # If ROCM home exists or we explicitly enable ROCm + if os.path.exists(ROCM_HOME) or check_env_flag('USE_ROCM'): + USE_ROCM = True