|
|
|
@@ -178,7 +178,7 @@ void Debugger::CheckDatasetGraph() { |
|
|
|
is_dataset_graph_ = false; |
|
|
|
} |
|
|
|
|
|
|
|
GraphProto Debugger::GetGraphProto() { |
|
|
|
GraphProto Debugger::GetGraphProto() const { |
|
|
|
// convert kernel graph to debugger modelproto |
|
|
|
ModelProto model = GetDebuggerFuncGraphProto(graph_ptr_); |
|
|
|
return model.graph(); |
|
|
|
@@ -261,12 +261,9 @@ void Debugger::CommandLoop() { |
|
|
|
MS_LOG(INFO) << "node name: " << node.node_name(); |
|
|
|
MS_LOG(INFO) << "node type: " << node.node_type(); |
|
|
|
} |
|
|
|
WatchCondition recieved_condition = GetWatchcondition(reply); |
|
|
|
MS_LOG(INFO) << "condition: " << recieved_condition.condition(); |
|
|
|
int32_t id = GetWatchpointID(reply); |
|
|
|
MS_LOG(INFO) << "id: " << id; |
|
|
|
bool delete_ = GetWatchpointDelete(reply); |
|
|
|
MS_LOG(INFO) << "delete: " << delete_; |
|
|
|
MS_LOG(INFO) << "condition: " << GetWatchcondition(reply).condition(); |
|
|
|
MS_LOG(INFO) << "id: " << GetWatchpointID(reply); |
|
|
|
MS_LOG(INFO) << "delete: " << GetWatchpointDelete(reply); |
|
|
|
} |
|
|
|
MS_LOG(INFO) << "Setting watchpoint"; |
|
|
|
if (GetWatchpointDelete(reply)) { |
|
|
|
@@ -284,15 +281,20 @@ void Debugger::CommandLoop() { |
|
|
|
MS_LOG(INFO) << "tensor node name: " << tensor.node_name(); |
|
|
|
MS_LOG(INFO) << "tensor slot: " << tensor.slot(); |
|
|
|
MS_LOG(INFO) << "tensor finished: " << std::boolalpha << tensor.finished() << std::noboolalpha; |
|
|
|
MS_LOG(INFO) << "tensor iter: " << tensor.iter(); |
|
|
|
MS_LOG(INFO) << "tensor truncate: " << std::boolalpha << tensor.truncate() << std::noboolalpha; |
|
|
|
} |
|
|
|
} |
|
|
|
MS_LOG(INFO) << "Sending tensors"; |
|
|
|
std::list<TensorProto> tensors = LoadTensors(GetTensors(reply)); |
|
|
|
{ |
|
|
|
// print view cmd reply |
|
|
|
for (auto tensor : tensors) { |
|
|
|
MS_LOG(INFO) << "tensor node name: " << tensor.node_name(); |
|
|
|
MS_LOG(INFO) << "tensor slot: " << tensor.slot(); |
|
|
|
MS_LOG(INFO) << "tensor finished: " << std::boolalpha << tensor.finished() << std::noboolalpha; |
|
|
|
MS_LOG(INFO) << "tensor iter: " << tensor.iter(); |
|
|
|
MS_LOG(INFO) << "tensor truncate: " << std::boolalpha << tensor.truncate() << std::noboolalpha; |
|
|
|
MS_LOG(INFO) << "tensor dims: "; |
|
|
|
for (auto dim : tensor.dims()) { |
|
|
|
MS_LOG(INFO) << dim << ","; |
|
|
|
@@ -309,68 +311,6 @@ void Debugger::CommandLoop() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
DebuggerCommand Debugger::GetCommand(const EventReply &reply) { |
|
|
|
DebuggerCommand cmd = DebuggerCommand::kUnknownCMD; |
|
|
|
switch (reply.cmd_case()) { |
|
|
|
case debugger::EventReply::CmdCase::kExit: |
|
|
|
cmd = DebuggerCommand::kExitCMD; |
|
|
|
break; |
|
|
|
case debugger::EventReply::CmdCase::kRunCmd: |
|
|
|
cmd = DebuggerCommand::kRunCMD; |
|
|
|
break; |
|
|
|
case debugger::EventReply::CmdCase::kSetCmd: |
|
|
|
cmd = DebuggerCommand::kSetCMD; |
|
|
|
break; |
|
|
|
case debugger::EventReply::CmdCase::kViewCmd: |
|
|
|
cmd = DebuggerCommand::kViewCMD; |
|
|
|
break; |
|
|
|
default: |
|
|
|
MS_LOG(ERROR) << "Error: UnknownCMD"; |
|
|
|
break; |
|
|
|
} |
|
|
|
return cmd; |
|
|
|
} |
|
|
|
|
|
|
|
ProtoVector<WatchNode> Debugger::GetWatchnodes(const EventReply &reply) { |
|
|
|
if (!reply.has_set_cmd()) { |
|
|
|
MS_LOG(ERROR) << "Error: Not SetCMD, can not get WatchNodes. Returning default value: ProtoVector<WatchNode>()."; |
|
|
|
return ProtoVector<WatchNode>(); |
|
|
|
} |
|
|
|
return reply.set_cmd().watch_nodes(); |
|
|
|
} |
|
|
|
|
|
|
|
WatchCondition Debugger::GetWatchcondition(const EventReply &reply) { |
|
|
|
if (!reply.has_set_cmd() || !reply.set_cmd().has_watch_condition()) { |
|
|
|
MS_LOG(ERROR) << "Error: Can not get WatchCondition from command. Returning default value: WatchCondition()."; |
|
|
|
return WatchCondition(); |
|
|
|
} |
|
|
|
return reply.set_cmd().watch_condition(); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t Debugger::GetWatchpointID(const EventReply &reply) { |
|
|
|
if (!reply.has_set_cmd()) { |
|
|
|
MS_LOG(ERROR) << "Error: Not SetCMD, can not get Watchpoint ID. Returning default value: 0."; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
return reply.set_cmd().id(); |
|
|
|
} |
|
|
|
|
|
|
|
bool Debugger::GetWatchpointDelete(const EventReply &reply) { |
|
|
|
if (!reply.has_set_cmd()) { |
|
|
|
MS_LOG(ERROR) << "Error: Not SetCMD, can not get Watchpoint delete flag. Returning default value: false."; |
|
|
|
return false; |
|
|
|
} |
|
|
|
return reply.set_cmd().delete_(); |
|
|
|
} |
|
|
|
|
|
|
|
ProtoVector<TensorProto> Debugger::GetTensors(const EventReply &reply) { |
|
|
|
if (!reply.has_view_cmd()) { |
|
|
|
MS_LOG(ERROR) << "Error: Not ViewCMD, can not get Tensors. Returning default value: ProtoVector<TensorProto>()."; |
|
|
|
return ProtoVector<TensorProto>(); |
|
|
|
} |
|
|
|
return reply.view_cmd().tensors(); |
|
|
|
} |
|
|
|
|
|
|
|
void Debugger::SetWatchpoint(const ProtoVector<WatchNode> &nodes, const WatchCondition &condition, const int32_t id) { |
|
|
|
std::vector<std::tuple<std::string, bool>> check_node_list; |
|
|
|
std::transform(nodes.begin(), nodes.end(), std::back_inserter(check_node_list), |
|
|
|
@@ -383,7 +323,7 @@ void Debugger::SetWatchpoint(const ProtoVector<WatchNode> &nodes, const WatchCon |
|
|
|
|
|
|
|
void Debugger::RemoveWatchpoint(const int32_t id) { debug_services_->remove_watchpoint(id); } |
|
|
|
|
|
|
|
std::list<TensorProto> Debugger::LoadTensors(const ProtoVector<TensorProto> &tensors) { |
|
|
|
std::list<TensorProto> Debugger::LoadTensors(const ProtoVector<TensorProto> &tensors) const { |
|
|
|
std::vector<std::string> name; |
|
|
|
std::vector<std::string> ret_name; |
|
|
|
std::vector<char *> data_ptr; |
|
|
|
@@ -391,38 +331,42 @@ std::list<TensorProto> Debugger::LoadTensors(const ProtoVector<TensorProto> &ten |
|
|
|
std::vector<TypePtr> dtype; |
|
|
|
std::vector<std::vector<int>> shape; |
|
|
|
|
|
|
|
std::transform(tensors.begin(), tensors.end(), std::back_inserter(name), |
|
|
|
[](TensorProto tensor) -> std::string { return tensor.node_name() + ":" + tensor.slot(); }); |
|
|
|
std::transform(tensors.begin(), tensors.end(), std::back_inserter(name), GetTensorFullName); |
|
|
|
|
|
|
|
// ret_name will contain tensor names that are found in TensorLoader |
|
|
|
// items in ret_name will be in the same order with tensors if found |
|
|
|
debug_services_->read_nodes_tensors(name, &ret_name, &data_ptr, &data_size, &dtype, &shape); |
|
|
|
|
|
|
|
std::list<TensorProto> tensor_list; |
|
|
|
unsigned int result_index = 0; |
|
|
|
TensorProto tensor_item; |
|
|
|
|
|
|
|
for (auto tensor : tensors) { |
|
|
|
TensorProto tensor_item; |
|
|
|
tensor_item.set_node_name(tensor.node_name()); |
|
|
|
tensor_item.set_slot(tensor.slot()); |
|
|
|
tensor_item.set_iter(tensor.iter()); |
|
|
|
tensor_item.set_truncate(tensor.truncate()); |
|
|
|
tensor_item.clear_tensor_content(); |
|
|
|
tensor_item.clear_data_type(); |
|
|
|
tensor_item.clear_dims(); |
|
|
|
// always set finished to true before big tensor splitting is supported |
|
|
|
tensor_item.set_finished(true); |
|
|
|
|
|
|
|
// return empty tensor if didn't find the requested tensor |
|
|
|
if (result_index >= ret_name.size() || ret_name[result_index] != tensor.node_name() + ":" + tensor.slot()) { |
|
|
|
if (result_index >= ret_name.size() || ret_name[result_index] != GetTensorFullName(tensor)) { |
|
|
|
tensor_list.push_back(tensor_item); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
tensor_item.set_tensor_content(data_ptr[result_index], data_size[result_index]); |
|
|
|
tensor_item.set_data_type(GetDebuggerNumberDataType(dtype[result_index])); |
|
|
|
tensor_item.clear_dims(); |
|
|
|
for (auto &elem : shape[result_index]) { |
|
|
|
tensor_item.add_dims(elem); |
|
|
|
} |
|
|
|
|
|
|
|
// add tensor to result list and increment result_index to check next item in ret_name |
|
|
|
tensor_list.push_back(tensor_item); |
|
|
|
|
|
|
|
result_index++; |
|
|
|
} |
|
|
|
|
|
|
|
return tensor_list; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -432,7 +376,7 @@ void Debugger::Exit() { |
|
|
|
std::exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
|
|
|
|
std::list<WatchpointHit> Debugger::CheckWatchpoints() { |
|
|
|
std::list<WatchpointHit> Debugger::CheckWatchpoints() const { |
|
|
|
std::vector<std::string> name; |
|
|
|
std::vector<std::string> slot; |
|
|
|
std::vector<char *> data_ptr; |
|
|
|
@@ -442,31 +386,23 @@ std::list<WatchpointHit> Debugger::CheckWatchpoints() { |
|
|
|
|
|
|
|
debug_services_->check_watchpoints(&name, &slot, &data_ptr, &data_size, &condition, &watchpoint_id); |
|
|
|
|
|
|
|
std::list<WatchpointHit> points; |
|
|
|
|
|
|
|
std::list<WatchpointHit> hits; |
|
|
|
for (unsigned int i = 0; i < name.size(); i++) { |
|
|
|
TensorProto *tensor_item; |
|
|
|
tensor_item = new TensorProto(); |
|
|
|
WatchpointHit hit; |
|
|
|
hit.set_id(watchpoint_id[i]); |
|
|
|
|
|
|
|
// here TensorProto act as a tensor indicator, not sending tensor content |
|
|
|
TensorProto *tensor_item = hit.mutable_tensor(); |
|
|
|
tensor_item->set_node_name(name[i]); |
|
|
|
tensor_item->set_slot(slot[i]); |
|
|
|
tensor_item->set_tensor_content(data_ptr[i], data_size[i]); |
|
|
|
|
|
|
|
// finished in TensorProto will always be true before we implement big tensor splitting |
|
|
|
tensor_item->set_finished(true); |
|
|
|
|
|
|
|
WatchCondition *condition_item; |
|
|
|
condition_item = new WatchCondition(); |
|
|
|
WatchCondition *condition_item = hit.mutable_watch_condition(); |
|
|
|
condition_item->set_condition(debugger::WatchCondition_Condition(condition[i])); |
|
|
|
|
|
|
|
WatchpointHit point; |
|
|
|
point.set_allocated_tensor(tensor_item); |
|
|
|
point.set_allocated_watch_condition(condition_item); |
|
|
|
point.set_id(watchpoint_id[i]); |
|
|
|
|
|
|
|
points.push_back(point); |
|
|
|
hits.push_back(hit); |
|
|
|
} |
|
|
|
|
|
|
|
return points; |
|
|
|
return hits; |
|
|
|
} |
|
|
|
|
|
|
|
void Debugger::SendWatchpointsAndSuspend(const std::list<WatchpointHit> &points) { |
|
|
|
@@ -481,8 +417,81 @@ void Debugger::SendWatchpointsAndSuspend(const std::list<WatchpointHit> &points) |
|
|
|
CommandLoop(); |
|
|
|
} |
|
|
|
|
|
|
|
DebugServices *Debugger::get_debug_services() { return debug_services_.get(); } |
|
|
|
DebugServices *Debugger::debug_services() const { return debug_services_.get(); } |
|
|
|
|
|
|
|
bool Debugger::debugger_enabled() const { return debugger_enabled_; } |
|
|
|
|
|
|
|
DebuggerCommand GetCommand(const EventReply &reply) { |
|
|
|
DebuggerCommand cmd = DebuggerCommand::kUnknownCMD; |
|
|
|
switch (reply.cmd_case()) { |
|
|
|
case debugger::EventReply::CmdCase::kExit: |
|
|
|
cmd = DebuggerCommand::kExitCMD; |
|
|
|
break; |
|
|
|
case debugger::EventReply::CmdCase::kRunCmd: |
|
|
|
cmd = DebuggerCommand::kRunCMD; |
|
|
|
break; |
|
|
|
case debugger::EventReply::CmdCase::kSetCmd: |
|
|
|
cmd = DebuggerCommand::kSetCMD; |
|
|
|
break; |
|
|
|
case debugger::EventReply::CmdCase::kViewCmd: |
|
|
|
cmd = DebuggerCommand::kViewCMD; |
|
|
|
break; |
|
|
|
default: |
|
|
|
MS_LOG(ERROR) << "Error: UnknownCMD"; |
|
|
|
break; |
|
|
|
} |
|
|
|
return cmd; |
|
|
|
} |
|
|
|
|
|
|
|
ProtoVector<WatchNode> GetWatchnodes(const EventReply &reply) { |
|
|
|
if (!reply.has_set_cmd()) { |
|
|
|
MS_LOG(ERROR) << "Error: Not SetCMD, can not get WatchNodes. Returning default value: ProtoVector<WatchNode>()."; |
|
|
|
return ProtoVector<WatchNode>(); |
|
|
|
} |
|
|
|
return reply.set_cmd().watch_nodes(); |
|
|
|
} |
|
|
|
|
|
|
|
WatchCondition GetWatchcondition(const EventReply &reply) { |
|
|
|
if (!reply.has_set_cmd() || !reply.set_cmd().has_watch_condition()) { |
|
|
|
MS_LOG(ERROR) << "Error: Can not get WatchCondition from command. Returning default value: WatchCondition()."; |
|
|
|
return WatchCondition(); |
|
|
|
} |
|
|
|
return reply.set_cmd().watch_condition(); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t GetWatchpointID(const EventReply &reply) { |
|
|
|
if (!reply.has_set_cmd()) { |
|
|
|
MS_LOG(ERROR) << "Error: Not SetCMD, can not get Watchpoint ID. Returning default value: 0."; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
return reply.set_cmd().id(); |
|
|
|
} |
|
|
|
|
|
|
|
bool Debugger::debugger_enabled() { return debugger_enabled_; } |
|
|
|
bool GetWatchpointDelete(const EventReply &reply) { |
|
|
|
if (!reply.has_set_cmd()) { |
|
|
|
MS_LOG(ERROR) << "Error: Not SetCMD, can not get Watchpoint delete flag. Returning default value: false."; |
|
|
|
return false; |
|
|
|
} |
|
|
|
return reply.set_cmd().delete_(); |
|
|
|
} |
|
|
|
|
|
|
|
ProtoVector<TensorProto> GetTensors(const EventReply &reply) { |
|
|
|
if (!reply.has_view_cmd()) { |
|
|
|
MS_LOG(ERROR) << "Error: Not ViewCMD, can not get Tensors. Returning default value: ProtoVector<TensorProto>()."; |
|
|
|
return ProtoVector<TensorProto>(); |
|
|
|
} |
|
|
|
return reply.view_cmd().tensors(); |
|
|
|
} |
|
|
|
|
|
|
|
std::string GetTensorFullName(const TensorProto &tensor) { |
|
|
|
string node_name = tensor.node_name(); |
|
|
|
if (tensor.truncate()) { |
|
|
|
// scopes in node name are seperated by '/' |
|
|
|
// use the name without scope if truncate is true |
|
|
|
std::size_t found = node_name.find_last_of("/"); |
|
|
|
node_name = node_name.substr(found + 1); |
|
|
|
} |
|
|
|
return node_name + ":" + tensor.slot() + (tensor.iter() == "" ? "" : ":" + tensor.iter()); |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace mindspore |