|
| 1 | + |
| 2 | +# BSD 2-Clause License |
| 3 | +# |
| 4 | +# Copyright (c) 2024, Hewlett Packard Enterprise |
| 5 | +# All rights reserved. |
| 6 | +# |
| 7 | +# Redistribution and use in source and binary forms, with or without |
| 8 | +# modification, are permitted provided that the following conditions are met: |
| 9 | +# |
| 10 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 11 | +# list of conditions and the following disclaimer. |
| 12 | +# |
| 13 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 14 | +# this list of conditions and the following disclaimer in the documentation |
| 15 | +# and/or other materials provided with the distribution. |
| 16 | +# |
| 17 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 21 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | + |
| 28 | +OS = linux |
| 29 | +ARCHITECTURE = x64 |
| 30 | +ROCM_VERSION = 6.1.2 |
| 31 | +STACK=rocm-$(ROCM_VERSION) |
| 32 | + |
| 33 | +# pyTorch options |
| 34 | +PYTORCH_VERSION = 2.4.0 |
| 35 | +TORCH_CMAKE_OPTIONS = -DBUILD_PYTHON=OFF |
| 36 | +TORCH_CMAKE_OPTIONS += -DUSE_ROCM=ON -DUSE_RCCL=ON -DROCM_SOURCE_DIR=${ROCM_PATH} |
| 37 | +TORCH_CMAKE_OPTIONS += -DUSE_NCCL=OFF -DUSE_CUDA=OFF -DUSE_STATIC_MKL=ON |
| 38 | +PYTORCH_PREBUILD_TARGETS = pytorch_rocm_checkout pytorch_rocm_prebuild |
| 39 | + |
| 40 | + |
| 41 | +# Tensorflow options |
| 42 | +TF_VERSION = 2.15 |
| 43 | +TF_TAG = r$(TF_VERSION)-rocm-enhanced |
| 44 | +TF_REMOTE = https://github.com/ROCm/tensorflow-upstream.git |
| 45 | +TF_PREBUILD_TARGETS = tf_rocm_checkout tf_rocm_prebuild |
| 46 | +TF_BAZEL_OPTS = --config=opt --verbose_failures |
| 47 | + |
| 48 | +ONNXRT_VERSION = 1.17.3 |
| 49 | +ONNXRT_OPTIONS = --use_rocm --rocm_home $(ROCM_PATH) |
| 50 | +ONNXRT_PREBUILD_TARGETS = onnxrt_checkout |
| 51 | +# No prebuild steps for ONNX |
| 52 | + |
| 53 | +# From PyTorch for ROCm instructions |
| 54 | +# https://github.com/pytorch/pytorch/blob/v2.3.1/README.md?plain=1#L241-L245 |
| 55 | +# For at ROCm 5.5.0 and later, also need to patch one of the ATen files |
| 56 | +pytorch_rocm_checkout: |
| 57 | + cd pytorch && \ |
| 58 | + git checkout v${PYTORCH_VERSION} && \ |
| 59 | + git submodule update --init --recursive && \ |
| 60 | + git reset --hard |
| 61 | + |
| 62 | +pytorch_rocm_prebuild: |
| 63 | + cd pytorch; python tools/amd_build/build_amd.py |
| 64 | + sed -i 's/attr.memoryType/attr.type/g' pytorch/aten/src/ATen/hip/detail/HIPHooks.cpp |
| 65 | + sed -i 's,/opt/rocm,${ROCM_PATH},g' pytorch/third_party/kineto/libkineto/CMakeLists.txt |
| 66 | + sed -i 's,\.,\\.,g' pytorch/cmake/public/LoadHIP.cmake |
| 67 | + |
| 68 | +# (1) Patch .bazelrc to avoid hard-coded paths to Clang |
| 69 | +# (2) Run the bazel configure script |
| 70 | +tf_rocm_prebuild: |
| 71 | + cd tensorflow; \ |
| 72 | + git restore .bazelrc |
| 73 | + # git apply ../patches/tensorflow/bazelrc.rocm.patch |
| 74 | + cd tensorflow; \ |
| 75 | + USE_DEFAULT_PYTHON_LIB_PATH=1 \ |
| 76 | + PYTHON_BIN_PATH=$$(which python) \ |
| 77 | + TF_NEED_CLANG=0 \ |
| 78 | + TF_NEED_ROCM=1 \ |
| 79 | + TF_NEED_CUDA=0 \ |
| 80 | + CC_OPT_FLAGS="-Wno-sign-compare -B/usr/bin" \ |
| 81 | + TF_SET_ANDROID_WORKSPACE=0 \ |
| 82 | + python configure.py |
| 83 | + |
| 84 | +tf_rocm_checkout: |
| 85 | + cd tensorflow; \ |
| 86 | + git fetch $(TF_REMOTE) $(TF_TAG) && \ |
| 87 | + git checkout FETCH_HEAD |
| 88 | + |
| 89 | +onnxrt_checkout: |
| 90 | + cd onnxruntime && \ |
| 91 | + git checkout v$(ONNXRT_VERSION) && \ |
| 92 | + git reset --hard && \ |
| 93 | + git clean -xdf && \ |
| 94 | + git submodule update --init --recursive |
0 commit comments