diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 81e7868a6ad3fee16911a49ff9d1394a103706c5..dfbe8b6febd658e7ef8f03bb818382a55e0f86e7 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -116,7 +116,6 @@ if (NOT WIN32) set(COMMON_FLAGS -fPIC -fno-omit-frame-pointer - -Werror -Wall -Wextra -Wnon-virtual-dtor diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 6679a09dfc9dd00cfe3b5c5da3e12bd1c1389432..f72cd61352dfb38a4f5a2a6a7e8effb9b4c11e9c 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -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() diff --git a/predictor/CMakeLists.txt b/predictor/CMakeLists.txt index 4896441e6a973c6453b521f4e5f366ef7c07c6ee..e017c0152f7a0aea80fd01f9edfa67cc864f8aa7 100644 --- a/predictor/CMakeLists.txt +++ b/predictor/CMakeLists.txt @@ -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) + diff --git a/predictor/common/CMakeLists.txt b/predictor/common/CMakeLists.txt index 7530df97284d15cfff65d3c5da369f676e67221a..22728514162ff36971225b0f0348fb90e8491d53 100644 --- a/predictor/common/CMakeLists.txt +++ b/predictor/common/CMakeLists.txt @@ -1,2 +1,3 @@ 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}) diff --git a/predictor/framework/CMakeLists.txt b/predictor/framework/CMakeLists.txt index 29b29be493ae4c4e6c6efdea9095a5fa5a34a9d6..641ba7efbad9c97497cd2ef9372fa08391f6769c 100644 --- a/predictor/framework/CMakeLists.txt +++ b/predictor/framework/CMakeLists.txt @@ -1,2 +1,3 @@ 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}) diff --git a/predictor/framework/logger.h b/predictor/framework/logger.h deleted file mode 100644 index d2c3a3bf32bf1536b6a90d7be9ba44d59662249d..0000000000000000000000000000000000000000 --- a/predictor/framework/logger.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef BAIDU_PADDLE_SERVING_PREDICTOR_LOGGER_H -#define BAIDU_PADDLE_SERVING_PREDICTOR_LOGGER_H - -#include - -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 diff --git a/predictor/op/CMakeLists.txt b/predictor/op/CMakeLists.txt index 191fe75dd5d991c7dee6773e61102b1ca3631f70..28a5b060ae58db63dfdd2d10269553def30244bd 100644 --- a/predictor/op/CMakeLists.txt +++ b/predictor/op/CMakeLists.txt @@ -1,2 +1,3 @@ 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}) diff --git a/predictor/plugin/CMakeLists.txt b/predictor/plugin/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..89ee09fbe2d2315ffd9ce6e1fcd0bd3ffb170944 --- /dev/null +++ b/predictor/plugin/CMakeLists.txt @@ -0,0 +1,2 @@ +FILE(GLOB plugin_srcs ${CMAKE_CURRENT_LIST_DIR}/*.cc) +LIST(APPEND pdcodegen_srcs ${plugin_srcs}) diff --git a/predictor/proto/CMakeLists.txt b/predictor/proto/CMakeLists.txt index 0ad5320a4428d3ade5bdc492bf127018e5432775..b24ff17ebc02c407a2131f32e91db241ef88e4cf 100644 --- a/predictor/proto/CMakeLists.txt +++ b/predictor/proto/CMakeLists.txt @@ -1,3 +1,20 @@ -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}) diff --git a/predictor/src/CMakeLists.txt b/predictor/src/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..428b6979eef73a397c9b34365c007b8f52b4a96c --- /dev/null +++ b/predictor/src/CMakeLists.txt @@ -0,0 +1,3 @@ +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) diff --git a/predictor/src/pdclient.cpp b/predictor/src/pdclient.cpp index 1731c201b8e6060ce1934cef842d09aaf1bdb76a..128252dd379997541badf53342e6cd82f77ee5f4 100644 --- a/predictor/src/pdclient.cpp +++ b/predictor/src/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 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; } diff --git a/predictor/src/pdserving.cpp b/predictor/src/pdserving.cpp index 5f2088d949e238ec14f19e4ea66cb486fb0010e8..cc257048ad08a3a3f57b84967ec36726ef1e9ff0 100644 --- a/predictor/src/pdserving.cpp +++ b/predictor/src/pdserving.cpp @@ -1,18 +1,17 @@ #include #include -#include // bthread_set_worker_startfn +#include // 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 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; }