Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
00f1ee94
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看板
提交
00f1ee94
编写于
3月 12, 2021
作者:
H
HexToString
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix memory bug
上级
c66eb3a7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
30 deletion
+35
-30
core/predictor/framework/infer.h
core/predictor/framework/infer.h
+35
-30
未找到文件。
core/predictor/framework/infer.h
浏览文件 @
00f1ee94
...
...
@@ -626,44 +626,49 @@ class FluidInferEngine : public CloneDBReloadableInferEngine<FluidFamilyCore> {
//get out and copy to void* out
TensorVector
*
tensorVector_out_pointer
=
reinterpret_cast
<
TensorVector
*>
(
out
);
std
::
vector
<
std
::
string
>
outnames
=
core
->
GetOutputNames
();
std
::
vector
<
int
>
output_shape
;
int
out_num
=
0
;
int
dataType
=
0
;
void
*
databuf_data
=
NULL
;
char
*
databuf_char
=
NULL
;
size_t
databuf_size
=
0
;
for
(
int
i
=
0
;
i
<
outnames
.
size
();
++
i
){
auto
lod_tensor_out
=
core
->
GetOutputHandle
(
outnames
[
i
]);
std
::
vector
<
int
>
output_shape
=
lod_tensor_out
->
shape
();
int
out_num
=
std
::
accumulate
(
output_shape
.
begin
(),
output_shape
.
end
(),
1
,
std
::
multiplies
<
int
>
());
int
dataType
=
lod_tensor_out
->
type
();
char
*
databuf_data
=
NULL
;
size_t
databuf_size
=
0
;
output_shape
=
lod_tensor_out
->
shape
();
out_num
=
std
::
accumulate
(
output_shape
.
begin
(),
output_shape
.
end
(),
1
,
std
::
multiplies
<
int
>
());
dataType
=
lod_tensor_out
->
type
();
if
(
dataType
==
paddle
::
PaddleDType
::
FLOAT32
){
float
*
data_out
=
new
float
[
out_num
];
lod_tensor_out
->
CopyToCpu
(
data_out
);
databuf_data
=
reinterpret_cast
<
char
*>
(
data_out
);
databuf_size
=
out_num
*
sizeof
(
float
);
}
else
if
(
dataType
==
paddle
::
PaddleDType
::
INT64
){
int64_t
*
data_out
=
new
int64_t
[
out_num
];
void
*
databuf_data
=
MempoolWrapper
::
instance
().
malloc
(
databuf_size
);
if
(
!
databuf_data
)
{
LOG
(
ERROR
)
<<
"Malloc failed, size: "
<<
databuf_size
;
return
-
1
;
}
float
*
data_out
=
reinterpret_cast
<
float
*>
(
databuf_data
);
//float* data_out = new float[out_num];
lod_tensor_out
->
CopyToCpu
(
data_out
);
databuf_data
=
reinterpret_cast
<
char
*>
(
data_out
);
databuf_char
=
reinterpret_cast
<
char
*>
(
data_out
);
}
else
if
(
dataType
==
paddle
::
PaddleDType
::
INT64
){
databuf_size
=
out_num
*
sizeof
(
int64_t
);
}
else
if
(
dataType
==
paddle
::
PaddleDType
::
INT32
){
int32_t
*
data_out
=
new
int32_t
[
out_num
];
void
*
databuf_data
=
MempoolWrapper
::
instance
().
malloc
(
databuf_size
);
if
(
!
databuf_data
)
{
LOG
(
ERROR
)
<<
"Malloc failed, size: "
<<
databuf_size
;
return
-
1
;
}
int64_t
*
data_out
=
reinterpret_cast
<
int64_t
*>
(
data_out
);
lod_tensor_out
->
CopyToCpu
(
data_out
);
databuf_data
=
reinterpret_cast
<
char
*>
(
data_out
);
databuf_char
=
reinterpret_cast
<
char
*>
(
data_out
);
}
else
if
(
dataType
==
paddle
::
PaddleDType
::
INT32
){
databuf_size
=
out_num
*
sizeof
(
int32_t
);
void
*
databuf_data
=
MempoolWrapper
::
instance
().
malloc
(
databuf_size
);
if
(
!
databuf_data
)
{
LOG
(
ERROR
)
<<
"Malloc failed, size: "
<<
databuf_size
;
return
-
1
;
}
int32_t
*
data_out
=
reinterpret_cast
<
int32_t
*>
(
databuf_data
);
lod_tensor_out
->
CopyToCpu
(
data_out
);
databuf_char
=
reinterpret_cast
<
char
*>
(
data_out
);
}
/*
paddle::PaddleTensor* tensor_out = new paddle::PaddleTensor();
tensor_out->name = outnames[i];
tensor_out->dtype = paddle::PaddleDType(dataType);
tensor_out->shape.assign(output_shape.begin(), output_shape.end());
std::vector<std::vector<size_t>> out_lod = lod_tensor_out->lod();
for (int li = 0; li < out_lod.size(); ++li) {
std::vector<size_t> lod_element;
lod_element.assign(out_lod[li].begin(), out_lod[li].end());
tensor_out->lod.push_back(lod_element);
}
paddle::PaddleBuf* newData = new paddle::PaddleBuf(databuf_data,databuf_size);
tensor_out->data = *newData;
tensorVector_out_pointer->push_back(*tensor_out);
*/
paddle
::
PaddleTensor
tensor_out
;
tensor_out
.
name
=
outnames
[
i
];
tensor_out
.
dtype
=
paddle
::
PaddleDType
(
dataType
);
...
...
@@ -674,7 +679,7 @@ class FluidInferEngine : public CloneDBReloadableInferEngine<FluidFamilyCore> {
lod_element
.
assign
(
out_lod
[
li
].
begin
(),
out_lod
[
li
].
end
());
tensor_out
.
lod
.
push_back
(
lod_element
);
}
paddle
::
PaddleBuf
paddleBuf
(
databuf_
data
,
databuf_size
);
paddle
::
PaddleBuf
paddleBuf
(
databuf_
char
,
databuf_size
);
tensor_out
.
data
=
paddleBuf
;
tensorVector_out_pointer
->
push_back
(
tensor_out
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录