1 /** 2 * Copyright 2023 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_PROFILING_PROFILING_FRAMEWORK_DATA_H_ 17 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_PROFILING_PROFILING_FRAMEWORK_DATA_H_ 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 #include <set> 24 #include <unordered_map> 25 #include <utility> 26 #include "kernel/kernel.h" 27 #include "common/debug/profiler/profiling_data_dumper.h" 28 #include "include/common/profiler.h" 29 30 namespace mindspore { 31 namespace profiler { 32 namespace ascend { 33 using mindspore::runtime::kProfilerEventString; 34 using mindspore::runtime::kProfilerModuleString; 35 using mindspore::runtime::kProfilerStageString; 36 using mindspore::runtime::ProfilerData; 37 38 enum class COMMON_EXPORT OpRangeDataType { 39 OP_RANGE_DATA = 1, 40 IS_ASYNC = 2, 41 NAME = 3, 42 INPUT_DTYPES = 4, 43 INPUT_SHAPE = 5, 44 STACK = 6, 45 MODULE_HIERARCHY = 7, 46 EXTRA_ARGS = 8, 47 RESERVED = 30, 48 }; 49 50 struct COMMON_EXPORT OpRangeData : BaseReportData { 51 int64_t start_ns{0}; 52 int64_t end_ns{0}; 53 int64_t sequence_number{0}; 54 uint64_t process_id{0}; 55 uint64_t start_thread_id{0}; 56 uint64_t end_thread_id{0}; 57 uint64_t forward_thread_id{0}; 58 bool is_async{false}; 59 std::string name; 60 std::vector<std::string> input_dtypes; 61 std::vector<std::vector<int64_t>> input_shapes; 62 std::vector<std::string> stack; 63 std::vector<std::string> module_hierarchy; 64 uint64_t flow_id{0}; 65 uint64_t step{0}; 66 // std::unordered_map<std::string, c10::IValue> extra_args; OpRangeDataOpRangeData67 OpRangeData(int64_t start_ns, int64_t end_ns, int64_t sequence_number, uint64_t process_id, uint64_t start_thread_id, 68 uint64_t end_thread_id, uint64_t forward_thread_id, bool is_async, std::string name, 69 std::vector<std::string> stack, uint64_t flow_id, int32_t device_id, uint64_t step) 70 : BaseReportData(device_id, "op_range_" + std::to_string(device_id)), 71 start_ns(start_ns), 72 end_ns(end_ns), 73 sequence_number(sequence_number), 74 process_id(process_id), 75 start_thread_id(start_thread_id), 76 end_thread_id(end_thread_id), 77 forward_thread_id(forward_thread_id), 78 is_async(is_async), 79 name(std::move(name)), 80 stack(std::move(stack)), 81 flow_id(flow_id), 82 step(step) {} 83 std::vector<uint8_t> encode(); 84 void preprocess(); 85 }; 86 87 class COMMON_EXPORT ProfilingFrameworkData { 88 public: 89 static void RecordHostProfile(std::shared_ptr<ProfilerData> data, uint64_t step = 0); 90 91 inline static std::map<std::string, uint64_t> kernel_launch_begin_; 92 inline static int32_t Device_Id = 0; 93 inline static bool added = false; 94 }; 95 } // namespace ascend 96 } // namespace profiler 97 } // namespace mindspore 98 #endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_PROFILING_PROFILING_FRAMEWORK_DATA_H_ 99