Skip to content

Commit

Permalink
Building for multiple CUDA versions
Browse files Browse the repository at this point in the history
  • Loading branch information
stemann committed Apr 30, 2022
1 parent deccd0d commit 7857a03
Showing 1 changed file with 67 additions and 56 deletions.
123 changes: 67 additions & 56 deletions O/ONNXRuntime/ONNXRuntime/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ version = v"1.10.0"

# Cf. https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements
# Cf. https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html#requirements
cuda_version = v"11.4"
cuda_versions = [v"10.2", v"11.0", v"11.1", v"11.2", v"11.3", v"11.4"]
cudnn_version = v"8.2.4"
tensorrt_version = v"8.0.1"

cuda_compat = "$(cuda_version.major).$(cuda_version.minor)"
cudnn_compat = string(cudnn_version.major)
tensorrt_compat = string(tensorrt_version.major)

Expand All @@ -20,53 +19,59 @@ sources = [
GitSource("https://github.com/microsoft/onnxruntime.git", "0d9030e79888d1d5828730b254fedc53c7b640c1"),
ArchiveSource("https://github.com/microsoft/onnxruntime/releases/download/v$version/onnxruntime-win-x64-$version.zip", "a0c6db3cff65bd282f6ba4a57789e619c27e55203321aa08c023019fe9da50d7"; unpack_target="onnxruntime-x86_64-w64-mingw32"),
ArchiveSource("https://github.com/microsoft/onnxruntime/releases/download/v$version/onnxruntime-win-x86-$version.zip", "fd1680fa7248ec334efc2564086e9c5e0d6db78337b55ec32e7b666164bdb88c"; unpack_target="onnxruntime-i686-w64-mingw32"),
ArchiveSource("https://github.com/microsoft/onnxruntime/releases/download/v$version/onnxruntime-linux-x64-gpu-$version.tgz", "bc880ba8a572acf79d50dcd35ba6dd8e5fb708d03883959ef60efbc15f5cdcb6"; unpack_target="onnxruntime-x86_64-linux-gnu-cuda"),
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")
]

