Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
4bf168b2
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4bf168b2
编写于
3月 19, 2018
作者:
K
Kexin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add fp16 kernel for elementwise add
上级
b3f076a6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
24 deletion
+51
-24
paddle/fluid/operators/elementwise_add_op.cu
paddle/fluid/operators/elementwise_add_op.cu
+11
-10
python/paddle/fluid/tests/unittests/test_elementwise_add_op.py
...n/paddle/fluid/tests/unittests/test_elementwise_add_op.py
+40
-14
未找到文件。
paddle/fluid/operators/elementwise_add_op.cu
浏览文件 @
4bf168b2
...
...
@@ -14,19 +14,20 @@ limitations under the License. */
#define EIGEN_USE_GPU
#include "paddle/fluid/operators/elementwise_add_op.h"
#include "paddle/fluid/platform/float16.h"
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
padddle
::
platform
;
REGISTER_OP_CUDA_KERNEL
(
elementwise_add
,
ops
::
ElementwiseAddKernel
<
p
addle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
ElementwiseAddKernel
<
p
addle
::
platform
::
CUDADeviceContext
,
double
>
,
ops
::
ElementwiseAddKernel
<
p
addle
::
platform
::
CUDADeviceContext
,
int
>
,
ops
::
ElementwiseAddKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int64_t
>
);
elementwise_add
,
ops
::
ElementwiseAddKernel
<
plat
::
CUDADeviceContext
,
float
>
,
ops
::
ElementwiseAddKernel
<
p
lat
::
CUDADeviceContext
,
double
>
,
ops
::
ElementwiseAddKernel
<
p
lat
::
CUDADeviceContext
,
int
>
,
ops
::
ElementwiseAddKernel
<
p
lat
::
CUDADeviceContext
,
int64_t
>
ops
::
ElementwiseAddKernel
<
plat
::
CUDADeviceContext
,
plat
::
float16
>
);
REGISTER_OP_CUDA_KERNEL
(
elementwise_add_grad
,
ops
::
ElementwiseAddGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
ElementwiseAddGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
,
ops
::
ElementwiseAddGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int
>
,
ops
::
ElementwiseAddGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int64_t
>
);
ops
::
ElementwiseAddGradKernel
<
plat
::
CUDADeviceContext
,
float
>
,
ops
::
ElementwiseAddGradKernel
<
plat
::
CUDADeviceContext
,
double
>
,
ops
::
ElementwiseAddGradKernel
<
plat
::
CUDADeviceContext
,
int
>
,
ops
::
ElementwiseAddGradKernel
<
plat
::
CUDADeviceContext
,
int64_t
>
);
python/paddle/fluid/tests/unittests/test_elementwise_add_op.py
浏览文件 @
4bf168b2
...
...
@@ -13,34 +13,60 @@
# limitations under the License.
import
unittest
import
numpy
as
np
import
paddle.fluid.core
as
core
from
op_test
import
OpTest
class
TestElementwiseOp
(
OpTest
):
class
TestElementwise
Add
Op
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
dtype
=
np
.
float32
init_dtype
()
x
=
np
.
random
.
uniform
(
0.1
,
1
,
[
13
,
17
]).
astype
(
self
.
dtype
)
y
=
np
.
random
.
uniform
(
0.1
,
1
,
[
13
,
17
]).
astype
(
self
.
dtype
)
self
.
inputs
=
{
'X'
:
np
.
random
.
uniform
(
0.1
,
1
,
[
13
,
17
]).
astype
(
"float32"
),
'Y'
:
np
.
random
.
uniform
(
0.1
,
1
,
[
13
,
17
]).
astype
(
"float32"
)
'X'
:
OpTest
.
np_dtype_to_fluid_dtype
(
x
),
'Y'
:
OpTest
.
np_dtype_to_fluid_dtype
(
y
)
}
self
.
outputs
=
{
'Out'
:
np
.
add
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
]
)}
self
.
outputs
=
{
'Out'
:
np
.
add
(
x
,
y
)}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad
([
'X'
,
'Y'
],
'Out'
,
max_relative_error
=
0.005
)
def
test_check_grad_ingore_x
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad
(
[
'Y'
],
'Out'
,
max_relative_error
=
0.005
,
no_grad_set
=
set
(
"X"
))
def
test_check_grad_ingore_y
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad
(
[
'X'
],
'Out'
,
max_relative_error
=
0.005
,
no_grad_set
=
set
(
'Y'
))
def
init_dtype
():
pass
class
TestFP16ElementwiseAddOp
(
TestElementwiseAddOp
):
def
init_dtype
():
self
.
dtype
=
np
.
float16
def
test_check_output
(
self
):
if
core
.
is_compiled_with_cuda
():
place
=
core
.
CUDAPlace
(
0
)
if
core
.
is_float16_supported
(
place
):
self
.
check_output_with_place
(
place
,
atol
=
1e-3
)
class
TestElementwiseAddOp_scalar
(
TestElementwiseOp
):
class
TestElementwiseAddOp_scalar
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
@@ -50,7 +76,7 @@ class TestElementwiseAddOp_scalar(TestElementwiseOp):
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
]
+
self
.
inputs
[
'Y'
]}
class
TestElementwiseAddOp_scalar2
(
TestElementwiseOp
):
class
TestElementwiseAddOp_scalar2
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
@@ -60,7 +86,7 @@ class TestElementwiseAddOp_scalar2(TestElementwiseOp):
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
]
+
self
.
inputs
[
'Y'
]}
class
TestElementwiseAddOp_Vector
(
TestElementwiseOp
):
class
TestElementwiseAddOp_Vector
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
@@ -70,7 +96,7 @@ class TestElementwiseAddOp_Vector(TestElementwiseOp):
self
.
outputs
=
{
'Out'
:
np
.
add
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
])}
class
TestElementwiseAddOp_broadcast_0
(
TestElementwiseOp
):
class
TestElementwiseAddOp_broadcast_0
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
@@ -84,7 +110,7 @@ class TestElementwiseAddOp_broadcast_0(TestElementwiseOp):
}
class
TestElementwiseAddOp_broadcast_1
(
TestElementwiseOp
):
class
TestElementwiseAddOp_broadcast_1
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
@@ -98,7 +124,7 @@ class TestElementwiseAddOp_broadcast_1(TestElementwiseOp):
}
class
TestElementwiseAddOp_broadcast_2
(
TestElementwiseOp
):
class
TestElementwiseAddOp_broadcast_2
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
@@ -111,7 +137,7 @@ class TestElementwiseAddOp_broadcast_2(TestElementwiseOp):
}
class
TestElementwiseAddOp_broadcast_3
(
TestElementwiseOp
):
class
TestElementwiseAddOp_broadcast_3
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
@@ -125,7 +151,7 @@ class TestElementwiseAddOp_broadcast_3(TestElementwiseOp):
}
class
TestElementwiseAddOp_broadcast_4
(
TestElementwiseOp
):
class
TestElementwiseAddOp_broadcast_4
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
@@ -139,7 +165,7 @@ class TestElementwiseAddOp_broadcast_4(TestElementwiseOp):
}
class
TestElementwiseAddOp_rowwise_add_0
(
TestElementwiseOp
):
class
TestElementwiseAddOp_rowwise_add_0
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
@@ -153,7 +179,7 @@ class TestElementwiseAddOp_rowwise_add_0(TestElementwiseOp):
}
class
TestElementwiseAddOp_rowwise_add_1
(
TestElementwiseOp
):
class
TestElementwiseAddOp_rowwise_add_1
(
TestElementwise
Add
Op
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_add"
self
.
inputs
=
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录