Skip to content

Commit 44ef7a6

Browse files
committed
Split ONNXRuntime into ONNXRuntime, and ONNXRuntime_CUDA
1 parent 0d51868 commit 44ef7a6

File tree

4 files changed

+187
-168
lines changed

4 files changed

+187
-168
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Note that this script can accept some limited command-line arguments, run
2+
# `julia build_tarballs.jl --help` to see a usage message.
3+
using BinaryBuilder, Pkg
4+
5+
name = "ONNXRuntime"
6+
version = v"1.10.0"
7+
8+
include(joinpath(@__DIR__, "..", "common.jl"))
9+
10+
# Override the default sources
11+
append!(sources, [
12+
ArchiveSource("https://github.com/microsoft/onnxruntime/releases/download/v$version/onnxruntime-win-x64-$version.zip", "a0c6db3cff65bd282f6ba4a57789e619c27e55203321aa08c023019fe9da50d7"; unpack_target="onnxruntime-x86_64-w64-mingw32"),
13+
ArchiveSource("https://github.com/microsoft/onnxruntime/releases/download/v$version/onnxruntime-win-x86-$version.zip", "fd1680fa7248ec334efc2564086e9c5e0d6db78337b55ec32e7b666164bdb88c"; unpack_target="onnxruntime-i686-w64-mingw32"),
14+
])
15+
16+
build_tarballs(ARGS, name, version, sources, script,
17+
platforms, products, dependencies;
18+
julia_compat = "1.6",
19+
preferred_gcc_version = v"8")
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Note that this script can accept some limited command-line arguments, run
2+
# `julia build_tarballs.jl --help` to see a usage message.
3+
using BinaryBuilder, Pkg
4+
5+
const YGGDRASIL_DIR = "../../.."
6+
include(joinpath(YGGDRASIL_DIR, "fancy_toys.jl"))
7+
include(joinpath(YGGDRASIL_DIR, "platforms", "cuda.jl"))
8+
9+
name = "ONNXRuntime_CUDA"
10+
version = v"1.10.0"
11+
12+
# Cf. https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements
13+
# Cf. https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html#requirements
14+
cuda_versions = [
15+
v"10.2",
16+
v"11.3", # Using 11.3, and not 11.4, to be compatible with CUDNN v8.2.4, and with TensorRT (JLL) v8.0.1 (where the latter includes aarch64 support).
17+
]
18+
cudnn_version = v"8.2.4"
19+
tensorrt_version = v"8.0.1"
20+
21+
cudnn_compat = string(cudnn_version.major)
22+
tensorrt_compat = string(tensorrt_version.major)
23+
24+
include(joinpath(@__DIR__, "..", "common.jl"))
25+
26+
# Override the default sources
27+
append!(sources, [
28+
ArchiveSource("https://github.com/microsoft/onnxruntime/releases/download/v$version/onnxruntime-win-x64-gpu-$version.zip", "0da11b8d953fad4ec75f87bb894f72dea511a3940cff2f4dad37451586d1ebbc"; unpack_target="onnxruntime-x86_64-w64-mingw32-cuda"),
29+
# aarch64-linux-gnu binaries for NVIDIA Jetson from NVIDIA-managed Jetson Zoo: https://elinux.org/Jetson_Zoo#ONNX_Runtime
30+
FileSource("https://nvidia.box.com/shared/static/jy7nqva7l88mq9i8bw3g3sklzf4kccn2.whl", "a608b7a4a4fc6ad5c90d6005edbfe0851847b991b08aafff4549bbbbdb938bf6"; filename = "onnxruntime-aarch64-linux-gnu-cuda.whl"),
31+
])
32+
33+
# Override the default platforms
34+
platforms = CUDA.supported_platforms(min_version=v"10.2", max_version=v"11")
35+
filter!(p -> !(arch(p) == "x86_64" && Sys.islinux(p) && p["cuda"] == "10.2"), platforms) # Fails with: nvcc error : 'ptxas' died due to signal 11 (Invalid memory reference)
36+
push!(platforms, Platform("x86_64", "Linux"; cuda = "11.3"))
37+
push!(platforms, Platform("x86_64", "Windows"; cuda = "11.3"))
38+
platforms = expand_cxxstring_abis(platforms; skip=!Sys.islinux)
39+
40+
# Override the default products
41+
append!(products, [
42+
LibraryProduct(["libonnxruntime_providers_cuda", "onnxruntime_providers_cuda"], :libonnxruntime_providers_cuda; dont_dlopen=true),
43+
LibraryProduct(["libonnxruntime_providers_shared", "onnxruntime_providers_shared"], :libonnxruntime_providers_shared),
44+
LibraryProduct(["libonnxruntime_providers_tensorrt", "onnxruntime_providers_tensorrt"], :libonnxruntime_providers_tensorrt; dont_dlopen=true),
45+
])
46+
47+
append!(dependencies, [
48+
Dependency(get_addable_spec("CUDNN_jll", v"8.2.4+0"); compat = cudnn_compat), # Using v"8.2.4+0" to get support for cuda = "11.3"
49+
Dependency("TensorRT_jll", tensorrt_version; compat = tensorrt_compat),
50+
Dependency("Zlib_jll"),
51+
])
52+
53+
builds = []
54+
for platform in platforms
55+
should_build_platform(platform) || continue
56+
additional_deps = BinaryBuilder.AbstractDependency[]
57+
if platform["cuda"] == "11.3"
58+
additional_deps = BinaryBuilder.AbstractDependency[
59+
BuildDependency(PackageSpec("CUDA_full_jll", v"11.3.1")),
60+
Dependency("CUDA_Runtime_jll", v"0.7.0"), # Using v"0.7.0" to get support for cuda = "11.3" - using Dependency rather than RuntimeDependency to be sure to pass audit
61+
]
62+
else
63+
additional_deps = CUDA.required_dependencies(platform, static_sdk = true)
64+
end
65+
push!(builds, (; platforms=[platform], dependencies=[dependencies; additional_deps]))
66+
end
67+
68+
# don't allow `build_tarballs` to override platform selection based on ARGS.
69+
# we handle that ourselves by calling `should_build_platform`
70+
non_platform_ARGS = filter(arg -> startswith(arg, "--"), ARGS)
71+
72+
# `--register` should only be passed to the latest `build_tarballs` invocation
73+
non_reg_ARGS = filter(arg -> arg != "--register", non_platform_ARGS)
74+
75+
for (i, build) in enumerate(builds)
76+
build_tarballs(i == lastindex(builds) ? non_platform_ARGS : non_reg_ARGS,
77+
name, version, sources, script,
78+
build.platforms, products, build.dependencies;
79+
augment_platform_block = CUDA.augment,
80+
julia_compat = "1.6",
81+
lazy_artifacts = true,
82+
preferred_gcc_version = v"8")
83+
end

