• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <string>
18 #include "include/common/profiler.h"
19 #include "runtime/pipeline/task/device_task.h"
20 #include "runtime/pipeline/pipeline.h"
21 
22 namespace mindspore {
23 namespace runtime {
24 namespace {
25 constexpr auto kProfilerNamePyboost = "pyboost";
26 }
27 
DeviceOpRunTask(std::shared_ptr<OpTaskContext> context,std::function<void (const std::shared_ptr<OpTaskContext> & context)> run_func)28 DeviceOpRunTask::DeviceOpRunTask(std::shared_ptr<OpTaskContext> context,
29                                  std::function<void(const std::shared_ptr<OpTaskContext> &context)> run_func)
30     : DeviceOpTask(std::move(context), kDeviceOpTask), run_func_(std::move(run_func)) {
31   context_->op_compiler_info()->UpdateStatus(false);
32 }
33 
~DeviceOpRunTask()34 DeviceOpRunTask::~DeviceOpRunTask() { context_->op_compiler_info()->UpdateStatus(true); }
35 
Run()36 void DeviceOpRunTask::Run() {
37   runtime::ProfilerRecorder profiler(runtime::ProfilerModule::kPynative, runtime::ProfilerEvent::kPyNativeDeviceTask,
38                                      context_->op_run_info()->base_op_run_info.op_name, false, false, task_id_);
39   Pipeline::Get().launch_stage()->Wait();
40   MS_EXCEPTION_IF_NULL(run_func_);
41   run_func_(context_);
42   run_func_ = nullptr;
43 }
44 
Run()45 void DeviceLaunchTask::Run() {
46   runtime::ProfilerRecorder profiler(runtime::ProfilerModule::kPynative, runtime::ProfilerEvent::kPyNativeLaunchTask,
47                                      kProfilerNamePyboost, false, false, task_id_);
48   if (run_func_) {
49     run_func_();
50   } else {
51     MS_LOG(EXCEPTION) << "No run function!";
52   }
53   run_func_ = nullptr;
54 }
55 
Run()56 void PyBoostDeviceTask::Run() {
57   runtime::ProfilerRecorder profiler(runtime::ProfilerModule::kPynative, runtime::ProfilerEvent::kPyNativeDeviceTask,
58                                      kProfilerNamePyboost, false, false, task_id_);
59   if (run_func_) {
60     run_func_();
61   } else {
62     MS_LOG(EXCEPTION) << "No run function!";
63   }
64   run_func_ = nullptr;
65 }
66 
Run()67 void PassthroughDeviceTask::Run() {
68   runtime::ProfilerRecorder profiler(runtime::ProfilerModule::kPynative, runtime::ProfilerEvent::kPyNativeDeviceTask,
69                                      runtime::ProfilerRecorder::kNoName, false, false, task_id_);
70   Pipeline::Get().launch_stage()->Wait();
71   run_func_();
72 }
73 }  // namespace runtime
74 }  // namespace mindspore
75