1 /** 2 * Copyright 2024 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 #ifndef MINDSPORE_ACL_DUMP_JSON_WRITER_H 18 #define MINDSPORE_ACL_DUMP_JSON_WRITER_H 19 #include <string> 20 #include <map> 21 #include <set> 22 #include <mutex> 23 #include <vector> 24 #include <memory> 25 #include "nlohmann/json.hpp" 26 #include "utils/ms_utils.h" 27 #include "include/backend/visible.h" 28 29 namespace mindspore { 30 class BACKEND_EXPORT AclDumpJsonWriter { 31 public: GetInstance()32 static AclDumpJsonWriter &GetInstance() { 33 std::call_once(instance_mutex_, []() { 34 if (instance_ == nullptr) { 35 instance_ = std::shared_ptr<AclDumpJsonWriter>(new AclDumpJsonWriter); 36 } 37 }); 38 return *instance_; 39 } Finalize()40 static void Finalize() { instance_ = nullptr; } 41 42 ~AclDumpJsonWriter() = default; 43 // Parse the json file by DumpJsonParser. 44 void Parse(); 45 // Write the parsed feilds to a new json file with acldump format. 46 bool WriteToFile(uint32_t device_id = 0, uint32_t step_id = 0, bool is_init = false, 47 nlohmann::json target_kernel_names = nlohmann::json::array()); GetAclDumpJsonPath()48 std::string GetAclDumpJsonPath() { return acl_dump_json_path_; } 49 50 private: 51 AclDumpJsonWriter() = default; 52 DISABLE_COPY_AND_ASSIGN(AclDumpJsonWriter) 53 inline static std::shared_ptr<AclDumpJsonWriter> instance_ = nullptr; 54 inline static std::once_flag instance_mutex_; 55 std::string acl_dump_json_path_ = ""; 56 std::string dump_base_path_ = ""; 57 std::string dump_mode_ = "all"; 58 nlohmann::json layer_ = nlohmann::json::array(); 59 std::string dump_scene_ = "normal"; 60 std::string dump_debug_ = "off"; 61 }; // class AclDumpJsonWriter 62 } // namespace mindspore 63 #endif // MINDSPORE_ACL_DUMP_JSON_WRITER_H 64