Skip to content
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
4 changes: 2 additions & 2 deletions caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ if(USE_ROCM)
hip_add_library(caffe2_hip ${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})
target_compile_options(caffe2_hip PRIVATE ${HIP_HIPCC_FLAGS})
target_link_libraries(caffe2_hip PUBLIC caffe2)
target_link_libraries(caffe2_hip PUBLIC ${Caffe2_HIP_DEPENDENCY_LIBS})

Expand Down Expand Up @@ -550,7 +550,7 @@ if (BUILD_PYTHON)
if(USE_ROCM)
hip_add_library(caffe2_pybind11_state_hip MODULE ${Caffe2_HIP_PYTHON_SRCS})
set_target_properties(caffe2_pybind11_state_hip PROPERTIES LINKER_LANGUAGE HIP)
set_target_properties(caffe2_pybind11_state_hip PROPERTIES COMPILE_FLAGS "${HIP_HIPCC_FLAGS} -fvisibility=hidden")
target_compile_options(caffe2_pybind11_state_hip PRIVATE ${HIP_HIPCC_FLAGS} -fvisibility=hidden)
set_target_properties(caffe2_pybind11_state_hip PROPERTIES PREFIX "")
set_target_properties(caffe2_pybind11_state_hip PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
if (APPLE)
Expand Down
24 changes: 12 additions & 12 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -523,18 +523,18 @@ if(NOT BUILD_ATEN_MOBILE)
message(INFO "Compiling with HIP for AMD.")
caffe2_update_option(USE_ROCM ON)

set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -fPIC")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -D__HIP_PLATFORM_HCC__=1")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -DCUDA_HAS_FP16=1")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -D__HIP_NO_HALF_OPERATORS__=1")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -D__HIP_NO_HALF_CONVERSIONS__=1")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -Wno-macro-redefined")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -Wno-inconsistent-missing-override")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -Wno-exceptions")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -Wno-shift-count-negative")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -Wno-shift-count-overflow")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -Wno-unused-command-line-argument")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -Wno-duplicate-decl-specifier")
list(APPEND HIP_HIPCC_FLAGS -fPIC)
list(APPEND HIP_HIPCC_FLAGS -D__HIP_PLATFORM_HCC__=1)
list(APPEND HIP_HIPCC_FLAGS -DCUDA_HAS_FP16=1)
list(APPEND HIP_HIPCC_FLAGS -D__HIP_NO_HALF_OPERATORS__=1)
list(APPEND HIP_HIPCC_FLAGS -D__HIP_NO_HALF_CONVERSIONS__=1)
list(APPEND HIP_HIPCC_FLAGS -Wno-macro-redefined)
list(APPEND HIP_HIPCC_FLAGS -Wno-inconsistent-missing-override)
list(APPEND HIP_HIPCC_FLAGS -Wno-exceptions)
list(APPEND HIP_HIPCC_FLAGS -Wno-shift-count-negative)
list(APPEND HIP_HIPCC_FLAGS -Wno-shift-count-overflow)
list(APPEND HIP_HIPCC_FLAGS -Wno-unused-command-line-argument)
list(APPEND HIP_HIPCC_FLAGS -Wno-duplicate-decl-specifier)

set(Caffe2_HIP_INCLUDES
${hip_INCLUDE_DIRS} ${hcc_INCLUDE_DIRS} ${hsa_INCLUDE_DIRS} ${rocrand_INCLUDE_DIRS} ${hiprand_INCLUDE_DIRS} ${rocblas_INCLUDE_DIRS} ${miopen_INCLUDE_DIRS} ${thrust_INCLUDE_DIRS} $<INSTALL_INTERFACE:include> ${Caffe2_HIP_INCLUDES})
Expand Down
41 changes: 32 additions & 9 deletions cmake/public/LoadHIP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ ELSE()
SET(ROCRAND_PATH $ENV{ROCRAND_PATH})
ENDIF()

# MIOPENGEMM
IF(NOT DEFINED ENV{MIOPENGEMM_PATH})
SET(MIOPENGEMM_PATH ${ROCM_PATH}/miopengemm)
ELSE()
SET(MIOPENGEMM_PATH $ENV{MIOPENGEMM_PATH})
ENDIF()

# MIOPEN_PATH
IF(NOT DEFINED ENV{MIOPEN_PATH})
SET(MIOPEN_PATH ${ROCM_PATH}/miopen)
Expand All @@ -96,8 +103,23 @@ set(CMAKE_MODULE_PATH ${HIP_PATH}/cmake ${CMAKE_MODULE_PATH})
# Disable Asserts In Code (Can't use asserts on HIP stack.)
ADD_DEFINITIONS(-DNDEBUG)

macro(find_package_and_print_version PACKAGE_NAME)
find_package("${PACKAGE_NAME}" ${ARGN})
message("${PACKAGE_NAME} VERSION: ${${PACKAGE_NAME}_VERSION}")
endmacro()

message("\n***** Library versions from dpkg *****\n")
execute_process(COMMAND dpkg -l COMMAND grep rocm-dev COMMAND awk "{print $2 \" VERSION: \" $3}")
execute_process(COMMAND dpkg -l COMMAND grep rocm-libs COMMAND awk "{print $2 \" VERSION: \" $3}")
execute_process(COMMAND dpkg -l COMMAND grep hsakmt-roct COMMAND awk "{print $2 \" VERSION: \" $3}")
execute_process(COMMAND dpkg -l COMMAND grep rocr-dev COMMAND awk "{print $2 \" VERSION: \" $3}")
execute_process(COMMAND dpkg -l COMMAND grep -w hcc COMMAND awk "{print $2 \" VERSION: \" $3}")
execute_process(COMMAND dpkg -l COMMAND grep hip_base COMMAND awk "{print $2 \" VERSION: \" $3}")
execute_process(COMMAND dpkg -l COMMAND grep hip_hcc COMMAND awk "{print $2 \" VERSION: \" $3}")

message("\n***** Library versions from cmake find_package *****\n")
# Find the HIP Package
FIND_PACKAGE(HIP 1.0)
find_package_and_print_version(HIP 1.0)

IF(HIP_FOUND)
set(PYTORCH_FOUND_HIP TRUE)
Expand All @@ -118,19 +140,20 @@ IF(HIP_FOUND)
set(rocrand_DIR ${ROCRAND_PATH}/lib/cmake/rocrand)
set(hiprand_DIR ${HIPRAND_PATH}/lib/cmake/hiprand)
set(rocblas_DIR ${ROCBLAS_PATH}/lib/cmake/rocblas)
set(miopengemm_DIR ${MIOPENGEMM_PATH}/lib/cmake/miopengemm)
set(miopen_DIR ${MIOPEN_PATH}/lib/cmake/miopen)
set(rocblas_DIR ${ROCBLAS_PATH}/lib/cmake/rocblas)
set(rocfft_DIR ${ROCFFT_PATH}/lib/cmake/rocfft)
set(hipsparse_DIR ${HIPSPARSE_PATH}/lib/cmake/hipsparse)
set(rocsparse_DIR ${ROCSPARSE_PATH}/lib/cmake/rocsparse)

find_package(rocrand REQUIRED)
find_package(hiprand REQUIRED)
find_package(rocblas REQUIRED)
find_package(rocfft REQUIRED)
find_package(miopen REQUIRED)
#find_package(rocsparse REQUIRED)
#find_package(hipsparse REQUIRED)
find_package_and_print_version(rocrand REQUIRED)
find_package_and_print_version(hiprand REQUIRED)
find_package_and_print_version(rocblas REQUIRED)
find_package_and_print_version(miopen REQUIRED)
find_package_and_print_version(miopengemm REQUIRED)
find_package_and_print_version(rocfft REQUIRED)
#find_package_and_print_version(hipsparse REQUIRED)
find_package_and_print_version(rocsparse REQUIRED)

