Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions o/onnxruntime/build_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"maintainer": "vinodk99",
"package_name": "onnxruntime",
"github_url": "https://github.com/microsoft/onnxruntime",
"version": "v1.23.2",
"version": "v1.25.1",
"default_branch": "main",
"package_dir": "o/onnxruntime",
"build_script": "onnxruntime_1.23.2_ubi_9.6.sh",
"build_script": "onnxruntime_1.25.1_ubi_9.6.sh",
"docker_build": false,
"validate_build_script": true,
"use_non_root_user": false,
Expand All @@ -22,7 +22,10 @@
"v1.22.0": {
"build_script": "onnxruntime_1.22.0_ubi_9.3.sh"
},
"*": {
"v1.23.2": {
"build_script": "onnxruntime_1.23.2_ubi_9.6.sh"
}
},
"*": {
"build_script": "onnxruntime_1.25.1_ubi_9.6.sh"
}
}
264 changes: 264 additions & 0 deletions o/onnxruntime/onnxruntime_1.25.1_ubi_9.6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
#!/bin/bash -e
# -----------------------------------------------------------------------------
#
# Package : onnxruntime
# Version : v1.25.1
# Source repo : https://github.com/microsoft/onnxruntime
# Tested on : UBI:9.6
# Language : Python
# Ci-Check : True
# Script License : Apache License, Version 2 or later
# Maintainer : BODAPATI MAHESH <bmahi496@linux.ibm.com>
#
# Disclaimer: This script has been tested in root mode on given
# ========== platform using the mentioned version of the package.
# It may not work as expected with newer versions of the
# package and/or distribution. In such case, please
# contact "Maintainer" of this script.
#
# ----------------------------------------------------------------------------

PACKAGE_NAME=onnxruntime
PACKAGE_VERSION=${1:-v1.25.1}
PACKAGE_URL=https://github.com/microsoft/onnxruntime
PACKAGE_DIR="onnxruntime"
WORK_DIR=$(pwd)
CURRENT_DIR=$(pwd)

echo "Installing dependencies..."
yum install -y git make libtool wget gcc-toolset-13-gcc gcc-toolset-13-gcc-c++ gcc-toolset-13-gcc-gfortran libevent-devel zlib-devel openssl-devel clang python3.12 python3.12-devel python3.12-pip cmake xz bzip2-devel libffi-devel patch ninja-build
export PATH=/opt/rh/gcc-toolset-13/root/usr/bin:$PATH
export LD_LIBRARY_PATH=/opt/rh/gcc-toolset-13/root/usr/lib64:$LD_LIBRARY_PATH
PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
if python3 -c 'import sys; sys.exit(0 if sys.version_info < (3,10) else 1)'; then
echo "Python version is $PYTHON_VERSION (< 3.10).Required >=3.10"
fi

PYTHON_VERSION=$(python3.12 --version 2>&1 | cut -d ' ' -f 2 | cut -d '.' -f 1,2)
"python$PYTHON_VERSION" -m venv --system-site-packages VENV_DIR
source VENV_DIR/bin/activate

export SITE_PACKAGE_PATH=/usr/local/lib/python${PYTHON_VERSION}/site-packages
export CC=/opt/rh/gcc-toolset-13/root/usr/bin/gcc
export CXX=/opt/rh/gcc-toolset-13/root/usr/bin/g++
export gcc_home=/opt/rh/gcc-toolset-13/root/usr
yum remove -y python3-chardet

gcc --version

echo "**** Checking GCC version..."
gcc -v || true


echo "Python version is supported: $PYTHON_VERSION"
# Get Python include path
PYTHON_INCLUDE=$(python3.12 -c "from sysconfig import get_paths; print(get_paths()['include'])")
export CPLUS_INCLUDE_PATH=$PYTHON_INCLUDE:$CPLUS_INCLUDE_PATH
export C_INCLUDE_PATH=$PYTHON_INCLUDE:$C_INCLUDE_PATH

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade cmake pip "setuptools<80" wheel ninja packaging tox pytest build mypy stubs

cd $CURRENT_DIR
python3 -m pip uninstall -y protobuf || true
# Set ABSEIL_VERSION and ABSEIL_URL
ABSEIL_VERSION=20240116.2
ABSEIL_URL="https://github.com/abseil/abseil-cpp"
git clone $ABSEIL_URL -b $ABSEIL_VERSION

echo " --------------------------------------------------- Abseil-Cpp Cloned --------------------------------------------------- "
# Build and install abseil
export ABSEIL_PREFIX=$(pwd)/abseil-cpp/install

cd abseil-cpp
mkdir build
cd build

cmake -G Ninja \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$ABSEIL_PREFIX \
..

cmake --build .
cmake --install .

cd $CURRENT_DIR

echo " --------------------------------------------------- Abseil Installed --------------------------------------------------- "

# Setting paths and versions
export C_COMPILER=$(which gcc)
export CXX_COMPILER=$(which g++)

