Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e07900d3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e07900d3
编写于
1月 17, 2019
作者:
Y
Yan Chunwei
提交者:
GitHub
1月 17, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cache tensor ptr in ZeroCopyTensor (#15352)
上级
b7916440
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
15 addition
and
6 deletion
+15
-6
paddle/fluid/inference/api/details/zero_copy_tensor.cc
paddle/fluid/inference/api/details/zero_copy_tensor.cc
+12
-6
paddle/fluid/inference/api/paddle_api.h
paddle/fluid/inference/api/paddle_api.h
+3
-0
未找到文件。
paddle/fluid/inference/api/details/zero_copy_tensor.cc
浏览文件 @
e07900d3
...
@@ -33,9 +33,15 @@ void ZeroCopyTensor::Reshape(const std::vector<int> &shape) {
...
@@ -33,9 +33,15 @@ void ZeroCopyTensor::Reshape(const std::vector<int> &shape) {
tensor
->
Resize
(
framework
::
make_ddim
(
shape
));
tensor
->
Resize
(
framework
::
make_ddim
(
shape
));
}
}
#define EAGER_GET_TENSOR \
if (!tensor_) { \
tensor_ = FindTensor(); \
} \
auto *tensor = static_cast<framework::LoDTensor *>(tensor_);
template
<
typename
T
>
template
<
typename
T
>
T
*
ZeroCopyTensor
::
mutable_data
(
PaddlePlace
place
)
{
T
*
ZeroCopyTensor
::
mutable_data
(
PaddlePlace
place
)
{
auto
*
tensor
=
static_cast
<
framework
::
LoDTensor
*>
(
FindTensor
())
;
EAGER_GET_TENSOR
;
switch
(
static_cast
<
int
>
(
place
))
{
switch
(
static_cast
<
int
>
(
place
))
{
case
static_cast
<
int
>
(
PaddlePlace
::
kCPU
):
{
case
static_cast
<
int
>
(
PaddlePlace
::
kCPU
):
{
return
tensor
->
mutable_data
<
T
>
(
platform
::
CPUPlace
());
return
tensor
->
mutable_data
<
T
>
(
platform
::
CPUPlace
());
...
@@ -52,7 +58,7 @@ T *ZeroCopyTensor::mutable_data(PaddlePlace place) {
...
@@ -52,7 +58,7 @@ T *ZeroCopyTensor::mutable_data(PaddlePlace place) {
template
<
typename
T
>
template
<
typename
T
>
T
*
ZeroCopyTensor
::
data
(
PaddlePlace
*
place
,
int
*
size
)
const
{
T
*
ZeroCopyTensor
::
data
(
PaddlePlace
*
place
,
int
*
size
)
const
{
auto
*
tensor
=
static_cast
<
framework
::
LoDTensor
*>
(
FindTensor
())
;
EAGER_GET_TENSOR
;
auto
*
res
=
tensor
->
data
<
T
>
();
auto
*
res
=
tensor
->
data
<
T
>
();
if
(
platform
::
is_cpu_place
(
tensor
->
place
()))
{
if
(
platform
::
is_cpu_place
(
tensor
->
place
()))
{
...
@@ -87,13 +93,13 @@ void *ZeroCopyTensor::FindTensor() const {
...
@@ -87,13 +93,13 @@ void *ZeroCopyTensor::FindTensor() const {
}
}
std
::
vector
<
int64_t
>
ZeroCopyTensor
::
shape
()
const
{
std
::
vector
<
int64_t
>
ZeroCopyTensor
::
shape
()
const
{
auto
*
tensor
=
static_cast
<
framework
::
LoDTensor
*>
(
FindTensor
())
;
EAGER_GET_TENSOR
;
PADDLE_ENFORCE
(
tensor
,
"not found tensor called %s in the scope"
,
name_
);
PADDLE_ENFORCE
(
tensor
_
,
"not found tensor called %s in the scope"
,
name_
);
return
framework
::
vectorize
(
tensor
->
dims
());
return
framework
::
vectorize
(
tensor
->
dims
());
}
}
void
ZeroCopyTensor
::
SetLoD
(
const
std
::
vector
<
std
::
vector
<
size_t
>>
&
x
)
{
void
ZeroCopyTensor
::
SetLoD
(
const
std
::
vector
<
std
::
vector
<
size_t
>>
&
x
)
{
auto
*
tensor
=
static_cast
<
framework
::
LoDTensor
*>
(
FindTensor
())
;
EAGER_GET_TENSOR
;
framework
::
LoD
lod
;
framework
::
LoD
lod
;
for
(
auto
&
level
:
x
)
{
for
(
auto
&
level
:
x
)
{
lod
.
emplace_back
(
level
);
lod
.
emplace_back
(
level
);
...
@@ -102,8 +108,8 @@ void ZeroCopyTensor::SetLoD(const std::vector<std::vector<size_t>> &x) {
...
@@ -102,8 +108,8 @@ void ZeroCopyTensor::SetLoD(const std::vector<std::vector<size_t>> &x) {
}
}
std
::
vector
<
std
::
vector
<
size_t
>>
ZeroCopyTensor
::
lod
()
const
{
std
::
vector
<
std
::
vector
<
size_t
>>
ZeroCopyTensor
::
lod
()
const
{
EAGER_GET_TENSOR
;
std
::
vector
<
std
::
vector
<
size_t
>>
res
;
std
::
vector
<
std
::
vector
<
size_t
>>
res
;
auto
*
tensor
=
static_cast
<
framework
::
LoDTensor
*>
(
FindTensor
());
for
(
auto
&
level
:
tensor
->
lod
())
{
for
(
auto
&
level
:
tensor
->
lod
())
{
res
.
emplace_back
(
level
);
res
.
emplace_back
(
level
);
}
}
...
...
paddle/fluid/inference/api/paddle_api.h
浏览文件 @
e07900d3
...
@@ -146,6 +146,9 @@ class ZeroCopyTensor {
...
@@ -146,6 +146,9 @@ class ZeroCopyTensor {
bool
input_or_output_
;
bool
input_or_output_
;
friend
class
AnalysisPredictor
;
friend
class
AnalysisPredictor
;
void
*
scope_
{
nullptr
};
void
*
scope_
{
nullptr
};
// The corresponding tensor pointer inside Paddle workspace is cached for
// performance.
mutable
void
*
tensor_
{
nullptr
};
};
};
/** A simple Inference API for Paddle.
/** A simple Inference API for Paddle.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录