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 #ifndef MINDSPORE_UTILS_H 17 #define MINDSPORE_UTILS_H 18 19 #include <vector> 20 #include <string> 21 #include <unordered_map> 22 namespace mindspore { 23 24 constexpr auto csvHeaderComm = "Op Type,Op Name,Task ID,Stream ID,Timestamp,IO,Slot,Data Size,Data Type,Shape"; 25 const std::unordered_map<std::string, std::string> header_map = {{"max", "Max Value"}, 26 {"min", "Min Value"}, 27 {"avg", "Avg Value"}, 28 {"count", "Count"}, 29 {"negative zero count", "Negative Zero Count"}, 30 {"positive zero count", "Positive Zero Count"}, 31 {"nan count", "NaN Count"}, 32 {"negative inf count", "Negative Inf Count"}, 33 {"positive inf count", "Positive Inf Count"}, 34 {"zero count", "Zero Count"}, 35 {"l2norm", "L2Norm Value"}, 36 {"md5", "MD5"}}; 37 38 class CsvHeaderUtil { 39 public: GetInstance()40 static CsvHeaderUtil &GetInstance() { 41 static CsvHeaderUtil instance; 42 return instance; 43 } SetStatCsvHeader(std::vector<std::string> headers)44 void SetStatCsvHeader(std::vector<std::string> headers) { 45 csv_header.assign(csvHeaderComm); 46 for (const auto &str : headers) { 47 // JsonDumpParser guarantee headers are valid. 48 csv_header = csv_header + "," + header_map.at(str); 49 } 50 csv_header += '\n'; 51 } GetStatCsvHeader()52 std::string GetStatCsvHeader() { return csv_header; } 53 54 private: CsvHeaderUtil()55 CsvHeaderUtil() : csv_header("") {} 56 std::string csv_header; 57 }; 58 59 bool CheckStoull(uint64_t *const output_digit, const std::string &input_str); 60 61 bool CheckStoul(size_t *const output_digit, const std::string &input_str); 62 63 bool CheckStoi(int64_t *const output_digit, const std::string &input_str); 64 65 void CheckStringMatch(size_t start, size_t end, std::string *matched_str, const std::string &input_str); 66 } // namespace mindspore 67 68 #endif // MINDSPORE_UTILS_H 69