Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
446d54f5
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
446d54f5
编写于
3月 18, 2018
作者:
K
Kexin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
ffa22a5f
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
27 addition
and
22 deletion
+27
-22
paddle/fluid/operators/batch_norm_op.cc
paddle/fluid/operators/batch_norm_op.cc
+1
-1
paddle/fluid/operators/batch_norm_op.cu.cc
paddle/fluid/operators/batch_norm_op.cu.cc
+20
-18
paddle/fluid/platform/cudnn_helper.h
paddle/fluid/platform/cudnn_helper.h
+6
-3
未找到文件。
paddle/fluid/operators/batch_norm_op.cc
浏览文件 @
446d54f5
...
...
@@ -83,7 +83,7 @@ class BatchNormOp : public framework::OperatorWithKernel {
protected:
framework
::
OpKernelType
GetExpectedKernelType
(
const
ExecutionContext
&
ctx
)
const
override
{
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
input_data_type
=
framework
::
ToDataType
(
ctx
.
Input
<
Tensor
>
(
"X"
)
->
type
());
// For float or float16 input tensor, the type of the scale, bias, mean,
...
...
paddle/fluid/operators/batch_norm_op.cu.cc
浏览文件 @
446d54f5
...
...
@@ -28,7 +28,7 @@ using DataLayout = framework::DataLayout;
template
<
typename
T
>
using
CudnnDataType
=
platform
::
CudnnDataType
<
T
>
;
template
<
typename
T
>
using
ScalingParamType
=
typename
CudnnDataType
<
T
>::
Scaling
ParamType
;
using
BatchNormParamType
=
typename
CudnnDataType
<
T
>::
BatchNorm
ParamType
;
void
ExtractNCWHD
(
const
framework
::
DDim
&
dims
,
const
DataLayout
&
data_layout
,
int
*
N
,
int
*
C
,
int
*
H
,
int
*
W
,
int
*
D
)
{
...
...
@@ -122,15 +122,16 @@ class BatchNormKernel<platform::CUDADeviceContext, T>
// alloc memory
y
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
mean_out
->
mutable_data
<
Scaling
ParamType
<
T
>>
(
ctx
.
GetPlace
());
variance_out
->
mutable_data
<
Scaling
ParamType
<
T
>>
(
ctx
.
GetPlace
());
saved_mean
->
mutable_data
<
Scaling
ParamType
<
T
>>
(
ctx
.
GetPlace
());
saved_variance
->
mutable_data
<
Scaling
ParamType
<
T
>>
(
ctx
.
GetPlace
());
mean_out
->
mutable_data
<
BatchNorm
ParamType
<
T
>>
(
ctx
.
GetPlace
());
variance_out
->
mutable_data
<
BatchNorm
ParamType
<
T
>>
(
ctx
.
GetPlace
());
saved_mean
->
mutable_data
<
BatchNorm
ParamType
<
T
>>
(
ctx
.
GetPlace
());
saved_variance
->
mutable_data
<
BatchNorm
ParamType
<
T
>>
(
ctx
.
GetPlace
());
auto
&
dev_ctx
=
ctx
.
template
device_context
<
platform
::
CUDADeviceContext
>();
math
::
SetConstant
<
platform
::
CUDADeviceContext
,
ScalingParamType
<
T
>>
functor
;
functor
(
dev_ctx
,
saved_mean
,
static_cast
<
ScalingParamType
<
T
>>
(
0
));
functor
(
dev_ctx
,
saved_variance
,
static_cast
<
ScalingParamType
<
T
>>
(
0
));
math
::
SetConstant
<
platform
::
CUDADeviceContext
,
BatchNormParamType
<
T
>>
functor
;
functor
(
dev_ctx
,
saved_mean
,
static_cast
<
BatchNormParamType
<
T
>>
(
0
));
functor
(
dev_ctx
,
saved_variance
,
static_cast
<
BatchNormParamType
<
T
>>
(
0
));
auto
handle
=
dev_ctx
.
cudnn_handle
();
...
...
@@ -151,10 +152,10 @@ class BatchNormKernel<platform::CUDADeviceContext, T>
CUDNN_BATCHNORM_SPATIAL
,
CudnnDataType
<
T
>::
kOne
(),
CudnnDataType
<
T
>::
kZero
(),
data_desc_
,
x
->
template
data
<
T
>(),
data_desc_
,
y
->
template
mutable_data
<
T
>(
ctx
.
GetPlace
()),
bn_param_desc_
,
scale
->
template
data
<
Scaling
ParamType
<
T
>
>
(),
bias
->
template
data
<
Scaling
ParamType
<
T
>
>
(),
est_mean
->
template
data
<
Scaling
ParamType
<
T
>
>
(),
est_var
->
template
data
<
Scaling
ParamType
<
T
>
>
(),
epsilon
));
bn_param_desc_
,
scale
->
template
data
<
BatchNorm
ParamType
<
T
>
>
(),
bias
->
template
data
<
BatchNorm
ParamType
<
T
>
>
(),
est_mean
->
template
data
<
BatchNorm
ParamType
<
T
>
>
(),
est_var
->
template
data
<
BatchNorm
ParamType
<
T
>
>
(),
epsilon
));
}
else
{
// Run training mode.
// obtain running mean and running inv var, and see if we need to
...
...
@@ -165,14 +166,15 @@ class BatchNormKernel<platform::CUDADeviceContext, T>
handle
,
mode_
,
CudnnDataType
<
T
>::
kOne
(),
CudnnDataType
<
T
>::
kZero
(),
data_desc_
,
x
->
template
data
<
T
>(),
data_desc_
,
y
->
template
mutable_data
<
T
>(
ctx
.
GetPlace
()),
bn_param_desc_
,
scale
->
template
data
<
ScalingParamType
<
T
>
>
(),
bias
->
template
data
<
ScalingParamType
<
T
>
>
(),
this_factor
,
mean_out
->
template
mutable_data
<
ScalingParamType
<
T
>
>
(
ctx
.
GetPlace
()),
variance_out
->
template
mutable_data
<
ScalingParamType
<
T
>
>
(
scale
->
template
data
<
BatchNormParamType
<
T
>
>
(),
bias
->
template
data
<
BatchNormParamType
<
T
>
>
(),
this_factor
,
mean_out
->
template
mutable_data
<
BatchNormParamType
<
T
>
>
(
ctx
.
GetPlace
()),
epsilon
,
saved_mean
->
template
mutable_data
<
Scaling
ParamType
<
T
>
>
(
variance_out
->
template
mutable_data
<
BatchNorm
ParamType
<
T
>
>
(
ctx
.
GetPlace
()),
saved_variance
->
template
mutable_data
<
ScalingParamType
<
T
>
>
(
epsilon
,
saved_mean
->
template
mutable_data
<
BatchNormParamType
<
T
>
>
(
ctx
.
GetPlace
()),
saved_variance
->
template
mutable_data
<
BatchNormParamType
<
T
>
>
(
ctx
.
GetPlace
())));
}
...
...
paddle/fluid/platform/cudnn_helper.h
浏览文件 @
446d54f5
...
...
@@ -86,7 +86,8 @@ class CudnnDataType<float16> {
public:
static
const
cudnnDataType_t
type
=
CUDNN_DATA_HALF
;
// The scaling param type is float for HALF and FLOAT tensors
typedef
const
float
ScalingParamType
;
using
ScalingParamType
=
const
float
;
using
BatchNormParamType
=
float
;
static
ScalingParamType
*
kOne
()
{
static
ScalingParamType
v
=
1.0
;
return
&
v
;
...
...
@@ -101,7 +102,8 @@ template <>
class
CudnnDataType
<
float
>
{
public:
static
const
cudnnDataType_t
type
=
CUDNN_DATA_FLOAT
;
typedef
const
float
ScalingParamType
;
using
ScalingParamType
=
const
float
;
using
BatchNormParamType
=
float
;
static
ScalingParamType
*
kOne
()
{
static
ScalingParamType
v
=
1.0
;
return
&
v
;
...
...
@@ -116,7 +118,8 @@ template <>
class
CudnnDataType
<
double
>
{
public:
static
const
cudnnDataType_t
type
=
CUDNN_DATA_DOUBLE
;
typedef
const
double
ScalingParamType
;
using
ScalingParamType
=
const
double
;
using
BatchNormParamType
=
double
;
static
ScalingParamType
*
kOne
()
{
static
ScalingParamType
v
=
1.0
;
return
&
v
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录