Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
124 changes: 37 additions & 87 deletions torchrec/inference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,110 +4,60 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(inference)
cmake_minimum_required(VERSION 3.8)

# This step is crucial to ensure that the
# _REFLECTION, _GRPC_GRPCPP and _PROTOBUF_LIBPROTOBUF variables are set.
# e.g. ~/gprc/examples/cpp/cmake/common.cmake
include(${GRPC_COMMON_CMAKE_PATH}/common.cmake)
project(inference C CXX)

include(/home/paulzhan/grpc/examples/cpp/cmake/common.cmake)

# abi and other flags

if(DEFINED GLIBCXX_USE_CXX11_ABI)
if(${GLIBCXX_USE_CXX11_ABI} EQUAL 1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=1")
endif()
endif()
# Proto file
get_filename_component(hw_proto "/home/paulzhan/torchrec/torchrec/inference/protos/predictor.proto" ABSOLUTE)
get_filename_component(hw_proto_path "${hw_proto}" PATH)

# keep it static for now since folly-shared version is broken
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
# Generated sources
set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/predictor.pb.cc")
set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/predictor.pb.h")
set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/predictor.grpc.pb.cc")
set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/predictor.grpc.pb.h")
add_custom_command(
OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${hw_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${hw_proto}"
DEPENDS "${hw_proto}")

# dependencies
find_package(Boost REQUIRED)
find_package(Torch REQUIRED)
find_package(folly REQUIRED)
find_package(gflags REQUIRED)

include_directories(${Torch_INCLUDE_DIRS})
include_directories(${folly_INCLUDE_DIRS})
include_directories(${PYTORCH_FMT_INCLUDE_PATH})
# Include generated *.pb.h files
include_directories("${CMAKE_CURRENT_BINARY_DIR}")

set(CMAKE_CXX_STANDARD 17)

# torch deploy library
add_library(torch_deploy_internal STATIC
${DEPLOY_INTERPRETER_PATH}/libtorch_deployinterpreter.o
${DEPLOY_SRC_PATH}/deploy.cpp
${DEPLOY_SRC_PATH}/loader.cpp
${DEPLOY_SRC_PATH}/path_environment.cpp
${DEPLOY_SRC_PATH}/elf_file.cpp)

# For python builtins. caffe2_interface_library properly
# makes use of the --whole-archive option.
target_link_libraries(torch_deploy_internal PRIVATE
crypt pthread dl util m z ffi lzma readline nsl ncursesw panelw
)
target_link_libraries(torch_deploy_internal
PUBLIC shm torch ${PYTORCH_LIB_FMT}
)
caffe2_interface_library(torch_deploy_internal torch_deploy)

# inference library

# for our own header files
include_directories(include/)
include_directories(gen/)

# define our library target
add_library(inference STATIC
src/Batching.cpp
src/BatchingQueue.cpp
src/GPUExecutor.cpp
src/ResultSplit.cpp
src/Exception.cpp
src/ResourceManager.cpp
)

# -rdynamic is needed to link against the static library
target_link_libraries(inference "-Wl,--no-as-needed -rdynamic"
dl torch_deploy "${TORCH_LIBRARIES}" ${FBGEMM_LIB} ${FOLLY_LIBRARIES}
)

# for generated protobuf

# grpc headers. e.g. ~/.local/include
include_directories(${GRPC_HEADER_INCLUDE_PATH})

set(pred_grpc_srcs "gen/torchrec/inference/predictor.grpc.pb.cc")
set(pred_grpc_hdrs "gen/torchrec/inference/predictor.grpc.pb.h")
set(pred_proto_srcs "gen/torchrec/inference/predictor.pb.cc")
set(pred_proto_hdrs "gen/torchrec/inference/predictor.pb.h")
# Torch + FBGEMM
find_package(Torch REQUIRED)
add_library( fbgemm SHARED IMPORTED GLOBAL )
set_target_properties(fbgemm PROPERTIES IMPORTED_LOCATION ${FBGEMM_LIB})

add_library(pred_grpc_proto STATIC
${pred_grpc_srcs}
${pred_grpc_hdrs}
${pred_proto_srcs}
${pred_proto_hdrs})

target_link_libraries(pred_grpc_proto
add_library(hw_grpc_proto STATIC
${hw_grpc_srcs}
${hw_grpc_hdrs}
${hw_proto_srcs}
${hw_proto_hdrs})
target_link_libraries(hw_grpc_proto
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})

# server
# Targets greeter_[async_](client|server)
add_executable(server server.cpp)
target_link_libraries(server
inference
torch_deploy
pred_grpc_proto
"${TORCH_LIBRARIES}"
${FOLLY_LIBRARIES}
${PYTORCH_LIB_FMT}
${FBGEMM_LIB}
fbgemm
hw_grpc_proto
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
${_PROTOBUF_LIBPROTOBUF}
)
Loading