Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
b39f0033
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b39f0033
编写于
8月 20, 2020
作者:
T
TeslaZhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bad code style by clang-format
上级
57fc2a09
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
197 addition
and
142 deletion
+197
-142
core/predictor/framework/factory.h
core/predictor/framework/factory.h
+50
-29
core/predictor/framework/op_repository.h
core/predictor/framework/op_repository.h
+2
-2
core/predictor/framework/service_manager.h
core/predictor/framework/service_manager.h
+39
-27
core/sdk-cpp/include/abtest.h
core/sdk-cpp/include/abtest.h
+4
-3
core/sdk-cpp/include/factory.h
core/sdk-cpp/include/factory.h
+102
-81
未找到文件。
core/predictor/framework/factory.h
浏览文件 @
b39f0033
...
...
@@ -23,18 +23,20 @@ namespace paddle_serving {
namespace
predictor
{
//////////////// DECLARE INTERFACE ////////////////
#define DECLARE_FACTORY_OBJECT(D, B) \
static int regist(const std::string& tag) { \
FactoryDerive<D, B>* factory = new (std::nothrow) FactoryDerive<D, B>();\
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(tag, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s in macro!", #D); \
RAW_LOG(FATAL, err_str); \
return -1; \
} \
return 0; \
#define DECLARE_FACTORY_OBJECT(D, B) \
static int regist(const std::string& tag) { \
FactoryDerive<D, B>* factory = new (std::nothrow) FactoryDerive<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(tag, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s in macro!", \
#D); \
RAW_LOG(FATAL, err_str); \
return -1; \
} \
return 0; \
}
#define PDS_STR_CAT(a, b) PDS_STR_CAT_I(a, b)
...
...
@@ -58,8 +60,11 @@ namespace predictor {
::baidu::paddle_serving::predictor::FactoryPool<B>::instance() \
.register_factory(#D, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", #D, #B); \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", \
#D, \
#B); \
RAW_LOG(FATAL, err_str); \
return; \
} \
...
...
@@ -76,13 +81,21 @@ namespace predictor {
if (factory == NULL || \
::baidu::paddle_serving::predictor::FactoryPool<B>::instance() \
.register_factory(N, factory) != 0) { \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s, tag: %s in macro!", #D, #B, N); \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s, tag: %s in macro!", \
#D, \
#B, \
N); \
RAW_LOG(FATAL, err_str); \
return; \
} \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Succ regist factory: %s->%s, tag: %s in macro!", #D, #B, N); \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Succ regist factory: %s->%s, tag: %s in macro!", \
#D, \
#B, \
N); \
RAW_LOG(WARNING, err_str); \
return; \
}
...
...
@@ -115,8 +128,10 @@ class FactoryPool {
typename
std
::
map
<
std
::
string
,
FactoryBase
<
B
>*>::
iterator
it
=
_pool
.
find
(
tag
);
if
(
it
!=
_pool
.
end
())
{
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Insert duplicate with tag: %s"
,
tag
.
c_str
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Insert duplicate with tag: %s"
,
tag
.
c_str
());
RAW_LOG
(
FATAL
,
err_str
);
return
-
1
;
}
...
...
@@ -124,15 +139,19 @@ class FactoryPool {
std
::
pair
<
typename
std
::
map
<
std
::
string
,
FactoryBase
<
B
>*>::
iterator
,
bool
>
r
=
_pool
.
insert
(
std
::
make_pair
(
tag
,
factory
));
if
(
!
r
.
second
)
{
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Failed insert new factory with: %s"
,
tag
.
c_str
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Failed insert new factory with: %s"
,
tag
.
c_str
());
RAW_LOG
(
FATAL
,
err_str
);
return
-
1
;
}
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Succ insert one factory, tag: %s, base type %s"
,
tag
.
c_str
(),
typeid
(
B
).
name
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Succ insert one factory, tag: %s, base type %s"
,
tag
.
c_str
(),
typeid
(
B
).
name
());
RAW_LOG
(
INFO
,
err_str
);
return
0
;
}
...
...
@@ -142,9 +161,11 @@ class FactoryPool {
_pool
.
find
(
tag
);
if
(
it
==
_pool
.
end
()
||
it
->
second
==
NULL
)
{
char
err_str
[
ERROR_STRING_LEN
];
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Not found factory pool, tag: %s, pool size %u"
,
tag
.
c_str
(),
_pool
.
size
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Not found factory pool, tag: %s, pool size %u"
,
tag
.
c_str
(),
_pool
.
size
());
RAW_LOG
(
FATAL
,
err_str
);
return
NULL
;
}
...
...
core/predictor/framework/op_repository.h
浏览文件 @
b39f0033
...
...
@@ -63,8 +63,8 @@ class OpRepository {
void
regist_op
(
std
::
string
op_type
)
{
_repository
[
op_type
]
=
&
OpFactory
<
OP_TYPE
>::
instance
();
char
err_str
[
ERROR_STRING_LEN
];
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Succ regist op: %s"
,
op_type
.
c_str
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Succ regist op: %s"
,
op_type
.
c_str
());
RAW_LOG
(
INFO
,
err_str
);
}
...
...
core/predictor/framework/service_manager.h
浏览文件 @
b39f0033
...
...
@@ -21,23 +21,27 @@ namespace baidu {
namespace
paddle_serving
{
namespace
predictor
{
#define REGIST_FORMAT_SERVICE(svr_name, svr) \
do { \
char err_str[ERROR_STRING_LEN]; \
int ret = \
::baidu::paddle_serving::predictor::FormatServiceManager::instance() \
.regist_service(svr_name, svr); \
if (ret != 0) { \
snprintf(err_str, ERROR_STRING_LEN - 1, "Failed regist service[%s][%s]", \
svr_name.c_str(), \
typeid(svr).name()); \
RAW_LOG(ERROR, err_str); \
} else { \
snprintf(err_str, ERROR_STRING_LEN - 1, "Success regist service[%s][%s]", \
svr_name.c_str(), \
typeid(svr).name()); \
RAW_LOG(INFO, err_str); \
} \
#define REGIST_FORMAT_SERVICE(svr_name, svr) \
do { \
char err_str[ERROR_STRING_LEN]; \
int ret = \
::baidu::paddle_serving::predictor::FormatServiceManager::instance() \
.regist_service(svr_name, svr); \
if (ret != 0) { \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist service[%s][%s]", \
svr_name.c_str(), \
typeid(svr).name()); \
RAW_LOG(ERROR, err_str); \
} else { \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Success regist service[%s][%s]", \
svr_name.c_str(), \
typeid(svr).name()); \
RAW_LOG(INFO, err_str); \
} \
} while (0)
class
FormatServiceManager
{
...
...
@@ -47,9 +51,11 @@ class FormatServiceManager {
int
regist_service
(
const
std
::
string
&
svr_name
,
Service
*
svr
)
{
char
err_str
[
ERROR_STRING_LEN
];
if
(
_service_map
.
find
(
svr_name
)
!=
_service_map
.
end
())
{
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Service[%s][%s] already exist!"
,
svr_name
.
c_str
(),
typeid
(
svr
).
name
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Service[%s][%s] already exist!"
,
svr_name
.
c_str
(),
typeid
(
svr
).
name
());
RAW_LOG
(
ERROR
,
err_str
);
return
-
1
;
}
...
...
@@ -57,15 +63,19 @@ class FormatServiceManager {
std
::
pair
<
boost
::
unordered_map
<
std
::
string
,
Service
*>::
iterator
,
bool
>
ret
;
ret
=
_service_map
.
insert
(
std
::
make_pair
(
svr_name
,
svr
));
if
(
ret
.
second
==
false
)
{
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Service[%s][%s] insert failed!"
,
svr_name
.
c_str
(),
typeid
(
svr
).
name
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Service[%s][%s] insert failed!"
,
svr_name
.
c_str
(),
typeid
(
svr
).
name
());
RAW_LOG
(
ERROR
,
err_str
);
return
-
1
;
}
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Service[%s] insert successfully!"
,
svr_name
.
c_str
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Service[%s] insert successfully!"
,
svr_name
.
c_str
());
RAW_LOG
(
INFO
,
err_str
);
return
0
;
}
...
...
@@ -74,8 +84,10 @@ class FormatServiceManager {
char
err_str
[
ERROR_STRING_LEN
];
boost
::
unordered_map
<
std
::
string
,
Service
*>::
iterator
res
;
if
((
res
=
_service_map
.
find
(
svr_name
))
==
_service_map
.
end
())
{
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Service[%s] not found in service manager!"
,
svr_name
.
c_str
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Service[%s] not found in service manager!"
,
svr_name
.
c_str
());
RAW_LOG
(
WARNING
,
err_str
);
return
NULL
;
}
...
...
core/sdk-cpp/include/abtest.h
浏览文件 @
b39f0033
...
...
@@ -50,8 +50,8 @@ class WeightedRandomRender : public EndpointRouterBase {
Factory
<
WeightedRandomRender
,
EndpointRouterBase
>*
factory
=
new
(
std
::
nothrow
)
Factory
<
WeightedRandomRender
,
EndpointRouterBase
>
();
if
(
factory
==
NULL
)
{
RAW_LOG
(
ERROR
,
"Failed regist factory: WeightedRandomRender->EndpointRouterBase \
RAW_LOG
(
ERROR
,
"Failed regist factory: WeightedRandomRender->EndpointRouterBase \
in macro!"
);
return
-
1
;
}
...
...
@@ -62,7 +62,8 @@ class WeightedRandomRender : public EndpointRouterBase {
// together.
if
(
FactoryPool
<
EndpointRouterBase
>::
instance
().
register_factory
(
"WeightedRandomRender"
,
factory
)
!=
0
)
{
RAW_LOG
(
INFO
,
"Factory has been registed: \
RAW_LOG
(
INFO
,
"Factory has been registed: \
WeightedRandomRender->EndpointRouterBase."
);
}
...
...
core/sdk-cpp/include/factory.h
浏览文件 @
b39f0033
...
...
@@ -29,31 +29,36 @@ namespace brpc = baidu::rpc;
#define ERROR_STRING_LEN 10240
#define INLINE_REGIST_OBJECT(D, B, E) \
do { \
Factory<D, B>* factory = new (std::nothrow) Factory<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(#D, factory) != 0) {\
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", #D, #B); \
RAW_LOG(ERROR, err_str); \
return E; \
} \
#define INLINE_REGIST_OBJECT(D, B, E) \
do { \
Factory<D, B>* factory = new (std::nothrow) Factory<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(#D, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", \
#D, \
#B); \
RAW_LOG(ERROR, err_str); \
return E; \
} \
} while (0)
#define DECLARE_FACTORY_OBJECT(D, B) \
static int regist(const std::string& tag) { \
Factory<D, B>* factory = new (std::nothrow) Factory<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(tag, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s in macro!", #D); \
RAW_LOG(ERROR, err_str); \
return -1; \
} \
return 0; \
#define DECLARE_FACTORY_OBJECT(D, B) \
static int regist(const std::string& tag) { \
Factory<D, B>* factory = new (std::nothrow) Factory<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(tag, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s in macro!", \
#D); \
RAW_LOG(ERROR, err_str); \
return -1; \
} \
return 0; \
}
#define PDS_STR_CAT(a, b) PDS_STR_CAT_I(a, b)
...
...
@@ -65,39 +70,46 @@ namespace brpc = baidu::rpc;
D::regist(#D); \
}
#define REGIST_FACTORY_OBJECT_IMPL(D, B) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory<D, B>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory<D, B>();\
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool<B>::instance() \
.register_factory(#D, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", #D, #B); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
#define REGIST_FACTORY_OBJECT_IMPL(D, B) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory<D, B>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory<D, B>(); \
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool<B>::instance() \
.register_factory(#D, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", \
#D, \
#B); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
}
#define REGIST_FACTORY_OBJECT_IMPL_WITH_TAG(D, B, T) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory<D, B>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory<D, B>();\
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool<B>::instance() \
.register_factory(T, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s, tag %s in macro!", #D, #B, T); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
}
#define REGIST_FACTORY_OBJECT_IMPL_WITH_TAG(D, B, T) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory<D, B>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory<D, B>(); \
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool<B>::instance() \
.register_factory(T, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s, tag %s in macro!", \
#D, \
#B, \
T); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
}
#define REGIST_ABTEST_OBJECT(D) \
REGIST_FACTORY_OBJECT_IMPL( \
...
...
@@ -107,26 +119,29 @@ namespace brpc = baidu::rpc;
REGIST_FACTORY_OBJECT_IMPL_WITH_TAG( \
D, ::baidu::paddle_serving::sdk_cpp::ABTestRouterBase, T)
#define REGIST_STUB_OBJECT_WITH_TAG(D, C, R, I, O, T) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory< \
::baidu::paddle_serving::sdk_cpp::StubImpl<D, C, R, I, O>, \
::baidu::paddle_serving::sdk_cpp::Stub>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory< \
::baidu::paddle_serving::sdk_cpp::StubImpl<D, C, R, I, O>, \
::baidu::paddle_serving::sdk_cpp::Stub>(); \
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool< \
::baidu::paddle_serving::sdk_cpp::Stub>::instance() \
.register_factory(T, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->Stub, tag: %s in macro!", #D, T); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
#define REGIST_STUB_OBJECT_WITH_TAG(D, C, R, I, O, T) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory< \
::baidu::paddle_serving::sdk_cpp::StubImpl<D, C, R, I, O>, \
::baidu::paddle_serving::sdk_cpp::Stub>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory< \
::baidu::paddle_serving::sdk_cpp::StubImpl<D, C, R, I, O>, \
::baidu::paddle_serving::sdk_cpp::Stub>(); \
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool< \
::baidu::paddle_serving::sdk_cpp::Stub>::instance() \
.register_factory(T, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->Stub, tag: %s in macro!", \
#D, \
T); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
}
class
Stub
;
...
...
@@ -161,8 +176,10 @@ class FactoryPool {
_pool
.
find
(
tag
);
if
(
it
!=
_pool
.
end
())
{
char
err_str
[
ERROR_STRING_LEN
];
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Insert duplicate with tag: %s"
,
tag
.
c_str
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Insert duplicate with tag: %s"
,
tag
.
c_str
());
RAW_LOG
(
ERROR
,
err_str
);
return
-
1
;
}
...
...
@@ -171,8 +188,10 @@ class FactoryPool {
r
=
_pool
.
insert
(
std
::
make_pair
(
tag
,
factory
));
if
(
!
r
.
second
)
{
char
err_str
[
ERROR_STRING_LEN
];
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Failed insert new factory with: %s"
,
tag
.
c_str
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Failed insert new factory with: %s"
,
tag
.
c_str
());
RAW_LOG
(
ERROR
,
err_str
);
return
-
1
;
}
...
...
@@ -185,9 +204,11 @@ class FactoryPool {
_pool
.
find
(
tag
);
if
(
it
==
_pool
.
end
()
||
it
->
second
==
NULL
)
{
char
err_str
[
ERROR_STRING_LEN
];
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Not found factory pool, tag: %s, pool size: %u"
,
tag
.
c_str
(),
_pool
.
size
());
snprintf
(
err_str
,
ERROR_STRING_LEN
-
1
,
"Not found factory pool, tag: %s, pool size: %u"
,
tag
.
c_str
(),
_pool
.
size
());
RAW_LOG
(
ERROR
,
err_str
);
return
NULL
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录