Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
80625baa
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
185
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
80625baa
编写于
12月 31, 2019
作者:
G
guru4elephant
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update demo client
上级
9cc3c843
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
161 addition
and
0 deletion
+161
-0
demo-client/CMakeLists.txt
demo-client/CMakeLists.txt
+5
-0
demo-client/conf/predictors.prototxt
demo-client/conf/predictors.prototxt
+16
-0
demo-client/src/load_general_model.cpp
demo-client/src/load_general_model.cpp
+140
-0
未找到文件。
demo-client/CMakeLists.txt
浏览文件 @
80625baa
...
...
@@ -25,6 +25,11 @@ target_link_libraries(ximage_press -Wl,--whole-archive sdk-cpp
-Wl,--no-whole-archive -lpthread -lcrypto -lm -lrt -lssl -ldl
-lz
)
add_executable
(
load_general_model
${
CMAKE_CURRENT_LIST_DIR
}
/src/load_general_model.cpp
)
target_link_libraries
(
load_general_model -Wl,--whole-archive sdk-cpp -Wl,--no-whole-archive
-lpthread -lcrypto -lm -lrt -lssl -ldl
-lz
)
add_executable
(
echo
${
CMAKE_CURRENT_LIST_DIR
}
/src/echo.cpp
)
target_link_libraries
(
echo -Wl,--whole-archive sdk-cpp -Wl,--no-whole-archive
-lpthread -lcrypto -lm -lrt -lssl -ldl
...
...
demo-client/conf/predictors.prototxt
浏览文件 @
80625baa
...
...
@@ -35,6 +35,7 @@ predictors {
}
}
predictors {
name: "echo_service"
service_name: "baidu.paddle_serving.predictor.echo_service.BuiltinTestEchoService"
...
...
@@ -65,6 +66,21 @@ predictors {
}
}
predictors {
name: "load_general_model_service"
service_name: "baidu.paddle_serving.predictor.load_general_model_service.LoadGeneralModelService"
endpoint_router: "WeightedRandomRender"
weighted_random_render_conf {
variant_weight_list: "50"
}
variants {
tag: "var1"
naming_conf {
cluster: "list://127.0.0.1:8010"
}
}
}
predictors {
name: "sparse_service"
service_name: "baidu.paddle_serving.predictor.sparse_service.BuiltinSparseFormatService"
...
...
demo-client/src/load_general_model.cpp
0 → 100644
浏览文件 @
80625baa
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fstream>
#include "sdk-cpp/builtin_format.pb.h"
#include "sdk-cpp/load_general_model_service.pb.h"
#include "sdk-cpp/include/common.h"
#include "sdk-cpp/include/predictor_sdk.h"
using
baidu
::
paddle_serving
::
sdk_cpp
::
Predictor
;
using
baidu
::
paddle_serving
::
sdk_cpp
::
PredictorApi
;
using
baidu
::
paddle_serving
::
predictor
::
load_general_model_service
::
RequestAndResponse
;
int
create_req
(
RequestAndResponse
&
req
)
{
// NOLINT
req
.
set_a
(
1
);
req
.
set_b
(
0.1
);
return
0
;
}
void
print_res
(
const
RequestAndResponse
&
req
,
const
RequestAndResponse
&
res
,
std
::
string
route_tag
,
uint64_t
elapse_ms
)
{
LOG
(
INFO
)
<<
"Reqeive result: a = "
<<
res
.
a
()
<<
", b = "
<<
res
.
b
();
LOG
(
INFO
)
<<
"Succ call predictor[echo_service], the tag is: "
<<
route_tag
<<
", elapse_ms: "
<<
elapse_ms
;
}
int
main
(
int
argc
,
char
**
argv
)
{
PredictorApi
api
;
// initialize logger instance
#ifdef BCLOUD
logging
::
LoggingSettings
settings
;
settings
.
logging_dest
=
logging
::
LOG_TO_FILE
;
std
::
string
filename
(
argv
[
0
]);
filename
=
filename
.
substr
(
filename
.
find_last_of
(
'/'
)
+
1
);
settings
.
log_file
=
(
std
::
string
(
"./log/"
)
+
filename
+
".log"
).
c_str
();
settings
.
delete_old
=
logging
::
DELETE_OLD_LOG_FILE
;
logging
::
InitLogging
(
settings
);
logging
::
ComlogSinkOptions
cso
;
cso
.
process_name
=
filename
;
cso
.
enable_wf_device
=
true
;
logging
::
ComlogSink
::
GetInstance
()
->
Setup
(
&
cso
);
#else
struct
stat
st_buf
;
int
ret
=
0
;
if
((
ret
=
stat
(
"./log"
,
&
st_buf
))
!=
0
)
{
mkdir
(
"./log"
,
0777
);
ret
=
stat
(
"./log"
,
&
st_buf
);
if
(
ret
!=
0
)
{
LOG
(
WARNING
)
<<
"Log path ./log not exist, and create fail"
;
return
-
1
;
}
}
FLAGS_log_dir
=
"./log"
;
google
::
InitGoogleLogging
(
strdup
(
argv
[
0
]));
#endif
if
(
api
.
create
(
"./conf"
,
"predictors.prototxt"
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Failed create predictors api!"
;
return
-
1
;
}
RequestAndResponse
req
;
RequestAndResponse
res
;
api
.
thrd_initialize
();
while
(
true
)
{
timeval
start
;
gettimeofday
(
&
start
,
NULL
);
api
.
thrd_clear
();
Predictor
*
predictor
=
api
.
fetch_predictor
(
"load_general_model_service"
);
if
(
!
predictor
)
{
LOG
(
ERROR
)
<<
"Failed fetch predictor: load_general_model_service"
;
return
-
1
;
}
req
.
Clear
();
res
.
Clear
();
if
(
create_req
(
req
)
!=
0
)
{
return
-
1
;
}
butil
::
IOBufBuilder
debug_os
;
if
(
predictor
->
debug
(
&
req
,
&
res
,
&
debug_os
)
!=
0
)
{
LOG
(
ERROR
)
<<
"failed call predictor with req:"
<<
req
.
ShortDebugString
();
return
-
1
;
}
butil
::
IOBuf
debug_buf
;
debug_os
.
move_to
(
debug_buf
);
LOG
(
INFO
)
<<
"Debug string: "
<<
debug_buf
;
timeval
end
;
gettimeofday
(
&
end
,
NULL
);
uint64_t
elapse_ms
=
(
end
.
tv_sec
*
1000
+
end
.
tv_usec
/
1000
)
-
(
start
.
tv_sec
*
1000
+
start
.
tv_usec
/
1000
);
print_res
(
req
,
res
,
predictor
->
tag
(),
elapse_ms
);
res
.
Clear
();
usleep
(
50
);
}
// while (true)
api
.
thrd_finalize
();
api
.
destroy
();
#ifndef BCLOUD
google
::
ShutdownGoogleLogging
();
#endif
return
0
;
}
/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录