Skip to content

Commit

Permalink
Handles the case where a kernel does not output anything yet it
Browse files Browse the repository at this point in the history
promises to.
Change: 112290467
  • Loading branch information
A. Unique TensorFlower authored and keveman committed Jan 16, 2016
1 parent d3d3e33 commit 64c9d61
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
36 changes: 35 additions & 1 deletion tensorflow/core/common_runtime/direct_session_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ limitations under the License.
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/testlib.h"
#include "tensorflow/core/kernels/ops_util.h"
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow/core/public/session_options.h"
Expand Down Expand Up @@ -361,6 +362,39 @@ TEST(DirectSessionTest, MultipleFeedTest) {
ASSERT_EQ(22.0, outputs[1].flat<float>()(0));
}

} // namespace
REGISTER_OP("Darth")
.Input("x: float")
.Output("y: float")
.Doc(R"doc(
Darth promises one return value.
x: float
y: float
)doc");

// The DarthOp kernel violates its promise to return one-value.
class DarthOp : public OpKernel {
public:
explicit DarthOp(OpKernelConstruction* ctx) : OpKernel(ctx) {}
void Compute(OpKernelContext* ctx) override {}
};
REGISTER_KERNEL_BUILDER(Name("Darth").Device(DEVICE_CPU), DarthOp);

TEST(DirectSessionTest, DarthKernel) {
Graph g(OpRegistry::Global());
Tensor vx(DT_FLOAT, TensorShape({}));
vx.scalar<float>()() = 1.0;
Node* x = test::graph::Constant(&g, vx);
Node* y = test::graph::Unary(&g, "Darth", x);
GraphDef def;
test::graph::ToGraphDef(&g, &def);
auto sess = CreateSession();
ASSERT_OK(sess->Create(def));
std::vector<Tensor> outputs;
auto s = sess->Run({}, {y->name() + ":0"}, {}, &outputs);
EXPECT_TRUE(errors::IsInternal(s));
delete sess;
}

} // namespace
} // namespace tensorflow
9 changes: 6 additions & 3 deletions tensorflow/core/common_runtime/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ limitations under the License.
#include "tensorflow/core/util/tensor_slice_reader_cache.h"

namespace tensorflow {

namespace {

// 1-D, 0 element tensor.
Expand Down Expand Up @@ -1070,8 +1069,12 @@ Status ExecutorState::ProcessOutputs(const NodeItem& item, OpKernelContext* ctx,
for (int i = 0; i < node->num_outputs(); ++i) {
TensorValue val = ctx->release_output(i);
if (*ctx->is_output_dead() || val.tensor == nullptr) {
DCHECK(IsSwitch(node) || IsRecv(node))
<< "Only Switch and Recv can generate new dead outputs.";
// Unless it's a Switch or a Recv, the node must produce a
// tensor value at i-th output.
if (!IsSwitch(node) && !IsRecv(node)) {
s.Update(errors::Internal("Missing ", i, "-th output from ",
SummarizeNodeDef(node->def())));
}
} else {
Entry* out = &((*outputs)[i]);
out->has_value = true;
Expand Down

0 comments on commit 64c9d61

Please sign in to comment.