Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
c8807749
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c8807749
编写于
6月 28, 2020
作者:
C
chujinjin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change pynative batchnorm same as graph mode
上级
012f108b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
25 addition
and
16 deletion
+25
-16
mindspore/ccsrc/device/ascend/ascend_device_address.cc
mindspore/ccsrc/device/ascend/ascend_device_address.cc
+7
-1
mindspore/ccsrc/device/ascend/ascend_device_address.h
mindspore/ccsrc/device/ascend/ascend_device_address.h
+1
-0
mindspore/ccsrc/device/device_address.h
mindspore/ccsrc/device/device_address.h
+2
-0
mindspore/ccsrc/device/kernel_runtime.cc
mindspore/ccsrc/device/kernel_runtime.cc
+4
-1
mindspore/ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
.../ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
+9
-11
mindspore/nn/layer/normalization.py
mindspore/nn/layer/normalization.py
+2
-3
未找到文件。
mindspore/ccsrc/device/ascend/ascend_device_address.cc
浏览文件 @
c8807749
...
@@ -174,7 +174,13 @@ bool AscendDeviceAddress::SyncDeviceToHostAndConvertFormat(const std::vector<int
...
@@ -174,7 +174,13 @@ bool AscendDeviceAddress::SyncDeviceToHostAndConvertFormat(const std::vector<int
if
(
format_
==
kOpFormat_FRAC_NZ
||
format_
==
kOpFormat_NDHWC
)
{
if
(
format_
==
kOpFormat_FRAC_NZ
||
format_
==
kOpFormat_NDHWC
)
{
device_shape
=
trans
::
TransShapeToDevice
(
host_shape
,
format_
);
device_shape
=
trans
::
TransShapeToDevice
(
host_shape
,
format_
);
}
else
{
}
else
{
host_shape
=
trans
::
PaddingShapeTo4d
(
host_shape
);
if
(
host_shape_
.
empty
())
{
host_shape
=
trans
::
PaddingShapeTo4d
(
host_shape
);
}
else
{
host_shape
.
clear
();
(
void
)
std
::
transform
(
host_shape_
.
begin
(),
host_shape_
.
end
(),
std
::
back_inserter
(
host_shape
),
IntToSize
);
}
device_shape
=
trans
::
TransShapeToDevice
(
host_shape
,
format_
);
device_shape
=
trans
::
TransShapeToDevice
(
host_shape
,
format_
);
}
}
if
(
type_id_
!=
type
)
{
if
(
type_id_
!=
type
)
{
...
...
mindspore/ccsrc/device/ascend/ascend_device_address.h
浏览文件 @
c8807749
...
@@ -47,6 +47,7 @@ class AscendDeviceAddress : public DeviceAddress {
...
@@ -47,6 +47,7 @@ class AscendDeviceAddress : public DeviceAddress {
bool
LoadMemToHost
(
bool
dump_mode
,
const
std
::
string
&
tensor_name
,
int
execution_order
,
const
std
::
string
&
host_fmt
,
bool
LoadMemToHost
(
bool
dump_mode
,
const
std
::
string
&
tensor_name
,
int
execution_order
,
const
std
::
string
&
host_fmt
,
const
std
::
vector
<
int
>
&
host_shape
,
TypeId
host_type
,
size_t
slot
,
Debugger
*
debugger
)
const
;
const
std
::
vector
<
int
>
&
host_shape
,
TypeId
host_type
,
size_t
slot
,
Debugger
*
debugger
)
const
;
#endif
#endif
private:
private:
bool
SyncDeviceToHostAndConvertFormat
(
const
std
::
vector
<
int
>
&
shape
,
size_t
size
,
TypeId
type
,
void
*
host_ptr
)
const
;
bool
SyncDeviceToHostAndConvertFormat
(
const
std
::
vector
<
int
>
&
shape
,
size_t
size
,
TypeId
type
,
void
*
host_ptr
)
const
;
bool
ConvertFormatAndSyncHostToDevice
(
const
std
::
vector
<
int
>
&
shape
,
size_t
size
,
TypeId
type
,
bool
ConvertFormatAndSyncHostToDevice
(
const
std
::
vector
<
int
>
&
shape
,
size_t
size
,
TypeId
type
,
...
...
mindspore/ccsrc/device/device_address.h
浏览文件 @
c8807749
...
@@ -63,6 +63,7 @@ class DeviceAddress {
...
@@ -63,6 +63,7 @@ class DeviceAddress {
size_t
GetSize
()
const
{
return
size_
;
}
size_t
GetSize
()
const
{
return
size_
;
}
std
::
string
format
()
const
{
return
format_
;
}
std
::
string
format
()
const
{
return
format_
;
}
TypeId
type_id
()
const
{
return
type_id_
;
}
TypeId
type_id
()
const
{
return
type_id_
;
}
void
set_host_shape
(
const
std
::
vector
<
int
>
&
shape
)
{
host_shape_
=
shape
;
}
virtual
void
set_status
(
DeviceAddressStatus
status
)
{}
virtual
void
set_status
(
DeviceAddressStatus
status
)
{}
virtual
DeviceAddressStatus
status
()
const
{
return
DeviceAddressStatus
::
kInDevice
;
}
virtual
DeviceAddressStatus
status
()
const
{
return
DeviceAddressStatus
::
kInDevice
;
}
virtual
DeviceAddressType
DeviceType
()
const
{
return
DeviceAddressType
::
kUnknown
;
}
virtual
DeviceAddressType
DeviceType
()
const
{
return
DeviceAddressType
::
kUnknown
;
}
...
@@ -77,6 +78,7 @@ class DeviceAddress {
...
@@ -77,6 +78,7 @@ class DeviceAddress {
string
format_
{
"DefaultFormat"
};
string
format_
{
"DefaultFormat"
};
TypeId
type_id_
{
kNumberTypeFloat16
};
TypeId
type_id_
{
kNumberTypeFloat16
};
bool
from_mem_pool_
{
false
};
bool
from_mem_pool_
{
false
};
std
::
vector
<
int
>
host_shape_
{};
friend
class
KernelRuntime
;
friend
class
KernelRuntime
;
friend
class
MemoryManager
;
friend
class
MemoryManager
;
friend
class
mindspore
::
device
::
ascend
::
tasksink
::
TaskGenerator
;
friend
class
mindspore
::
device
::
ascend
::
tasksink
::
TaskGenerator
;
...
...
mindspore/ccsrc/device/kernel_runtime.cc
浏览文件 @
c8807749
...
@@ -258,6 +258,7 @@ void KernelRuntime::RunOpAssignOutputMemory(const AnfNodePtr &kernel) {
...
@@ -258,6 +258,7 @@ void KernelRuntime::RunOpAssignOutputMemory(const AnfNodePtr &kernel) {
std
::
string
output_format
=
AnfAlgo
::
GetOutputFormat
(
kernel
,
i
);
std
::
string
output_format
=
AnfAlgo
::
GetOutputFormat
(
kernel
,
i
);
auto
output_type
=
AnfAlgo
::
GetOutputDeviceDataType
(
kernel
,
i
);
auto
output_type
=
AnfAlgo
::
GetOutputDeviceDataType
(
kernel
,
i
);
auto
device_address
=
CreateDeviceAddress
(
nullptr
,
output_sizes
[
i
],
output_format
,
output_type
);
auto
device_address
=
CreateDeviceAddress
(
nullptr
,
output_sizes
[
i
],
output_format
,
output_type
);
device_address
->
set_host_shape
(
trans
::
GetRuntimePaddingShape
(
kernel
,
i
));
MS_EXCEPTION_IF_NULL
(
device_address
);
MS_EXCEPTION_IF_NULL
(
device_address
);
auto
ret
=
mem_manager_
->
MallocMemFromMemPool
(
device_address
,
output_sizes
[
i
]);
auto
ret
=
mem_manager_
->
MallocMemFromMemPool
(
device_address
,
output_sizes
[
i
]);
if
(
!
ret
)
{
if
(
!
ret
)
{
...
@@ -506,7 +507,9 @@ void KernelRuntime::AssignNodeOutputMem(int flag, const AnfNodePtr &node, int in
...
@@ -506,7 +507,9 @@ void KernelRuntime::AssignNodeOutputMem(int flag, const AnfNodePtr &node, int in
}
}
std
::
string
output_format
=
AnfAlgo
::
GetOutputFormat
(
node
,
i
);
std
::
string
output_format
=
AnfAlgo
::
GetOutputFormat
(
node
,
i
);
auto
output_type
=
AnfAlgo
::
GetOutputDeviceDataType
(
node
,
i
);
auto
output_type
=
AnfAlgo
::
GetOutputDeviceDataType
(
node
,
i
);
AnfAlgo
::
SetOutputAddr
(
CreateDeviceAddress
(
ptr
,
output_sizes
[
i
],
output_format
,
output_type
),
i
,
node
.
get
());
auto
device_address
=
CreateDeviceAddress
(
ptr
,
output_sizes
[
i
],
output_format
,
output_type
);
device_address
->
set_host_shape
(
trans
::
GetRuntimePaddingShape
(
node
,
i
));
AnfAlgo
::
SetOutputAddr
(
device_address
,
i
,
node
.
get
());
}
}
}
}
...
...
mindspore/ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
浏览文件 @
c8807749
...
@@ -238,16 +238,11 @@ void AscendBackendIRFusionOptimization(const std::shared_ptr<session::KernelGrap
...
@@ -238,16 +238,11 @@ void AscendBackendIRFusionOptimization(const std::shared_ptr<session::KernelGrap
}
}
auto
optimizer
=
std
::
make_shared
<
GraphOptimizer
>
();
auto
optimizer
=
std
::
make_shared
<
GraphOptimizer
>
();
auto
ir_fusion_pm
=
std
::
make_shared
<
PassManager
>
(
"ir_fusion_pm"
);
auto
ir_fusion_pm
=
std
::
make_shared
<
PassManager
>
(
"ir_fusion_pm"
);
if
(
context_ptr
->
execution_mode
()
==
kPynativeMode
)
{
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
BatchNormGradSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
BnSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
LayerNormGradSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
BnGradSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
FusedBatchNormFusion
>
());
}
else
{
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
FusedBatchNormMixPrecisionFusion0
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
BatchNormGradSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
FusedBatchNormMixPrecisionFusion1
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
LayerNormGradSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
FusedBatchNormFusion
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
FusedBatchNormMixPrecisionFusion0
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
FusedBatchNormMixPrecisionFusion1
>
());
}
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
InsertPadForNMSWithMask
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
InsertPadForNMSWithMask
>
());
if
(
context_ptr
->
ir_fusion_flag
())
{
if
(
context_ptr
->
ir_fusion_flag
())
{
AddAscendBackendOptionalIRFusion
(
ir_fusion_pm
.
get
());
AddAscendBackendOptionalIRFusion
(
ir_fusion_pm
.
get
());
...
@@ -287,8 +282,11 @@ void RunOpAscendBackendIRFusionOptimization(const std::shared_ptr<session::Kerne
...
@@ -287,8 +282,11 @@ void RunOpAscendBackendIRFusionOptimization(const std::shared_ptr<session::Kerne
}
}
auto
optimizer
=
std
::
make_shared
<
GraphOptimizer
>
();
auto
optimizer
=
std
::
make_shared
<
GraphOptimizer
>
();
auto
ir_fusion_pm
=
std
::
make_shared
<
PassManager
>
(
"ir_fusion_pm"
);
auto
ir_fusion_pm
=
std
::
make_shared
<
PassManager
>
(
"ir_fusion_pm"
);
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
B
n
Split
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
B
atchNormGrad
Split
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
LayerNormGradSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
LayerNormGradSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
FusedBatchNormFusion
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
FusedBatchNormMixPrecisionFusion0
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
FusedBatchNormMixPrecisionFusion1
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
TopKSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
TopKSplit
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
AddnFission
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
AddnFission
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
InsertPadForNMSWithMask
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
InsertPadForNMSWithMask
>
());
...
...
mindspore/nn/layer/normalization.py
浏览文件 @
c8807749
...
@@ -84,14 +84,13 @@ class _BatchNorm(Cell):
...
@@ -84,14 +84,13 @@ class _BatchNorm(Cell):
self
.
dtype
=
P
.
DType
()
self
.
dtype
=
P
.
DType
()
self
.
reshape
=
P
.
Reshape
()
self
.
reshape
=
P
.
Reshape
()
self
.
is_ascend
=
context
.
get_context
(
"device_target"
)
==
"Ascend"
self
.
is_ascend
=
context
.
get_context
(
"device_target"
)
==
"Ascend"
self
.
is_graph_mode
=
context
.
get_context
(
"mode"
)
==
context
.
GRAPH_MODE
self
.
momentum
=
1.0
-
momentum
self
.
momentum
=
1.0
-
momentum
if
context
.
get_context
(
"enable_ge"
):
if
context
.
get_context
(
"enable_ge"
):
self
.
is_ge_backend
=
True
self
.
is_ge_backend
=
True
else
:
else
:
self
.
is_ge_backend
=
False
self
.
is_ge_backend
=
False
if
self
.
is_g
raph_mode
and
(
self
.
is_ge_backend
or
self
.
is_ascend
)
:
if
self
.
is_g
e_backend
or
self
.
is_ascend
:
self
.
bn_train
=
P
.
BatchNorm
(
is_training
=
True
,
self
.
bn_train
=
P
.
BatchNorm
(
is_training
=
True
,
epsilon
=
self
.
eps
)
epsilon
=
self
.
eps
)
else
:
else
:
...
@@ -153,7 +152,7 @@ class _BatchNorm(Cell):
...
@@ -153,7 +152,7 @@ class _BatchNorm(Cell):
if
self
.
is_ge_backend
and
self
.
is_global
:
if
self
.
is_ge_backend
and
self
.
is_global
:
axes
,
re_shape
=
_shape_infer
(
F
.
shape
(
x
),
self
.
num_features
)
axes
,
re_shape
=
_shape_infer
(
F
.
shape
(
x
),
self
.
num_features
)
y
=
self
.
_global_sync
(
x
,
axes
,
re_shape
)
y
=
self
.
_global_sync
(
x
,
axes
,
re_shape
)
elif
self
.
is_g
raph_mode
and
(
self
.
is_ge_backend
or
self
.
is_ascend
)
:
elif
self
.
is_g
e_backend
or
self
.
is_ascend
:
if
self
.
is_global
:
if
self
.
is_global
:
axes
,
re_shape
=
_shape_infer
(
F
.
shape
(
x
),
self
.
num_features
)
axes
,
re_shape
=
_shape_infer
(
F
.
shape
(
x
),
self
.
num_features
)
y
=
self
.
_global_sync
(
x
,
axes
,
re_shape
)
y
=
self
.
_global_sync
(
x
,
axes
,
re_shape
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录