Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
e146fe83
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e146fe83
编写于
7月 03, 2017
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix compile errors and add assert test
上级
9f408dfb
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
76 addition
and
49 deletion
+76
-49
paddle/framework/tensor.h
paddle/framework/tensor.h
+19
-6
paddle/framework/tensor_test.cc
paddle/framework/tensor_test.cc
+57
-43
未找到文件。
paddle/framework/tensor.h
浏览文件 @
e146fe83
...
...
@@ -20,7 +20,6 @@ limitations under the License. */
#include "paddle/framework/ddim.h"
#include "paddle/framework/enforce.h"
#include "paddle/memory/memory.h"
#include "paddle/platform/assert.h"
#include "paddle/platform/place.h"
namespace
paddle
{
...
...
@@ -63,21 +62,35 @@ class Tensor {
template
<
typename
T
>
struct
PlaceholderImpl
:
public
Placeholder
{
PlaceholderImpl
(
paddle
::
platform
::
Place
pl
,
size_t
size
)
:
ptr_
(
paddle
::
memory
::
Alloc
(
pl
,
size
),
paddle
::
memory
::
Deleter
(
pl
)),
place_
(
pl
),
private:
class
Deleter
{
public:
Deleter
(
platform
::
Place
place
)
:
place_
(
place
)
{}
void
operator
()(
T
*
ptr
)
{
paddle
::
memory
::
Free
(
place_
,
static_cast
<
void
*>
(
ptr
));
}
private:
paddle
::
platform
::
Place
place_
;
};
public:
PlaceholderImpl
(
paddle
::
platform
::
Place
place
,
size_t
size
)
:
ptr_
(
static_cast
<
T
*>
(
paddle
::
memory
::
Alloc
(
place
,
size
)),
Deleter
(
place
)),
place_
(
place
),
size_
(
size
)
{}
virtual
void
*
Ptr
()
const
{
return
static_cast
<
void
*>
(
ptr_
.
get
());
}
virtual
size_t
Size
()
const
{
return
size_
;
}
virtual
paddle
::
platform
::
Place
Place
()
const
{
return
place_
;
}
std
::
unique_ptr
<
T
,
memory
::
Deleter
>
ptr_
;
std
::
unique_ptr
<
T
,
Deleter
>
ptr_
;
paddle
::
platform
::
Place
place_
;
// record the place of ptr_.
size_t
size_
;
// size of the memory block.
};
std
::
unique
_ptr
<
Placeholder
>
holder_
;
// holds the memory block if allocated.
std
::
shared
_ptr
<
Placeholder
>
holder_
;
// holds the memory block if allocated.
};
}
// namespace framework
...
...
paddle/framework/tensor_test.cc
浏览文件 @
e146fe83
...
...
@@ -13,12 +13,23 @@
#include "paddle/framework/tensor.h"
#include <gtest/gtest.h>
#include <string>
TEST
(
Tensor
,
Data
)
{
using
namespace
paddle
::
framework
;
using
namespace
paddle
::
platform
;
TEST
(
Tensor
,
ASSERT
)
{
paddle
::
framework
::
Tensor
cpu_tensor
;
Tensor
cpu_tensor
;
bool
caught
=
false
;
try
{
const
double
*
p
__attribute__
((
unused
))
=
cpu_tensor
.
data
<
double
>
();
}
catch
(
paddle
::
framework
::
EnforceNotMet
err
)
{
caught
=
true
;
std
::
string
msg
=
"Tensor::data must be called after Tensor::mutable_data"
;
const
char
*
what
=
err
.
what
();
for
(
size_t
i
=
0
;
i
<
msg
.
length
();
++
i
)
{
ASSERT_EQ
(
what
[
i
],
msg
[
i
]);
}
}
ASSERT_TRUE
(
caught
);
}
/* mutable_data() is not tested at present
...
...
@@ -27,7 +38,7 @@ TEST(Tensor, Data) {
TEST(Tensor, MutableData) {
using namespace paddle::framework;
using namespace paddle::platform;
{
Tensor cpu_tensor;
float* p1 = nullptr;
float* p2 = nullptr;
...
...
@@ -47,7 +58,9 @@ TEST(Tensor, MutableData) {
// momery block is supposed to be unchanged
p2 = cpu_tensor.mutable_data<float>(make_ddim({2, 2}));
EXPECT_EQ(p1, p2);
}
{
Tensor gpu_tensor;
float* p1 = nullptr;
float* p2 = nullptr;
...
...
@@ -67,5 +80,6 @@ TEST(Tensor, MutableData) {
// momery block is supposed to be unchanged
p2 = gpu_tensor.mutable_data<float>(make_ddim({2, 2}));
EXPECT_EQ(p1, p2);
}
}
*/
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录