tensorflow/core/grappler/optimizers/data/map_fusion.cc
// Sets basic function parameters and copies attributes from parent and map
// node.
Sets basic function parameters and copies attributes from parent and map
node.
Sets basic function parameters and copies attributes from parent and map node .
NodeDef MakeFusedNode(const NodeDef& parent_map_node, const NodeDef& map_node,
                      const FunctionDef& fused_function,
                      MutableGraphView* graph) {
  NodeDef fused_node;
  graph_utils::SetUniqueGraphNodeName("fused_map", graph->graph(), &fused_node);
  fused_node.set_op("MapDataset");
  fused_node.add_input(parent_map_node.input(0));
  auto attr = parent_map_node.attr().at("f");
  *attr.mutable_func()->mutable_name() = fused_function.signature().name();
  (*fused_node.mutable_attr())["f"] = std::move(attr);
  graph_utils::CopyAttribute("Targuments", parent_map_node, &fused_node);
  graph_utils::CopyShapesAndTypesAttrs(map_node, &fused_node);
  auto value_or_false = [](const AttrValue* attr) {
    if (!attr) return false;
    return attr->b();
  };
  const auto* first_parallelism =
      gtl::FindOrNull(parent_map_node.attr(), "use_inter_op_parallelism");
  const auto* second_parallelism =
      gtl::FindOrNull(map_node.attr(), "use_inter_op_parallelism");
  (*fused_node.mutable_attr())["use_inter_op_parallelism"].set_b(
      value_or_false(first_parallelism) || value_or_false(second_parallelism));
  const auto* first_cardinality =
      gtl::FindOrNull(parent_map_node.attr(), "preserve_cardinality");
  const auto* second_cardinality =
      gtl::FindOrNull(map_node.attr(), "preserve_cardinality");
  (*fused_node.mutable_attr())["preserve_cardinality"].set_b(
      value_or_false(first_cardinality) && value_or_false(second_cardinality));
  graph_utils::MaybeSetFusedMetadata(parent_map_node, map_node, &fused_node);
  return fused_node;
}
NodeDef MakeFusedNode ( const NodeDef & parent_map_node , const NodeDef & map_node , const FunctionDef & fused_function , MutableGraphView * graph ) { NodeDef fused_node ; graph_utils :: SetUniqueGraphNodeName ( " " , graph -> graph ( ) , & fused_node ) ; fused_node . set_op ( " " ) ; fused_node . add_input ( parent_map_node . input ( 0 ) ) ; auto attr = parent_map_node . attr ( ) . at ( " " ) ; * attr . mutable_func ( ) -> mutable_name ( ) = fused_function . signature ( ) . name ( ) ; ( * fused_node . mutable_attr ( ) ) [ " " ] = std :: move ( attr ) ; graph_utils :: CopyAttribute ( " " , parent_map_node , & fused_node ) ; graph_utils :: CopyShapesAndTypesAttrs ( map_node , & fused_node ) ; auto value_or_false = [ ] ( const AttrValue * attr ) { if ( ! attr ) return false ; return attr -> b ( ) ; } ; const auto * first_parallelism = gtl :: FindOrNull ( parent_map_node . attr ( ) , " " ) ; const auto * second_parallelism = gtl :: FindOrNull ( map_node . attr ( ) , " " ) ; ( * fused_node . mutable_attr ( ) ) [ " " ] . set_b ( value_or_false ( first_parallelism ) || value_or_false ( second_parallelism ) ) ; const auto * first_cardinality = gtl :: FindOrNull ( parent_map_node . attr ( ) , " " ) ; const auto * second_cardinality = gtl :: FindOrNull ( map_node . attr ( ) , " " ) ; ( * fused_node . mutable_attr ( ) ) [ " " ] . set_b ( value_or_false ( first_cardinality ) && value_or_false ( second_cardinality ) ) ; graph_utils :: MaybeSetFusedMetadata ( parent_map_node , map_node , & fused_node ) ; return fused_node ; }
Sets basic function parameters and copies attributes from parent and map
node.
Sets basic function parameters and copies attributes from parent and map node .
// Some graphs cannot execute with use_inter_op_parallelism=False, so we need // to set it to true if one of the ops have it set to true.