mkdir -p $(pwd)/local/libprotobuf
LIBPROTO_INSTALL=$(pwd)/local/libprotobuf
echo "LIBPROTO_INSTALL set to $LIBPROTO_INSTALL"

# Clone Source-code
PACKAGE_VERSION_LIB="v4.25.8"
PACKAGE_GIT_URL="https://github.com/protocolbuffers/protobuf"
git clone $PACKAGE_GIT_URL -b $PACKAGE_VERSION_LIB

echo " --------------------------------------------------- Libprotobuf Installing --------------------------------------------------- "

# Build libprotobuf
echo "protobuf build starts!!"
cd protobuf
git submodule update --init --recursive
rm -rf ./third_party/googletest | true
rm -rf ./third_party/abseil-cpp | true
mkdir build
cd build
cmake -G "Ninja" \
${CMAKE_ARGS} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_C_COMPILER=$C_COMPILER \
-DCMAKE_CXX_COMPILER=$CXX_COMPILER \
-DCMAKE_INSTALL_PREFIX=$LIBPROTO_INSTALL \
-Dprotobuf_BUILD_TESTS=OFF \
-Dprotobuf_BUILD_LIBUPB=OFF \
-Dprotobuf_BUILD_SHARED_LIBS=ON \
-Dprotobuf_ABSL_PROVIDER=package \
-DABSL_ROOT=$ABSEIL_PREFIX \
-DCMAKE_PREFIX_PATH=$ABSEIL_PREFIX \
-Dprotobuf_JSONCPP_PROVIDER="package" \
-Dprotobuf_USE_EXTERNAL_GTEST=OFF \
..
cmake --build . --verbose
cmake --install .
cd ..

echo " --------------------------------------------------- Libprotobuf Successfully Installed --------------------------------------------------- "

export PROTOC="$LIBPROTO_INSTALL/bin/protoc"
export LD_LIBRARY_PATH="$ABSEIL_PREFIX/lib:$ABSEIL_PREFIX/lib64:$LIBPROTO_INSTALL/lib64:$LD_LIBRARY_PATH"
export LIBRARY_PATH="$ABSEIL_PREFIX/lib:$ABSEIL_PREFIX/lib64:$LIBPROTO_INSTALL/lib64:$LIBRARY_PATH"
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION

# Apply patch
echo "Applying patch from https://raw.githubusercontent.com/ppc64le/build-scripts/refs/heads/master/p/protobuf/set_cpp_to_17_v4.25.3.patch"
wget https://raw.githubusercontent.com/ppc64le/build-scripts/refs/heads/master/p/protobuf/set_cpp_to_17_v4.25.3.patch
git apply set_cpp_to_17_v4.25.3.patch

export LD_LIBRARY_PATH="$ABSEIL_PREFIX/lib:$ABSEIL_PREFIX/lib64:$LIBPROTO_INSTALL/lib64:$LD_LIBRARY_PATH"
export LIBRARY_PATH="$ABSEIL_PREFIX/lib:$ABSEIL_PREFIX/lib64:$LIBPROTO_INSTALL/lib64:$LIBRARY_PATH"

# Build Python package
cd python
python3.12 setup.py install
echo " --------------------------------------------------- Protobuf Patch Applied Successfully --------------------------------------------------- "

cd $CURRENT_DIR

python3.12 -m pip install pybind11==2.12.0
PYBIND11_PREFIX=$SITE_PACKAGE_PATH/pybind11
export CMAKE_PREFIX_PATH="$ABSEIL_PREFIX;$LIBPROTO_INSTALL;$PYBIND11_PREFIX"
echo "Updated CMAKE_PREFIX_PATH after OpenBLAS: $CMAKE_PREFIX_PATH"
export LD_LIBRARY_PATH="$LIBPROTO_INSTALL/lib64:$ABSEIL_PREFIX/lib:$LD_LIBRARY_PATH"
echo "Updated LD_LIBRARY_PATH : $LD_LIBRARY_PATH"

echo " --------------------------------------------------- Onnx Installing --------------------------------------------------- "

git clone https://github.com/onnx/onnx
cd onnx
git checkout v1.17.0
git submodule update --init --recursive
sed -i 's|https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.tar.gz|https://github.com/abseil/abseil-cpp/archive/refs/tags/20240116.2.tar.gz|g' CMakeLists.txt && \
sed -i 's|e21faa0de5afbbf8ee96398ef0ef812daf416ad8|bb8a766f3aef8e294a864104b8ff3fc37b393210|g' CMakeLists.txt && \
sed -i 's|https://github.com/protocolbuffers/protobuf/releases/download/v22.3/protobuf-22.3.tar.gz|https://github.com/protocolbuffers/protobuf/archive/refs/tags/v4.25.3.tar.gz|g' CMakeLists.txt && \
sed -i 's|310938afea334b98d7cf915b099ec5de5ae3b5c5|4ba37c659f85c20abb0cc595bfac5e3a385e8e93|g' CMakeLists.txt && \
sed -i 's|set(Protobuf_VERSION "4.22.3")|set(Protobuf_VERSION "v4.25.3")|g' CMakeLists.txt

