Skip to content
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

Draft of ORT GPU build #5622

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c80e36c
OnnxRuntime build on AMD GPU's
ChSonnabend Aug 15, 2024
4d42b1f
Merge branch 'alisw:master' into onnxruntime-gpu
ChSonnabend Aug 16, 2024
23c3e5f
Modifying recipe for build on Nvidia GPU's (still needs testing)
ChSonnabend Sep 4, 2024
78fcf07
Updating ONNX build flags
ChSonnabend Sep 17, 2024
6e3689b
Merge branch 'alisw:master' into onnxruntime-gpu
ChSonnabend Sep 17, 2024
0fa8a06
Merge branch 'master' into onnxruntime-gpu
ChSonnabend Sep 27, 2024
73b54ce
Updating version to 1.19.0
ChSonnabend Sep 27, 2024
5e42e46
Adding automatic checks for migraphx, changing build cmake flags and …
ChSonnabend Oct 3, 2024
9e47dfd
Merge branch 'master' into onnxruntime-gpu
ChSonnabend Oct 3, 2024
e90a9e5
This builds ORT with the GPU flags. Note: In the al9_gpu container th…
ChSonnabend Oct 4, 2024
d7b089d
Adding comments and reshuffeling for better readibility
ChSonnabend Oct 4, 2024
d45d194
Adding checks for Cuda and ROCm libraries
ChSonnabend Nov 18, 2024
000afbb
Updating to a recent version of ONNX
ChSonnabend Nov 19, 2024
9613081
Merge branch 'alisw:master' into onnxruntime-gpu
ChSonnabend Nov 21, 2024
f28a341
Changing to -eq 1
ChSonnabend Nov 22, 2024
4813226
Changing to double-brace syntax
ChSonnabend Nov 26, 2024
2713a61
Changing to version 1.20 since 1.19 has issues for GPU execution
ChSonnabend Nov 26, 2024
62ece4e
Adding check for Alma9 (if system is AlmaLinux). exports's still need…
ChSonnabend Nov 28, 2024
ea219bf
Adding compile flags for ONNXRuntime
ChSonnabend Nov 28, 2024
ae214b5
Adding AlmaLinux 9 as general &&-check
ChSonnabend Nov 29, 2024
6f3d636
Adding ORT_ROCM_BUILD check for CUDA build
ChSonnabend Nov 29, 2024
f5fd93b
Removing C/CXX flag for template-id-cdtor
ChSonnabend Nov 30, 2024
5e0f296
Force disabling for alma linux distribution
ChSonnabend Dec 1, 2024
e01351a
Adding ORT variables to be available at build time (and LD_LIBRARY_PA…
ChSonnabend Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion o2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ cmake $SOURCEDIR -DCMAKE_INSTALL_PREFIX=$INSTALLROOT
${ARROW_ROOT:+-DArrow_DIR=$ARROW_ROOT/lib/cmake/Arrow} \
${CLANG_REVISION:+-DCLANG_EXECUTABLE="$CLANG_ROOT/bin-safe/clang"} \
${CLANG_REVISION:+-DLLVM_LINK_EXECUTABLE="$CLANG_ROOT/bin/llvm-link"} \
${ITSRESPONSE_ROOT:+-DITSRESPONSE=${ITSRESPONSE_ROOT}}
${ITSRESPONSE_ROOT:+-DITSRESPONSE=${ITSRESPONSE_ROOT}} \
${ORT_ROCM_BUILD:+-DORT_ROCM_BUILD=${ORT_ROCM_BUILD}} \
${ORT_CUDA_BUILD:+-DORT_CUDA_BUILD=${ORT_CUDA_BUILD}} \
${ORT_MIGRAPHX_BUILD:+-DORT_MIGRAPHX_BUILD=${ORT_MIGRAPHX_BUILD}} \
${ORT_TENSORRT_BUILD:+-DORT_TENSORRT_BUILD=${ORT_TENSORRT_BUILD}}
# LLVM_ROOT is required for Gandiva

cmake --build . -- ${JOBS+-j $JOBS} install
Expand Down
110 changes: 90 additions & 20 deletions onnxruntime.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package: ONNXRuntime
version: "%(tag_basename)s"
tag: v1.18.1
tag: v1.20.0
source: https://github.com/microsoft/onnxruntime
requires:
- protobuf
Expand All @@ -19,24 +19,95 @@ prepend_path:

mkdir -p $INSTALLROOT

cmake "$SOURCEDIR/cmake" \
-DCMAKE_INSTALL_PREFIX=$INSTALLROOT \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_LIBDIR=lib \
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \
-Donnxruntime_BUILD_UNIT_TESTS=OFF \
-Donnxruntime_PREFER_SYSTEM_LIB=ON \
-Donnxruntime_BUILD_SHARED_LIB=ON \
-DProtobuf_USE_STATIC_LIBS=ON \
${PROTOBUF_ROOT:+-DProtobuf_LIBRARY=$PROTOBUF_ROOT/lib/libprotobuf.a} \
${PROTOBUF_ROOT:+-DProtobuf_LITE_LIBRARY=$PROTOBUF_ROOT/lib/libprotobuf-lite.a} \
${PROTOBUF_ROOT:+-DProtobuf_PROTOC_LIBRARY=$PROTOBUF_ROOT/lib/libprotoc.a} \
${PROTOBUF_ROOT:+-DProtobuf_INCLUDE_DIR=$PROTOBUF_ROOT/include} \
${PROTOBUF_ROOT:+-DProtobuf_PROTOC_EXECUTABLE=$PROTOBUF_ROOT/bin/protoc} \
${RE2_ROOT:+-DRE2_INCLUDE_DIR=${RE2_ROOT}/include} \
${BOOST_ROOT:+-DBOOST_INCLUDE_DIR=${BOOST_ROOT}/include} \
-DCMAKE_CXX_FLAGS="$CXXFLAGS -Wno-unknown-warning -Wno-unknown-warning-option -Wno-error=unused-but-set-variable -Wno-error=deprecated" \
-DCMAKE_C_FLAGS="$CFLAGS -Wno-unknown-warning -Wno-unknown-warning-option -Wno-error=unused-but-set-variable -Wno-error=deprecated"
# Check ROCm build conditions
if [[ -f /etc/redhat-release ]]; then
export ALMA_LINUX_MAJOR_VERSION=$(awk '{print $3}' /etc/redhat-release | cut -d. -f1)
fi

if [[ "$ALIBUILD_O2_FORCE_GPU" -eq 1 ]] || [[ "$ALIBUILD_ENABLE_HIP" -eq 1 ]] || \
( ( [[ -z "$DISABLE_GPU" ]] || [[ "$DISABLE_GPU" -eq 0 ]] ) && \
( command -v /opt/rocm/bin/rocminfo >/dev/null 2>&1 ) && \
[[ -d /opt/rocm/include/hiprand ]] && \
[[ -d /opt/rocm/include/hipblas ]] && \
[[ -d /opt/rocm/include/hipsparse ]] && \
[[ -d /opt/rocm/include/hipfft ]] && \
[[ -d /opt/rocm/include/rocblas ]] && \
[[ -d /opt/rocm/include/rocrand ]] && \
[[ -d /opt/rocm/include/miopen ]] && \
[[ -d /opt/rocm/include/rccl ]] && \
[[ -z "$ORT_ROCM_BUILD" ]] ) && \
([[ -z "$ALMA_LINUX_MAJOR_VERSION" ]] || [[ "$ALMA_LINUX_MAJOR_VERSION" -eq 9 ]]); then
export ORT_ROCM_BUILD=1
: ${ALIBUILD_O2_OVERRIDE_HIP_ARCHS:="gfx906,gfx908"}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm/lib
else
export ORT_ROCM_BUILD=0
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fi
mkdir -p $INSTALLROOT/etc
cat << EOF > $INSTALLROOT/etc/ort-init.sh
export ORT_ROCM_BUILD=$ORT_ROCM_BUILD
EOF


# Check CUDA build conditions
if ( [[ "$ALIBUILD_O2_FORCE_GPU" -eq 1 ]] || [[ "$ALIBUILD_ENABLE_CUDA" -eq 1 ]] || \
( ( [[ -z "$DISABLE_GPU" ]] || [[ "$DISABLE_GPU" -eq 0 ]] ) && \
( command -v nvcc >/dev/null 2>&1 ) && \
[[ -f /usr/include/cudnn.h ]] && \
[[ -z "$ORT_CUDA_BUILD" ]] ) ) && \
[[ "$ORT_ROCM_BUILD" -eq 0 ]]; then
export ORT_CUDA_BUILD=1
: ${ALIBUILD_O2_OVERRIDE_CUDA_ARCHS:="sm_86"}
else
export ORT_CUDA_BUILD=0
fi

# Optional builds
### MIGraphX
if ( [[ "$ORT_ROCM_BUILD" -eq 1 ]] && [[ $(find /opt/rocm* -name "libmigraphx*" -print -quit | wc -l 2>&1) -eq 1 ]] ) && \
[[ -z "$ORT_MIGRAPHX_BUILD" ]]; then
export ORT_MIGRAPHX_BUILD=1
elif [[ -z "$ORT_MIGRAPHX_BUILD" ]]; then
export ORT_MIGRAPHX_BUILD=0
fi
### TensorRT
if ( [[ "$ORT_CUDA_BUILD" -eq 1 ]] && [[ $(find /usr -name "libnvinfer*" -print -quit | wc -l 2>&1) -eq 1 ]] ) && \
[[ -z "$ORT_MIGRAPHX_BUILD" ]]; then
export ORT_TENSORRT_BUILD=1
elif [[ -z "$ORT_TENSORRT_BUILD" ]]; then
export ORT_TENSORRT_BUILD=0
fi

cmake "$SOURCEDIR/cmake" \
-DCMAKE_INSTALL_PREFIX=$INSTALLROOT \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_LIBDIR=lib \
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \
-Donnxruntime_BUILD_UNIT_TESTS=OFF \
-Donnxruntime_PREFER_SYSTEM_LIB=ON \
-Donnxruntime_BUILD_SHARED_LIB=ON \
-DProtobuf_USE_STATIC_LIBS=ON \
-Donnxruntime_ENABLE_TRAINING=OFF \
${PROTOBUF_ROOT:+-DProtobuf_LIBRARY=$PROTOBUF_ROOT/lib/libprotobuf.a} \
${PROTOBUF_ROOT:+-DProtobuf_LITE_LIBRARY=$PROTOBUF_ROOT/lib/libprotobuf-lite.a} \
${PROTOBUF_ROOT:+-DProtobuf_PROTOC_LIBRARY=$PROTOBUF_ROOT/lib/libprotoc.a} \
${PROTOBUF_ROOT:+-DProtobuf_INCLUDE_DIR=$PROTOBUF_ROOT/include} \
${PROTOBUF_ROOT:+-DProtobuf_PROTOC_EXECUTABLE=$PROTOBUF_ROOT/bin/protoc} \
${RE2_ROOT:+-DRE2_INCLUDE_DIR=${RE2_ROOT}/include} \
${BOOST_ROOT:+-DBOOST_INCLUDE_DIR=${BOOST_ROOT}/include} \
-Donnxruntime_USE_MIGRAPHX=${ORT_MIGRAPHX_BUILD} \
-Donnxruntime_USE_ROCM=${ORT_ROCM_BUILD} \
-Donnxruntime_ROCM_HOME=/opt/rocm \
-Donnxruntime_CUDA_HOME=/usr/local/cuda \
-DCMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++ \
-D__HIP_PLATFORM_AMD__=${ORT_ROCM_BUILD} \
${ALIBUILD_O2_OVERRIDE_HIP_ARCHS:+-DCMAKE_HIP_ARCHITECTURES=${ALIBUILD_O2_OVERRIDE_HIP_ARCHS}} \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is also an OVERRIDE_CUDA_ARCH, could you check and use that as well?

${ALIBUILD_O2_OVERRIDE_CUDA_ARCH:+-CMAKE_CUDA_ARCHITECTURES=${ALIBUILD_O2_OVERRIDE_CUDA_ARCHS}} \
-Donnxruntime_USE_COMPOSABLE_KERNEL=OFF \
-Donnxruntime_USE_ROCBLAS_EXTENSION_API=${ORT_ROCM_BUILD} \
-Donnxruntime_USE_COMPOSABLE_KERNEL_CK_TILE=ON \
-Donnxruntime_DISABLE_RTTI=OFF \
-DMSVC=OFF \
-Donnxruntime_USE_CUDA=${ORT_CUDA_BUILD} \
-Donnxruntime_USE_CUDA_NHWC_OPS=${ORT_CUDA_BUILD} \
-Donnxruntime_CUDA_USE_TENSORRT=${ORT_TENSORRT_BUILD} \
-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 -Wno-error=template-id-cdtor" \
-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 -Wno-error=template-id-cdtor"

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

Expand All @@ -45,7 +116,6 @@ mkdir -p "$INSTALLROOT/etc/modulefiles"
MODULEFILE="$INSTALLROOT/etc/modulefiles/$PKGNAME"
alibuild-generate-module --lib > "$MODULEFILE"
cat >> "$MODULEFILE" <<EoF

# Our environment
set ${PKGNAME}_ROOT \$::env(BASEDIR)/$PKGNAME/\$version
prepend-path ROOT_INCLUDE_PATH \$${PKGNAME}_ROOT/include/onnxruntime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prepend-path ROOT_INCLUDE_PATH \$${PKGNAME}_ROOT/include/onnxruntime
prepend-path ROOT_INCLUDE_PATH \$${PKGNAME}_ROOT/include/onnxruntime
append-path LD_LIBRARY_PATH /opt/rocm/lib

Expand Down