forked from mindspore-Ecosystem/mindspore
Fix code warnings in debugger
This commit is contained in:
parent
b1c95375e4
commit
badfaadc0d
|
@ -393,8 +393,8 @@ bool IsIterInRange(uint32_t iteration, const std::string &range) {
|
|||
if (low_range_str.empty() || high_range_str.empty()) {
|
||||
return false;
|
||||
}
|
||||
uint32_t low_range = std::stoul(low_range_str);
|
||||
uint32_t high_range = std::stoul(high_range_str);
|
||||
uint32_t low_range = static_cast<uint32_t>(std::stoul(low_range_str));
|
||||
uint32_t high_range = static_cast<uint32_t>(std::stoul(high_range_str));
|
||||
return (low_range <= iteration) && (iteration <= high_range);
|
||||
}
|
||||
|
||||
|
|
|
@ -567,7 +567,10 @@ void DebugServices::ReadTensorFromNpy(const std::string &tensor_name, const std:
|
|||
MS_LOG(ERROR) << "Failed to open file (In ReadTensorFromNpy) " << file_path << " Errno:" << errno;
|
||||
const int kMaxFilenameLength = 128;
|
||||
char err_info[kMaxFilenameLength];
|
||||
MS_LOG(ERROR) << " ErrInfo:" << strerror_r(errno, err_info, sizeof(err_info));
|
||||
auto ret = strerror_r(errno, err_info, sizeof(err_info));
|
||||
if (ret != nullptr) {
|
||||
MS_LOG(ERROR) << " ErrInfo:" << ret;
|
||||
}
|
||||
return;
|
||||
}
|
||||
const int substr_len = 2;
|
||||
|
@ -611,6 +614,9 @@ void DebugServices::ReadTensorFromNpy(const std::string &tensor_name, const std:
|
|||
std::size_t word_size = std::stoul(std::string(1, (*tensor_type)[1]));
|
||||
std::size_t data_len = std::accumulate(shape->begin(), shape->end(), 1, std::multiplies<uint64_t>());
|
||||
std::size_t data_size = data_len * word_size;
|
||||
if (!data_size) {
|
||||
return;
|
||||
}
|
||||
// Check memory available before loading tensor into host.
|
||||
bool has_enough_memory = true;
|
||||
if (tensor_loader_->EnableMemoryControl()) {
|
||||
|
@ -880,7 +886,7 @@ void DebugServices::AddToTensorData(const std::string &backend_name, const std::
|
|||
tensor_data->SetDeviceId(device_id);
|
||||
tensor_data->SetRootGraphId(root_graph_id);
|
||||
tensor_data->SetIsOutput(is_output);
|
||||
if (data_size) {
|
||||
if (buffer != nullptr) {
|
||||
tensor_data->SetDataPtr(buffer->data());
|
||||
} else {
|
||||
tensor_data->SetDataPtr(nullptr);
|
||||
|
@ -930,8 +936,11 @@ std::string GetTimeStampStr(std::string file_path) {
|
|||
size_t third_dot = file_name.rfind(".", second_dot - 1);
|
||||
size_t fourth_dot = file_name.rfind(".", third_dot - 1);
|
||||
size_t fifth_dot = file_name.rfind(".", fourth_dot - 1);
|
||||
std::string time_stamp = file_name.substr(fifth_dot + 1, fourth_dot - fifth_dot - 1);
|
||||
return time_stamp;
|
||||
if (fourth_dot != std::string::npos && fifth_dot != std::string::npos && fourth_dot > fifth_dot) {
|
||||
std::string time_stamp = file_name.substr(fifth_dot + 1, fourth_dot - fifth_dot - 1);
|
||||
return time_stamp;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void DebugServices::ReadDumpedTensor(std::vector<std::string> backend_name, std::vector<size_t> slot,
|
||||
|
@ -973,7 +982,7 @@ void DebugServices::ReadFileAndAddToTensor(const bool found, const std::vector<s
|
|||
const unsigned int root_graph_id, const bool &is_output, size_t slot,
|
||||
bool *no_mem_to_read, unsigned int iteration,
|
||||
std::vector<std::shared_ptr<TensorData>> *result_list) {
|
||||
std::string time_stamp;
|
||||
std::string time_stamp = "";
|
||||
std::string type_name = "";
|
||||
uint64_t data_size = 0;
|
||||
std::vector<int64_t> shape;
|
||||
|
|
|
@ -59,8 +59,8 @@ int32_t DbgServices::Initialize(const std::string net_name, const std::string du
|
|||
debug_services_->SetSyncMode(is_sync_mode);
|
||||
// Set the memory ratio used by tensor cache. Leave 50% for other debugger backend usage.
|
||||
const uint64_t kMegabytesToBytes = 1048576; // max_mem_usage will be bytes in unit in debugger backend.
|
||||
auto cache_mem_ratio = 0.5;
|
||||
const uint64_t memlimit = max_mem_usage * kMegabytesToBytes * cache_mem_ratio;
|
||||
const uint64_t ratio_inversion = 2;
|
||||
const uint64_t memlimit = max_mem_usage * kMegabytesToBytes / ratio_inversion;
|
||||
debug_services_->SetMemLimit(memlimit);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -402,7 +402,7 @@ void DebuggerProtoExporter::ExportCNodes(const FuncGraphPtr &func_graph, debugge
|
|||
}
|
||||
auto cnode = node->cast<CNodePtr>();
|
||||
if (cnode != func_graph->get_return()) {
|
||||
ExportCNode(func_graph, cnode, &apply_map, const_map_ptr, graph_proto);
|
||||
ExportCNode(func_graph, cnode, &apply_map, const_map_ptr, graph_proto, dump_location);
|
||||
} else {
|
||||
ExportFuncGraphOutput(func_graph, cnode, apply_map, const_map_ptr, graph_proto);
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ void DebuggerProtoExporter::ExportCNodes(const FuncGraphPtr &func_graph, debugge
|
|||
void DebuggerProtoExporter::ExportCNode(const FuncGraphPtr &func_graph, const CNodePtr &node,
|
||||
std::map<AnfNodePtr, size_t> *apply_map_ptr,
|
||||
std::map<AnfNodePtr, size_t> *const_map_ptr,
|
||||
debugger::GraphProto *const graph_proto) {
|
||||
debugger::GraphProto *const graph_proto, LocDebugDumpMode dump_location) {
|
||||
if (func_graph == nullptr || node == nullptr || apply_map_ptr == nullptr || const_map_ptr == nullptr ||
|
||||
graph_proto == nullptr) {
|
||||
return;
|
||||
|
@ -440,14 +440,14 @@ void DebuggerProtoExporter::ExportCNode(const FuncGraphPtr &func_graph, const CN
|
|||
std::string full_name = GetKernelNodeName(node);
|
||||
node_proto->set_full_name(full_name);
|
||||
MS_LOG(INFO) << "full_name: " << full_name;
|
||||
|
||||
std::ostringstream buffer;
|
||||
auto traces = mindspore::trace::GetSourceLineList(node);
|
||||
for (auto &trace : traces) {
|
||||
buffer << " # " << trace;
|
||||
if (dump_location == kDebugWholeStack) {
|
||||
std::ostringstream buffer;
|
||||
auto traces = mindspore::trace::GetSourceLineList(node);
|
||||
for (auto &trace : traces) {
|
||||
buffer << " # " << trace;
|
||||
}
|
||||
node_proto->set_source_address(buffer.str());
|
||||
}
|
||||
node_proto->set_source_address(buffer.str());
|
||||
|
||||
// process OP inputs
|
||||
for (size_t i = 1; i < inputs.size(); ++i) {
|
||||
debugger::InputProto *input_proto = node_proto->add_input();
|
||||
|
|
|
@ -55,7 +55,8 @@ class DebuggerProtoExporter {
|
|||
void ExportCNodes(const FuncGraphPtr &func_graph, debugger::GraphProto *const graph_proto,
|
||||
std::map<AnfNodePtr, size_t> *const_map_ptr, LocDebugDumpMode dump_location = kDebugWholeStack);
|
||||
void ExportCNode(const FuncGraphPtr &func_graph, const CNodePtr &node, std::map<AnfNodePtr, size_t> *apply_map_ptr,
|
||||
std::map<AnfNodePtr, size_t> *const_map_ptr, debugger::GraphProto *const graph_proto);
|
||||
std::map<AnfNodePtr, size_t> *const_map_ptr, debugger::GraphProto *const graph_proto,
|
||||
LocDebugDumpMode dump_location);
|
||||
void ExportFuncGraphOutput(const FuncGraphPtr &func_graph, const CNodePtr &ret_node,
|
||||
const std::map<AnfNodePtr, size_t> &apply_map, std::map<AnfNodePtr, size_t> *const_map_ptr,
|
||||
debugger::GraphProto *graph_proto);
|
||||
|
|
|
@ -132,6 +132,7 @@ def replace_minus_one(value):
|
|||
""" replace -1 with a default value """
|
||||
return value if value != -1 else UINT32_MAX
|
||||
|
||||
|
||||
def check_param_id(info_param, info_name):
|
||||
"""
|
||||
Check the type of info_param.
|
||||
|
|
Loading…
Reference in New Issue