1 /** 2 * Copyright 2019 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 #ifndef MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_TASK_TASK_BUILD_H_ 17 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_TASK_TASK_BUILD_H_ 18 19 #include <algorithm> 20 #include <map> 21 #include <memory> 22 #include <string> 23 #include <unordered_map> 24 #include <vector> 25 #include <fstream> 26 #include "runtime/device/kernel_runtime.h" 27 #include "ir/anf.h" 28 #include "backend/kernel_compiler/ascend_kernel_mod.h" 29 #include "runtime/device/ascend/ge_runtime/task_info.h" 30 31 namespace mindspore { 32 namespace device { 33 namespace ascend { 34 namespace tasksink { 35 using mindspore::kernel::Address; 36 using mindspore::kernel::AddressPtr; 37 using AddressPtrList = std::vector<mindspore::kernel::AddressPtr>; 38 using ge::model_runner::TaskInfo; 39 using TaskInfoPtr = std::shared_ptr<TaskInfo>; 40 class TaskDebugInfo { 41 public: 42 std::string op_name_; 43 std::size_t task_num_{0}; 44 uint32_t stream_id_{0}; 45 uint32_t type_{0}; 46 bool dump_flag_{false}; 47 std::vector<AddressPtr> input_addrs_; 48 std::vector<AddressPtr> output_addrs_; 49 std::vector<AddressPtr> workspace_addrs_; 50 }; 51 using TaskDebugInfoPtr = std::shared_ptr<TaskDebugInfo>; 52 53 class TaskGenerator { 54 public: 55 TaskGenerator() = default; 56 ~TaskGenerator() = default; 57 TaskGenerator(const TaskGenerator &in) = delete; 58 TaskGenerator &operator=(const TaskGenerator &in) = delete; 59 60 bool GenTasks(const std::vector<CNodePtr> &anf_node_list, std::vector<TaskInfoPtr> *task_info_list, 61 uint32_t graph_id); GetTaskDebugInfo()62 std::vector<TaskDebugInfoPtr> GetTaskDebugInfo() const { return task_debug_info_list_; } 63 static void DumpTaskInfo(const string &real_filename, const std::vector<TaskDebugInfoPtr> &task_debug_info_list); 64 65 private: 66 std::vector<TaskDebugInfoPtr> task_debug_info_list_; 67 static void LaunchAddrCleanKernel(const CNodePtr &anf_node_ptr, AddressPtrList *kernel_inputs); 68 static void LaunchAddrCleanAkgKernel(const CNodePtr &anf_node_ptr, AddressPtrList *kernel_inputs); 69 bool LaunchKernel(const CNodePtr &anf_node_ptr, uint32_t stream_id, std::vector<TaskInfoPtr> *task_info_list); 70 bool LaunchAllKernel(const std::vector<CNodePtr> &anf_node_list, std::vector<TaskInfoPtr> *task_info_list, 71 uint32_t graph_id); 72 void DumpTaskInfo(const string &real_filename); 73 static void SaveTaskDebugInfoToFile(const std::string &real_filename, 74 const std::vector<TaskDebugInfoPtr> &task_debug_info_list); 75 }; 76 } // namespace tasksink 77 } // namespace ascend 78 } // namespace device 79 } // namespace mindspore 80 81 #endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_TASK_TASK_BUILD_H_ 82