Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
0f38bb45
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
未验证
提交
0f38bb45
编写于
4月 09, 2018
作者:
K
Kexin Zhao
提交者:
GitHub
4月 09, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add fp16 support to activation op (#9769)
上级
22b9d4e6
变更
5
展开全部
显示空白变更内容
内联
并排
Showing
5 changed file
with
742 addition
and
150 deletion
+742
-150
paddle/fluid/operators/activation_op.cc
paddle/fluid/operators/activation_op.cc
+0
-11
paddle/fluid/operators/activation_op.cu
paddle/fluid/operators/activation_op.cu
+13
-28
paddle/fluid/operators/activation_op.h
paddle/fluid/operators/activation_op.h
+17
-3
paddle/fluid/platform/float16.h
paddle/fluid/platform/float16.h
+40
-0
python/paddle/fluid/tests/unittests/test_activation_op.py
python/paddle/fluid/tests/unittests/test_activation_op.py
+672
-108
未找到文件。
paddle/fluid/operators/activation_op.cc
浏览文件 @
0f38bb45
...
@@ -662,14 +662,3 @@ REGISTER_OP(swish, ops::ActivationOp, ops::SwishOpMaker, swish_grad,
...
@@ -662,14 +662,3 @@ REGISTER_OP(swish, ops::ActivationOp, ops::SwishOpMaker, swish_grad,
ops::grad_functor<double>>);
ops::grad_functor<double>>);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_ACTIVATION_CPU_KERNEL
);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_ACTIVATION_CPU_KERNEL
);
REGISTER_OP_CPU_KERNEL
(
relu
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CPUDeviceContext
,
ops
::
ReluFunctor
<
float
>>
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CPUDeviceContext
,
ops
::
ReluFunctor
<
double
>>
);
REGISTER_OP_CPU_KERNEL
(
relu_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
ops
::
ReluGradFunctor
<
float
>>
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
ops
::
ReluGradFunctor
<
double
>>
);
paddle/fluid/operators/activation_op.cu
浏览文件 @
0f38bb45
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -17,31 +14,19 @@ limitations under the License. */
...
@@ -17,31 +14,19 @@ limitations under the License. */
#include "paddle/fluid/platform/float16.h"
#include "paddle/fluid/platform/float16.h"
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
#define REGISTER_ACTIVATION_CUDA_KERNEL(act_type, functor, grad_functor) \
#define REGISTER_ACTIVATION_CUDA_KERNEL(act_type, functor, grad_functor) \
REGISTER_OP_CUDA_KERNEL( \
REGISTER_OP_CUDA_KERNEL( \
act_type, ops::ActivationKernel<paddle::platform::CUDADeviceContext, \
act_type, \
ops::functor<float>>, \
ops::ActivationKernel<plat::CUDADeviceContext, ops::functor<float>>, \
ops::ActivationKernel<paddle::platform::CUDADeviceContext, \
ops::ActivationKernel<plat::CUDADeviceContext, ops::functor<double>>, \
ops::functor<double>>); \
ops::ActivationKernel<plat::CUDADeviceContext, \
ops::functor<plat::float16>>); \
REGISTER_OP_CUDA_KERNEL( \
REGISTER_OP_CUDA_KERNEL( \
act_type##_grad, \
act_type##_grad, ops::ActivationGradKernel<plat::CUDADeviceContext, \
ops::ActivationGradKernel<paddle::platform::CUDADeviceContext, \
ops::grad_functor<float>>, \
ops::grad_functor<float>>, \
ops::ActivationGradKernel<p
addle::platform::CUDADeviceContext,
\
ops::ActivationGradKernel<p
lat::CUDADeviceContext,
\
ops::grad_functor<double>>);
ops::grad_functor<double>>);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_ACTIVATION_CUDA_KERNEL
);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_ACTIVATION_CUDA_KERNEL
);
REGISTER_OP_CUDA_KERNEL
(
relu
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluFunctor
<
float
>>
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluFunctor
<
double
>>
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluFunctor
<
paddle
::
platform
::
float16
>>
);
REGISTER_OP_CUDA_KERNEL
(
relu_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluGradFunctor
<
float
>>
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluGradFunctor
<
double
>>
);
paddle/fluid/operators/activation_op.h
浏览文件 @
0f38bb45
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -15,9 +12,11 @@ limitations under the License. */
...
@@ -15,9 +12,11 @@ limitations under the License. */
#pragma once
#pragma once
#include <utility>
#include <utility>
#include <vector>
#include <vector>
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/operators/detail/safe_ref.h"
#include "paddle/fluid/operators/detail/safe_ref.h"
#include "paddle/fluid/platform/float16.h"
#ifdef PADDLE_WITH_MKLDNN
#ifdef PADDLE_WITH_MKLDNN
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
...
@@ -338,11 +337,25 @@ struct Sine {
...
@@ -338,11 +337,25 @@ struct Sine {
HOSTDEVICE
T
operator
()(
const
T
&
val
)
const
{
return
sin
(
val
);
}
HOSTDEVICE
T
operator
()(
const
T
&
val
)
const
{
return
sin
(
val
);
}
};
};
template
<
>
struct
Sine
<
platform
::
float16
>
{
HOSTDEVICE
platform
::
float16
operator
()(
const
platform
::
float16
&
val
)
const
{
return
platform
::
float16
(
sin
(
static_cast
<
float
>
(
val
)));
}
};
template
<
typename
T
>
template
<
typename
T
>
struct
Cosine
{
struct
Cosine
{
HOSTDEVICE
T
operator
()(
const
T
&
val
)
const
{
return
cos
(
val
);
}
HOSTDEVICE
T
operator
()(
const
T
&
val
)
const
{
return
cos
(
val
);
}
};
};
template
<
>
struct
Cosine
<
platform
::
float16
>
{
HOSTDEVICE
platform
::
float16
operator
()(
const
platform
::
float16
&
val
)
const
{
return
platform
::
float16
(
cos
(
static_cast
<
float
>
(
val
)));
}
};
// cosine'(x) = -sin(x)
// cosine'(x) = -sin(x)
template
<
typename
T
>
template
<
typename
T
>
struct
CosGradFunctor
:
public
BaseActivationFunctor
<
T
>
{
struct
CosGradFunctor
:
public
BaseActivationFunctor
<
T
>
{
...
@@ -826,6 +839,7 @@ struct SwishGradFunctor : public BaseActivationFunctor<T> {
...
@@ -826,6 +839,7 @@ struct SwishGradFunctor : public BaseActivationFunctor<T> {
__macro(sigmoid, SigmoidFunctor, SigmoidGradFunctor); \
__macro(sigmoid, SigmoidFunctor, SigmoidGradFunctor); \
__macro(logsigmoid, LogSigmoidFunctor, LogSigmoidGradFunctor); \
__macro(logsigmoid, LogSigmoidFunctor, LogSigmoidGradFunctor); \
__macro(exp, ExpFunctor, ExpGradFunctor); \
__macro(exp, ExpFunctor, ExpGradFunctor); \
__macro(relu, ReluFunctor, ReluGradFunctor); \
__macro(tanh, TanhFunctor, TanhGradFunctor); \
__macro(tanh, TanhFunctor, TanhGradFunctor); \
__macro(softshrink, SoftShrinkFunctor, SoftShrinkGradFunctor); \
__macro(softshrink, SoftShrinkFunctor, SoftShrinkGradFunctor); \
__macro(sqrt, SqrtFunctor, SqrtGradFunctor); \
__macro(sqrt, SqrtFunctor, SqrtGradFunctor); \
...
...
paddle/fluid/platform/float16.h
浏览文件 @
0f38bb45
...
@@ -1003,6 +1003,46 @@ HOSTDEVICE inline float16 exp(const float16& a) {
...
@@ -1003,6 +1003,46 @@ HOSTDEVICE inline float16 exp(const float16& a) {
return
float16
(
::
expf
(
static_cast
<
float
>
(
a
)));
return
float16
(
::
expf
(
static_cast
<
float
>
(
a
)));
}
}
template
<
>
HOSTDEVICE
inline
float16
log
(
const
float16
&
a
)
{
return
float16
(
::
logf
(
static_cast
<
float
>
(
a
)));
}
template
<
>
HOSTDEVICE
inline
float16
tanh
(
const
float16
&
a
)
{
return
float16
(
::
tanhf
(
static_cast
<
float
>
(
a
)));
}
template
<
>
HOSTDEVICE
inline
float16
sqrt
(
const
float16
&
a
)
{
return
float16
(
::
sqrtf
(
static_cast
<
float
>
(
a
)));
}
template
<
>
HOSTDEVICE
inline
float16
ceil
(
const
float16
&
a
)
{
return
float16
(
::
ceilf
(
static_cast
<
float
>
(
a
)));
}
template
<
>
HOSTDEVICE
inline
float16
floor
(
const
float16
&
a
)
{
return
float16
(
::
floorf
(
static_cast
<
float
>
(
a
)));
}
template
<
>
HOSTDEVICE
inline
float16
round
(
const
float16
&
a
)
{
return
float16
(
::
roundf
(
static_cast
<
float
>
(
a
)));
}
template
<
>
HOSTDEVICE
inline
float16
pow
(
const
float16
&
a
,
const
float16
&
b
)
{
return
float16
(
::
powf
(
static_cast
<
float
>
(
a
),
static_cast
<
float
>
(
b
)));
}
template
<
>
HOSTDEVICE
inline
float16
abs
(
const
float16
&
a
)
{
return
float16
(
::
fabs
(
static_cast
<
float
>
(
a
)));
}
}
// namespace numext
}
// namespace numext
}
// namespace Eigen
}
// namespace Eigen
python/paddle/fluid/tests/unittests/test_activation_op.py
浏览文件 @
0f38bb45
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录