Skip to content

Commit

Permalink
Add initial gRPC implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
varunsh-xilinx committed Feb 25, 2022
1 parent ef051a3 commit 37a6aad
Show file tree
Hide file tree
Showing 20 changed files with 1,144 additions and 93 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Expand Up @@ -78,6 +78,9 @@ find_package(OpenCV)
find_package(opentelemetry-cpp CONFIG)
find_package(spdlog)
find_package(Threads REQUIRED)
find_package(Protobuf)
find_package(absl CONFIG)
find_package(gRPC CONFIG)

find_package(xir QUIET)
find_package(vart QUIET)
Expand All @@ -103,6 +106,7 @@ endif()
configure_file(${PROJECT_SOURCE_DIR}/src/proteus/version.hpp.in ${PROJECT_SOURCE_DIR}/src/proteus/version.hpp)

option(PROTEUS_ENABLE_REST "Enable the REST server" ON)
option(PROTEUS_ENABLE_GRPC "Enable the gRPC server" ${gRPC_FOUND})
option(PROTEUS_ENABLE_METRICS "Enable Prometheus metrics" ON)
option(PROTEUS_ENABLE_LOGGING "Enable logging" ${spdlog_FOUND})
option(PROTEUS_ENABLE_TRACING "Enable Jaeger tracing" ${opentelemetry-cpp_FOUND})
Expand All @@ -111,7 +115,7 @@ option(PROTEUS_ENABLE_VITIS "Enable Vitis dependencies" ${PROTEUS_VITIS_FOUND})
option(PROTEUS_BUILD_EXAMPLES "Build examples" ON)
option(PROTEUS_BUILD_SHARED "Build Proteus as a shared library" ON)
option(PROTEUS_BUILD_TESTING "Build C++ tests" ${PROTEUS_BUILD_TESTING_DEFAULT})
option(PROTEUS_ENABLE_IPO "Enable interprocedural optimizations" ON)
option(PROTEUS_ENABLE_IPO "Enable interprocedural optimizations" OFF)

if(${PROTEUS_ENABLE_REST} OR ${PROTEUS_ENABLE_METRICS})
set(PROTEUS_ENABLE_HTTP ON)
Expand All @@ -123,6 +127,7 @@ set(PROTEUS_DEFAULT_HTTP_PORT 8998)

message(STATUS "Build Options:")
message(STATUS " PROTEUS_ENABLE_REST: " ${PROTEUS_ENABLE_REST})
message(STATUS " PROTEUS_ENABLE_GRPC: " ${PROTEUS_ENABLE_GRPC})
message(STATUS " PROTEUS_ENABLE_METRICS: " ${PROTEUS_ENABLE_METRICS})
message(STATUS " PROTEUS_ENABLE_LOGGING: " ${PROTEUS_ENABLE_LOGGING})
message(STATUS " PROTEUS_ENABLE_TRACING: " ${PROTEUS_ENABLE_TRACING})
Expand Down
2 changes: 1 addition & 1 deletion docs/dependencies.rst
Expand Up @@ -172,7 +172,7 @@ The following files are included in the Xilinx Inference Server repository under
CodeCoverage.cmake,:github:`bilke/cmake-modules`,`CodeCoverage.cmake <https://www.github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake>`__,BSD-3,Cmake module for test coverage measurement
ctpl.h,:github:`vit-vit/CTPL`,`ctpl.h <https://www.github.com/vit-vit/CTPL/blob/master/ctpl.h>`__,Apache 2.0,C++ Thread pool library
dog-3619020_640.jpg,`Pixabay <https://pixabay.com/photos/dog-spitz-smile-ginger-home-pet-3619020/>`__,`dog-3619020_640.jpg <https://cdn.pixabay.com/photo/2018/08/20/14/08/dog-3619020_640.jpg>`__,`Pixabay License <https://pixabay.com/service/license/>`_,Used for testing
proteusConfig.cmake,:github:`alexreinking/SharedStaticStarter`,`SomeLibConfig.cmake <https://www.github.com/alexreinking/SharedStaticStarter/blob/master/packaging/SomeLibConfig.cmake>`__,MIT,Cmake module for installing libraries
proteusConfig.cmake,:github:`alexreinking/SharedStaticStarter`,`SomeLibConfig.cmake <https://www.github.com/alexreinking/SharedStaticStarter/blob/master/packaging/SomeLibConfig.cmake>`__,MIT,CMake module for installing libraries
Queue.js,`Kate Rose Morley <https://code.iamkate.com/javascript/queues/>`__,`Queue.src.js <https://code.iamkate.com/javascript/queues/Queue.src.js>`__,`CC0 1.0 Universal <https://creativecommons.org/publicdomain/zero/1.0/legalcode>`__,JavaScript class for a queue
sport-1284275_640.jpg,`Pixabay <https://pixabay.com/photos/sport-skateboard-skateboarding-fun-1284275/>`__,`sport-1284275_640.jpg <https://cdn.pixabay.com/photo/2016/03/27/21/05/sport-1284275_640.jpg>`__,`Pixabay License <https://pixabay.com/service/license/>`_,Used for testing

