Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
c793540c
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看板
提交
c793540c
编写于
5月 19, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
5月 19, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1231 Assign label resource for new control sink
Merge pull request !1231 from zhoufeng/label-assign
上级
18c94950
c99f9042
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
150 addition
and
0 deletion
+150
-0
mindspore/ccsrc/device/ascend/ascend_label_assign.cc
mindspore/ccsrc/device/ascend/ascend_label_assign.cc
+88
-0
mindspore/ccsrc/device/ascend/ascend_label_assign.h
mindspore/ccsrc/device/ascend/ascend_label_assign.h
+48
-0
mindspore/ccsrc/session/ascend_session.cc
mindspore/ccsrc/session/ascend_session.cc
+9
-0
mindspore/ccsrc/session/ascend_session.h
mindspore/ccsrc/session/ascend_session.h
+1
-0
tests/ut/cpp/stub/tasksink/ascend_stream_assign_stub.cc
tests/ut/cpp/stub/tasksink/ascend_stream_assign_stub.cc
+4
-0
未找到文件。
mindspore/ccsrc/device/ascend/ascend_label_assign.cc
0 → 100644
浏览文件 @
c793540c
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <vector>
#include "device/ascend/ascend_label_assign.h"
#include "session/anf_runtime_algorithm.h"
static
constexpr
uint32_t
kLabelGotoLabelId
=
1
;
static
constexpr
uint32_t
kLabelSwitchLabelId
=
2
;
namespace
mindspore
{
namespace
device
{
namespace
ascend
{
static
void
UpdateLabelGoto
(
NotNull
<
CNodePtr
>
node
)
{
if
(
node
->
size
()
<=
kLabelGotoLabelId
)
{
MS_LOG
(
EXCEPTION
)
<<
"Node "
<<
node
->
DebugString
()
<<
" has invalid input size "
<<
node
->
size
();
}
auto
label_set
=
AnfAlgo
::
GetCNodePrimitive
(
node
->
input
(
kLabelGotoLabelId
));
MS_EXCEPTION_IF_NULL
(
label_set
);
auto
value
=
label_set
->
GetAttr
(
kAttrLabelIndex
);
MS_EXCEPTION_IF_NULL
(
value
);
uint32_t
goto_label_id
=
GetValue
<
uint32_t
>
(
value
);
AnfAlgo
::
SetNodeAttr
(
kAttrLabelIndex
,
MakeValue
<
uint32_t
>
(
goto_label_id
),
node
.
get
());
MS_LOG
(
INFO
)
<<
"Node "
<<
node
->
DebugString
()
<<
" goto label id "
<<
goto_label_id
;
}
static
void
UpdateLabelSwitch
(
NotNull
<
CNodePtr
>
node
)
{
if
(
node
->
size
()
<=
kLabelGotoLabelId
)
{
MS_LOG
(
EXCEPTION
)
<<
"Node "
<<
node
->
DebugString
()
<<
" has invalid input size "
<<
node
->
size
();
}
std
::
vector
<
uint32_t
>
label_list
;
for
(
size_t
i
=
kLabelSwitchLabelId
;
i
<
node
->
size
();
++
i
)
{
auto
input
=
node
->
input
(
i
);
if
(
!
input
->
isa
<
CNode
>
()
||
AnfAlgo
::
GetCNodeName
(
input
)
!=
kLabelSetOpName
)
{
break
;
}
auto
label_set
=
AnfAlgo
::
GetCNodePrimitive
(
input
);
MS_EXCEPTION_IF_NULL
(
label_set
);
auto
value
=
label_set
->
GetAttr
(
kAttrLabelIndex
);
MS_EXCEPTION_IF_NULL
(
value
);
uint32_t
goto_label_id
=
GetValue
<
uint32_t
>
(
value
);
label_list
.
push_back
(
goto_label_id
);
MS_LOG
(
INFO
)
<<
"Switch "
<<
node
->
DebugString
()
<<
" case "
<<
i
-
kLabelSwitchLabelId
<<
": id "
<<
goto_label_id
;
}
AnfAlgo
::
SetNodeAttr
(
kAttrLabelSwitchList
,
MakeValue
<
std
::
vector
<
uint32_t
>>
(
label_list
),
node
.
get
());
}
void
AscendLabelAssign
::
AssignLabel
(
NotNull
<
const
std
::
shared_ptr
<
session
::
KernelGraph
>
&>
graph
)
{
auto
cnode_list
=
graph
->
execution_order
();
// 1 assign label id to label_set
uint32_t
cur_label_id
=
0
;
for
(
auto
&
node
:
cnode_list
)
{
if
(
AnfAlgo
::
GetCNodeName
(
node
)
==
kLabelSetOpName
)
{
AnfAlgo
::
SetNodeAttr
(
kAttrLabelIndex
,
MakeValue
<
uint32_t
>
(
cur_label_id
),
node
);
MS_LOG
(
INFO
)
<<
"Node "
<<
node
->
DebugString
()
<<
" assign label id "
<<
cur_label_id
;
++
cur_label_id
;
}
}
// 2 update label_switch / label_goto
for
(
auto
&
node
:
cnode_list
)
{
if
(
AnfAlgo
::
GetCNodeName
(
node
)
==
kLabelGotoOpName
)
{
UpdateLabelGoto
(
NOT_NULL
(
node
));
}
if
(
AnfAlgo
::
GetCNodeName
(
node
)
==
kLabelSwitchOpName
)
{
UpdateLabelSwitch
(
NOT_NULL
(
node
));
}
}
}
}
// namespace ascend
}
// namespace device
}
// namespace mindspore
mindspore/ccsrc/device/ascend/ascend_label_assign.h
0 → 100644
浏览文件 @
c793540c
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_DEVICE_ASCEND_ASCEND_LABEL_ASSIGN_H_
#define MINDSPORE_CCSRC_DEVICE_ASCEND_ASCEND_LABEL_ASSIGN_H_
#include <memory>
#include "session/kernel_graph.h"
#include "utils/contract.h"
namespace
mindspore
{
namespace
device
{
namespace
ascend
{
class
AscendLabelAssign
{
public:
static
AscendLabelAssign
&
GetInstance
()
{
static
AscendLabelAssign
instance
;
// Guaranteed to be destroyed.
return
instance
;
}
AscendLabelAssign
(
const
AscendLabelAssign
&
)
=
delete
;
AscendLabelAssign
&
operator
=
(
const
AscendLabelAssign
&
)
=
delete
;
void
AssignLabel
(
NotNull
<
const
std
::
shared_ptr
<
session
::
KernelGraph
>
&>
graph
);
private:
AscendLabelAssign
()
=
default
;
~
AscendLabelAssign
()
=
default
;
};
}
// namespace ascend
}
// namespace device
}
// namespace mindspore
#endif // MINDSPORE_CCSRC_DEVICE_ASCEND_ASCEND_LABEL_ASSIGN_H_
mindspore/ccsrc/session/ascend_session.cc
浏览文件 @
c793540c
...
...
@@ -30,6 +30,7 @@
#include "pre_activate/ascend/ascend_backend_optimization.h"
#include "device/kernel_adjust.h"
#include "device/ascend/ascend_stream_assign.h"
#include "device/ascend/ascend_label_assign.h"
#include "predict/predict.h"
#include "session/anf_runtime_algorithm.h"
#include "ir/scalar.h"
...
...
@@ -189,6 +190,8 @@ GraphId AscendSession::CompileGraph(NotNull<FuncGraphPtr> func_graph) {
RootGraphExecutorValidate
(
graph
.
get
());
// assign stream
AssignStream
(
graph
);
// assign label
AssignLabel
(
NOT_NULL
(
graph
));
// build kernel if node is cnode
BuildKernel
(
graph
);
// alloc mem
...
...
@@ -469,6 +472,12 @@ void AscendSession::AssignStream(const std::shared_ptr<KernelGraph> &kernel_grap
MS_LOG
(
INFO
)
<<
"Finish!"
;
}
void
AscendSession
::
AssignLabel
(
NotNull
<
const
KernelGraphPtr
&>
kernel_graph
)
const
{
MS_LOG
(
INFO
)
<<
"Start!"
;
device
::
ascend
::
AscendLabelAssign
::
GetInstance
().
AssignLabel
(
kernel_graph
);
MS_LOG
(
INFO
)
<<
"Finish!"
;
}
void
AscendSession
::
BuildKernel
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
)
const
{
MS_LOG
(
INFO
)
<<
"Start!"
;
struct
timeval
start_time
,
end_time
;
...
...
mindspore/ccsrc/session/ascend_session.h
浏览文件 @
c793540c
...
...
@@ -74,6 +74,7 @@ class AscendSession : public SessionBasic {
void
AdjustKernel
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
)
const
;
void
RunOpAdjustKernel
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
)
const
;
void
AssignStream
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
)
const
;
void
AssignLabel
(
NotNull
<
const
KernelGraphPtr
&>
kernel_graph
)
const
;
void
BuildKernel
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
)
const
;
void
MemoryAlloc
(
KernelGraph
*
kernel_graph
)
const
;
void
RunOpMemoryAlloc
(
const
std
::
vector
<
tensor
::
TensorPtr
>
&
input_tensors
,
KernelGraph
*
kernel_graph
)
const
;
...
...
tests/ut/cpp/stub/tasksink/ascend_stream_assign_stub.cc
浏览文件 @
c793540c
...
...
@@ -14,12 +14,16 @@
* limitations under the License.
*/
#include "device/ascend/ascend_stream_assign.h"
#include "device/ascend/ascend_label_assign.h"
#include "device/ascend/tasksink/task_generator.h"
#include "device/kernel_adjust.h"
namespace
mindspore
{
namespace
device
{
namespace
ascend
{
void
AscendLabelAssign
::
AssignLabel
(
NotNull
<
const
std
::
shared_ptr
<
session
::
KernelGraph
>
&>
)
{}
void
AscendStreamAssign
::
AssignStreamNew
(
const
KernelGraphPtr
&
graph
)
{
return
;
}
uint32_t
AscendStreamAssign
::
GetTotalStreamNum
()
const
{
return
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录