!35945 runtime performance optimize-enable record actor on demand

Merge pull request !35945 from limingqi107/new_actor_runtime
This commit is contained in:
i-robot 2022-06-16 14:11:03 +00:00 committed by Gitee
commit 9cde9cb666
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 37 additions and 56 deletions

View File

@ -296,7 +296,9 @@ void GraphScheduler::Clear(const ActorInfo &actor_info, const std::vector<Kernel
for (auto &base_actor : base_actors) {
MS_EXCEPTION_IF_NULL(base_actor);
EraseActor(base_actor->GetAID().Name());
actor_manager->Terminate(base_actor->GetAID());
if (base_actor->parent_fusion_actor_ == nullptr) {
actor_manager->Terminate(base_actor->GetAID());
}
}
}
@ -431,11 +433,24 @@ void GraphScheduler::BuildAndScheduleGlobalActor() {
(void)actor_manager->Spawn(base_actor, false);
// Create and schedule recorder actor.
auto recorder_actor = std::make_shared<RecorderActor>();
MS_EXCEPTION_IF_NULL(recorder_actor);
recorder_aid_ = &(recorder_actor->GetAID());
auto base_recorder_actor = static_cast<ActorReference>(recorder_actor);
(void)actor_manager->Spawn(base_recorder_actor, true);
bool recorder_actor_need = false;
#ifndef ENABLE_SECURITY
if (profiler::ProfilerManager::GetInstance()->GetProfilingEnableFlag()) {
recorder_actor_need = true;
}
#endif
#ifdef ENABLE_DUMP_IR
if (mindspore::RecorderManager::Instance().RdrEnable()) {
recorder_actor_need = true;
}
#endif
if (recorder_actor_need) {
auto recorder_actor = std::make_shared<RecorderActor>();
MS_EXCEPTION_IF_NULL(recorder_actor);
recorder_aid_ = &(recorder_actor->GetAID());
auto base_recorder_actor = static_cast<ActorReference>(recorder_actor);
(void)actor_manager->Spawn(base_recorder_actor, true);
}
// Create and schedule debug actor.
// debugger_actor_need is true for CPU when e2e dump is enabled and for Ascend and GPU is true when debugger or dump
@ -548,6 +563,22 @@ void GraphScheduler::Run(ActorSet *const actor_set, const std::vector<DeviceCont
SignalGuard sg(IntHandler);
#endif
// Create recorder actor in the running to support the profiler in callback scene.
#ifndef ENABLE_SECURITY
if (profiler::ProfilerManager::GetInstance()->GetProfilingEnableFlag() && (recorder_aid_ == nullptr)) {
auto recorder_actor = std::make_shared<RecorderActor>();
MS_EXCEPTION_IF_NULL(recorder_actor);
recorder_aid_ = &(recorder_actor->GetAID());
auto base_recorder_actor = static_cast<ActorReference>(recorder_actor);
auto actor_manager = ActorMgr::GetActorMgrRef();
MS_EXCEPTION_IF_NULL(actor_manager);
(void)actor_manager->Spawn(base_recorder_actor, true);
if (actor_set->loop_count_actor_ != nullptr) {
actor_set->loop_count_actor_->recorder_aid_ = recorder_aid_;
}
}
#endif
// Construct OpContext.
OpContext<DeviceTensor> op_context;
std::vector<Promise<int>> result(1);

View File

@ -1,50 +0,0 @@
# Copyright 2022 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.
import numpy as np
import pytest
import mindspore
from mindspore import context, ops, nn, Tensor
class Net(nn.Cell):
def __init__(self):
super().__init__()
self.relu = ops.ReLU()
self.add = ops.Add()
def construct(self, input_x):
output = self.relu(input_x)
for _ in range(200):
output = self.add(output, 1)
return output
@pytest.mark.level1
@pytest.mark.platform_x86_cpu
@pytest.mark.platform_x86_gpu_training
@pytest.mark.env_onecard
def test_multi_actor_fusion():
"""
Feature: Multi actor fusion.
Description: Test the net which is non concurrent, that can trigger the function of multi actor fusion.
Expectation: The value and shape of output are the expected values.
"""
context.set_context(mode=context.GRAPH_MODE)
x = Tensor(np.ones(2), mindspore.float32)
net = Net()
expect = np.array([201, 201])
for _ in range(20):
output = net(x)
assert (output.asnumpy() == expect).all()