1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #include "tensorflow/core/tpu/graph_rewrite/incomplete_nodedef_builder.h"
17
18 #include "tensorflow/compiler/xla/status_macros.h"
19 #include "tensorflow/core/common_runtime/function.h"
20
21 namespace tensorflow {
22
IncompleteNodeDefBuilder(const string & name,const string & op,const NodeDebugInfo & debug)23 IncompleteNodeDefBuilder::IncompleteNodeDefBuilder(const string& name,
24 const string& op,
25 const NodeDebugInfo& debug) {
26 nodedef_.set_name(name);
27 nodedef_.set_op(op);
28 MergeDebugInfo(debug, &nodedef_);
29 }
30
AddAttr(const string & attr,const DataType & type)31 IncompleteNodeDefBuilder& IncompleteNodeDefBuilder::AddAttr(
32 const string& attr, const DataType& type) {
33 AddNodeAttr(attr, type, &nodedef_);
34 return *this;
35 }
36
AddAttr(const string & attr,int val)37 IncompleteNodeDefBuilder& IncompleteNodeDefBuilder::AddAttr(const string& attr,
38 int val) {
39 AddNodeAttr(attr, val, &nodedef_);
40 return *this;
41 }
42
Device(const string & device)43 IncompleteNodeDefBuilder& IncompleteNodeDefBuilder::Device(
44 const string& device) {
45 nodedef_.set_device(device);
46 return *this;
47 }
48
Build(Graph * graph,Node ** n)49 Status IncompleteNodeDefBuilder::Build(Graph* graph, Node** n) {
50 Status status;
51 *n = graph->AddNode(nodedef_, &status);
52 return status;
53 }
54
Identity(const string & name,const DataType & type,const NodeDebugInfo & debug)55 IncompleteNodeDefBuilder IncompleteNodeDefBuilder::Identity(
56 const string& name, const DataType& type, const NodeDebugInfo& debug) {
57 return IncompleteNodeDefBuilder(name, "Identity", debug).AddAttr("T", type);
58 }
59
Merge(const string & name,const DataType & type,const NodeDebugInfo & debug,int n)60 IncompleteNodeDefBuilder IncompleteNodeDefBuilder::Merge(
61 const string& name, const DataType& type, const NodeDebugInfo& debug,
62 int n) {
63 return IncompleteNodeDefBuilder(name, "Merge", debug)
64 .AddAttr("T", type)
65 .AddAttr("N", n);
66 }
67
Switch(const string & name,const DataType & type,const NodeDebugInfo & debug)68 IncompleteNodeDefBuilder IncompleteNodeDefBuilder::Switch(
69 const string& name, const DataType& type, const NodeDebugInfo& debug) {
70 return IncompleteNodeDefBuilder(name, "Switch", debug).AddAttr("T", type);
71 }
72
73 } // namespace tensorflow
74