-
Notifications
You must be signed in to change notification settings - Fork 35
/
CMakeLists.txt
267 lines (229 loc) · 11.2 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#=============================================================================
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
cmake_minimum_required(VERSION 3.26.4 FATAL_ERROR)
option(TRITON_ENABLE_GPU "Enable GPU support in backend" ON)
option(TRITON_ENABLE_STATS "Include statistics collections in backend" ON)
option(TRITON_FIL_DOCKER_BUILD OFF)
option(BUILD_SHARED_LIBS OFF)
set(TRITON_REPO_ORGANIZATION "https://github.com/triton-inference-server" CACHE STRING "Git repository to pull triton libraries from")
set(TRITON_COMMON_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/common repo")
set(TRITON_CORE_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/core repo")
set(TRITON_BACKEND_REPO_TAG "main" CACHE STRING "Tag for triton-inference-server/backend repo")
# Specify *minimum* version for all RAPIDS dependencies
# Some RAPIDS deps may have later versions
set(RAPIDS_DEPENDENCIES_VERSION "24.10" CACHE STRING "RAPIDS projects dependencies version")
set(RAPIDS_TRITON_REPO_PATH "https://github.com/rapidsai/rapids-triton.git" CACHE STRING "Git repository to pull rapids_triton from")
set(RAPIDS_TRITON_REPO_TAG "branch-${RAPIDS_DEPENDENCIES_VERSION}" CACHE STRING "Tag for rapidsai/rapids-triton repo")
if(TRITON_FIL_DOCKER_BUILD)
project(RAPIDS_TRITON_BACKEND VERSION 22.10.00)
set(TRITON_BUILD_CONTAINER "nvcr.io/nvidia/tritonserver:23.09-py3" CACHE STRING "Build image for Dockerized builds")
set(TRITON_BUILD_CONTAINER_VERSION "23.09" CACHE STRING "Triton version for Dockerized builds")
add_custom_command(
OUTPUT fil/libtriton_fil.so $<$<BOOL:${TRITON_ENABLE_GPU}>:fil/libcuml++.so>
COMMAND DOCKER_BUILDKIT=1 docker build -t
triton_fil_builder
--build-arg BUILD_TYPE=${CMAKE_BUILD_TYPE}
--build-arg TRITON_VERSION=${TRITON_BUILD_CONTAINER_VERSION}
--build-arg BASE_IMAGE=${TRITON_BUILD_CONTAINER}
--build-arg TRITON_ENABLE_GPU=${TRITON_ENABLE_GPU}
--build-arg TRITON_ENABLE_STATS=${TRITON_ENABLE_GPU}
--build-arg TRITON_REPO_ORGANIZATION=${TRITON_REPO_ORGANIZATION}
--build-arg TRITON_COMMON_REPO_TAG=${TRITON_COMMON_REPO_TAG}
--build-arg TRITON_CORE_REPO_TAG=${TRITON_CORE_REPO_TAG}
--build-arg TRITON_BACKEND_REPO_TAG=${TRITON_BACKEND_REPO_TAG}
--build-arg RAPIDS_DEPENDENCIES_VERSION=${RAPIDS_DEPENDENCIES_VERSION}
--build-arg RAPIDS_TRITON_REPO_TAG=${RAPIDS_TRITON_REPO_TAG}
--build-arg RAPIDS_TRITON_REPO_PATH=${RAPIDS_TRITON_REPO_PATH}
-f ${CMAKE_CURRENT_LIST_DIR}/ops/Dockerfile
${CMAKE_CURRENT_LIST_DIR}
COMMAND docker rm triton_fil_builder || echo 'error ignored..' || true
COMMAND docker create --name triton_fil_builder triton_fil_builder
COMMAND rm -rf fil
COMMAND docker cp triton_fil_builder:/opt/tritonserver/backends/fil fil
COMMAND docker rm triton_fil_builder
COMMENT "Building FIL backend in Docker"
)
add_custom_target(
fil_docker
ALL
DEPENDS fil/libtriton_fil.so $<$<BOOL:${TRITON_ENABLE_GPU}>:fil/libcuml++.so>
)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fil
DESTINATION ${CMAKE_INSTALL_PREFIX}/backends
)
else()
##############################################################################
# - Target names -------------------------------------------------------------
set(BACKEND_NAME "fil")
set(BACKEND_TARGET "triton_${BACKEND_NAME}")
##############################################################################
# - Prepare rapids-cmake -----------------------------------------------------
file(DOWNLOAD
https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-24.10/RAPIDS.cmake
${CMAKE_BINARY_DIR}/RAPIDS.cmake)
include(${CMAKE_BINARY_DIR}/RAPIDS.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-cuda)
include(rapids-export)
include(rapids-find)
##############################################################################
# - User Options ------------------------------------------------------------
option(BUILD_BACKEND_TESTS "Build RAPIDS_TRITON_BACKEND unit-tests" ON)
option(CUDA_ENABLE_KERNEL_INFO "Enable kernel resource usage info" OFF)
option(CUDA_ENABLE_LINE_INFO "Enable lineinfo in nvcc" OFF)
option(DETECT_CONDA_ENV "Enable detection of conda environment for dependencies" ON)
option(DISABLE_DEPRECATION_WARNINGS "Disable depreaction warnings " ON)
option(NVTX "Enable nvtx markers" OFF)
set(BACKEND_FOLDER "/opt/tritonserver/backends" CACHE STRING "Triton backend folder path")
option(TRITON_FIL_USE_TREELITE_STATIC "Link Treelite statically in libtriton_fil.so and cuml++.so" ON)
message(VERBOSE "RAPIDS_TRITON_BACKEND: Enabling detection of conda environment for dependencies: ${DETECT_CONDA_ENV}")
message(VERBOSE "RAPIDS_TRITON_BACKEND: Enabling kernelinfo in nvcc: ${CUDA_ENABLE_KERNEL_INFO}")
message(VERBOSE "RAPIDS_TRITON_BACKEND: Enabling lineinfo in nvcc: ${CUDA_ENABLE_LINE_INFO}")
message(VERBOSE "RAPIDS_TRITON_BACKEND: Enabling nvtx markers: ${NVTX}")
message(VERBOSE "RAPIDS_TRITON_BACKEND: Build RAPIDS_TRITON_BACKEND unit-tests: ${BUILD_TESTS}")
message(VERBOSE "RAPIDS_TRITON_BACKEND: RAPIDS projects dependencies version: ${RAPIDS_DEPENDENCIES_VERSION}")
message(VERBOSE "RAPIDS_TRITON_BACKEND: Linking Treelite statically: ${FIL_TRITON_USE_TREELITE_STATIC}")
# Set RMM logging level
set(RMM_LOGGING_LEVEL "INFO" CACHE STRING "Choose the logging level.")
set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF")
message(VERBOSE "RAPIDS_TRITON_BACKEND: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'.")
##############################################################################
# - Project Initialization ---------------------------------------------------
if(TRITON_ENABLE_GPU)
rapids_cuda_init_architectures(RAPIDS_TRITON_BACKEND)
project(RAPIDS_TRITON_BACKEND VERSION 22.10.00 LANGUAGES CXX CUDA)
else()
project(RAPIDS_TRITON_BACKEND VERSION 22.10.00 LANGUAGES CXX)
endif()
##############################################################################
# - build type ---------------------------------------------------------------
# Set a default build type if none was specified
rapids_cmake_build_type(Release)
# this is needed for clang-tidy runs
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
##############################################################################
# - Conda environment detection ----------------------------------------------
if(DETECT_CONDA_ENV)
rapids_cmake_support_conda_env( conda_env MODIFY_PREFIX_PATH )
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND DEFINED ENV{CONDA_PREFIX})
message(STATUS "RAPIDS_TRITON_BACKEND: No CMAKE_INSTALL_PREFIX argument detected, setting to: $ENV{CONDA_PREFIX}")
set(CMAKE_INSTALL_PREFIX "$ENV{CONDA_PREFIX}")
endif()
endif()
##############################################################################
# - compiler options ---------------------------------------------------------
set(CMAKE_C_COMPILER_LAUNCHER ccache)
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
if(TRITON_ENABLE_GPU)
set(CMAKE_CUDA_COMPILER_LAUNCHER ccache)
# * find CUDAToolkit package
# * determine GPU architectures
# * enable the CMake CUDA language
# * set other CUDA compilation flags
rapids_find_package(CUDAToolkit REQUIRED
BUILD_EXPORT_SET rapids_triton-exports
INSTALL_EXPORT_SET rapids_triton-exports
)
include(cmake/modules/ConfigureCUDA.cmake)
endif()
##############################################################################
# - Requirements -------------------------------------------------------------
# add third party dependencies using CPM
rapids_cpm_init()
find_package(OpenMP REQUIRED)
if(TRITON_ENABLE_GPU)
include(cmake/thirdparty/get_cuml.cmake)
else()
include(cmake/thirdparty/get_treelite.cmake)
endif()
include(cmake/thirdparty/get_rapids-triton.cmake)
if(BUILD_TESTS)
include(cmake/thirdparty/get_gtest.cmake)
endif()
##############################################################################
# - install targets-----------------------------------------------------------
add_library(
${BACKEND_TARGET} SHARED
src/api.cc
)
IF(TRITON_ENABLE_GPU)
set_target_properties(${BACKEND_TARGET}
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
# set target compile options
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)
else()
set_target_properties(${BACKEND_TARGET}
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
# set target compile options
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)
endif()
target_compile_options(${BACKEND_TARGET}
PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${RAPIDS_TRITON_BACKEND_CXX_FLAGS}>"
"$<$<COMPILE_LANGUAGE:CUDA>:${RAPIDS_TRITON_BACKEND_CUDA_FLAGS}>"
)
target_include_directories(${BACKEND_TARGET}
PRIVATE "$<BUILD_INTERFACE:${RAPIDS_TRITON_BACKEND_SOURCE_DIR}/include>"
"${CMAKE_CURRENT_SOURCE_DIR}/src"
)
if(TRITON_FIL_USE_TREELITE_STATIC)
list(APPEND TREELITE_LIBS treelite::treelite_static)
list(APPEND TREELITE_LIBS_NO_PREFIX treelite_static)
else()
list(APPEND TREELITE_LIBS treelite::treelite)
list(APPEND TREELITE_LIBS_NO_PREFIX treelite)
endif()
target_link_libraries(${BACKEND_TARGET}
PRIVATE
$<$<BOOL:${TRITON_ENABLE_GPU}>:cuml++>
${TREELITE_LIBS}
rapids_triton::rapids_triton
triton-core-serverstub
triton-backend-utils
"${TRITONSERVER_LIB}"
$<TARGET_NAME_IF_EXISTS:conda_env>
OpenMP::OpenMP_CXX
)
if(TRITON_ENABLE_GPU)
list(APPEND BACKEND_TARGET "cuml++")
endif()
if(NOT TRITON_FIL_USE_TREELITE_STATIC)
list(APPEND BACKEND_TARGET ${TREELITE_LIBS_NO_PREFIX})
endif()
install(
TARGETS ${BACKEND_TARGET}
LIBRARY DESTINATION ${BACKEND_FOLDER}/${BACKEND_NAME}
)
##############################################################################
# - build test executable ----------------------------------------------------
# TODO (wphicks)
# if(BUILD_TESTS)
# include(test/CMakeLists.txt)
# endif()
endif() # TRITON_FIL_DOCKER_BUILD