| 708 | } |
| 709 | |
| 710 | void GraphTransferer::RegisterPadNode( |
| 711 | const IRemoteFusedGraphOpsDefinitions& ops_definitions, |
| 712 | const ShapeRefiner& shape_refiner, const Node& node) { |
| 713 | static constexpr int PAD_WIDTH = 4; |
| 714 | static constexpr int PAD_HEIGHT = 2; |
| 715 | VLOG(1) << "Register generic node: " << node.name(); |
| 716 | CHECK_EQ(node_name_to_id_cache_map_.count(node.name()), 1); |
| 717 | const int id = node_name_to_id_cache_map_[node.name()]; |
| 718 | |
| 719 | // TODO(satok): Set correct data type if it's given. |
| 720 | const int op_type_id = ops_definitions.GetOpIdFor(node.type_string(), {}); |
| 721 | CHECK(op_type_id >= 0 && op_type_id < ops_definitions.GetTotalOpsCount()); |
| 722 | |
| 723 | CHECK_EQ(2, node.num_inputs()); |
| 724 | |
| 725 | GraphTransferNodeInputInfo& node_input_info = |
| 726 | *graph_transfer_info_->add_node_input_info(); |
| 727 | node_input_info.set_node_id(id); |
| 728 | |
| 729 | AddNodeInputByInputIndex(node, 0, &node_input_info); |
| 730 | |
| 731 | const Edge* edge = nullptr; |
| 732 | TF_CHECK_OK(node.input_edge(1, &edge)); |
| 733 | const Node* input_node = edge->src(); |
| 734 | CHECK_NOTNULL(input_node); |
| 735 | CHECK(input_node->IsConstant()); |
| 736 | |
| 737 | const TensorProto* tensor_proto = nullptr; |
| 738 | TF_CHECK_OK(GetNodeAttr(input_node->attrs(), "value", &tensor_proto)); |
| 739 | CHECK_NOTNULL(tensor_proto); |
| 740 | Tensor const_tensor; |
| 741 | TF_CHECK_OK(MakeTensorFromProto(*tensor_proto, &const_tensor)); |
| 742 | CHECK_EQ(2, const_tensor.shape().dims()); |
| 743 | CHECK_EQ(PAD_HEIGHT, const_tensor.shape().dim_size(1)); |
| 744 | if (const_tensor.shape().dim_size(0) == PAD_WIDTH) { |
| 745 | AddNodeInputByInputIndex(node, 1, &node_input_info); |
| 746 | } else if (const_tensor.shape().dim_size(0) < PAD_WIDTH) { |
| 747 | const int width = const_tensor.shape().dim_size(0); |
| 748 | const TensorProto* proto = nullptr; |
| 749 | TF_CHECK_OK(GetNodeAttr(input_node->attrs(), "value", &proto)); |
| 750 | Tensor const_tensor; |
| 751 | TF_CHECK_OK(MakeTensorFromProto(*proto, &const_tensor)); |
| 752 | CHECK_EQ(DT_INT32, const_tensor.dtype()); |
| 753 | // reshape tensor input to be rank 4. |
| 754 | // TODO(satok): Never assume rank is 4. |
| 755 | Tensor new_const_tensor(const_tensor.dtype(), TensorShape{4, 2}); |
| 756 | for (int i = 0; i < PAD_HEIGHT; ++i) { |
| 757 | for (int j = 0; j < PAD_WIDTH; ++j) { |
| 758 | if (j < PAD_WIDTH - width) { |
| 759 | new_const_tensor.matrix<int32>()(j, i) = 0; |
| 760 | } else { |
| 761 | new_const_tensor.matrix<int32>()(j, i) = |
| 762 | const_tensor.matrix<int32>()(j - (PAD_WIDTH - width), i); |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | const int id = RegisterConstTensor( |
nothing calls this directly
no test coverage detected