Skip to content

Commit d38aa45

Browse files
kiddyjinjintianjinjin
and
tianjinjin
authored
[Backend]add poros to fastdeploy (#671)
* add poros to fastdeploy * update readme * update readme & add license for all files * update benchmark * update copyright for some files Co-authored-by: tianjinjin <tianjinjin@baidu.com>
1 parent 42f1888 commit d38aa45

File tree

224 files changed

+40494
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+40494
-0
lines changed

poros/CMakeLists.txt

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
project(poros)
3+
set(CMAKE_CXX_STANDARD 14)
4+
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
5+
6+
7+
option(BUILD_STATIC "build lib${PROJECT_NAME}.a static lib" OFF)
8+
option(BUILD_KERNEL "build lib${PROJECT_NAME}-kernel.so shared lib" OFF)
9+
option(BUILD_STATIC_KERNEL "build lib${PROJECT_NAME}-kernel.a static lib" OFF)
10+
option(BUILD_TOOL "build ${PROJECT_NAME}-tool, an executable binary output" OFF)
11+
option(TEST "build for test. copy '.so' to site-packages automatically after compile" OFF)
12+
option(DEBUG "build for debug. add '-g' flag to gcc for detailed debug information" ON)
13+
option(UT "build for unit test" OFF)
14+
15+
16+
# minimum requirements
17+
set(PYTHON_MINIMUM_VERSION 3.6)
18+
set(CUDA_MINIMUM_VERSION 10.2)
19+
set(PYTORCH_MINIMUM_VERSION 1.9)
20+
set(TENSORRT_MINIMUM_VERSION 8.2)
21+
set(CUDNN_MINIMUM_VERSION 8.0)
22+
23+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
24+
25+
# find cuda
26+
find_package(CUDAToolkit ${CUDA_MINIMUM_VERSION} REQUIRED)
27+
28+
# find python3
29+
find_package(Python3 ${PYTHON_MINIMUM_VERSION} REQUIRED COMPONENTS Interpreter Development)
30+
message(STATUS "Found Python: ${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}.${Python3_VERSION_PATCH}")
31+
32+
if (NOT Python3_SITELIB)
33+
message(FATAL_ERROR "site-packages not found. ")
34+
else ()
35+
message(STATUS "site-packages: ${Python3_SITELIB}")
36+
endif ()
37+
38+
# find pytorch
39+
find_package(Torch ${PYTORCH_MINIMUM_VERSION} REQUIRED HINTS ${Python3_SITELIB})
40+
41+
# find TensorRT
42+
find_package(TensorRT ${TENSORRT_MINIMUM_VERSION} REQUIRED)
43+
get_filename_component(TENSORRT_LIB_DIR ${TensorRT_LIBRARIES} DIRECTORY)
44+
45+
46+
# find CUDNN
47+
find_package(CUDNN ${CUDNN_MINIMUM_VERSION} REQUIRED)
48+
49+
50+
## release headers
51+
# engine
52+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/engine/iengine.h" "${PROJECT_SOURCE_DIR}/src/poros/engine/engine_context.h")
53+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/engine")
54+
# compile
55+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/compile/poros_module.h")
56+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/compile")
57+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/compile/compile.h")
58+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/compile")
59+
# converter
60+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/converter/iconverter.h")
61+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/converter")
62+
# iplugin
63+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/iplugin/*.h")
64+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/iplugin")
65+
## context
66+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/context/*.h")
67+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/context")
68+
## context
69+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/context/*.h")
70+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/context")
71+
## lowering
72+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/lowering/*.h")
73+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/lowering")
74+
## util
75+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/util/*.h")
76+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/util")
77+
## log
78+
file(GLOB headers "${PROJECT_SOURCE_DIR}/src/poros/log/*.h")
79+
file(COPY ${headers} DESTINATION "${PROJECT_SOURCE_DIR}/build/include/poros/log")
80+
81+
82+
include_directories(${TORCH_INCLUDE_DIRS})
83+
include_directories(${TensorRT_INCLUDE_DIRS})
84+
include_directories(${CUDA_INCLUDE_DIRS})
85+
include_directories(${CUDNN_INCLUDE_PATH})
86+
include_directories(src)
87+
include_directories(src/poros/compile)
88+
89+
90+
add_compile_options(-D__const__= -D_GNU_SOURCE)
91+
add_compile_options(-lpthread -lcrypto -lrt -ldl -lz -fPIC -rdynamic)
92+
add_compile_options(-std=c++17 -O2 -g -pipe -W -Wall -fPIC -Wno-deprecated-declarations -Wno-unused-parameter)
93+
if (DEBUG)
94+
add_compile_options(-g) # for debug
95+
endif ()
96+
97+
add_compile_options(
98+
-Wall
99+
-Wno-comment
100+
-Wno-error=implicit-fallthrough
101+
-Wno-error=unused-but-set-variable
102+
-Wno-error=misleading-indentation
103+
-Wno-error=unused-function
104+
-Wno-error=terminate
105+
-Wno-unused-parameter
106+
-Wno-deprecated-declarations
107+
)
108+
109+
110+
file(
111+
GLOB POROS_CPP_FILES
112+
"./src/poros/*/*.cpp"
113+
"./src/poros/converter/*/*.cpp"
114+
"./src/poros/converter/gpu/plugins/*.cpp"
115+
)
116+
117+
118+
# libporos.so
119+
add_library(${PROJECT_NAME} SHARED ${POROS_CPP_FILES})
120+
121+
#set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/poros/lib)
122+
set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/lib)
123+
124+
#add_custom_command(
125+
# TARGET ${PROJECT_NAME}
126+
# COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/output/lib/lib${PROJECT_NAME}.so ${CMAKE_CURRENT_SOURCE_DIR}/python/poros/lib/
127+
#)
128+
129+
# copy libporos.so to python site-packages/poros/lib for testing
130+
if (TEST)
131+
add_custom_command(
132+
TARGET ${PROJECT_NAME}
133+
POST_BUILD
134+
COMMENT "copy ${LIBRARY_OUTPUT_PATH}/lib${PROJECT_NAME}.so to ${Python3_SITELIB}/poros/lib/lib${PROJECT_NAME}.so for rapid testing"
135+
COMMAND ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_DIRECTORY}/lib${PROJECT_NAME}.so ${Python3_SITELIB}/poros/lib/lib${PROJECT_NAME}.so
136+
)
137+
endif ()
138+
139+
140+
if (BUILD_STATIC)
141+
add_library(${PROJECT_NAME}-static STATIC ${POROS_CPP_FILES})
142+
set_target_properties(${PROJECT_NAME}-static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
143+
endif ()
144+
145+
# build gflags
146+
set(GFLAGS_NAMESPACE google)
147+
add_subdirectory(third_party/gflags)
148+
149+
150+
find_package(BLAS)
151+
152+
add_custom_target(
153+
Creating_Symlink ALL
154+
COMMAND_EXPAND_LISTS
155+
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR}/third_party
156+
COMMAND ${CMAKE_COMMAND} -E create_symlink ${TENSORRT_LIB_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/third_party/tensorrtlib
157+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
158+
COMMENT "Creating Symlink ${CMAKE_CURRENT_SOURCE_DIR}/third_party/tensorrtlib -> ${TENSORRT_LIB_DIR} "
159+
VERBATIM
160+
)
161+
162+
# executable
163+
if (BUILD_TOOL)
164+
set(POROS_TOOL ${PROJECT_NAME}-tool)
165+
166+
167+
add_executable(${POROS_TOOL})
168+
169+
target_sources(${POROS_TOOL} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tools/main.cpp)
170+
target_sources(${POROS_TOOL} PUBLIC ${POROS_CPP_FILES})
171+
172+
target_link_libraries(${POROS_TOOL} gflags::gflags)
173+
target_link_libraries(${POROS_TOOL} TensorRT::TensorRT TensorRT::Plugin)
174+
target_link_libraries(${POROS_TOOL} torch)
175+
# target_link_libraries(${POROS_TOOL} CUDA::toolkit)
176+
target_link_libraries(${POROS_TOOL} CUDA::cudart CUDA::cusolver CUDA::cublas CUDA::cusolver CUDA::cusparse)
177+
target_link_libraries(${POROS_TOOL} BLAS::BLAS)
178+
179+
endif ()
180+
181+
182+
183+
# kernel
184+
file(
185+
GLOB POROS_KERNEL_CPP_FILES
186+
./src/poros/compile/*.cpp
187+
./src/poros/context/*.cpp
188+
./src/poros/iplugin/*.cpp
189+
./src/poros/log/*.cpp
190+
./src/poros/lowering/*.cpp
191+
./src/poros/util/*.cpp
192+
./src/poros/engine/engine.cpp
193+
)
194+
195+
# kernel SHARED
196+
if (BUILD_KERNEL)
197+
add_library(${PROJECT_NAME}-kernel SHARED ${POROS_KERNEL_CPP_FILES})
198+
endif ()
199+
200+
# kernel STATIC
201+
if (BUILD_STATIC_KERNEL)
202+
add_library(${PROJECT_NAME}-kernel-static STATIC ${POROS_KERNEL_CPP_FILES})
203+
set_target_properties(${PROJECT_NAME}-kernel-static PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-kernel)
204+
endif ()
205+
206+
if (UT)
207+
add_subdirectory(third_party/googletest)
208+
add_subdirectory(unittest)
209+
endif ()

0 commit comments

Comments
 (0)