O/ONNXRuntime/build_tarballs.jl

Lines changed: 0 additions & 168 deletions
This file was deleted.

O/ONNXRuntime/common.jl

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using BinaryBuilder
2+
using BinaryBuilderBase
3+
using Pkg
4+
5+
sources = AbstractSource[
6+
GitSource("https://github.com/microsoft/onnxruntime.git", "0d9030e79888d1d5828730b254fedc53c7b640c1"),
7+
]
8+
9+
script = raw"""
10+
cd $WORKSPACE/srcdir
11+
12+
cuda_version=${bb_full_target##*-cuda+}
13+
if [[ $target != *-w64-mingw32* ]]; then
14+
if [[ $bb_full_target == x86_64-linux-gnu-*-cuda* ]]; then
15+
export CUDA_PATH="$prefix/cuda"
16+
mkdir $WORKSPACE/tmpdir
17+
export TMPDIR=$WORKSPACE/tmpdir
18+
cmake_extra_args=(
19+
-DCUDAToolkit_ROOT=$CUDA_PATH
20+
-Donnxruntime_CUDA_HOME=$CUDA_PATH
21+
-Donnxruntime_CUDNN_HOME=$prefix
22+
-Donnxruntime_USE_CUDA=ON
23+
-Donnxruntime_USE_TENSORRT=ON
24+
)
25+
fi
26+
27+
# Cross-compiling for aarch64-apple-darwin on x86_64 requires setting arch.: https://github.com/microsoft/onnxruntime/blob/v1.10.0/cmake/CMakeLists.txt#L186
28+
if [[ $target == aarch64-apple-darwin* ]]; then
29+
cmake_extra_args+=("-DCMAKE_OSX_ARCHITECTURES='arm64'")
30+
fi
31+
32+
cd onnxruntime
33+
git submodule update --init --recursive --depth 1 --jobs $nproc
34+
mkdir build
35+
cd build
36+
cmake \
37+
-DCMAKE_INSTALL_PREFIX=$prefix \
38+
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
39+
-DCMAKE_BUILD_TYPE=Release \
40+
-DONNX_CUSTOM_PROTOC_EXECUTABLE=$host_bindir/protoc \
41+
-Donnxruntime_BUILD_SHARED_LIB=ON \
42+
-Donnxruntime_BUILD_UNIT_TESTS=OFF \
43+
-Donnxruntime_DISABLE_RTTI=OFF \
44+
"${cmake_extra_args[@]}" \
45+
$WORKSPACE/srcdir/onnxruntime/cmake
46+
make -j $nproc
47+
make install
48+
install_license $WORKSPACE/srcdir/onnxruntime/LICENSE
49+
else
50+
if [[ $bb_full_target == *-cuda* ]]; then
51+
srcdir=onnxruntime-$target-cuda
52+
else
53+
srcdir=onnxruntime-$target
54+
fi
55+
chmod 755 $srcdir/onnxruntime-*/lib/*
56+
mkdir -p $includedir $libdir
57+
cp -av $srcdir/onnxruntime-*/include/* $includedir
58+
find $srcdir/onnxruntime-*/lib -not -type d | xargs -Isrc cp -av src $libdir
59+
install_license $srcdir/onnxruntime-*/LICENSE
60+
fi
61+
62+
if [[ $bb_full_target == aarch64-linux-gnu*-cuda* ]]; then
63+
cd $WORKSPACE/srcdir
64+
unzip -d onnxruntime-$target-cuda onnxruntime-$target-cuda.whl
65+
mkdir -p $libdir
66+
find onnxruntime-$target-cuda/onnxruntime_gpu*.data/purelib/onnxruntime/capi -name *.so* -not -name *py* | xargs -Isrc cp -av src $libdir
67+
fi
68+
"""
69+
70+
function platform_exclude_filter(p::Platform)
71+
libc(p) == "musl" ||
72+
p == Platform("i686", "Linux") || # No binary - and source build fails linking CXX shared library libonnxruntime.so
73+
Sys.isfreebsd(p)
74+
end
75+
platforms = supported_platforms(; exclude=platform_exclude_filter)
76+
platforms = expand_cxxstring_abis(platforms; skip=!Sys.islinux)
77+
78+
products = Product[
79+
LibraryProduct(["libonnxruntime", "onnxruntime"], :libonnxruntime)
80+
]
81+
82+
dependencies = AbstractDependency[
83+
HostBuildDependency(PackageSpec("protoc_jll", v"3.16.1"))
84+
]
85+

0 commit comments

Comments
 (0)