Expand Down
2 changes: 2 additions & 0 deletions include/proteus/core/data_types.hpp
Expand Up @@ -108,6 +108,8 @@ constexpr size_t getSize(DataType type) {
*/
std::string mapTypeToStr(DataType type);

DataType mapStrToType(const std::string& type);

std::ostream& operator<<(std::ostream& os, const DataType& bar);

#ifdef PROTEUS_ENABLE_VITIS
Expand Down
15 changes: 11 additions & 4 deletions proteus
Expand Up @@ -109,15 +109,20 @@ def run_tty_command(command: str, dry_run: bool):
sys.exit(exit_code)


def run_command(command: str, dry_run: bool, exit_on_error=True):
def run_command(command: str, dry_run: bool, exit_on_error=True, quiet=False):
if dry_run:
print(command)
return

try:
subprocess.check_call(
shlex.split(command), stdout=sys.stdout, stderr=subprocess.STDOUT
)
if quiet:
subprocess.check_call(
shlex.split(command), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
else:
subprocess.check_call(
shlex.split(command), stdout=sys.stdout, stderr=subprocess.STDOUT
)
except subprocess.CalledProcessError as error:
if exit_on_error:
sys.exit(error.returncode)
Expand Down Expand Up @@ -397,6 +402,8 @@ class Build:
shared_libs = " ".join(glob.glob(f"{str(build_dir)}/src/proteus/workers/*.so"))
command = f"cp -fs {shared_libs} {path}/"
run_command(command, args.dry_run)
command = f"symlinks -rc {path}"
run_command(command, args.dry_run, quiet=True)
if not args.dry_run:
print("")
print("======================")
Expand Down
10 changes: 5 additions & 5 deletions src/proteus/CMakeLists.txt
Expand Up @@ -14,14 +14,11 @@

add_executable(proteus-server main.cpp)
target_include_directories(proteus-server PRIVATE ${PROTEUS_INCLUDE_DIRS})
target_include_directories(proteus-server PRIVATE $<TARGET_PROPERTY:lib_grpc,INCLUDE_DIRECTORIES>)
target_link_options(proteus-server PRIVATE "LINKER:-E")
enable_ipo_on_target(proteus-server)

target_link_libraries(proteus-server PRIVATE batching buffers clients core)

if(${PROTEUS_ENABLE_HTTP})
target_link_libraries(proteus-server PRIVATE http_server websocket_server)
endif()
target_link_libraries(proteus-server PRIVATE batching buffers clients core servers)

add_subdirectory(batching)
add_subdirectory(buffers)
Expand Down Expand Up @@ -66,6 +63,9 @@ endif()
if(${PROTEUS_ENABLE_HTTP})
target_link_libraries(proteus PRIVATE drogon trantor)
endif()
if(${PROTEUS_ENABLE_GRPC})
target_link_libraries(proteus PRIVATE lib_grpc)
endif()
if(${PROTEUS_ENABLE_TRACING})
get_target_property(TRACING_LINK_LIBS tracing INTERFACE_LINK_LIBRARIES)
target_link_libraries(proteus PRIVATE ${TRACING_LINK_LIBS})
Expand Down
2 changes: 2 additions & 0 deletions src/proteus/build_options.hpp.in
Expand Up @@ -27,6 +27,8 @@
#cmakedefine PROTEUS_ENABLE_METRICS
/// Enables Proteus's HTTP server
#cmakedefine PROTEUS_ENABLE_HTTP
/// Enables Proteus's gRPC server
#cmakedefine PROTEUS_ENABLE_GRPC
/// Enables Proteus's tracing
#cmakedefine PROTEUS_ENABLE_TRACING
/// Enables Proteus's logging
Expand Down
54 changes: 36 additions & 18 deletions src/proteus/core/CMakeLists.txt
Expand Up @@ -13,41 +13,59 @@
# limitations under the License.

list(APPEND targets
predict_api
predict_api_internal
fake_predict_api
manager
worker_info
data_types
interface
predict_api
predict_api_internal
fake_predict_api
manager
worker_info
data_types
interface
)

foreach(target ${targets})
add_library(${target} OBJECT ${target}.cpp)
target_include_directories(${target} PRIVATE ${PROTEUS_INCLUDE_DIRS})
enable_ipo_on_target(${target})
add_library(${target} OBJECT ${target}.cpp)
target_include_directories(${target} PRIVATE ${PROTEUS_INCLUDE_DIRS})
enable_ipo_on_target(${target})

list(APPEND CORE_OBJS $<TARGET_OBJECTS:${target}>)
list(APPEND CORE_OBJS $<TARGET_OBJECTS:${target}>)
endforeach()

if(${PROTEUS_ENABLE_GRPC})
target_include_directories(predict_api_internal PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(predict_api_internal INTERFACE lib_grpc)
endif()
target_link_libraries(predict_api INTERFACE jsoncpp)
target_link_libraries(worker_info INTERFACE ${CMAKE_DL_LIBS})
if(${PROTEUS_ENABLE_VITIS})
target_link_libraries(data_types INTERFACE xir)
target_link_libraries(data_types INTERFACE xir)
endif()

add_library(lib_predict_api INTERFACE)
target_link_libraries(lib_predict_api INTERFACE
$<TARGET_OBJECTS:predict_api>
predict_api
$<TARGET_OBJECTS:predict_api_internal>
predict_api_internal
$<TARGET_OBJECTS:predict_api>
predict_api
$<TARGET_OBJECTS:predict_api_internal>
predict_api_internal
)

if(${PROTEUS_ENABLE_GRPC})
add_library(lib_grpc predict_api.proto)
target_include_directories(lib_grpc PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(lib_grpc INTERFACE gRPC::grpc++)

get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION)
protobuf_generate(TARGET lib_grpc LANGUAGE cpp)
protobuf_generate(TARGET lib_grpc LANGUAGE grpc GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}")
endif()

add_library(core INTERFACE)
target_link_libraries(core INTERFACE
${CORE_OBJS}
${targets}
${CORE_OBJS}
${targets}
)

if(${PROTEUS_ENABLE_GRPC})
target_link_libraries(core INTERFACE lib_grpc)
endif()

set(CORE_OBJS ${CORE_OBJS} PARENT_SCOPE)
42 changes: 42 additions & 0 deletions src/proteus/core/data_types.cpp
Expand Up @@ -168,6 +168,48 @@ std::string mapTypeToStr(DataType type) {
}
}

// TODO(varunsh): fix long if-else tree
DataType mapStrToType(const std::string& type) {
if (type == "BOOL") {
return DataType::BOOL;
}
if (type == "UINT8") {
return DataType::UINT8;
}
if (type == "UINT16") {
return DataType::UINT16;
}
if (type == "UINT32") {
return DataType::UINT32;
}
if (type == "UINT64") {
return DataType::UINT64;
}
if (type == "INT8") {
return DataType::INT8;
}
if (type == "INT16") {
return DataType::INT16;
}
if (type == "INT32") {
return DataType::INT32;
}
if (type == "INT64") {
return DataType::INT64;
}
if (type == "FP16") {
return DataType::FP16;
}
if (type == "FP32") {
return DataType::FP32;
}
if (type == "FP64") {
return DataType::FP64;
} else {
return DataType::STRING;
}
}

std::ostream& operator<<(std::ostream& os, const DataType& bar) {
return os << mapTypeToStr(bar);
}
Expand Down
18 changes: 8 additions & 10 deletions src/proteus/core/manager.hpp
Expand Up @@ -29,9 +29,8 @@
#include <unordered_map> // for unordered_map
#include <utility> // for move, pair

#include "proteus/build_options.hpp" // for PROTEUS_ENABLE_LOGGING
#include "proteus/core/predict_api.hpp" // for RequestParameters
// #include "proteus/core/worker_info.hpp" // for WorkerInfo
#include "proteus/build_options.hpp" // for PROTEUS_ENABLE_LOGGING
#include "proteus/core/predict_api.hpp" // for RequestParameters
#include "proteus/helpers/queue.hpp" // for BlockingConcurrentQueue
#include "proteus/observation/logging.hpp" // for LoggerPtr

Expand Down Expand Up @@ -100,6 +99,12 @@ class Manager {
return instance;
}

Manager(Manager const&) = delete; ///< Copy constructor
Manager& operator=(const Manager&) = delete; ///< Copy assignment constructor
Manager(Manager&& other) = delete; ///< Move constructor
Manager& operator=(Manager&& other) =
delete; ///< Move assignment constructor

std::string loadWorker(std::string const& key, RequestParameters parameters);
void unloadWorker(std::string const& key);

Expand Down Expand Up @@ -183,13 +188,6 @@ class Manager {
* @param input_queue queue where update requests will arrive
*/
void update_manager(UpdateCommandQueue* input_queue);

public:
Manager(Manager const&) = delete; ///< Copy constructor
Manager& operator=(const Manager&) = delete; ///< Copy assignment constructor
Manager(Manager&& other) = delete; ///< Move constructor
Manager& operator=(Manager&& other) =
delete; ///< Move assignment constructor
};

} // namespace proteus
Expand Down

0 comments on commit 37a6aad

Please sign in to comment.