export ONNX_ML=1
export ONNX_PREFIX=$(pwd)/../onnx-prefix
AR=$gcc_home/bin/ar
LD=$gcc_home/bin/ld
NM=$gcc_home/bin/nm
OBJCOPY=$gcc_home/bin/objcopy
OBJDUMP=$gcc_home/bin/objdump
RANLIB=$gcc_home/bin/ranlib
STRIP=$gcc_home/bin/strip
export CMAKE_ARGS=""
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX=$ONNX_PREFIX"
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_AR=${AR}"
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_LINKER=${LD}"
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_NM=${NM}"
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_OBJCOPY=${OBJCOPY}"
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_OBJDUMP=${OBJDUMP}"
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_RANLIB=${RANLIB}"
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_STRIP=${STRIP}"
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_CXX_STANDARD=17"
export CMAKE_ARGS="${CMAKE_ARGS} -DProtobuf_PROTOC_EXECUTABLE=$PROTOC"
export CMAKE_ARGS="${CMAKE_ARGS} -DProtobuf_LIBRARY=$LIBPROTO_INSTALL/lib64/libprotobuf.so"
export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH"
export CXXFLAGS="-I$ABSEIL_PREFIX/include -I$LIBPROTO_INSTALL/include $CXXFLAGS"

# Adding this source due to - (Unable to detect linker for compiler `cc -Wl,--version`)
source /opt/rh/gcc-toolset-13/enable
python3.12 -m pip install cython meson
python3.12 -m pip install numpy
python3.12 -m pip install parameterized
python3.12 -m pip install pytest nbval pythran

python3.12 setup.py install
echo "--------------onnx installed------------------"
cd ..

cd $CURRENT_DIR
#Build
git clone $PACKAGE_URL
cd $PACKAGE_DIR
git checkout $PACKAGE_VERSION

export CXXFLAGS="-Wno-stringop-overflow -Wno-psabi"
export CFLAGS="-Wno-stringop-overflow"
python3.12 -m pip install packaging wheel
NUMPY_INCLUDE=$(python -c "import numpy; print(numpy.get_include())")
echo "NumPy include path: $NUMPY_INCLUDE"

NUMPY_INCLUDE=$(python3.12 -c "import numpy; print(numpy.get_include())")
export CMAKE_PREFIX_PATH="$ABSEIL_PREFIX:$LIBPROTO_INSTALL:$PYBIND11_PREFIX:$CMAKE_PREFIX_PATH"
export LD_LIBRARY_PATH="$LIBPROTO_INSTALL/lib64:$ABSEIL_PREFIX/lib:$LD_LIBRARY_PATH"
export CXXFLAGS="-I${NUMPY_INCLUDE} $CXXFLAGS"
export Python3_NumPy_INCLUDE_DIR=${NUMPY_INCLUDE}
# Add Python include path to build environment
export CPLUS_INCLUDE_PATH=$PYTHON_INCLUDE:$CPLUS_INCLUDE_PATH
export C_INCLUDE_PATH=$PYTHON_INCLUDE:$C_INCLUDE_PATH
cmake --version
#Build and Test
#Building and testing both are performed in build.sh
if ! (./build.sh \
--cmake_extra_defines \
onnxruntime_PREFER_SYSTEM_LIB=ON \
Protobuf_PROTOC_EXECUTABLE=$PROTOC \
Protobuf_INCLUDE_DIR=$LIBPROTO_INSTALL/include \
Python3_NumPy_INCLUDE_DIR=$NUMPY_INCLUDE \
onnxruntime_USE_COREML=OFF \
onnxruntime_BUILD_UNIT_TESTS=OFF \
onnxruntime_RUN_ONNX_TESTS=OFF \
onnxruntime_GENERATE_TEST_REPORTS=OFF \
--cmake_generator Ninja \
--build_shared_lib \
--config Release \
--update \
--build \
--build_wheel \
--skip_tests \
--skip_submodule_sync \
--parallel \
--allow_running_as_root) ; then
echo "------------------$PACKAGE_NAME:BUILD OR TEST FAILED----------------------"
echo "$PACKAGE_URL $PACKAGE_NAME"
echo "$PACKAGE_NAME | $PACKAGE_URL | $PACKAGE_VERSION | GitHub | Fail | Either_Build_OR_Test_Failed"
exit 2
else
echo "------------------$PACKAGE_NAME:BUILD AND TEST SUCCESS-------------------------"
echo "$PACKAGE_URL $PACKAGE_NAME"
echo "$PACKAGE_NAME | $PACKAGE_URL | $PACKAGE_VERSION | GitHub | Pass | Build_and_Test_Success"
fi

cp $CURRENT_DIR/onnxruntime/build/Linux/Release/dist/*.whl "$CURRENT_DIR"
exit 0
Loading