static
| 297 | |
| 298 | // static |
| 299 | Status DebugNodeInserter::CreateCopyNode( |
| 300 | Graph* graph, const DeviceType device_type, const bool is_host_memory, |
| 301 | const string& src_node_name, const int src_output, const DataType src_dt, |
| 302 | const string& tensor_name, const std::vector<string>& debug_ops, |
| 303 | const std::vector<string>& debug_urls, Node** copy_node) { |
| 304 | const string kGatedGrpcAttributeKey = "gated_grpc"; |
| 305 | |
| 306 | NodeDef node_def; |
| 307 | const KernelDef* kdef; |
| 308 | |
| 309 | const string copy_op_name = is_host_memory ? "CopyHost" : "Copy"; |
| 310 | const string copy_node_name = GetCopyNodeName(src_node_name, src_output); |
| 311 | |
| 312 | // Cross debug_ops and debug_urls to get the list of debug ops and watches. |
| 313 | std::vector<string> debug_ops_spec; |
| 314 | for (const string& debug_op : debug_ops) { |
| 315 | for (const string& debug_url : debug_urls) { |
| 316 | string debug_op_name_proper; |
| 317 | std::unordered_map<string, string> custom_attributes; |
| 318 | TF_RETURN_IF_ERROR(ParseDebugOpName(debug_op, &debug_op_name_proper, |
| 319 | &custom_attributes)); |
| 320 | |
| 321 | bool gated_grpc_value = false; |
| 322 | if (custom_attributes.find(kGatedGrpcAttributeKey) != |
| 323 | custom_attributes.end()) { |
| 324 | TF_RETURN_IF_ERROR(ParseBoolString( |
| 325 | custom_attributes[kGatedGrpcAttributeKey], &gated_grpc_value)); |
| 326 | } |
| 327 | debug_ops_spec.push_back(strings::StrCat(debug_op_name_proper, ";", |
| 328 | debug_url, ";", |
| 329 | gated_grpc_value ? "1" : "0")); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | auto builder = NodeDefBuilder(copy_node_name, copy_op_name) |
| 334 | .Input(src_node_name, src_output, src_dt) |
| 335 | .Attr("debug_ops_spec", debug_ops_spec); |
| 336 | |
| 337 | if (!builder.Finalize(&node_def).ok()) { |
| 338 | return Status( |
| 339 | error::FAILED_PRECONDITION, |
| 340 | strings::StrCat("Failed to create node definition ", "for copy op ", |
| 341 | copy_node_name, " on watched tensor ", tensor_name)); |
| 342 | } |
| 343 | Status s = FindKernelDef(device_type, node_def, &kdef, nullptr); |
| 344 | |
| 345 | if (!s.ok()) { |
| 346 | return Status( |
| 347 | error::FAILED_PRECONDITION, |
| 348 | strings::StrCat("Failed to find kernel definition ", "for copy op ", |
| 349 | copy_node_name, " on watched tensor ", tensor_name)); |
| 350 | } |
| 351 | if (!NodeBuilder(builder).Finalize(graph, copy_node).ok()) { |
| 352 | return Status(error::FAILED_PRECONDITION, |
| 353 | strings::StrCat("Failed to create copy node ", copy_node_name, |
| 354 | " on watched tensor ", tensor_name)); |
| 355 | } |
| 356 |
nothing calls this directly
no test coverage detected