• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 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/ir/tf_op_wrapper.h"
17 
18 #include "tensorflow/core/ir/dialect.h"
19 
20 namespace mlir {
21 namespace tfg {
22 
TFOp(Operation & op)23 TFOp::TFOp(Operation &op) : op_(op) {
24   assert(isa<TFGraphDialect>(op.getDialect()));
25 }
26 
nameAttr()27 StringAttr TFOp::nameAttr() {
28   return op_.getAttrOfType<StringAttr>(getDialect()->getNameAttrIdentifier());
29 }
name()30 StringRef TFOp::name() { return nameAttr().getValue(); }
requestedDeviceAttr()31 StringAttr TFOp::requestedDeviceAttr() {
32   return op_.getAttrOfType<StringAttr>(getDialect()->getDeviceAttrIdentifier());
33 }
requestedDevice()34 StringRef TFOp::requestedDevice() { return requestedDeviceAttr().getValue(); }
assignedDeviceAttr()35 StringAttr TFOp::assignedDeviceAttr() {
36   return op_.getAttrOfType<StringAttr>(
37       getDialect()->getAssignedDeviceAttrIdentifier());
38 }
assignedDevice()39 StringRef TFOp::assignedDevice() { return assignedDeviceAttr().getValue(); }
40 
getCalledFunction(Operation * op,SymbolTable & symbol_table)41 GraphFuncOp getCalledFunction(Operation *op, SymbolTable &symbol_table) {
42   // Check if a node does indirect function call via PartitionedCallOp.
43   if (op->getName().getStringRef() == "tfg.PartitionCall" ||
44       op->getName().getStringRef() == "tfg.StatefulPartitionedCall") {
45     auto func_attr = op->getAttrOfType<FuncAttr>("f");
46     if (!func_attr) return {};
47     GraphFuncOp callee = symbol_table.lookup<GraphFuncOp>(
48         func_attr.getName().getLeafReference());
49     if (callee) return callee;
50   }
51   return symbol_table.lookup<GraphFuncOp>(op->getName().stripDialect());
52 }
53 
54 }  // namespace tfg
55 }  // namespace mlir
56