Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
78bd815e
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
78bd815e
编写于
7月 17, 2017
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine conditional compilation and remove `numel_`
上级
1cd14f66
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
23 deletion
+17
-23
paddle/framework/tensor.h
paddle/framework/tensor.h
+17
-23
未找到文件。
paddle/framework/tensor.h
浏览文件 @
78bd815e
...
...
@@ -27,7 +27,7 @@ namespace framework {
class
Tensor
{
public:
Tensor
()
:
numel_
(
0
),
offset_
(
0
)
{}
Tensor
()
:
offset_
(
0
)
{}
template
<
typename
T
>
const
T
*
data
()
const
{
...
...
@@ -44,30 +44,26 @@ class Tensor {
template
<
typename
T
>
T
*
mutable_data
(
platform
::
Place
place
)
{
PADDLE_ENFORCE
(
numel_
>
0
,
"Tensor
::numel_
must be larger than zero to call "
PADDLE_ENFORCE
(
product
(
dims_
)
>
0
,
"Tensor
's numel
must be larger than zero to call "
"Tensor::mutable_data. Call Tensor::set_dim first."
);
if
(
holder_
==
nullptr
||
!
(
holder_
->
place
()
==
place
)
/* some versions of boost::variant don't have operator!= */
||
holder_
->
size
()
<
numel_
*
sizeof
(
T
)
+
offset_
)
{
||
holder_
->
size
()
<
product
(
dims_
)
*
sizeof
(
T
)
+
offset_
)
{
if
(
platform
::
is_cpu_place
(
place
))
{
holder_
.
reset
(
new
PlaceholderImpl
<
T
,
platform
::
CPUPlace
>
(
boost
::
get
<
platform
::
CPUPlace
>
(
place
),
product
(
dims_
)
*
sizeof
(
T
)));
}
else
if
(
platform
::
is_gpu_place
(
place
))
{
#ifdef __CUDACC__
switch
(
place
.
which
())
{
case
0
:
holder_
.
reset
(
new
PlaceholderImpl
<
T
,
platform
::
GPUPlace
>
(
boost
::
get
<
platform
::
GPUPlace
>
(
place
),
numel_
*
sizeof
(
T
)));
break
;
case
1
:
holder_
.
reset
(
new
PlaceholderImpl
<
T
,
platform
::
CPUPlace
>
(
boost
::
get
<
platform
::
CPUPlace
>
(
place
),
numel_
*
sizeof
(
T
)));
break
;
}
holder_
.
reset
(
new
PlaceholderImpl
<
T
,
platform
::
GPUPlace
>
(
boost
::
get
<
platform
::
GPUPlace
>
(
place
),
product
(
dims_
)
*
sizeof
(
T
)));
#else
holder_
.
reset
(
new
PlaceholderImpl
<
T
,
platform
::
CPUPlace
>
(
boost
::
get
<
platform
::
CPUPlace
>
(
place
),
numel_
*
sizeof
(
T
)));
PADDLE_ENFORCE
(
true
,
"'GPUPlace' is not supported in CPU only device."
);
#endif
}
else
{
PADDLE_ENFORCE
(
true
,
"Unknown 'place'."
);
}
offset_
=
0
;
}
return
reinterpret_cast
<
T
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
...
...
@@ -88,7 +84,7 @@ class Tensor {
platform
::
is_cpu_place
(
dst_place
),
"Tensor::CopyFrom only support CPU now."
);
src
.
CheckDims
<
T
>
();
size_t
size
=
src
.
numel_
*
sizeof
(
T
);
size_t
size
=
product
(
src
.
dims_
)
*
sizeof
(
T
);
set_dims
(
src
.
dims
());
const
void
*
src_ptr
=
static_cast
<
const
void
*>
(
src
.
data
<
T
>
());
void
*
dst_ptr
=
static_cast
<
void
*>
(
mutable_data
<
T
>
(
dst_place
));
...
...
@@ -122,7 +118,6 @@ class Tensor {
return
;
}
dims_
=
dims
;
numel_
=
product
(
dims_
);
}
DDim
dims
()
const
{
return
dims_
;
}
...
...
@@ -170,16 +165,15 @@ class Tensor {
inline
void
CheckDims
()
const
{
PADDLE_ENFORCE
(
holder_
!=
nullptr
,
"Tenosr holds no memory. Call Tensor::mutable_data first."
);
PADDLE_ENFORCE
(
holder_
->
size
()
>=
numel_
*
sizeof
(
T
)
+
offset_
,
PADDLE_ENFORCE
(
holder_
->
size
()
>=
product
(
dims_
)
*
sizeof
(
T
)
+
offset_
,
"Tensor's dims_ is out of bound. Call Tensor::mutable_data "
"first to re-allocate memory."
);
}
std
::
shared_ptr
<
Placeholder
>
holder_
;
// holds the memory block if allocated.
DDim
dims_
;
size_t
numel_
;
// cache of `product(dims_)`
size_t
offset_
;
// marks the begin of tensor data area.
};
// namespace framework
};
}
// namespace framework
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录