Skip to content

Fix the PyTorch HIP Build Configuration #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .jenkins/pytorch/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 2 additions & 0 deletions cmake/public/LoadHIP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tools/amd_build/build_pytorch_amd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""Requires the hipify-python.py script (https://github.com/ROCm-Developer-Tools/pyHIPIFY)."""
import shutil
import subprocess
import os
Expand All @@ -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/*"
Expand All @@ -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)
Expand Down
18 changes: 14 additions & 4 deletions tools/setup_helpers/rocm.py
Original file line number Diff line number Diff line change
@@ -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