cuda_sources = [
ArchiveSource("https://github.com/microsoft/onnxruntime/releases/download/v$version/onnxruntime-linux-x64-gpu-$version.tgz", "bc880ba8a572acf79d50dcd35ba6dd8e5fb708d03883959ef60efbc15f5cdcb6"; unpack_target="onnxruntime-x86_64-linux-gnu"),
ArchiveSource("https://github.com/microsoft/onnxruntime/releases/download/v$version/onnxruntime-win-x64-gpu-$version.zip", "0da11b8d953fad4ec75f87bb894f72dea511a3940cff2f4dad37451586d1ebbc"; unpack_target="onnxruntime-x86_64-w64-mingw32"),
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir
if [[ $bb_full_target != *cuda* ]]; then
if [[ $target == *-w64-mingw32* ]]; then
chmod 755 onnxruntime-$target/onnxruntime-*/lib/*
mkdir -p $includedir $libdir
cp -av onnxruntime-$target/onnxruntime-*/include/* $includedir
cp -av onnxruntime-$target/onnxruntime-*/lib/* $libdir
install_license onnxruntime-$target/onnxruntime-*/LICENSE
else
# 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
if [[ $target == aarch64-apple-darwin* ]]; then
cmake_extra_args="-DCMAKE_OSX_ARCHITECTURES='arm64'"
fi
cd onnxruntime
git submodule update --init --recursive
mkdir -p build
cd build
cmake $WORKSPACE/srcdir/onnxruntime/cmake \
-DCMAKE_INSTALL_PREFIX=$prefix \
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
-DCMAKE_BUILD_TYPE=Release \
-DONNX_CUSTOM_PROTOC_EXECUTABLE=$host_bindir/protoc \
-Donnxruntime_BUILD_SHARED_LIB=ON \
-Donnxruntime_BUILD_UNIT_TESTS=OFF \
-Donnxruntime_DISABLE_RTTI=OFF \
$cmake_extra_args
make -j $nproc
make install
install_license $WORKSPACE/srcdir/onnxruntime/LICENSE
fi
if [[ $target == *-w64-mingw32* ]]; then
chmod 755 onnxruntime-$target/onnxruntime-*/lib/*
mkdir -p $includedir $libdir
cp -av onnxruntime-$target/onnxruntime-*/include/* $includedir
cp -av onnxruntime-$target/onnxruntime-*/lib/* $libdir
install_license onnxruntime-$target/onnxruntime-*/LICENSE
else
if [[ $target == *-w64-mingw32* ]]; then
chmod 755 onnxruntime-$target-cuda/onnxruntime-*/lib/*
# 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
if [[ $target == aarch64-apple-darwin* ]]; then
cmake_extra_args="-DCMAKE_OSX_ARCHITECTURES='arm64'"
fi
mkdir -p $includedir $libdir
cp -av onnxruntime-$target-cuda/onnxruntime-*/include/* $includedir
find onnxruntime-$target-cuda/onnxruntime-*/lib -not -type d | xargs -Isrc cp -av src $libdir
install_license onnxruntime-$target-cuda/onnxruntime-*/LICENSE
cd onnxruntime
git submodule update --init --recursive
mkdir -p build
cd build
cmake $WORKSPACE/srcdir/onnxruntime/cmake \
-DCMAKE_INSTALL_PREFIX=$prefix \
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
-DCMAKE_BUILD_TYPE=Release \
-DONNX_CUSTOM_PROTOC_EXECUTABLE=$host_bindir/protoc \
-Donnxruntime_BUILD_SHARED_LIB=ON \
-Donnxruntime_BUILD_UNIT_TESTS=OFF \
-Donnxruntime_DISABLE_RTTI=OFF \
$cmake_extra_args
make -j $nproc
make install
install_license $WORKSPACE/srcdir/onnxruntime/LICENSE
fi
"""

cuda_script = raw"""
cd $WORKSPACE/srcdir
find onnxruntime-$target
if [[ $target == *-w64-mingw32* ]]; then
chmod 755 onnxruntime-$target/onnxruntime-*/lib/*
fi
mkdir -p $includedir $libdir
cp -av onnxruntime-$target/onnxruntime-*/include/* $includedir
find onnxruntime-$target/onnxruntime-*/lib -not -type d | xargs -Isrc cp -av src $libdir
install_license onnxruntime-$target/onnxruntime-*/LICENSE
"""

# These are the platforms we will build for by default, unless further
Expand All @@ -77,34 +82,40 @@ function platform_exclude_filter(p::Platform)
Sys.isfreebsd(p)
end
platforms = supported_platforms(; exclude=platform_exclude_filter)

cuda_platforms = [
Platform("x86_64", "Linux"; cuda = cuda_compat),
Platform("x86_64", "Windows"; cuda = cuda_compat)
]
for p in cuda_platforms
push!(platforms, p)
end

platforms = expand_cxxstring_abis(platforms; skip=!Sys.islinux)
cuda_platforms = expand_cxxstring_abis(cuda_platforms; skip=!Sys.islinux)

# The products that we will ensure are always built
products = [
LibraryProduct(["libonnxruntime", "onnxruntime"], :libonnxruntime)
]

cuda_products = [
LibraryProduct(["libonnxruntime", "onnxruntime"], :libonnxruntime),
LibraryProduct(["libonnxruntime_providers_shared", "onnxruntime_providers_shared"], :libonnxruntime_providers_shared),
LibraryProduct(["libonnxruntime_providers_cuda", "onnxruntime_providers_cuda"], :libonnxruntime_providers_cuda; dont_dlopen = true),
LibraryProduct(["libonnxruntime_providers_tensorrt", "onnxruntime_providers_tensorrt"], :libonnxruntime_providers_tensorrt; dont_dlopen = true),
]

# Dependencies that must be installed before this package can be built
dependencies = [
Dependency("CUDNN_jll", cudnn_version;
compat = cudnn_compat,
platforms = cuda_platforms),
Dependency("TensorRT_jll", tensorrt_version;
compat = tensorrt_compat,
platforms = cuda_platforms),
HostBuildDependency(PackageSpec("protoc_jll", Base.UUID("c7845625-083e-5bbe-8504-b32d602b7110"), v"3.16.1"))
]

cuda_dependencies = [
Dependency("CUDNN_jll", cudnn_version; compat = cudnn_compat),
Dependency("TensorRT_jll", tensorrt_version; compat = tensorrt_compat),
]

for cuda_version in cuda_versions
cuda_tag = "$(cuda_version.major).$(cuda_version.minor)"
cuda_platforms = [
Platform("x86_64", "Linux"; cuda = cuda_tag),
Platform("x86_64", "Windows"; cuda = cuda_tag)
]
build_tarballs(ARGS, name, version, cuda_sources, cuda_script, cuda_platforms, products, cuda_dependencies;
julia_compat = "1.6")
end

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
preferred_gcc_version = v"8",
Expand Down

0 comments on commit 7857a03

Please sign in to comment.