forked from huawei/mindspore2022
fix codedex in RDR
1. check whether path is empty in IsEveryFilenameValid(). 2. do not print the string in IsStrLengthValid(), it's not safe. 3. make the constants about hash in recorder_manager.h. 4. initialize some variables.
This commit is contained in:
parent
eec1b4441d
commit
facff39ff8
|
|
@ -172,18 +172,11 @@ std::optional<std::string> Common::GetEnvConfigFile() {
|
||||||
return config_file;
|
return config_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Common::IsStrLengthValid(const std::string &str, const int &length_limit, const std::string &error_message,
|
bool Common::IsStrLengthValid(const std::string &str, const int &length_limit, const std::string &error_message) {
|
||||||
const bool &print_str) {
|
|
||||||
const int len_str = str.length();
|
const int len_str = str.length();
|
||||||
if (len_str > length_limit) {
|
if (len_str > length_limit) {
|
||||||
std::ostringstream msg;
|
MS_LOG(WARNING) << error_message << "The length is " << str.length() << ", exceeding the limit of " << length_limit
|
||||||
if (print_str) {
|
<< ".";
|
||||||
msg << error_message << "The string is " << str << ", its length is " << str.length();
|
|
||||||
} else {
|
|
||||||
msg << error_message << "The length is " << str.length();
|
|
||||||
}
|
|
||||||
msg << ", exceeding the limit of " << length_limit << ".";
|
|
||||||
MS_LOG(WARNING) << msg.str();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -191,6 +184,10 @@ bool Common::IsStrLengthValid(const std::string &str, const int &length_limit, c
|
||||||
|
|
||||||
bool Common::IsEveryFilenameValid(const std::string &path, const int &length_limit, const std::string &error_message) {
|
bool Common::IsEveryFilenameValid(const std::string &path, const int &length_limit, const std::string &error_message) {
|
||||||
int left_pos = 0;
|
int left_pos = 0;
|
||||||
|
if (path.empty()) {
|
||||||
|
MS_LOG(WARNING) << error_message << "The path is empty.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
int len_path = path.length();
|
int len_path = path.length();
|
||||||
for (int i = 0; i < len_path; i++) {
|
for (int i = 0; i < len_path; i++) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
|
|
@ -216,8 +213,7 @@ bool Common::IsEveryFilenameValid(const std::string &path, const int &length_lim
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Common::IsPathValid(const std::string &path, const int &length_limit, const std::string &error_message,
|
bool Common::IsPathValid(const std::string &path, const int &length_limit, const std::string &error_message) {
|
||||||
const bool &print_str) {
|
|
||||||
std::string err_msg = "Detail: ";
|
std::string err_msg = "Detail: ";
|
||||||
if (!error_message.empty()) {
|
if (!error_message.empty()) {
|
||||||
err_msg = error_message + " " + err_msg;
|
err_msg = error_message + " " + err_msg;
|
||||||
|
|
@ -228,7 +224,7 @@ bool Common::IsPathValid(const std::string &path, const int &length_limit, const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsStrLengthValid(path, length_limit, err_msg, print_str)) {
|
if (!IsStrLengthValid(path, length_limit, err_msg)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,8 @@ class Common {
|
||||||
static std::optional<std::string> GetRealPath(const std::string &input_path);
|
static std::optional<std::string> GetRealPath(const std::string &input_path);
|
||||||
static std::optional<std::string> GetConfigFile(const std::string &env);
|
static std::optional<std::string> GetConfigFile(const std::string &env);
|
||||||
static std::optional<std::string> GetEnvConfigFile();
|
static std::optional<std::string> GetEnvConfigFile();
|
||||||
static bool IsStrLengthValid(const std::string &str, const int &length_limit, const std::string &error_message = "",
|
static bool IsStrLengthValid(const std::string &str, const int &length_limit, const std::string &error_message = "");
|
||||||
const bool &print_str = true);
|
static bool IsPathValid(const std::string &path, const int &length_limit, const std::string &error_message = "");
|
||||||
static bool IsPathValid(const std::string &path, const int &length_limit, const std::string &error_message = "",
|
|
||||||
const bool &print_str = true);
|
|
||||||
static bool IsFilenameValid(const std::string &filename, const int &length_limit,
|
static bool IsFilenameValid(const std::string &filename, const int &length_limit,
|
||||||
const std::string &error_message = "");
|
const std::string &error_message = "");
|
||||||
static bool CreateNotExistDirs(const std::string &path);
|
static bool CreateNotExistDirs(const std::string &path);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ std::optional<std::string> GetRdrPathFromEnv() {
|
||||||
std::string err_msg = "RDR path parse from environment variable failed. Please check the settings about '" +
|
std::string err_msg = "RDR path parse from environment variable failed. Please check the settings about '" +
|
||||||
std::string(kPathEnv) + "' in environment variables.";
|
std::string(kPathEnv) + "' in environment variables.";
|
||||||
std::string path = path_char;
|
std::string path = path_char;
|
||||||
if (!Common::IsPathValid(path, maxDirectoryLength, err_msg, false)) {
|
if (!Common::IsPathValid(path, maxDirectoryLength, err_msg)) {
|
||||||
return std::string("");
|
return std::string("");
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
|
|
@ -186,7 +186,7 @@ void EnvConfigParser::ParseRdrPath(const nlohmann::json &content) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string path = content;
|
std::string path = content;
|
||||||
if (!Common::IsPathValid(path, maxDirectoryLength, err_msg, false)) {
|
if (!Common::IsPathValid(path, maxDirectoryLength, err_msg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ void GraphRecorder::Export() {
|
||||||
LocDumpMode dump_mode = LocDumpMode(dump_graph_info_.dump_mode);
|
LocDumpMode dump_mode = LocDumpMode(dump_graph_info_.dump_mode);
|
||||||
DumpIRForRDR(realpath_ir, func_graph_, dump_graph_info_.dump_full_name, dump_mode);
|
DumpIRForRDR(realpath_ir, func_graph_, dump_graph_info_.dump_full_name, dump_mode);
|
||||||
} else {
|
} else {
|
||||||
MS_LOG(WARNING) << "Unknown save graph LocDumoMode: " << dump_graph_info_.dump_mode
|
MS_LOG(WARNING) << "Unknown save graph LocDumpMode: " << dump_graph_info_.dump_mode
|
||||||
<< ", it must be in the range [0,2].";
|
<< ", it must be in the range [0,2].";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class GraphRecorder : public BaseRecorder {
|
||||||
private:
|
private:
|
||||||
FuncGraphPtr func_graph_;
|
FuncGraphPtr func_graph_;
|
||||||
std::string graph_type_;
|
std::string graph_type_;
|
||||||
DumpGraphParams dump_graph_info_;
|
DumpGraphParams dump_graph_info_{false, 0};
|
||||||
};
|
};
|
||||||
using GraphRecorderPtr = std::shared_ptr<GraphRecorder>;
|
using GraphRecorderPtr = std::shared_ptr<GraphRecorder>;
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,14 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
|
// The number is the reciprocal of the golden ratio.
|
||||||
|
const unsigned int magicConstant = 0x9e3779b9;
|
||||||
|
const unsigned int hashShiftLeft = 6;
|
||||||
|
const unsigned int hashShiftRight = 2;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void hash_combine(std::size_t *seed, const T &val) {
|
inline void hash_combine(std::size_t *seed, const T &val) {
|
||||||
// The number is the reciprocal of the golden ratio.
|
*seed ^= std::hash<T>()(val) + magicConstant + (*seed << hashShiftLeft) + (*seed >> hashShiftRight);
|
||||||
unsigned int magic_constant = 0x9e3779b9;
|
|
||||||
|
|
||||||
int shift_left = 6;
|
|
||||||
int shift_right = 2;
|
|
||||||
*seed ^= std::hash<T>()(val) + magic_constant + (*seed << shift_left) + (*seed >> shift_right);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class ExecNode {
|
||||||
uint32_t logic_id_;
|
uint32_t logic_id_;
|
||||||
uint32_t stream_id_;
|
uint32_t stream_id_;
|
||||||
std::string node_info_;
|
std::string node_info_;
|
||||||
uint32_t event_id_;
|
uint32_t event_id_{0};
|
||||||
std::vector<uint32_t> label_ids_;
|
std::vector<uint32_t> label_ids_;
|
||||||
std::vector<uint32_t> active_stream_ids_;
|
std::vector<uint32_t> active_stream_ids_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue