-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add ROCM to the DGL build #3
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f8a99c1
Scripts for Hipifying DGL in place
GMNGeoffrey e60c8ed
Hipify source in place
GMNGeoffrey d327c3b
Check in original copies of hipified source
GMNGeoffrey 1be5063
Add ROCM to the DGL build
GMNGeoffrey bafd87b
Fix typo
GMNGeoffrey 9ef8479
Fix another typo
GMNGeoffrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# ROCm Module | ||
if(USE_ROCM) | ||
find_rocm(${USE_ROCM} REQUIRED) | ||
else(USE_ROCM) | ||
return() | ||
endif() | ||
|
||
###### Borrowed from MSHADOW project | ||
|
||
include(CheckCXXCompilerFlag) | ||
check_cxx_compiler_flag("-std=c++17" SUPPORT_CXX17) | ||
|
||
################################################################################################ | ||
# Config rocm compilation and append ROCm libraries to linker_libs | ||
# Usage: | ||
# dgl_config_rocm(linker_libs) | ||
macro(dgl_config_rocm linker_libs) | ||
if(NOT ROCM_FOUND) | ||
message(FATAL_ERROR "Cannot find ROCm.") | ||
endif() | ||
|
||
enable_language(HIP) | ||
|
||
add_definitions(-DDGL_USE_ROCM) | ||
# We need the newest stuff that isn't turned on by default yet | ||
add_definitions(-DHIP_ENABLE_WARP_SYNC_BUILTINS) | ||
|
||
list(APPEND ${linker_libs} | ||
hip::host | ||
roc::hipblas | ||
roc::hipsparse | ||
hip::hiprand) | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
####################################################### | ||
# Usage: | ||
# find_rocm(${USE_ROCM}) | ||
# | ||
# - When USE_ROCM=ON, use auto search | ||
# | ||
# Please use the CMAKE variable ROCM_HOME to set ROCm directory | ||
# | ||
# Provide variables: | ||
# | ||
# - ROCM_FOUND | ||
# | ||
|
||
macro(find_rocm use_rocm) | ||
# ROCM prints out a nonsense version here from | ||
# ROCmCMakeBuildToolsConfigVersion.cmake that is just going to confuse people | ||
find_package(ROCM REQUIRED) | ||
find_package_and_print_version(HIP REQUIRED) | ||
find_package_and_print_version(hipBLAS REQUIRED) | ||
find_package_and_print_version(hipRAND REQUIRED) | ||
find_package_and_print_version(hipSPARSE REQUIRED) | ||
endmacro(find_rocm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,47 @@ | ||
#!/bin/bash | ||
# Helper script to build dgl sparse libraries for PyTorch | ||
set -e | ||
set -euo pipefail | ||
|
||
mkdir -p build | ||
mkdir -p $BINDIR/dgl_sparse | ||
cd build | ||
SPARSE_BINDIR="${BINDIR}/dgl_sparse" | ||
SPARSE_SRCDIR="${SRCDIR}/dgl_sparse" | ||
mkdir -p "${SPARSE_BINDIR}/build" | ||
cd "${SPARSE_BINDIR}/build" | ||
|
||
if [ $(uname) = 'Darwin' ]; then | ||
CPSOURCE=*.dylib | ||
CPSOURCE=*.dylib | ||
else | ||
CPSOURCE=*.so | ||
CPSOURCE=*.so | ||
fi | ||
|
||
CMAKE_FLAGS="-DCUDA_TOOLKIT_ROOT_DIR=$CUDA_TOOLKIT_ROOT_DIR -DTORCH_CUDA_ARCH_LIST=$TORCH_CUDA_ARCH_LIST -DUSE_CUDA=$USE_CUDA -DEXTERNAL_DMLC_LIB_PATH=$EXTERNAL_DMLC_LIB_PATH" | ||
# CMake passes in the list of directories separated by spaces. Here we replace them with semicolons. | ||
CMAKE_FLAGS="$CMAKE_FLAGS -DDGL_INCLUDE_DIRS=${INCLUDEDIR// /;} -DDGL_BUILD_DIR=$BINDIR" | ||
echo $CMAKE_FLAGS | ||
declare -a CMAKE_FLAGS=( | ||
"-G${GENERATOR}" | ||
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" | ||
"-DCUDA_TOOLKIT_ROOT_DIR=${CUDA_TOOLKIT_ROOT_DIR}" | ||
"-DTORCH_CUDA_ARCH_LIST=${TORCH_CUDA_ARCH_LIST:-}" | ||
"-DUSE_CUDA=${USE_CUDA}" | ||
"-DUSE_ROCM=${USE_ROCM}" | ||
"-DEXTERNAL_DMLC_LIB_PATH=${EXTERNAL_DMLC_LIB_PATH:-}" | ||
# CMake passes in the list of directories separated by spaces. Here we | ||
# replace them with semicolons. | ||
"-DDGL_INCLUDE_DIRS=${INCLUDEDIR// /;}" | ||
"-DDGL_BUILD_DIR=${BINDIR}" | ||
) | ||
echo "DGL Sparse CMAKE_FLAGS: ${CMAKE_FLAGS[@]}" | ||
|
||
if [ $# -eq 0 ]; then | ||
$CMAKE_COMMAND $CMAKE_FLAGS .. | ||
make -j | ||
cp -v $CPSOURCE $BINDIR/dgl_sparse | ||
"${CMAKE_COMMAND}" "${CMAKE_FLAGS[@]}" "${SPARSE_SRCDIR}" | ||
cmake --build . | ||
# CPSOURCE deliberately unquoted to expand wildcard | ||
cp -v ${CPSOURCE} "${SPARSE_BINDIR}" | ||
else | ||
for PYTHON_INTERP in $@; do | ||
TORCH_VER=$($PYTHON_INTERP -c 'import torch; print(torch.__version__.split("+")[0])') | ||
mkdir -p $TORCH_VER | ||
cd $TORCH_VER | ||
$CMAKE_COMMAND $CMAKE_FLAGS -DPYTHON_INTERP=$PYTHON_INTERP ../.. | ||
make -j | ||
cp -v $CPSOURCE $BINDIR/dgl_sparse | ||
cd .. | ||
done | ||
for PYTHON_INTERP in "$@"; do | ||
TORCH_VER="$("${PYTHON_INTERP}" -c 'import torch; print(torch.__version__.split("+")[0])')" | ||
mkdir -p "${TORCH_VER}" | ||
cd "${TORCH_VER}" | ||
"${CMAKE_COMMAND}" "${CMAKE_FLAGS[@]}" -DPYTHON_INTERP="${PYTHON_INTERP}" "${SPARSE_SRCDIR}" | ||
cmake --build . | ||
# CPSOURCE deliberately unquoted to expand wildcard | ||
cp -v ${CPSOURCE} "${SPARSE_BINDIR}" | ||
cd .. | ||
done | ||
fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware we have a hip_add_library but I'm not sure if or when it is preferred over just add_library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, the HIP docs just use
add_library
: https://rocm.docs.amd.com/en/latest/conceptual/cmake-packages.html#using-hip-in-cmake. I can look intohip_add_library
, although this appears to work.