Skip to content

Commit d6337fa

Browse files
committed
[ROCm] Hipify changes
- Add Hipify as a git submodule - Trigger hipify from cmake build - TP_USE_ROCM controls the trigger, which will be set to ON when building on ROCm
1 parent 1cd0ac3 commit d6337fa

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
[submodule "third_party/libnop"]
1212
path = third_party/libnop
1313
url = https://github.com/google/libnop.git
14+
[submodule "third_party/hipify"]
15+
path = third_party/hipify
16+
url = https://github.com/ROCmSoftwarePlatform/hipify-torch.git

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ include(Sanitize)
2121
# Misc checks to cope with various compiler modes.
2222
include(MiscCheck)
2323

24+
# ROCm related
25+
if (TP_USE_ROCM)
26+
include(Hipify)
27+
endif()
28+
2429
add_subdirectory(tensorpipe)
2530

2631
install(EXPORT TensorpipeTargets

cmake/Hipify.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) Facebook, Inc. and its affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# cmake file to trigger hipify
8+
9+
set(HIPIFY_SCRIPTS_DIR ${PROJECT_SOURCE_DIR}/tools/amd_build)
10+
set(HIPIFY_COMMAND
11+
${HIPIFY_SCRIPTS_DIR}/build_amd.py
12+
--project-directory ${PROJECT_SOURCE_DIR}
13+
--output-directory ${PROJECT_SOURCE_DIR}
14+
)
15+
16+
execute_process(
17+
COMMAND ${HIPIFY_COMMAND}
18+
RESULT_VARIABLE hipify_return_value
19+
)
20+
if (NOT hipify_return_value EQUAL 0)
21+
message(FATAL_ERROR "Failed to hipify files!")
22+
endif()
23+

cmake/Options.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ endmacro()
3131

3232
# TODO: Default to ON if CUDA available.
3333
option(TP_USE_CUDA "Enable support for CUDA tensors" OFF)
34+
option(TP_USE_ROCM "Enable support for ROCM tensors" OFF)
35+
36+
# if both TP_USE_CUDA and TP_USE_ROCM is set then break
37+
if(TP_USE_CUDA AND TP_USE_ROCM)
38+
message(FATAL_ERROR "Tensorpipe can be built either for CUDA or ROCm, TP_USE_CUDA and TP_USE_ROCM both are set, erroring out!!!!")
39+
endif()
3440

3541
# Optional features
3642
option(TP_BUILD_BENCHMARK "Build benchmarks" OFF)

tools/amd_build/build_amd.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) Facebook, Inc. and its affiliates.
4+
# All rights reserved.
5+
#
6+
# This source code is licensed under the BSD-style license found in the
7+
# LICENSE file in the root directory of this source tree.
8+
9+
import os
10+
import sys
11+
import argparse
12+
13+
sys.path.append(os.path.realpath(os.path.join(
14+
os.path.dirname(__file__),
15+
os.path.pardir,
16+
os.path.pardir,
17+
'third_party')))
18+
19+
from hipify import hipify_python
20+
21+
parser = argparse.ArgumentParser(description='Top-level script for HIPifying, filling in most common parameters')
22+
parser.add_argument(
23+
'--project-directory',
24+
type=str,
25+
help="The root of the project. (default: %(default)s)",
26+
required=True)
27+
28+
parser.add_argument(
29+
'--output-directory',
30+
type=str,
31+
help="The Directory to Store the Hipified Project",
32+
required=True)
33+
34+
args = parser.parse_args()
35+
36+
includes = [
37+
'*'
38+
]
39+
40+
ignores = [
41+
]
42+
43+
# capturing the return value which is a dict[filename]:HipifyResult
44+
HipifyFinalResult = hipify_python.hipify(
45+
project_directory=args.project_directory,
46+
output_directory=args.output_directory,
47+
includes=includes,
48+
ignores=ignores,
49+
is_pytorch_extension=True)

0 commit comments

Comments
 (0)