# TODO: hip_hcc has an interface include flag "-hc" which is only
# recognizable by hcc, but not gcc and clang. Right now in our
Expand Down
56 changes: 8 additions & 48 deletions docker/caffe2/jenkins/common/install_rocm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ install_ubuntu() {
apt-get install -y wget
apt-get install -y libopenblas-dev

DEB_ROCM_REPO=http://repo.radeon.com/rocm/apt/debian
DEB_ROCM_REPO=http://repo.radeon.com/rocm/misc/facebook/apt/.apt_1.9.white_rabbit/debian
# Add rocm repository
wget -qO - $DEB_ROCM_REPO/rocm.gpg.key | apt-key add -
echo "deb [arch=amd64] $DEB_ROCM_REPO xenial main" > /etc/apt/sources.list.d/rocm.list
Expand All @@ -22,15 +22,12 @@ install_ubuntu() {
miopengemm \
rocblas \
rocm-profiler \
cxlactivitylogger
cxlactivitylogger \
rocsparse \
hipsparse \
rocrand \
hip-thrust

# hotfix a bug in hip's cmake files, this has been fixed in
# https://github.com/ROCm-Developer-Tools/HIP/pull/516 but for
# some reason it has not included in the latest rocm release
if [[ -f /opt/rocm/hip/cmake/FindHIP.cmake ]]; then
sudo sed -i 's/\ -I${dir}/\ $<$<BOOL:${dir}>:-I${dir}>/' /opt/rocm/hip/cmake/FindHIP.cmake
fi

# HIP has a bug that drops DEBUG symbols in generated MakeFiles.
# https://github.com/ROCm-Developer-Tools/HIP/pull/588
if [[ -f /opt/rocm/hip/cmake/FindHIP.cmake ]]; then
Expand All @@ -45,47 +42,13 @@ install_centos() {

install_hip_thrust() {
# Needed for now, will be replaced soon
# We are now (redundantly) installing the Thrust package into another location (/opt/rocm/include/thrust) which we will
# switch over to
git clone --recursive https://github.com/ROCmSoftwarePlatform/Thrust.git /data/Thrust
rm -rf /data/Thrust/thrust/system/cuda/detail/cub-hip
git clone --recursive https://github.com/ROCmSoftwarePlatform/cub-hip.git /data/Thrust/thrust/system/cuda/detail/cub-hip
}

# Install an updated version of rocRand that's PyTorch compatible.
install_rocrand() {
mkdir -p /opt/rocm/debians
curl https://s3.amazonaws.com/ossci-linux/rocrand-1.8.0-Linux.deb -o /opt/rocm/debians/rocrand.deb
dpkg -i /opt/rocm/debians/rocrand.deb
}

# Install rocSPARSE/hipSPARSE that will be released soon - can co-exist w/ hcSPARSE which will be removed soon
install_hipsparse() {
mkdir -p /opt/rocm/debians
curl https://s3.amazonaws.com/ossci-linux/rocsparse-0.1.2.114-Linux.deb -o /opt/rocm/debians/rocsparse.deb
curl https://s3.amazonaws.com/ossci-linux/hipsparse-0.1.2.55-Linux.deb -o /opt/rocm/debians/hipsparse.deb
dpkg -i /opt/rocm/debians/rocsparse.deb
dpkg -i /opt/rocm/debians/hipsparse.deb
}

# Install custom hcc containing two compiler fixes relevant to PyTorch
install_customhcc() {
HIP_VERSION="1.5.18354"
mkdir -p /opt/rocm/debians
curl https://s3.amazonaws.com/ossci-linux/hcc-1.2.18272-Linux.deb -o /opt/rocm/debians/hcc-Linux.deb
curl "https://s3.amazonaws.com/ossci-linux/hip_base-$HIP_VERSION.deb" -o /opt/rocm/debians/hip_base.deb
curl "https://s3.amazonaws.com/ossci-linux/hip_doc-$HIP_VERSION.deb" -o /opt/rocm/debians/hip_doc.deb
curl "https://s3.amazonaws.com/ossci-linux/hip_samples-$HIP_VERSION.deb" -o /opt/rocm/debians/hip_samples.deb
curl "https://s3.amazonaws.com/ossci-linux/hip_hcc-$HIP_VERSION.deb" -o /opt/rocm/debians/hip_hcc.deb
dpkg -i /opt/rocm/debians/hcc-Linux.deb
dpkg -i /opt/rocm/debians/hip_base.deb
dpkg -i /opt/rocm/debians/hip_doc.deb
dpkg -i /opt/rocm/debians/hip_samples.deb
dpkg -i /opt/rocm/debians/hip_hcc.deb

if [[ -f /opt/rocm/hip/cmake/FindHIP.cmake ]]; then
sudo sed -i 's/\ -I${dir}/\ $<$<BOOL:${dir}>:-I${dir}>/' /opt/rocm/hip/cmake/FindHIP.cmake
fi
}

# Install Python packages depending on the base OS
if [ -f /etc/lsb-release ]; then
install_ubuntu
Expand All @@ -97,6 +60,3 @@ else
fi

install_hip_thrust
install_rocrand
install_hipsparse
install_customhcc
4 changes: 4 additions & 0 deletions test/test_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ def test_growing_dataset(self):
self.assertEqual(len(dataloader_shuffle), 5)

@unittest.skipIf(not TEST_CUDA, "CUDA unavailable")
@skipIfRocm
def test_sequential_pin_memory(self):
loader = DataLoader(self.dataset, batch_size=2, pin_memory=True)
for input, target in loader:
Expand Down Expand Up @@ -575,6 +576,7 @@ def test_batch_sampler(self):
self._test_batch_sampler(num_workers=4)

@unittest.skipIf(not TEST_CUDA, "CUDA unavailable")
@skipIfRocm
def test_shuffle_pin_memory(self):
loader = DataLoader(self.dataset, batch_size=2, shuffle=True, num_workers=4, pin_memory=True)
for input, target in loader:
Expand Down Expand Up @@ -809,6 +811,7 @@ def setUp(self):
self.dataset = StringDataset()

@unittest.skipIf(not TEST_CUDA, "CUDA unavailable")
@skipIfRocm
def test_shuffle_pin_memory(self):
loader = DataLoader(self.dataset, batch_size=2, shuffle=True, num_workers=4, pin_memory=True)
for batch_ndx, (s, n) in enumerate(loader):
Expand Down Expand Up @@ -852,6 +855,7 @@ def test_sequential_batch(self):
self.assertEqual(n[1], idx + 1)

@unittest.skipIf(not TEST_CUDA, "CUDA unavailable")
@skipIfRocm
def test_pin_memory(self):
loader = DataLoader(self.dataset, batch_size=2, pin_memory=True)
for batch_ndx, sample in enumerate(loader):
Expand Down
1 change: 1 addition & 0 deletions test/test_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8201,6 +8201,7 @@ def test_empty_like(self):
self.assertEqual(torch.empty_like(a).type(), a.type())

@unittest.skipIf(not torch.cuda.is_available(), 'no CUDA')
@skipIfRocm
def test_pin_memory(self):
x = torch.randn(3, 5)
self.assertFalse(x.is_pinned())
Expand Down