-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial backend template based on onnxruntime_backend
- Loading branch information
David Goodwin
committed
Feb 5, 2021
1 parent
d1d015d
commit ad2d2f9
Showing
7 changed files
with
2,332 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
cmake_minimum_required(VERSION 3.17) | ||
|
||
project(tritonopenvinobackend LANGUAGES C CXX) | ||
|
||
# | ||
# Set TRITON_BUILD_OPENVINO_VERSION to the version of OpenVINO that | ||
# you want to be built for the backend. Set | ||
# TRITON_BUILD_CONTAINER_VERSION to the Triton container version that | ||
# you want to target with the build. | ||
# | ||
option(TRITON_ENABLE_STATS "Include statistics collections in backend" ON) | ||
set(TRITON_BUILD_CONTAINER_VERSION "" CACHE STRING "Triton container version to build for") | ||
set(TRITON_BUILD_OPENVINO_VERSION "" CACHE STRING "OpenVINO version to build") | ||
|
||
set(TRITON_BACKEND_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/backend repo") | ||
set(TRITON_CORE_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/core repo") | ||
set(TRITON_COMMON_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/common repo") | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
if(NOT TRITON_BUILD_OPENVINO_VERSION) | ||
message(FATAL_ERROR "TRITON_BUILD_OPENVINO_VERSION is required") | ||
endif() | ||
if(NOT TRITON_BUILD_CONTAINER_VERSION) | ||
message(FATAL_ERROR "TRITON_BUILD_OPENVINO_VERSION requires TRITON_BUILD_CONTAINER_VERSION") | ||
endif() | ||
|
||
set(TRITON_OPENVINO_INCLUDE_PATHS "${CMAKE_CURRENT_BINARY_DIR}/openvino/include") | ||
set(TRITON_OPENVINO_LIB_PATHS "${CMAKE_CURRENT_BINARY_DIR}/openvino/lib") | ||
set(TRITON_OPENVINO_DOCKER_IMAGE "tritonserver_openvino") | ||
set(OPENVINO_LIBRARY "libinference_engine.so") | ||
|
||
# | ||
# Dependencies | ||
# | ||
# FetchContent's composibility isn't very good. We must include the | ||
# transitive closure of all repos so that we can override the tag. | ||
# | ||
include(FetchContent) | ||
|
||
FetchContent_Declare( | ||
repo-common | ||
GIT_REPOSITORY https://github.com/triton-inference-server/common.git | ||
GIT_TAG ${TRITON_COMMON_REPO_TAG} | ||
GIT_SHALLOW ON | ||
) | ||
FetchContent_Declare( | ||
repo-core | ||
GIT_REPOSITORY https://github.com/triton-inference-server/core.git | ||
GIT_TAG ${TRITON_CORE_REPO_TAG} | ||
GIT_SHALLOW ON | ||
) | ||
FetchContent_Declare( | ||
repo-backend | ||
GIT_REPOSITORY https://github.com/triton-inference-server/backend.git | ||
GIT_TAG ${TRITON_BACKEND_REPO_TAG} | ||
GIT_SHALLOW ON | ||
) | ||
FetchContent_MakeAvailable(repo-common repo-core repo-backend) | ||
|
||
# | ||
# Shared library implementing the Triton Backend API | ||
# | ||
configure_file(src/libtriton_openvino.ldscript libtriton_openvino.ldscript COPYONLY) | ||
|
||
add_library( | ||
triton-openvino-backend SHARED | ||
src/openvino.cc | ||
) | ||
|
||
add_library( | ||
TritonOpenVINOBackend::triton-openvino-backend ALIAS triton-openvino-backend | ||
) | ||
|
||
target_include_directories( | ||
triton-openvino-backend | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/src | ||
${TRITON_OPENVINO_INCLUDE_PATHS} | ||
) | ||
|
||
target_compile_features(triton-openvino-backend PRIVATE cxx_std_11) | ||
target_compile_options( | ||
triton-openvino-backend PRIVATE | ||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: | ||
-Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Werror> | ||
$<$<CXX_COMPILER_ID:MSVC>:/Wall /D_WIN32_WINNT=0x0A00 /EHsc> | ||
) | ||
|
||
set_target_properties( | ||
triton-openvino-backend | ||
PROPERTIES | ||
POSITION_INDEPENDENT_CODE ON | ||
OUTPUT_NAME triton_openvino | ||
SKIP_BUILD_RPATH TRUE | ||
BUILD_WITH_INSTALL_RPATH TRUE | ||
INSTALL_RPATH_USE_LINK_PATH FALSE | ||
INSTALL_RPATH "$\{ORIGIN\}" | ||
LINK_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libtriton_openvino.ldscript | ||
LINK_FLAGS "-Wl,--version-script libtriton_openvino.ldscript" | ||
) | ||
|
||
FOREACH(p ${TRITON_OPENVINO_LIB_PATHS}) | ||
set(TRITON_OPENVINO_LDFLAGS ${TRITON_OPENVINO_LDFLAGS} "-L${p}") | ||
ENDFOREACH(p) | ||
|
||
target_link_libraries( | ||
triton-openvino-backend | ||
PRIVATE | ||
triton-core-serverapi # from repo-core | ||
triton-core-backendapi # from repo-core | ||
triton-core-serverstub # from repo-core | ||
triton-backend-utils # from repo-backend | ||
${TRITON_OPENVINO_LDFLAGS} | ||
${OPENVINO_LIBRARY} | ||
) | ||
|
||
# | ||
# Build the OpenVINO libraries using docker. | ||
# | ||
add_custom_command( | ||
OUTPUT | ||
openvino/lib/${OPENVINO_LIBRARY} | ||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_openvino_dockerfile.py --triton-container="nvcr.io/nvidia/tritonserver:${TRITON_BUILD_CONTAINER_VERSION}-py3-min" --openvino-version="${TRITON_BUILD_OPENVINO_VERSION}" --output=Dockerfile.openvino | ||
COMMAND docker build --cache-from=${TRITON_OPENVINO_DOCKER_IMAGE} --cache-from=${TRITON_OPENVINO_DOCKER_IMAGE}_cache0 --cache-from=${TRITON_OPENVINO_DOCKER_IMAGE}_cache1 -t ${TRITON_OPENVINO_DOCKER_IMAGE} -f ./Dockerfile.openvino ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMAND docker rm openvino_backend_ov || echo "error ignored..." || true | ||
COMMAND docker create --name openvino_backend_ov ${TRITON_OPENVINO_DOCKER_IMAGE} | ||
COMMAND rm -fr openvino | ||
COMMAND docker cp openvino_backend_ov:/opt/openvino openvino | ||
COMMAND docker rm openvino_backend_ov | ||
COMMENT "Building OpenVino" | ||
) | ||
add_custom_target(ov_target DEPENDS openvino/lib/${OPENVINO_LIBRARY}) | ||
add_library(openvino-library SHARED IMPORTED GLOBAL) | ||
add_dependencies(openvino-library ov_target) | ||
add_dependencies(triton-openvino-backend openvino-library) | ||
set_target_properties( | ||
openvino-library | ||
PROPERTIES | ||
IMPORTED_LOCATION openvino/lib/${OPENVINO_LIBRARY} | ||
) | ||
|
||
# | ||
# Install | ||
# | ||
include(GNUInstallDirs) | ||
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/TritonOpenVINOBackend) | ||
|
||
install( | ||
TARGETS | ||
triton-openvino-backend | ||
EXPORT | ||
triton-openvino-backend-targets | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/backends/openvino | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/backends/openvino | ||
) | ||
|
||
install( | ||
DIRECTORY | ||
${CMAKE_CURRENT_BINARY_DIR}/openvino/ | ||
DESTINATION ${CMAKE_INSTALL_PREFIX}/backends/openvino | ||
PATTERN *lib EXCLUDE | ||
PATTERN *bin EXCLUDE | ||
PATTERN *include EXCLUDE | ||
) | ||
|
||
install( | ||
DIRECTORY | ||
${CMAKE_CURRENT_BINARY_DIR}/openvino/lib/ | ||
USE_SOURCE_PERMISSIONS | ||
DESTINATION ${CMAKE_INSTALL_PREFIX}/backends/openvino | ||
) | ||
|
||
install( | ||
EXPORT | ||
triton-openvino-backend-targets | ||
FILE | ||
TritonOpenVINOBackendTargets.cmake | ||
NAMESPACE | ||
TritonOpenVINOBackend:: | ||
DESTINATION | ||
${INSTALL_CONFIGDIR} | ||
) | ||
|
||
include(CMakePackageConfigHelpers) | ||
configure_package_config_file( | ||
${CMAKE_CURRENT_LIST_DIR}/cmake/TritonOpenVINOBackendConfig.cmake.in | ||
${CMAKE_CURRENT_BINARY_DIR}/TritonOpenVINOBackendConfig.cmake | ||
INSTALL_DESTINATION ${INSTALL_CONFIGDIR} | ||
) | ||
|
||
install( | ||
FILES | ||
${CMAKE_CURRENT_BINARY_DIR}/TritonOpenVINOBackendConfig.cmake | ||
DESTINATION ${INSTALL_CONFIGDIR} | ||
) | ||
|
||
# | ||
# Export from build tree | ||
# | ||
export( | ||
EXPORT triton-openvino-backend-targets | ||
FILE ${CMAKE_CURRENT_BINARY_DIR}/TritonOpenVINOBackendTargets.cmake | ||
NAMESPACE TritonOpenVINOBackend:: | ||
) | ||
|
||
export(PACKAGE TritonOpenVINOBackend) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of NVIDIA CORPORATION nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
# openvino_backend | ||
<!-- | ||
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
--> | ||
|
||
[](https://opensource.org/licenses/BSD-3-Clause) | ||
|
||
# OpenVINO Backend | ||
|
||
The Triton backend for the | ||
[OpenVINO](https://docs.openvinotoolkit.org/latest/index.html). You | ||
can learn more about Triton backends in the [backend | ||
repo](https://github.com/triton-inference-server/backend). Ask | ||
questions or report problems in the main Triton [issues | ||
page](https://github.com/triton-inference-server/server/issues). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
include(CMakeFindDependencyMacro) | ||
|
||
get_filename_component( | ||
TRITONOPENVINOBACKEND_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH | ||
) | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${TRITONOPENVINOBACKEND_CMAKE_DIR}) | ||
|
||
if(NOT TARGET TritonOpenVINOBackend::triton-openvino-backend) | ||
include("${TRITONOPENVINOBACKEND_CMAKE_DIR}/TritonOpenVINOBackendTargets.cmake") | ||
endif() | ||
|
||
set(TRITONOPENVINOBACKEND_LIBRARIES TritonOpenVINOBackend::triton-openvino-backend) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
{ | ||
global: | ||
TRITONBACKEND_*; | ||
local: *; | ||
}; |
Oops, something went wrong.