|
4 | 4 | # This source code is licensed under the BSD-style license found in the |
5 | 5 | # LICENSE file in the root directory of this source tree. |
6 | 6 |
|
7 | | -cmake_minimum_required(VERSION 3.13 FATAL_ERROR) |
8 | | -project(inference) |
| 7 | +cmake_minimum_required(VERSION 3.8) |
9 | 8 |
|
10 | | -# This step is crucial to ensure that the |
11 | | -# _REFLECTION, _GRPC_GRPCPP and _PROTOBUF_LIBPROTOBUF variables are set. |
12 | | -# e.g. ~/gprc/examples/cpp/cmake/common.cmake |
13 | | -include(${GRPC_COMMON_CMAKE_PATH}/common.cmake) |
| 9 | +project(inference C CXX) |
14 | 10 |
|
| 11 | +include(/home/paulzhan/grpc/examples/cpp/cmake/common.cmake) |
15 | 12 |
|
16 | | -# abi and other flags |
17 | 13 |
|
18 | | -if(DEFINED GLIBCXX_USE_CXX11_ABI) |
19 | | - if(${GLIBCXX_USE_CXX11_ABI} EQUAL 1) |
20 | | - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1") |
21 | | - set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=1") |
22 | | - endif() |
23 | | -endif() |
| 14 | +# Proto file |
| 15 | +get_filename_component(hw_proto "/home/paulzhan/torchrec/torchrec/inference/protos/predictor.proto" ABSOLUTE) |
| 16 | +get_filename_component(hw_proto_path "${hw_proto}" PATH) |
24 | 17 |
|
25 | | -# keep it static for now since folly-shared version is broken |
26 | | -# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") |
27 | | -# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") |
| 18 | +# Generated sources |
| 19 | +set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/predictor.pb.cc") |
| 20 | +set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/predictor.pb.h") |
| 21 | +set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/predictor.grpc.pb.cc") |
| 22 | +set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/predictor.grpc.pb.h") |
| 23 | +add_custom_command( |
| 24 | + OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" |
| 25 | + COMMAND ${_PROTOBUF_PROTOC} |
| 26 | + ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" |
| 27 | + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" |
| 28 | + -I "${hw_proto_path}" |
| 29 | + --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" |
| 30 | + "${hw_proto}" |
| 31 | + DEPENDS "${hw_proto}") |
28 | 32 |
|
29 | | -# dependencies |
30 | | -find_package(Boost REQUIRED) |
31 | | -find_package(Torch REQUIRED) |
32 | | -find_package(folly REQUIRED) |
33 | | -find_package(gflags REQUIRED) |
34 | | - |
35 | | -include_directories(${Torch_INCLUDE_DIRS}) |
36 | | -include_directories(${folly_INCLUDE_DIRS}) |
37 | | -include_directories(${PYTORCH_FMT_INCLUDE_PATH}) |
| 33 | +# Include generated *.pb.h files |
| 34 | +include_directories("${CMAKE_CURRENT_BINARY_DIR}") |
38 | 35 |
|
39 | 36 | set(CMAKE_CXX_STANDARD 17) |
40 | 37 |
|
41 | | -# torch deploy library |
42 | | -add_library(torch_deploy_internal STATIC |
43 | | - ${DEPLOY_INTERPRETER_PATH}/libtorch_deployinterpreter.o |
44 | | - ${DEPLOY_SRC_PATH}/deploy.cpp |
45 | | - ${DEPLOY_SRC_PATH}/loader.cpp |
46 | | - ${DEPLOY_SRC_PATH}/path_environment.cpp |
47 | | - ${DEPLOY_SRC_PATH}/elf_file.cpp) |
48 | | - |
49 | | -# For python builtins. caffe2_interface_library properly |
50 | | -# makes use of the --whole-archive option. |
51 | | -target_link_libraries(torch_deploy_internal PRIVATE |
52 | | - crypt pthread dl util m z ffi lzma readline nsl ncursesw panelw |
53 | | -) |
54 | | -target_link_libraries(torch_deploy_internal |
55 | | - PUBLIC shm torch ${PYTORCH_LIB_FMT} |
56 | | -) |
57 | | -caffe2_interface_library(torch_deploy_internal torch_deploy) |
58 | | - |
59 | | -# inference library |
60 | | - |
61 | | -# for our own header files |
62 | | -include_directories(include/) |
63 | | -include_directories(gen/) |
64 | | - |
65 | | -# define our library target |
66 | | -add_library(inference STATIC |
67 | | - src/Batching.cpp |
68 | | - src/BatchingQueue.cpp |
69 | | - src/GPUExecutor.cpp |
70 | | - src/ResultSplit.cpp |
71 | | - src/Exception.cpp |
72 | | - src/ResourceManager.cpp |
73 | | -) |
74 | | - |
75 | | -# -rdynamic is needed to link against the static library |
76 | | -target_link_libraries(inference "-Wl,--no-as-needed -rdynamic" |
77 | | - dl torch_deploy "${TORCH_LIBRARIES}" ${FBGEMM_LIB} ${FOLLY_LIBRARIES} |
78 | | -) |
79 | | - |
80 | | -# for generated protobuf |
81 | | - |
82 | | -# grpc headers. e.g. ~/.local/include |
83 | | -include_directories(${GRPC_HEADER_INCLUDE_PATH}) |
84 | | - |
85 | | -set(pred_grpc_srcs "gen/torchrec/inference/predictor.grpc.pb.cc") |
86 | | -set(pred_grpc_hdrs "gen/torchrec/inference/predictor.grpc.pb.h") |
87 | | -set(pred_proto_srcs "gen/torchrec/inference/predictor.pb.cc") |
88 | | -set(pred_proto_hdrs "gen/torchrec/inference/predictor.pb.h") |
| 38 | +# Torch + FBGEMM |
| 39 | +find_package(Torch REQUIRED) |
| 40 | +add_library( fbgemm SHARED IMPORTED GLOBAL ) |
| 41 | +set_target_properties(fbgemm PROPERTIES IMPORTED_LOCATION ${FBGEMM_LIB}) |
89 | 42 |
|
90 | | -add_library(pred_grpc_proto STATIC |
91 | | - ${pred_grpc_srcs} |
92 | | - ${pred_grpc_hdrs} |
93 | | - ${pred_proto_srcs} |
94 | | - ${pred_proto_hdrs}) |
95 | 43 |
|
96 | | -target_link_libraries(pred_grpc_proto |
| 44 | +add_library(hw_grpc_proto STATIC |
| 45 | + ${hw_grpc_srcs} |
| 46 | + ${hw_grpc_hdrs} |
| 47 | + ${hw_proto_srcs} |
| 48 | + ${hw_proto_hdrs}) |
| 49 | +target_link_libraries(hw_grpc_proto |
97 | 50 | ${_REFLECTION} |
98 | 51 | ${_GRPC_GRPCPP} |
99 | 52 | ${_PROTOBUF_LIBPROTOBUF}) |
100 | 53 |
|
101 | | -# server |
| 54 | +# Targets greeter_[async_](client|server) |
102 | 55 | add_executable(server server.cpp) |
103 | 56 | target_link_libraries(server |
104 | | - inference |
105 | | - torch_deploy |
106 | | - pred_grpc_proto |
107 | 57 | "${TORCH_LIBRARIES}" |
108 | | - ${FOLLY_LIBRARIES} |
109 | | - ${PYTORCH_LIB_FMT} |
110 | | - ${FBGEMM_LIB} |
| 58 | + fbgemm |
| 59 | + hw_grpc_proto |
111 | 60 | ${_REFLECTION} |
112 | 61 | ${_GRPC_GRPCPP} |
113 | | - ${_PROTOBUF_LIBPROTOBUF}) |
| 62 | + ${_PROTOBUF_LIBPROTOBUF} |
| 63 | +) |
0 commit comments