From d6337fac4a7017547d55cbffd19d976ba8068efd Mon Sep 17 00:00:00 2001 From: Pruthvi Madugundu Date: Thu, 24 Jun 2021 00:07:42 -0700 Subject: [PATCH 1/4] [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 --- .gitmodules | 3 +++ CMakeLists.txt | 5 ++++ cmake/Hipify.cmake | 23 +++++++++++++++++ cmake/Options.cmake | 6 +++++ tools/amd_build/build_amd.py | 49 ++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 cmake/Hipify.cmake create mode 100755 tools/amd_build/build_amd.py diff --git a/.gitmodules b/.gitmodules index 7207ef9b6..0777fa968 100644 --- a/.gitmodules +++ b/.gitmodules @@ -11,3 +11,6 @@ [submodule "third_party/libnop"] path = third_party/libnop url = https://github.com/google/libnop.git +[submodule "third_party/hipify"] + path = third_party/hipify + url = https://github.com/ROCmSoftwarePlatform/hipify-torch.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 640054ee3..8342e13de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,11 @@ include(Sanitize) # Misc checks to cope with various compiler modes. include(MiscCheck) +# ROCm related +if (TP_USE_ROCM) + include(Hipify) +endif() + add_subdirectory(tensorpipe) install(EXPORT TensorpipeTargets diff --git a/cmake/Hipify.cmake b/cmake/Hipify.cmake new file mode 100644 index 000000000..af132961a --- /dev/null +++ b/cmake/Hipify.cmake @@ -0,0 +1,23 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# cmake file to trigger hipify + +set(HIPIFY_SCRIPTS_DIR ${PROJECT_SOURCE_DIR}/tools/amd_build) +set(HIPIFY_COMMAND + ${HIPIFY_SCRIPTS_DIR}/build_amd.py + --project-directory ${PROJECT_SOURCE_DIR} + --output-directory ${PROJECT_SOURCE_DIR} +) + +execute_process( + COMMAND ${HIPIFY_COMMAND} + RESULT_VARIABLE hipify_return_value +) +if (NOT hipify_return_value EQUAL 0) + message(FATAL_ERROR "Failed to hipify files!") +endif() + diff --git a/cmake/Options.cmake b/cmake/Options.cmake index 10e09c94e..4a6da4458 100644 --- a/cmake/Options.cmake +++ b/cmake/Options.cmake @@ -31,6 +31,12 @@ endmacro() # TODO: Default to ON if CUDA available. option(TP_USE_CUDA "Enable support for CUDA tensors" OFF) +option(TP_USE_ROCM "Enable support for ROCM tensors" OFF) + +# if both TP_USE_CUDA and TP_USE_ROCM is set then break +if(TP_USE_CUDA AND TP_USE_ROCM) + message(FATAL_ERROR "Tensorpipe can be built either for CUDA or ROCm, TP_USE_CUDA and TP_USE_ROCM both are set, erroring out!!!!") +endif() # Optional features option(TP_BUILD_BENCHMARK "Build benchmarks" OFF) diff --git a/tools/amd_build/build_amd.py b/tools/amd_build/build_amd.py new file mode 100755 index 000000000..d5b36755b --- /dev/null +++ b/tools/amd_build/build_amd.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +# Copyright (c) Facebook, Inc. and its affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +import os +import sys +import argparse + +sys.path.append(os.path.realpath(os.path.join( + os.path.dirname(__file__), + os.path.pardir, + os.path.pardir, + 'third_party'))) + +from hipify import hipify_python + +parser = argparse.ArgumentParser(description='Top-level script for HIPifying, filling in most common parameters') +parser.add_argument( + '--project-directory', + type=str, + help="The root of the project. (default: %(default)s)", + required=True) + +parser.add_argument( + '--output-directory', + type=str, + help="The Directory to Store the Hipified Project", + required=True) + +args = parser.parse_args() + +includes = [ + '*' +] + +ignores = [ +] + +# capturing the return value which is a dict[filename]:HipifyResult +HipifyFinalResult = hipify_python.hipify( + project_directory=args.project_directory, + output_directory=args.output_directory, + includes=includes, + ignores=ignores, + is_pytorch_extension=True) From 528bcacaa07fcbef614b0ffe55ef1d1e77e4b576 Mon Sep 17 00:00:00 2001 From: Pruthvi Madugundu Date: Mon, 19 Jul 2021 12:00:07 -0700 Subject: [PATCH 2/4] Hipify related files moved to hipify-torch repo --- CMakeLists.txt | 2 +- cmake/Hipify.cmake | 23 ----------------- tools/amd_build/build_amd.py | 49 ------------------------------------ 3 files changed, 1 insertion(+), 73 deletions(-) delete mode 100644 cmake/Hipify.cmake delete mode 100755 tools/amd_build/build_amd.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 8342e13de..865830f3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ project(tensorpipe LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 14) -list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${PROJECT_SOURCE_DIR}/third_party/hipify/cmake") # Expose build options. include(Options) diff --git a/cmake/Hipify.cmake b/cmake/Hipify.cmake deleted file mode 100644 index af132961a..000000000 --- a/cmake/Hipify.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) Facebook, Inc. and its affiliates. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. - -# cmake file to trigger hipify - -set(HIPIFY_SCRIPTS_DIR ${PROJECT_SOURCE_DIR}/tools/amd_build) -set(HIPIFY_COMMAND - ${HIPIFY_SCRIPTS_DIR}/build_amd.py - --project-directory ${PROJECT_SOURCE_DIR} - --output-directory ${PROJECT_SOURCE_DIR} -) - -execute_process( - COMMAND ${HIPIFY_COMMAND} - RESULT_VARIABLE hipify_return_value -) -if (NOT hipify_return_value EQUAL 0) - message(FATAL_ERROR "Failed to hipify files!") -endif() - diff --git a/tools/amd_build/build_amd.py b/tools/amd_build/build_amd.py deleted file mode 100755 index d5b36755b..000000000 --- a/tools/amd_build/build_amd.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) Facebook, Inc. and its affiliates. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. - -import os -import sys -import argparse - -sys.path.append(os.path.realpath(os.path.join( - os.path.dirname(__file__), - os.path.pardir, - os.path.pardir, - 'third_party'))) - -from hipify import hipify_python - -parser = argparse.ArgumentParser(description='Top-level script for HIPifying, filling in most common parameters') -parser.add_argument( - '--project-directory', - type=str, - help="The root of the project. (default: %(default)s)", - required=True) - -parser.add_argument( - '--output-directory', - type=str, - help="The Directory to Store the Hipified Project", - required=True) - -args = parser.parse_args() - -includes = [ - '*' -] - -ignores = [ -] - -# capturing the return value which is a dict[filename]:HipifyResult -HipifyFinalResult = hipify_python.hipify( - project_directory=args.project_directory, - output_directory=args.output_directory, - includes=includes, - ignores=ignores, - is_pytorch_extension=True) From 39ee45884dc82ac506588b0b59fc8aa42050163e Mon Sep 17 00:00:00 2001 From: Pruthvi Madugundu Date: Tue, 20 Jul 2021 10:13:33 -0700 Subject: [PATCH 3/4] Moving the CMAKE_MODULE_PATH update into TP_USE_ROCM guard --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 865830f3f..b5b43047f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ project(tensorpipe LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 14) -list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${PROJECT_SOURCE_DIR}/third_party/hipify/cmake") +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Expose build options. include(Options) @@ -23,6 +23,7 @@ include(MiscCheck) # ROCm related if (TP_USE_ROCM) + list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/third_party/hipify/cmake") include(Hipify) endif() From 86323d8fb93b7696eb8c383492d08ce3b0b40731 Mon Sep 17 00:00:00 2001 From: Pruthvi Madugundu Date: Wed, 25 Aug 2021 13:07:38 -0700 Subject: [PATCH 4/4] Updates to use new hipify() cmake API --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5b43047f..c31e61436 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ include(MiscCheck) if (TP_USE_ROCM) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/third_party/hipify/cmake") include(Hipify) + hipify(CUDA_SOURCE_DIR ${PROJECT_SOURCE_DIR}) endif() add_subdirectory(tensorpipe)