Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
7f00716c
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,发现更多精彩内容 >>
未验证
提交
7f00716c
编写于
3月 07, 2018
作者:
K
kexinzhao
提交者:
GitHub
3月 07, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add context wait in type_transform (#8850)
上级
6f50dee4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
33 addition
and
25 deletion
+33
-25
paddle/fluid/framework/data_type_transform.cc
paddle/fluid/framework/data_type_transform.cc
+1
-0
paddle/fluid/framework/data_type_transform_test.cc
paddle/fluid/framework/data_type_transform_test.cc
+12
-12
paddle/fluid/framework/data_type_transform_test.cu
paddle/fluid/framework/data_type_transform_test.cu
+20
-13
未找到文件。
paddle/fluid/framework/data_type_transform.cc
浏览文件 @
7f00716c
...
...
@@ -53,6 +53,7 @@ struct CastDataType {
auto
*
context
=
static_cast
<
const
platform
::
CUDADeviceContext
*>
(
ctx_
);
trans
(
*
context
,
in_begin
,
in_end
,
out_begin
,
CastDataTypeFunctor
<
InType
,
OutType
>
());
context
->
Wait
();
#endif
}
else
{
PADDLE_THROW
(
"Unsupported place!"
);
...
...
paddle/fluid/framework/data_type_transform_test.cc
浏览文件 @
7f00716c
...
...
@@ -50,13 +50,13 @@ TEST(DataTypeTransform, CPUTransform) {
TransDataType
(
kernel_fp32
,
kernel_fp64
,
in
,
&
out
);
double
*
out_data_double
=
out
.
data
<
double
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_double
[
i
],
static_cast
<
double
>
(
i
/
3
));
EXPEC
T_EQ
(
out_data_double
[
i
],
static_cast
<
double
>
(
i
/
3
));
}
TransDataType
(
kernel_fp32
,
kernel_int32
,
in
,
&
out
);
int
*
out_data_int
=
out
.
data
<
int
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_int
[
i
],
static_cast
<
int
>
(
i
/
3
));
EXPEC
T_EQ
(
out_data_int
[
i
],
static_cast
<
int
>
(
i
/
3
));
}
}
...
...
@@ -76,31 +76,31 @@ TEST(DataTypeTransform, CPUTransform) {
TransDataType
(
kernel_fp16
,
kernel_fp32
,
in
,
&
out
);
float
*
out_data_float
=
out
.
data
<
float
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_float
[
i
],
static_cast
<
float
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_float
[
i
],
static_cast
<
float
>
(
ptr
[
i
]));
}
TransDataType
(
kernel_fp16
,
kernel_fp64
,
in
,
&
out
);
double
*
out_data_double
=
out
.
data
<
double
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_double
[
i
],
static_cast
<
double
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_double
[
i
],
static_cast
<
double
>
(
ptr
[
i
]));
}
TransDataType
(
kernel_fp16
,
kernel_int32
,
in
,
&
out
);
int
*
out_data_int
=
out
.
data
<
int
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_int
[
i
],
static_cast
<
int
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_int
[
i
],
static_cast
<
int
>
(
ptr
[
i
]));
}
TransDataType
(
kernel_fp16
,
kernel_int64
,
in
,
&
out
);
int64_t
*
out_data_int64
=
out
.
data
<
int64_t
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_int64
[
i
],
static_cast
<
int64_t
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_int64
[
i
],
static_cast
<
int64_t
>
(
ptr
[
i
]));
}
TransDataType
(
kernel_fp16
,
kernel_bool
,
in
,
&
out
);
bool
*
out_data_bool
=
out
.
data
<
bool
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_bool
[
i
],
static_cast
<
bool
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_bool
[
i
],
static_cast
<
bool
>
(
ptr
[
i
]));
}
// transform float to float16
...
...
@@ -112,7 +112,7 @@ TEST(DataTypeTransform, CPUTransform) {
TransDataType
(
kernel_fp32
,
kernel_fp16
,
in
,
&
out
);
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_float
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_float
[
i
]).
x
);
}
// transform double to float16
...
...
@@ -124,7 +124,7 @@ TEST(DataTypeTransform, CPUTransform) {
TransDataType
(
kernel_fp64
,
kernel_fp16
,
in
,
&
out
);
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_double
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_double
[
i
]).
x
);
}
// transform int to float16
...
...
@@ -136,7 +136,7 @@ TEST(DataTypeTransform, CPUTransform) {
TransDataType
(
kernel_int32
,
kernel_fp16
,
in
,
&
out
);
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_int
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_int
[
i
]).
x
);
}
// transform int64 to float16
...
...
@@ -148,7 +148,7 @@ TEST(DataTypeTransform, CPUTransform) {
TransDataType
(
kernel_int64
,
kernel_fp16
,
in
,
&
out
);
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_int64
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_int64
[
i
]).
x
);
}
// transform bool to float16
...
...
@@ -160,7 +160,7 @@ TEST(DataTypeTransform, CPUTransform) {
TransDataType
(
kernel_bool
,
kernel_fp16
,
in
,
&
out
);
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_bool
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_bool
[
i
]).
x
);
}
}
}
paddle/fluid/framework/data_type_transform_test.cu
浏览文件 @
7f00716c
...
...
@@ -49,15 +49,16 @@ TEST(DataTypeTransform, GPUTransform) {
float
arr
[
6
]
=
{
0
,
1
,
2
,
3
,
4
,
5
};
int
data_number
=
sizeof
(
arr
)
/
sizeof
(
arr
[
0
]);
memcpy
(
in_ptr
,
arr
,
sizeof
(
arr
));
TensorCopy
(
in
,
gpu_place
,
context
,
&
in_gpu
);
TensorCopy
(
in
,
gpu_place
,
context
,
&
in_gpu
);
context
.
Wait
();
TransDataType
(
kernel_fp32
,
kernel_fp64
,
in_gpu
,
&
out_gpu
);
TensorCopy
(
out_gpu
,
cpu_place
,
context
,
&
out
);
context
.
Wait
();
double
*
out_data_double
=
out
.
data
<
double
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_double
[
i
],
static_cast
<
double
>
(
arr
[
i
]));
EXPEC
T_EQ
(
out_data_double
[
i
],
static_cast
<
double
>
(
arr
[
i
]));
}
TransDataType
(
kernel_fp32
,
kernel_int32
,
in_gpu
,
&
out_gpu
);
...
...
@@ -66,7 +67,7 @@ TEST(DataTypeTransform, GPUTransform) {
int
*
out_data_int
=
out
.
data
<
int
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_int
[
i
],
static_cast
<
int
>
(
arr
[
i
]));
EXPEC
T_EQ
(
out_data_int
[
i
],
static_cast
<
int
>
(
arr
[
i
]));
}
}
...
...
@@ -83,6 +84,7 @@ TEST(DataTypeTransform, GPUTransform) {
int
data_number
=
sizeof
(
arr
)
/
sizeof
(
arr
[
0
]);
memcpy
(
ptr
,
arr
,
sizeof
(
arr
));
TensorCopy
(
in
,
gpu_place
,
context
,
&
in_gpu
);
context
.
Wait
();
// transform from float16 to other data types
TransDataType
(
kernel_fp16
,
kernel_fp32
,
in_gpu
,
&
out_gpu
);
...
...
@@ -91,7 +93,7 @@ TEST(DataTypeTransform, GPUTransform) {
float
*
out_data_float
=
out
.
data
<
float
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_float
[
i
],
static_cast
<
float
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_float
[
i
],
static_cast
<
float
>
(
ptr
[
i
]));
}
TransDataType
(
kernel_fp16
,
kernel_fp64
,
in_gpu
,
&
out_gpu
);
...
...
@@ -100,7 +102,7 @@ TEST(DataTypeTransform, GPUTransform) {
double
*
out_data_double
=
out
.
data
<
double
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_double
[
i
],
static_cast
<
double
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_double
[
i
],
static_cast
<
double
>
(
ptr
[
i
]));
}
TransDataType
(
kernel_fp16
,
kernel_int32
,
in_gpu
,
&
out_gpu
);
...
...
@@ -109,7 +111,7 @@ TEST(DataTypeTransform, GPUTransform) {
int
*
out_data_int
=
out
.
data
<
int
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_int
[
i
],
static_cast
<
int
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_int
[
i
],
static_cast
<
int
>
(
ptr
[
i
]));
}
TransDataType
(
kernel_fp16
,
kernel_int64
,
in_gpu
,
&
out_gpu
);
...
...
@@ -118,7 +120,7 @@ TEST(DataTypeTransform, GPUTransform) {
int64_t
*
out_data_int64
=
out
.
data
<
int64_t
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_int64
[
i
],
static_cast
<
int64_t
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_int64
[
i
],
static_cast
<
int64_t
>
(
ptr
[
i
]));
}
TransDataType
(
kernel_fp16
,
kernel_bool
,
in_gpu
,
&
out_gpu
);
...
...
@@ -127,7 +129,7 @@ TEST(DataTypeTransform, GPUTransform) {
bool
*
out_data_bool
=
out
.
data
<
bool
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
out_data_bool
[
i
],
static_cast
<
bool
>
(
ptr
[
i
]));
EXPEC
T_EQ
(
out_data_bool
[
i
],
static_cast
<
bool
>
(
ptr
[
i
]));
}
// transform float to float16
...
...
@@ -137,13 +139,14 @@ TEST(DataTypeTransform, GPUTransform) {
}
TensorCopy
(
in
,
gpu_place
,
context
,
&
in_gpu
);
context
.
Wait
();
TransDataType
(
kernel_fp32
,
kernel_fp16
,
in_gpu
,
&
out_gpu
);
TensorCopy
(
out_gpu
,
cpu_place
,
context
,
&
out
);
context
.
Wait
();
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_float
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_float
[
i
]).
x
);
}
// transform double to float16
...
...
@@ -154,13 +157,14 @@ TEST(DataTypeTransform, GPUTransform) {
}
TensorCopy
(
in
,
gpu_place
,
context
,
&
in_gpu
);
context
.
Wait
();
TransDataType
(
kernel_fp64
,
kernel_fp16
,
in_gpu
,
&
out_gpu
);
TensorCopy
(
out_gpu
,
cpu_place
,
context
,
&
out
);
context
.
Wait
();
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_double
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_double
[
i
]).
x
);
}
// transform int to float16
...
...
@@ -170,13 +174,14 @@ TEST(DataTypeTransform, GPUTransform) {
}
TensorCopy
(
in
,
gpu_place
,
context
,
&
in_gpu
);
context
.
Wait
();
TransDataType
(
kernel_int32
,
kernel_fp16
,
in_gpu
,
&
out_gpu
);
TensorCopy
(
out_gpu
,
cpu_place
,
context
,
&
out
);
context
.
Wait
();
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_int
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_int
[
i
]).
x
);
}
// transform int64 to float16
...
...
@@ -187,13 +192,14 @@ TEST(DataTypeTransform, GPUTransform) {
}
TensorCopy
(
in
,
gpu_place
,
context
,
&
in_gpu
);
context
.
Wait
();
TransDataType
(
kernel_int64
,
kernel_fp16
,
in_gpu
,
&
out_gpu
);
TensorCopy
(
out_gpu
,
cpu_place
,
context
,
&
out
);
context
.
Wait
();
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_int64
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_int64
[
i
]).
x
);
}
// transform bool to float16
...
...
@@ -203,13 +209,14 @@ TEST(DataTypeTransform, GPUTransform) {
}
TensorCopy
(
in
,
gpu_place
,
context
,
&
in_gpu
);
context
.
Wait
();
TransDataType
(
kernel_bool
,
kernel_fp16
,
in_gpu
,
&
out_gpu
);
TensorCopy
(
out_gpu
,
cpu_place
,
context
,
&
out
);
context
.
Wait
();
ptr
=
out
.
data
<
float16
>
();
for
(
int
i
=
0
;
i
<
data_number
;
++
i
)
{
ASSER
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_bool
[
i
]).
x
);
EXPEC
T_EQ
(
ptr
[
i
].
x
,
static_cast
<
float16
>
(
in_data_bool
[
i
]).
x
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录