Skip to content

Commit 54466f4

Browse files
authored
ORT GPU build (#5622)
1 parent f9bf4da commit 54466f4

File tree

2 files changed

+112
-22
lines changed

2 files changed

+112
-22
lines changed

o2.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ valid_defaults:
139139
#!/bin/sh
140140
export ROOTSYS=$ROOT_ROOT
141141

142+
if [[ -n $ONNXRUNTIME_REVISION ]]; then
143+
source $ONNXRUNTIME_ROOT/etc/ort-init.sh
144+
echo "ORT_ROCM_BUILD: $ORT_ROCM_BUILD"
145+
echo "ORT_CUDA_BUILD: $ORT_CUDA_BUILD"
146+
fi
147+
142148
# Making sure people do not have SIMPATH set when they build fairroot.
143149
# Unfortunately SIMPATH seems to be hardcoded in a bunch of places in
144150
# fairroot, so this really should be cleaned up in FairRoot itself for
@@ -207,7 +213,11 @@ cmake $SOURCEDIR -DCMAKE_INSTALL_PREFIX=$INSTALLROOT
207213
${ARROW_ROOT:+-DArrow_DIR=$ARROW_ROOT/lib/cmake/Arrow} \
208214
${CLANG_REVISION:+-DCLANG_EXECUTABLE="$CLANG_ROOT/bin-safe/clang"} \
209215
${CLANG_REVISION:+-DLLVM_LINK_EXECUTABLE="$CLANG_ROOT/bin/llvm-link"} \
210-
${ITSRESPONSE_ROOT:+-DITSRESPONSE=${ITSRESPONSE_ROOT}}
216+
${ITSRESPONSE_ROOT:+-DITSRESPONSE=${ITSRESPONSE_ROOT}} \
217+
${ORT_ROCM_BUILD:+-DORT_ROCM_BUILD=${ORT_ROCM_BUILD}} \
218+
${ORT_CUDA_BUILD:+-DORT_CUDA_BUILD=${ORT_CUDA_BUILD}} \
219+
${ORT_MIGRAPHX_BUILD:+-DORT_MIGRAPHX_BUILD=${ORT_MIGRAPHX_BUILD}} \
220+
${ORT_TENSORRT_BUILD:+-DORT_TENSORRT_BUILD=${ORT_TENSORRT_BUILD}}
211221
# LLVM_ROOT is required for Gandiva
212222

213223
cmake --build . -- ${JOBS+-j $JOBS} install

onnxruntime.sh

Lines changed: 101 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package: ONNXRuntime
22
version: "%(tag_basename)s"
3-
tag: v1.18.1
3+
tag: v1.20.0
44
source: https://github.com/microsoft/onnxruntime
55
requires:
66
- protobuf
@@ -18,24 +18,105 @@ prepend_path:
1818

1919
mkdir -p $INSTALLROOT
2020

21-
cmake "$SOURCEDIR/cmake" \
22-
-DCMAKE_INSTALL_PREFIX=$INSTALLROOT \
23-
-DCMAKE_BUILD_TYPE=Release \
24-
-DCMAKE_INSTALL_LIBDIR=lib \
25-
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \
26-
-Donnxruntime_BUILD_UNIT_TESTS=OFF \
27-
-Donnxruntime_PREFER_SYSTEM_LIB=ON \
28-
-Donnxruntime_BUILD_SHARED_LIB=ON \
29-
-DProtobuf_USE_STATIC_LIBS=ON \
30-
${PROTOBUF_ROOT:+-DProtobuf_LIBRARY=$PROTOBUF_ROOT/lib/libprotobuf.a} \
31-
${PROTOBUF_ROOT:+-DProtobuf_LITE_LIBRARY=$PROTOBUF_ROOT/lib/libprotobuf-lite.a} \
32-
${PROTOBUF_ROOT:+-DProtobuf_PROTOC_LIBRARY=$PROTOBUF_ROOT/lib/libprotoc.a} \
33-
${PROTOBUF_ROOT:+-DProtobuf_INCLUDE_DIR=$PROTOBUF_ROOT/include} \
34-
${PROTOBUF_ROOT:+-DProtobuf_PROTOC_EXECUTABLE=$PROTOBUF_ROOT/bin/protoc} \
35-
${RE2_ROOT:+-DRE2_INCLUDE_DIR=${RE2_ROOT}/include} \
36-
${BOOST_ROOT:+-DBOOST_INCLUDE_DIR=${BOOST_ROOT}/include} \
37-
-DCMAKE_CXX_FLAGS="$CXXFLAGS -Wno-unknown-warning -Wno-unknown-warning-option -Wno-error=unused-but-set-variable -Wno-error=deprecated" \
38-
-DCMAKE_C_FLAGS="$CFLAGS -Wno-unknown-warning -Wno-unknown-warning-option -Wno-error=unused-but-set-variable -Wno-error=deprecated"
21+
# Check ROCm build conditions
22+
if [[ -f /etc/redhat-release ]]; then
23+
export ALMA_LINUX_MAJOR_VERSION=$(awk '{print $3}' /etc/redhat-release | cut -d. -f1)
24+
fi
25+
26+
if [[ "$ALIBUILD_O2_FORCE_GPU" -eq 1 ]] || [[ "$ALIBUILD_ENABLE_HIP" -eq 1 ]] || \
27+
( ( [[ -z "$DISABLE_GPU" ]] || [[ "$DISABLE_GPU" -eq 0 ]] ) && \
28+
( command -v /opt/rocm/bin/rocminfo >/dev/null 2>&1 ) && \
29+
[[ -d /opt/rocm/include/hiprand ]] && \
30+
[[ -d /opt/rocm/include/hipblas ]] && \
31+
[[ -d /opt/rocm/include/hipsparse ]] && \
32+
[[ -d /opt/rocm/include/hipfft ]] && \
33+
[[ -d /opt/rocm/include/rocblas ]] && \
34+
[[ -d /opt/rocm/include/rocrand ]] && \
35+
[[ -d /opt/rocm/include/miopen ]] && \
36+
[[ -d /opt/rocm/include/rccl ]] && \
37+
[[ -d /opt/rocm/lib/hipblaslt ]] && \
38+
[[ -z "$ORT_ROCM_BUILD" ]] ) && \
39+
([[ -z "$ALMA_LINUX_MAJOR_VERSION" ]] || [[ "$ALMA_LINUX_MAJOR_VERSION" -eq 9 ]]); then
40+
export ORT_ROCM_BUILD="1"
41+
: ${ALIBUILD_O2_OVERRIDE_HIP_ARCHS:="gfx906,gfx908"}
42+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm/lib
43+
else
44+
export ORT_ROCM_BUILD="0"
45+
fi
46+
47+
# Check CUDA build conditions
48+
if ( [[ "$ALIBUILD_O2_FORCE_GPU" -eq 1 ]] || [[ "$ALIBUILD_ENABLE_CUDA" -eq 1 ]] || \
49+
( ( [[ -z "$DISABLE_GPU" ]] || [[ "$DISABLE_GPU" -eq 0 ]] ) && \
50+
( command -v nvcc >/dev/null 2>&1 ) && \
51+
[[ -f /usr/include/cudnn.h ]] && \
52+
[[ -z "$ORT_CUDA_BUILD" ]] ) ) && \
53+
[[ "$ORT_ROCM_BUILD" -eq 0 ]] && \
54+
[[ -z "$ALMA_LINUX_MAJOR_VERSION" ]]; then
55+
export ORT_CUDA_BUILD="1"
56+
: ${ALIBUILD_O2_OVERRIDE_CUDA_ARCHS:="sm_86"}
57+
else
58+
export ORT_CUDA_BUILD="0"
59+
fi
60+
61+
# Optional builds
62+
### MIGraphX
63+
if ( [[ "$ORT_ROCM_BUILD" -eq 1 ]] && [[ $(find /opt/rocm* -name "libmigraphx*" -print -quit | wc -l 2>&1) -eq 1 ]] ) && \
64+
[[ -z "$ORT_MIGRAPHX_BUILD" ]]; then
65+
export ORT_MIGRAPHX_BUILD="1"
66+
elif [[ -z "$ORT_MIGRAPHX_BUILD" ]]; then
67+
export ORT_MIGRAPHX_BUILD="0"
68+
fi
69+
### TensorRT
70+
if ( [[ "$ORT_CUDA_BUILD" -eq 1 ]] && [[ $(find /usr -name "libnvinfer*" -print -quit | wc -l 2>&1) -eq 1 ]] ) && \
71+
[[ -z "$ORT_MIGRAPHX_BUILD" ]]; then
72+
export ORT_TENSORRT_BUILD="1"
73+
elif [[ -z "$ORT_TENSORRT_BUILD" ]]; then
74+
export ORT_TENSORRT_BUILD="0"
75+
fi
76+
77+
mkdir -p $INSTALLROOT/etc
78+
cat << EOF > $INSTALLROOT/etc/ort-init.sh
79+
export ORT_ROCM_BUILD=$ORT_ROCM_BUILD
80+
export ORT_CUDA_BUILD=$ORT_CUDA_BUILD
81+
export ORT_MIGRAPHX_BUILD=$ORT_MIGRAPHX_BUILD
82+
export ORT_TENSORRT_BUILD=$ORT_TENSORRT_BUILD
83+
EOF
84+
85+
cmake "$SOURCEDIR/cmake" \
86+
-DCMAKE_INSTALL_PREFIX="$INSTALLROOT" \
87+
-DCMAKE_BUILD_TYPE=Release \
88+
-DCMAKE_INSTALL_LIBDIR=lib \
89+
-DPYTHON_EXECUTABLE="$(python3 -c 'import sys; print(sys.executable)')" \
90+
-Donnxruntime_BUILD_UNIT_TESTS=OFF \
91+
-Donnxruntime_PREFER_SYSTEM_LIB=ON \
92+
-Donnxruntime_BUILD_SHARED_LIB=ON \
93+
-DProtobuf_USE_STATIC_LIBS=ON \
94+
-Donnxruntime_ENABLE_TRAINING=OFF \
95+
${PROTOBUF_ROOT:+-DProtobuf_LIBRARY=$PROTOBUF_ROOT/lib/libprotobuf.a} \
96+
${PROTOBUF_ROOT:+-DProtobuf_LITE_LIBRARY=$PROTOBUF_ROOT/lib/libprotobuf-lite.a} \
97+
${PROTOBUF_ROOT:+-DProtobuf_PROTOC_LIBRARY=$PROTOBUF_ROOT/lib/libprotoc.a} \
98+
${PROTOBUF_ROOT:+-DProtobuf_INCLUDE_DIR=$PROTOBUF_ROOT/include} \
99+
${PROTOBUF_ROOT:+-DProtobuf_PROTOC_EXECUTABLE=$PROTOBUF_ROOT/bin/protoc} \
100+
${RE2_ROOT:+-DRE2_INCLUDE_DIR=${RE2_ROOT}/include} \
101+
${BOOST_ROOT:+-DBOOST_INCLUDE_DIR=${BOOST_ROOT}/include} \
102+
-Donnxruntime_USE_MIGRAPHX=${ORT_MIGRAPHX_BUILD} \
103+
-Donnxruntime_USE_ROCM=${ORT_ROCM_BUILD} \
104+
-Donnxruntime_ROCM_HOME=/opt/rocm \
105+
-Donnxruntime_CUDA_HOME=/usr/local/cuda \
106+
-DCMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++ \
107+
-D__HIP_PLATFORM_AMD__=${ORT_ROCM_BUILD} \
108+
${ALIBUILD_O2_OVERRIDE_HIP_ARCHS:+-DCMAKE_HIP_ARCHITECTURES=${ALIBUILD_O2_OVERRIDE_HIP_ARCHS}} \
109+
${ALIBUILD_O2_OVERRIDE_CUDA_ARCH:+-CMAKE_CUDA_ARCHITECTURES=${ALIBUILD_O2_OVERRIDE_CUDA_ARCHS}} \
110+
-Donnxruntime_USE_COMPOSABLE_KERNEL=OFF \
111+
-Donnxruntime_USE_ROCBLAS_EXTENSION_API=${ORT_ROCM_BUILD} \
112+
-Donnxruntime_USE_COMPOSABLE_KERNEL_CK_TILE=ON \
113+
-Donnxruntime_DISABLE_RTTI=OFF \
114+
-DMSVC=OFF \
115+
-Donnxruntime_USE_CUDA=${ORT_CUDA_BUILD} \
116+
-Donnxruntime_USE_CUDA_NHWC_OPS=${ORT_CUDA_BUILD} \
117+
-Donnxruntime_CUDA_USE_TENSORRT=${ORT_TENSORRT_BUILD} \
118+
-DCMAKE_CXX_FLAGS="$CXXFLAGS -Wno-unknown-warning -Wno-unknown-warning-option -Wno-pass-failed -Wno-error=unused-but-set-variable -Wno-pass-failed=transform-warning -Wno-error=deprecated -Wno-error=maybe-uninitialized" \
119+
-DCMAKE_C_FLAGS="$CFLAGS -Wno-unknown-warning -Wno-unknown-warning-option -Wno-pass-failed -Wno-error=unused-but-set-variable -Wno-pass-failed=transform-warning -Wno-error=deprecated -Wno-error=maybe-uninitialized"
39120

40121
cmake --build . -- ${JOBS:+-j$JOBS} install
41122

@@ -44,8 +125,7 @@ mkdir -p "$INSTALLROOT/etc/modulefiles"
44125
MODULEFILE="$INSTALLROOT/etc/modulefiles/$PKGNAME"
45126
alibuild-generate-module --lib > "$MODULEFILE"
46127
cat >> "$MODULEFILE" <<EoF
47-
48128
# Our environment
49-
set ${PKGNAME}_ROOT \$::env(BASEDIR)/$PKGNAME/\$version
50129
prepend-path ROOT_INCLUDE_PATH \$${PKGNAME}_ROOT/include/onnxruntime
130+
append-path LD_LIBRARY_PATH /opt/rocm/lib
51131
EoF

0 commit comments

Comments
 (0)