Skip to content

Commit

Permalink
Merge pull request #6776 from hqucms/dev/CMSSW_11_3_X/onnx-gpu
Browse files Browse the repository at this point in the history
Add GPU support for ONNXRuntime
  • Loading branch information
cmsbuild committed Apr 9, 2021
2 parents cbb0c9a + 7cc7fb0 commit f6c50ee
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmssw-tool-conf.spec
Expand Up @@ -171,6 +171,10 @@ Requires: cuda-toolfile
Requires: alpaka-toolfile
Requires: cupla-toolfile

%if "%{cmsos}" != "slc7_aarch64"
Requires: cudnn-toolfile
%endif

%ifnarch ppc64le
Requires: libunwind-toolfile
Requires: igprof-toolfile
Expand Down
22 changes: 22 additions & 0 deletions cudnn-toolfile.spec
@@ -0,0 +1,22 @@
### RPM external cudnn-toolfile 1.0
Requires: cudnn
%prep

%build

%install
mkdir -p %i/etc/scram.d
cat << \EOF_TOOLFILE >%i/etc/scram.d/cudnn.xml
<tool name="cudnn" version="@TOOL_VERSION@">
<info url="https://docs.nvidia.com/deeplearning/cudnn/index.html"/>
<lib name="cudnn"/>
<client>
<environment name="CUDNN_BASE" default="@TOOL_ROOT@"/>
<environment name="INCLUDE" default="$CUDNN_BASE/include"/>
<environment name="LIBDIR" default="$CUDNN_BASE/lib64"/>
</client>
<use name="cuda"/>
</tool>
EOF_TOOLFILE

## IMPORT scram-tools-post
37 changes: 37 additions & 0 deletions cudnn.spec
@@ -0,0 +1,37 @@
### RPM external cudnn 8.1.1.33
## INITENV +PATH LD_LIBRARY_PATH %i/lib64

%define cudaver 11.2
%define cudnnver_maj %(echo %{realversion} | cut -f1,2,3 -d.)

%ifarch x86_64
Source: https://developer.download.nvidia.com/compute/redist/cudnn/v%{cudnnver_maj}/cudnn-%{cudaver}-linux-x64-v%{realversion}.tgz
%endif
%ifarch ppc64le
Source: https://developer.download.nvidia.com/compute/redist/cudnn/v%{cudnnver_maj}/cudnn-%{cudaver}-linux-ppc64le-v%{realversion}.tgz
%endif
%ifarch aarch64
Source: https://developer.download.nvidia.com/compute/redist/cudnn/v%{cudnnver_maj}/cudnn-%{cudaver}-linux-aarch64sbsa-v%{realversion}.tgz
%endif
Requires: cuda

%prep
%setup -n cuda

if [ "${CUDA_VERSION%.*}" != %{cudaver} ]; then
echo 'Incompatible CUDA version in cudnn.spec!'
exit 1
fi

%build

%install
%ifarch ppc64le
rm -f %_builddir/cuda/targets/ppc64le-linux/lib/*.a
mv %_builddir/cuda/targets/ppc64le-linux/lib %{i}/lib64
mv %_builddir/cuda/targets/ppc64le-linux/* %{i}/
%else
rm -f %_builddir/cuda/lib64/*.a
mv %_builddir/cuda/* %{i}/
%endif

4 changes: 4 additions & 0 deletions onnxruntime-toolfile.spec
Expand Up @@ -16,6 +16,10 @@ cat << \EOF_TOOLFILE >%i/etc/scram.d/onnxruntime.xml
<environment name="LIBDIR" default="$ONNXRUNTIME_BASE/lib"/>
</client>
<use name="protobuf"/>
%if "%{cmsos}" != "slc7_aarch64"
<use name="cuda"/>
<use name="cudnn"/>
%endif
<runtime name="MLAS_DYNAMIC_CPU_ARCH" value="0"/>
</tool>
EOF_TOOLFILE
Expand Down
17 changes: 16 additions & 1 deletion onnxruntime.spec
Expand Up @@ -7,21 +7,33 @@ Source: git+https://github.com/%{github_user}/%{n}.git?obj=%{branch}/%{tag}&expo

BuildRequires: cmake ninja
Requires: protobuf py3-numpy py2-wheel py2-onnx zlib libpng py2-pybind11
%if "%{cmsos}" != "slc7_aarch64"
Requires: cuda cudnn
%endif

%prep
%setup -q -n %{n}-%{realversion}

%build
rm -rf ../build; mkdir ../build; cd ../build

%if "%{cmsos}" != "slc7_aarch64"
USE_CUDA=ON
%else
USE_CUDA=OFF
%endif

cmake ../%{n}-%{realversion}/cmake -GNinja \
-DPYTHON_EXECUTABLE=${PYTHON3_ROOT}/bin/python3 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="%{i}" \
-DCMAKE_INSTALL_LIBDIR=lib \
-Donnxruntime_ENABLE_PYTHON=ON \
-Donnxruntime_BUILD_SHARED_LIB=ON \
-Donnxruntime_USE_CUDA=OFF \
-Donnxruntime_USE_CUDA=${USE_CUDA} \
-Donnxruntime_CUDA_VERSION="${CUDA_VERSION}" \
-Donnxruntime_CUDA_HOME="${CUDA_ROOT}" \
-Donnxruntime_CUDNN_HOME="${CUDNN_ROOT}" \
-Donnxruntime_BUILD_CSHARP=OFF \
-Donnxruntime_USE_EIGEN_FOR_BLAS=ON \
-Donnxruntime_USE_OPENBLAS=OFF \
Expand All @@ -39,6 +51,9 @@ cmake ../%{n}-%{realversion}/cmake -GNinja \
-Donnxruntime_DISABLE_CONTRIB_OPS=OFF \
-Donnxruntime_USE_PREINSTALLED_PROTOBUF=ON \
-Donnxruntime_PREFER_SYSTEM_LIB=ON \
-DCMAKE_CUDA_FLAGS="-cudart shared" \
-DCMAKE_CUDA_RUNTIME_LIBRARY=Shared \
-DCMAKE_TRY_COMPILE_PLATFORM_VARIABLES="CMAKE_CUDA_RUNTIME_LIBRARY" \
-DCMAKE_PREFIX_PATH="${ZLIB_ROOT};${LIBPNG_ROOT};${PROTOBUF_ROOT};${PY2_PYBIND11_ROOT}"

ninja -v %{makeprocesses}
Expand Down

0 comments on commit f6c50ee

Please sign in to comment.