#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/graph_def_builder.h"
+#include "tensorflow/core/graph/graph_def_builder_util.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/platform/test.h"
ops::UnaryOp("UncompilableUnary", c, builder.opts().WithName("D"));
Node* e = ops::UnaryOp("Relu", d, builder.opts().WithName("E"));
ops::UnaryOp("Relu", e, builder.opts().WithName("F"));
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
Node* b =
ops::UnaryOp("UncompilableUnary", a, builder.opts().WithName("B"));
ops::BinaryOp("MatMul", a, b, builder.opts().WithName("C"));
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
.WithAttr("value", Tensor()));
Node* b = ops::UnaryOp("Relu", a, builder.opts().WithName("B"));
ops::BinaryOp("MatMul", a, b, builder.opts().WithName("C"));
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
.WithAttr("value", Tensor(DT_COMPLEX128, TensorShape())));
Node* b = ops::UnaryOp("Neg", a, builder.opts().WithName("B"));
ops::BinaryOp("MatMul", a, b, builder.opts().WithName("C"));
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
concat_builder.Input(dim).Input({a, a}).Attr("N", 2);
builder.opts().FinalizeBuilder(&concat_builder);
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
Node* c = ops::UnaryOp("Relu", b, builder.opts().WithName("C"));
ops::UnaryOp("UncompilableFn", c, builder.opts().WithName("D"));
ops::BinaryOp("NoInlineFn", c, c, builder.opts().WithName("E"));
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph, &flib_def));
Node* c = ops::UnaryOp("Rank", b, builder.opts().WithName("C"));
Node* d = ops::UnaryOp("Size", c, builder.opts().WithName("D"));
ops::UnaryOp("Shape", d, builder.opts().WithName("E"));
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
auto clusters = GetClusters(*graph);
d_builder.Input({c, c});
builder.opts().FinalizeBuilder(&d_builder);
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
ops::BinaryOp(
"MatMul", a, b,
builder.opts().WithName("C").WithAttr(kXlaScopeAttr, "ScopeC"));
- TF_CHECK_OK(builder.ToGraph(graph.get()));
+ TF_CHECK_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
ops::BinaryOp(
"Add", b, c,
builder.opts().WithName("D").WithAttr(kXlaScopeAttr, "Scope2"));
- TF_CHECK_OK(builder.ToGraph(graph.get()));
+ TF_CHECK_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
"Relu", a,
builder.opts().WithName("B").WithAttr(kXlaScopeAttr, "ScopeB"));
ops::BinaryOp("MatMul", a, b, builder.opts().WithName("C"));
- TF_CHECK_OK(builder.ToGraph(graph.get()));
+ TF_CHECK_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
Node* c = ops::UnaryOp("ResourceOutput", b, builder.opts().WithName("C"));
Node* d = ops::UnaryOp("ResourceInput", c, builder.opts().WithName("D"));
ops::UnaryOp("Relu", d, builder.opts().WithName("E"));
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
auto clusters = GetClusters(*graph);
.WithAttr("T", DT_FLOAT)
.WithAttr("index", 0));
- TF_EXPECT_OK(builder.ToGraph(graph.get()));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get()));
}
TF_ASSERT_OK(MarkForCompilation(&graph));
"${tensorflow_source_dir}/tensorflow/core/graph/edgeset.cc"
"${tensorflow_source_dir}/tensorflow/core/graph/graph.h"
"${tensorflow_source_dir}/tensorflow/core/graph/graph.cc"
+ "${tensorflow_source_dir}/tensorflow/core/graph/graph_def_builder.h"
+ "${tensorflow_source_dir}/tensorflow/core/graph/graph_def_builder.cc"
+ "${tensorflow_source_dir}/tensorflow/core/graph/node_builder.h"
+ "${tensorflow_source_dir}/tensorflow/core/graph/node_builder.cc"
+ "${tensorflow_source_dir}/tensorflow/core/graph/tensor_id.h"
+ "${tensorflow_source_dir}/tensorflow/core/graph/tensor_id.cc"
"${tensorflow_source_dir}/tensorflow/core/graph/while_context.h"
"${tensorflow_source_dir}/tensorflow/core/graph/while_context.cc"
"${tensorflow_source_dir}/tensorflow/core/grappler/clusters/single_machine.h"
"${tensorflow_source_dir}/tensorflow/core/graph/edgeset.cc"
"${tensorflow_source_dir}/tensorflow/core/graph/graph.h"
"${tensorflow_source_dir}/tensorflow/core/graph/graph.cc"
+ "${tensorflow_source_dir}/tensorflow/core/graph/graph_def_builder.h"
+ "${tensorflow_source_dir}/tensorflow/core/graph/graph_def_builder.cc"
+ "${tensorflow_source_dir}/tensorflow/core/graph/node_builder.h"
+ "${tensorflow_source_dir}/tensorflow/core/graph/node_builder.cc"
+ "${tensorflow_source_dir}/tensorflow/core/graph/tensor_id.h"
+ "${tensorflow_source_dir}/tensorflow/core/graph/tensor_id.cc"
"${tensorflow_source_dir}/tensorflow/core/graph/while_context.h"
"${tensorflow_source_dir}/tensorflow/core/graph/while_context.cc"
"${tensorflow_source_dir}/tensorflow/core/util/*.h"
"graph/graph.h",
"graph/graph_constructor.h",
"graph/graph_def_builder.h",
+ "graph/graph_def_builder_util.h",
"graph/node_builder.h",
"graph/validate.h",
"graph/while_context.h",
"platform/variant_coding.h",
"graph/edgeset.h",
"graph/graph.h",
+ "graph/graph_def_builder.h",
+ "graph/node_builder.h",
+ "graph/tensor_id.h",
] + glob(
[
"example/**/*.h",
] + [
"graph/edgeset.cc",
"graph/graph.cc",
+ "graph/graph_def_builder.cc",
+ "graph/node_builder.cc",
+ "graph/tensor_id.cc",
"graph/while_context.h",
"graph/while_context.cc",
],
"graph/graph.h",
"graph/graph_constructor.h", # NOTE(mrry): Don't include the .cc since it depends on common_runtime.
"graph/graph_def_builder.h",
+ "graph/graph_def_builder_util.h",
"graph/graph_partition.h",
"graph/mkl_layout_pass.h",
"graph/mkl_tfconversion_pass.h",
"graph/colors.cc",
"graph/control_flow.cc",
"graph/costmodel.cc",
- "graph/graph_def_builder.cc",
"graph/graph_partition.cc",
- "graph/node_builder.cc",
"graph/optimizer_cse.cc",
"graph/subgraph.cc",
- "graph/tensor_id.cc",
"graph/validate.cc",
],
hdrs = GRAPH_HDRS,
"common_runtime/shape_refiner.h",
"framework/versions.h",
"graph/graph_constructor.cc", # Depends on common_runtime.
+ "graph/graph_def_builder_util.cc", # Depends on common_runtime.
"public/session.h",
"public/session_options.h",
"public/version.h",
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_def_builder.h"
+#include "tensorflow/core/graph/graph_def_builder_util.h"
#include "tensorflow/core/lib/core/error_codes.pb.h"
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/status_test_util.h"
// Builds the given graph, and (if successful) indexes the node
// names for use in placement, and later lookup.
Status BuildGraph(const GraphDefBuilder& builder, Graph* out_graph) {
- TF_RETURN_IF_ERROR(builder.ToGraph(out_graph));
+ TF_RETURN_IF_ERROR(GraphDefBuilderToGraph(builder, out_graph));
nodes_by_name_.clear();
for (Node* node : out_graph->nodes()) {
nodes_by_name_[node->name()] = node->id();
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
-#include "tensorflow/core/kernels/data/dataset.h"
-#include "tensorflow/core/common_runtime/device.h"
+#include "tensorflow/core/framework/dataset.h"
+
#include "tensorflow/core/graph/graph_def_builder.h"
#include "tensorflow/core/graph/node_builder.h"
MakeDataset(ctx, input, another_input, output);
}
-Allocator* IteratorContext::allocator(AllocatorAttributes attrs) {
- return params_.lib->device()->GetAllocator(attrs);
-}
-
const char GraphDatasetBase::kDatasetGraphKey[] = "_DATASET_GRAPH";
const char GraphDatasetBase::kDatasetGraphOutputNodeKey[] =
"_DATASET_GRAPH_OUTPUT_NODE";
std::shared_ptr<const FunctionLibraryDefinition> function_library = nullptr;
// The Allocator to be used to allocate the output of an iterator.
- Allocator* allocator = nullptr;
+ std::function<Allocator*(AllocatorAttributes)> allocator_getter = nullptr;
};
explicit IteratorContext(Params params) : params_(std::move(params)) {}
void set_lib(FunctionLibraryRuntime* lib) { params_.lib = lib; }
- Allocator* allocator(AllocatorAttributes attrs);
+ Allocator* allocator(AllocatorAttributes attrs) {
+ return params_.allocator_getter(attrs);
+ }
private:
Params params_;
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_def_builder.h"
+#include "tensorflow/core/graph/graph_def_builder_util.h"
#include "tensorflow/core/graph/subgraph.h"
#include "tensorflow/core/kernels/ops_util.h"
#include "tensorflow/core/lib/core/status.h"
BinaryOp("TestMul", w2, {input, 1}, b.opts().WithName("t3"));
Graph g(OpRegistry::Global());
- TF_ASSERT_OK(b.ToGraph(&g));
+ TF_ASSERT_OK(GraphDefBuilderToGraph(b, &g));
std::vector<Node*> order;
// Test reverse post order:
BinaryOp("TestMul", w1, {input, 1}, b.opts().WithName("t3"));
Graph g(OpRegistry::Global());
- TF_ASSERT_OK(b.ToGraph(&g));
+ TF_ASSERT_OK(GraphDefBuilderToGraph(b, &g));
std::vector<Node*> order;
// Test reverse post order generates expected ordering.
#include <utility>
-#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/tensor_id.h"
#include "tensorflow/core/lib/core/errors.h"
return status_;
}
-Status GraphDefBuilder::ToGraph(Graph* graph) const {
- if (status_.ok()) {
- GraphDef graph_def;
- graph_.ToGraphDef(&graph_def);
- GraphConstructorOptions opts;
- TF_RETURN_IF_ERROR(ConvertGraphDefToGraph(opts, graph_def, graph));
- }
- return status_;
-}
-
string GraphDefBuilder::Options::GetNameForOp(StringPiece op) const {
if (name_.empty()) return graph_->NewName(op);
return name_;
// successful, and if so fill *graph_def.
Status ToGraphDef(GraphDef* graph_def) const;
- // Like ToGraphDef(), but converts to a Graph (using the default
- // GraphConstructorOptions).
- // TODO(josh11b): Make this faster; right now it converts
- // Graph->GraphDef->Graph. This cleans up the graph (e.g. adds
- // edges from the source and to the sink node, resolves back edges
- // by name), and makes sure the resulting graph is valid.
- Status ToGraph(Graph* graph) const;
-
// Adds the function and gradient definitions in `fdef_lib` to this graph's op
// registry. Ignores duplicate functions, and returns a bad status if an
// imported function differs from an existing function or op with the same
#include "tensorflow/core/framework/versions.pb.h"
#include "tensorflow/core/graph/graph.h"
+#include "tensorflow/core/graph/graph_def_builder_util.h"
#include "tensorflow/core/kernels/ops_util.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/platform/test.h"
// Check version when we convert to a Graph
Graph graph(OpRegistry::Global());
- TF_EXPECT_OK(builder.ToGraph(&graph));
+ TF_EXPECT_OK(GraphDefBuilderToGraph(builder, &graph));
ASSERT_EQ(graph.versions().producer(), TF_GRAPH_DEF_VERSION);
ASSERT_EQ(graph.versions().min_consumer(), TF_GRAPH_DEF_VERSION_MIN_CONSUMER);
--- /dev/null
+/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+#include "tensorflow/core/graph/graph_def_builder_util.h"
+
+#include "tensorflow/core/graph/graph_constructor.h"
+
+namespace tensorflow {
+
+Status GraphDefBuilderToGraph(const GraphDefBuilder& builder, Graph* graph) {
+ GraphDef graph_def;
+ TF_RETURN_IF_ERROR(builder.ToGraphDef(&graph_def));
+ GraphConstructorOptions opts;
+ return ConvertGraphDefToGraph(opts, graph_def, graph);
+}
+
+} // namespace tensorflow
--- /dev/null
+/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+#ifndef TENSORFLOW_CORE_GRAPH_GRAPH_DEF_BUILDER_UTIL_H_
+#define TENSORFLOW_CORE_GRAPH_GRAPH_DEF_BUILDER_UTIL_H_
+
+#include "tensorflow/core/graph/graph_def_builder.h"
+#include "tensorflow/core/lib/core/status.h"
+
+namespace tensorflow {
+
+class Graph;
+
+// Converts the `GraphDef` being built by `builder` to a `Graph` and
+// stores it in `*graph`.
+// TODO(josh11b): Make this faster; right now it converts
+// Graph->GraphDef->Graph. This cleans up the graph (e.g. adds
+// edges from the source and to the sink node, resolves back edges
+// by name), and makes sure the resulting graph is valid.
+Status GraphDefBuilderToGraph(const GraphDefBuilder& builder, Graph* graph);
+
+} // namespace tensorflow
+
+#endif // TENSORFLOW_CORE_GRAPH_GRAPH_DEF_BUILDER_UTIL_H_
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/graph_def_builder.h"
+#include "tensorflow/core/graph/graph_def_builder_util.h"
#include "tensorflow/core/kernels/ops_util.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/status_test_util.h"
last_node = ops::SourceOp("In", b.opts().WithName(name));
}
}
- TF_CHECK_OK(b.ToGraph(&g));
+ TF_CHECK_OK(GraphDefBuilderToGraph(b, &g));
}
std::vector<string> fed;
],
)
+# TODO(mrry): Remove this empty forwarding library.
cc_library(
name = "dataset",
- srcs = ["dataset.cc"],
+ srcs = [],
hdrs = ["dataset.h"],
deps = [
"//tensorflow/core:core_cpu",
params.runner = *(ctx->runner());
params.function_library = flib_def;
params.lib = lib_;
+ DeviceBase* device = lib_->device();
+ params.allocator_getter = [device](AllocatorAttributes attrs) {
+ return device->GetAllocator(attrs);
+ };
IteratorContext iter_ctx(std::move(params));
TF_RETURN_IF_ERROR(captured_iterator->Restore(&iter_ctx, reader));
params.env = ctx->env();
params.runner = *(ctx->runner());
params.lib = ctx->function_library();
+ DeviceBase* device = ctx->function_library()->device();
+ params.allocator_getter = [device](AllocatorAttributes attrs) {
+ return device->GetAllocator(attrs);
+ };
+
IteratorContext iter_ctx(std::move(params));
std::vector<Tensor> components;
};
params.runner = *(ctx->runner());
params.function_library = iterator->function_library();
+ DeviceBase* device = ctx->function_library()->device();
+ params.allocator_getter = [device](AllocatorAttributes attrs) {
+ return device->GetAllocator(attrs);
+ };
IteratorContext iter_ctx(std::move(params));
OP_REQUIRES_OK_ASYNC(
};
params.runner = *(ctx->runner());
params.function_library = iterator->function_library();
+ DeviceBase* device = ctx->function_library()->device();
+ params.allocator_getter = [device](AllocatorAttributes attrs) {
+ return device->GetAllocator(attrs);
+ };
IteratorContext iter_ctx(std::move(params));
OP_REQUIRES_OK(ctx,