提交 cc1c24d7 编写于 作者: W wangguibao

libpdserving & libpdclient

上级 00986291
......@@ -116,7 +116,6 @@ if (NOT WIN32)
set(COMMON_FLAGS
-fPIC
-fno-omit-frame-pointer
-Werror
-Wall
-Wextra
-Wnon-virtual-dtor
......
......@@ -792,3 +792,60 @@ function(brpc_library TARGET_NAME)
cc_library("${TARGET_NAME}_proto" SRCS "${brpc_proto_srcs}")
cc_library("${TARGET_NAME}" SRCS "${brpc_library_SRCS}" DEPS "${TARGET_NAME}_proto" "${brpc_library_DEPS}")
endfunction()
function(PROTOBUF_GENERATE_SERVING_CPP SRCS HDRS)
if(NOT ARGN)
message(SEND_ERROR "Error: PROTOBUF_GENERATE_SERVING_CPP() called without any proto files")
return()
endif()
if(PROTOBUF_GENERATE_CPP_APPEND_PATH) # This variable is common for all types of output.
# Create an include path for each file specified
foreach(FIL ${ARGN})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(ABS_PATH ${ABS_FIL} PATH)
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
if(${_contains_already} EQUAL -1)
list(APPEND _protobuf_include_path -I ${ABS_PATH})
endif()
endforeach()
else()
set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(DEFINED PROTOBUF_IMPORT_DIRS)
foreach(DIR ${Protobuf_IMPORT_DIRS})
get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
if(${_contains_already} EQUAL -1)
list(APPEND _protobuf_include_path -I ${ABS_PATH})
endif()
endforeach()
endif()
set(${SRCS})
set(${HDRS})
foreach(FIL ${ARGN})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(FIL_WE ${FIL} NAME_WE)
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --pdcodegen_out=${CMAKE_CURRENT_BINARY_DIR}
--plugin=protoc-gen-pdcodegen=${CMAKE_CURRENT_BINARY_DIR}/pdcodegen
--proto_path=.
${_protobuf_include_path} ${ABS_FIL}
DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}
COMMENT "Running Paddle-serving C++ protocol buffer compiler on ${FIL}"
VERBATIM)
endforeach()
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
endfunction()
......@@ -2,13 +2,41 @@ include(proto/CMakeLists.txt)
include(common/CMakeLists.txt)
include(op/CMakeLists.txt)
include(framework/CMakeLists.txt)
add_library(predictor ${predictor_srcs})
include(plugin/CMakeLists.txt)
include(src/CMakeLists.txt)
add_executable(pdcodegen ${pdcodegen_srcs})
target_link_libraries(pdcodegen protobuf ${PROTOBUF_PROTOC_LIBRARY})
target_include_directories(pdcodegen PUBLIC
${CMAKE_CURRENT_LIST_DIR}/
${CMAKE_CURRENT_BINARY_DIR}/)
add_library(pdserving ${pdserving_srcs})
set_source_files_properties(
${pdserving_srcs}
PROPERTIES
COMPILE_FLAGS "-Wno-strict-aliasing -Wno-unused-variable -Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor")
add_dependencies(pdserving protobuf boost brpc pdcodegen)
target_include_directories(pdserving PUBLIC
${CMAKE_CURRENT_LIST_DIR}/
${CMAKE_CURRENT_BINARY_DIR}/
${CMAKE_CURRENT_LIST_DIR}/../configure
${CMAKE_CURRENT_LIST_DIR}/../mempool
${CMAKE_CURRENT_LIST_DIR}/../spreg
${CMAKE_CURRENT_LIST_DIR}/../ullib/include
${CMAKE_CURRENT_BINARY_DIR}/../bsl/include)
target_link_libraries(pdserving -lpthread -lcrypto -lm -lrt -lssl -ldl -lz)
add_library(pdclient ${pdclient_srcs})
set_source_files_properties(
${predictor_srcs}
${pdclient_srcs}
PROPERTIES
COMPILE_FLAGS "-Wno-strict-aliasing -Wno-unused-variable -Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor")
add_dependencies(predictor protobuf boost brpc)
target_include_directories(predictor PUBLIC
add_dependencies(pdclient protobuf boost brpc pdcodegen)
target_include_directories(pdclient PUBLIC
${CMAKE_CURRENT_LIST_DIR}/
${CMAKE_CURRENT_BINARY_DIR}/
${CMAKE_CURRENT_LIST_DIR}/../configure
......@@ -16,3 +44,5 @@ target_include_directories(predictor PUBLIC
${CMAKE_CURRENT_LIST_DIR}/../spreg
${CMAKE_CURRENT_LIST_DIR}/../ullib/include
${CMAKE_CURRENT_BINARY_DIR}/../bsl/include)
target_link_libraries(pdclient -lpthread -lcrypto -lm -lrt -lssl -ldl -lz)
FILE(GLOB common_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
LIST(APPEND predictor_srcs ${common_srcs})
LIST(APPEND pdserving_srcs ${common_srcs})
LIST(APPEND pdclient_srcs ${common_srcs})
FILE(GLOB framework_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
LIST(APPEND predictor_srcs ${framework_srcs})
LIST(APPEND pdserving_srcs ${framework_srcs})
LIST(APPEND pclient_srcs ${framework_srcs})
#ifndef BAIDU_PADDLE_SERVING_PREDICTOR_LOGGER_H
#define BAIDU_PADDLE_SERVING_PREDICTOR_LOGGER_H
#include <butil/comlog_sink.h>
namespace baidu {
namespace paddle_serving {
namespace predictor {
class LoggerWrapper {
public:
static LoggerWrapper& instance() {
static LoggerWrapper lw;
return lw;
}
int initialize(const std::string& path, const std::string& name) {
if (com_loadlog(path.c_str(), name.c_str()) != 0) {
LOG(ERROR) << "Fail to com_loadlog from: "
<< path << "/" << name;
return -1;
}
return 0;
}
int finalize() {
return 0;
}
};
}
}
}
#endif
FILE(GLOB op_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
LIST(APPEND predictor_srcs ${op_srcs})
LIST(APPEND pdserving_srcs ${op_srcs})
LIST(APPEND pdclient_srcs ${op_srcs})
FILE(GLOB plugin_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cc)
LIST(APPEND pdcodegen_srcs ${plugin_srcs})
FILE(GLOB protofiles "${CMAKE_CURRENT_LIST_DIR}/*.proto")
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${protofiles})
LIST(APPEND predictor_srcs ${PROTO_SRCS})
PROTOBUF_GENERATE_CPP(pdcodegen_proto_srcs pdcodegen_proto_hdrs
${CMAKE_CURRENT_LIST_DIR}/pds_option.proto)
LIST(APPEND pdcodegen_srcs ${pdcodegen_proto_srcs})
LIST(APPEND protofiles
${CMAKE_CURRENT_LIST_DIR}/./builtin_format.proto
${CMAKE_CURRENT_LIST_DIR}/./dense_service.proto
${CMAKE_CURRENT_LIST_DIR}/./echo_service.proto
${CMAKE_CURRENT_LIST_DIR}/./image_classification.proto
${CMAKE_CURRENT_LIST_DIR}/./int64tensor_service.proto
${CMAKE_CURRENT_LIST_DIR}/./msg_data.proto
${CMAKE_CURRENT_LIST_DIR}/./sparse_service.proto
${CMAKE_CURRENT_LIST_DIR}/./xrecord_format.proto
)
# PROTOBUF_GENERATE_SERVING_CPP(PROTO_SRCS PROTO_HDRS ${protofiles})
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${protofiles})
LIST(APPEND pdserving_srcs ${PROTO_SRCS} ${pdcodegen_proto_srcs})
LIST(APPEND pdclient_srcs ${PROTO_SRCS} ${pdcodegen_proto_srcs})
LIST(APPEND pdcodegen_srcs ${CMAKE_CURRENT_LIST_DIR}/pdcodegen.cpp)
LIST(APPEND pdserving_srcs ${CMAKE_CURRENT_LIST_DIR}/pdserving.cpp)
LIST(APPEND pdclient_srcs ${CMAKE_CURRENT_LIST_DIR}/pdclient.cpp)
......@@ -24,11 +24,9 @@
#include "common/utils.h"
#include "common/inner_common.h"
#include "common/constant.h"
#include "framework/logger.h"
#include "butil/logging.h"
DEFINE_string(attachment, "foo", "Carry this along with requests");
DEFINE_bool(auth, false, "Enable Giano authentication");
DEFINE_string(auth_group, "g_guest", "Giano Group");
DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in protocol/baidu/rpc/options.proto");
DEFINE_bool(compress, true, "Enable compression");
//DEFINE_string(protocol, "http", "Protocol type. Defined in protocol/baidu/rpc/options.proto");
......@@ -42,7 +40,6 @@ DEFINE_string(http_content_type, "application/json", "Content type of http reque
using baidu::paddle_serving::predictor::FLAGS_logger_path;
using baidu::paddle_serving::predictor::FLAGS_logger_file;
using baidu::paddle_serving::predictor::LoggerWrapper;
namespace dense_format {
......@@ -372,25 +369,8 @@ int main(int argc, char* argv[]) {
google::ParseCommandLineFlags(&argc, &argv, true);
// initialize logger instance
if (LoggerWrapper::instance().initialize(
FLAGS_logger_path, FLAGS_logger_file) != 0) {
LOG(ERROR) << "Failed initialize logger, conf:"
<< FLAGS_logger_path << "/" << FLAGS_logger_file;
return -1;
}
google::InitGoogleLogging(strdup(argv[0]));
// Login to get `CredentialGenerator' (see baas-lib-c/baas.h for more
// information) and then pass it to `GianoAuthenticator'.
std::unique_ptr<brpc::policy::GianoAuthenticator> auth;
if (FLAGS_auth) {
if (baas::BAAS_Init() != 0) {
LOG(ERROR) << "Fail to init BAAS";
return -1;
}
baas::CredentialGenerator gen = baas::ClientUtility::Login(FLAGS_auth_group);
auth.reset(new brpc::policy::GianoAuthenticator(&gen, NULL));
}
// A Channel represents a communication line to a Server. Notice that
// Channel is thread-safe and can be shared by all threads in your program.
brpc::Channel channel;
......@@ -399,7 +379,6 @@ int main(int argc, char* argv[]) {
brpc::ChannelOptions options;
options.protocol = FLAGS_protocol;
options.connection_type = FLAGS_connection_type;
options.auth = auth.get();
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
options.max_retry = FLAGS_max_retry;
if (channel.Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &options) != 0) {
......@@ -441,6 +420,8 @@ int main(int argc, char* argv[]) {
}
LOG(INFO) << "Pdserving Client is going to quit";
google::ShutdownGoogleLogging();
return 0;
}
#include <iostream>
#include <fstream>
#include <bthread_unstable.h> // bthread_set_worker_startfn
#include <bthread/unstable.h> // bthread_set_worker_startfn
#include "common/inner_common.h"
#include "framework/workflow.h"
#include "framework/service.h"
#include "framework/manager.h"
#include "framework/server.h"
#include "framework/logger.h"
#include "butil/logging.h"
#include "framework/resource.h"
#include "common/constant.h"
using baidu::paddle_serving::predictor::ServerManager;
using baidu::paddle_serving::predictor::WorkflowManager;
using baidu::paddle_serving::predictor::LoggerWrapper;
using baidu::paddle_serving::predictor::InferServiceManager;
using baidu::paddle_serving::predictor::Resource;
using baidu::paddle_serving::predictor::FLAGS_workflow_path;
......@@ -40,7 +39,7 @@ void print_revision(std::ostream& os, void*) {
static bvar::PassiveStatus<std::string> s_predictor_revision(
"predictor_revision", print_revision, NULL);
DEFINE_bool(v, false, "print version, bool");
DEFINE_bool(V, false, "print version, bool");
DEFINE_bool(g, false, "user defined gflag path");
DECLARE_string(flagfile);
......@@ -72,7 +71,7 @@ int main(int argc, char** argv) {
#endif
google::ParseCommandLineFlags(&argc, &argv, true);
if (FLAGS_v) {
if (FLAGS_V) {
print_revision(std::cout, NULL);
std::cout << std::flush;
return 0;
......@@ -87,12 +86,7 @@ int main(int argc, char** argv) {
g_change_server_port();
// initialize logger instance
if (LoggerWrapper::instance().initialize(
FLAGS_logger_path, FLAGS_logger_file) != 0) {
LOG(ERROR) << "Failed initialize logger, conf:"
<< FLAGS_logger_path << "/" << FLAGS_logger_file;
return -1;
}
google::InitGoogleLogging(strdup(argv[0]));
LOG(INFO) << "Succ initialize logger";
......@@ -149,10 +143,7 @@ int main(int argc, char** argv) {
LOG(ERROR) << "Failed finalize resource manager";
}
if (LoggerWrapper::instance().finalize() != 0) {
LOG(ERROR) << "Failed finalize logger wrapper";
}
google::ShutdownGoogleLogging();
LOG(INFO) << "Paddle Inference Server exit successfully!";
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册