• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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 "runtime/device/ascend/profiling/reporter/task_desc_reporter.h"
18 #include "backend/session/anf_runtime_algorithm.h"
19 #include "backend/kernel_compiler/ascend_kernel_mod.h"
20 
21 namespace mindspore {
22 namespace device {
23 namespace ascend {
ReportData()24 void TaskDescReporter::ReportData() {
25   MS_LOG(INFO) << "cnode_list.size()=" << cnode_list_.size() << " task_ids_.size()=" << task_ids_.size();
26   if (cnode_list_.size() != task_ids_.size()) {
27     MS_LOG(ERROR) << "cnode list size not equal task ids size";
28     return;
29   }
30 
31   size_t task_index = 0;
32   for (const auto &node : cnode_list_) {
33     MS_EXCEPTION_IF_NULL(node);
34     if (AnfAlgo::GetKernelType(node) != TBE_KERNEL && AnfAlgo::GetKernelType(node) != AKG_KERNEL) {
35       MS_LOG(INFO) << "Skip non tbe kernel:" << node->fullname_with_scope();
36       ++task_index;
37       continue;
38     }
39     auto kernel_mod = AnfAlgo::GetKernelMod(node);
40     auto ascend_kernel_mod = dynamic_cast<kernel::AscendKernelMod *>(kernel_mod);
41     MS_EXCEPTION_IF_NULL(ascend_kernel_mod);
42     // Check task_id and stream_id valid
43     CheckStreamTaskValid(task_index, task_index);
44     auto desc_ptr = std::make_shared<TaskDesc>(node->fullname_with_scope(), task_ids_[task_index],
45                                                ascend_kernel_mod->block_dim(), stream_ids_[task_index]);
46     prof_desc_list_.emplace_back(desc_ptr);
47     ++task_index;
48   }
49   ReportAllLine();
50 }
51 
CheckStreamTaskValid(size_t task_id,size_t stream_id) const52 void TaskDescReporter::CheckStreamTaskValid(size_t task_id, size_t stream_id) const {
53   if (task_id >= task_ids_.size() || stream_id >= stream_ids_.size()) {
54     MS_LOG(EXCEPTION) << "Index invalid. task_id:" << task_id << ", task_ids.size:" << task_ids_.size()
55                       << ", stream_id:" << stream_id << ", stream_ids.size:" << stream_ids_.size();
56   }
57 }
58 }  // namespace ascend
59 }  // namespace device
60 }  // namespace mindspore
61