From 8f6cb22c675b5c0b553334a8f04daef462905d69 Mon Sep 17 00:00:00 2001 From: Jonathan Hseu Date: Wed, 16 Nov 2016 14:11:44 -0800 Subject: [PATCH] Rename TF_Port to TF_Output and add a TF_Input type. Change: 139377074 --- RELEASE.md | 1 + tensorflow/c/c_api.cc | 73 +++++++++--------- tensorflow/c/c_api.h | 74 ++++++++++--------- tensorflow/c/c_api_test.cc | 51 ++++++------- .../g3doc/how_tos/language_bindings/index.md | 8 +- tensorflow/go/graph.go | 2 +- tensorflow/go/operation.go | 4 +- tensorflow/go/session.go | 8 +- 8 files changed, 116 insertions(+), 105 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 7dc78be02d6102..d74053760b6f00 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -13,6 +13,7 @@ BUS_ANY was used. What was previously `TF_Session` has been renamed to `TF_DeprecatedSession`. * Renamed Tensor to Output in the Python API. Tensor will be an alias for Output until TensorFlow 2.0 is released. +* Renamed TF_Port to TF_Output in the C API. # Release 0.11.0 diff --git a/tensorflow/c/c_api.cc b/tensorflow/c/c_api.cc index cf524c8bc9ee56..17d72835a0f793 100644 --- a/tensorflow/c/c_api.cc +++ b/tensorflow/c/c_api.cc @@ -769,8 +769,9 @@ TF_Operation* ToOperation(Node* node) { return static_cast(static_cast(node)); } -tensorflow::string PortName(const TF_Port& port) { - return tensorflow::strings::StrCat(port.oper->node.name(), ":", port.index); +tensorflow::string OutputName(const TF_Output& output) { + return tensorflow::strings::StrCat(output.oper->node.name(), ":", + output.index); } const tensorflow::AttrValue* GetAttrValue(TF_Operation* oper, @@ -789,9 +790,10 @@ const tensorflow::AttrValue* GetAttrValue(TF_Operation* oper, // Shape functions ----------------------------------------------------------- -void TF_GraphSetTensorShape(TF_Graph* graph, TF_Port port, const int64_t* dims, - const int num_dims, TF_Status* status) { - Node* node = &port.oper->node; +void TF_GraphSetTensorShape(TF_Graph* graph, TF_Output output, + const int64_t* dims, const int num_dims, + TF_Status* status) { + Node* node = &output.oper->node; mutex_lock l(graph->mu); // Set the shape. @@ -809,11 +811,12 @@ void TF_GraphSetTensorShape(TF_Graph* graph, TF_Port port, const int64_t* dims, } tensorflow::shape_inference::ShapeHandle new_shape = ic->MakeShape(dim_vec); - status->status = graph->refiner.SetShape(node, port.index, new_shape); + status->status = graph->refiner.SetShape(node, output.index, new_shape); } -int TF_GraphGetTensorNumDims(TF_Graph* graph, TF_Port port, TF_Status* status) { - Node* node = &port.oper->node; +int TF_GraphGetTensorNumDims(TF_Graph* graph, TF_Output output, + TF_Status* status) { + Node* node = &output.oper->node; mutex_lock l(graph->mu); tensorflow::shape_inference::InferenceContext* ic = @@ -824,7 +827,7 @@ int TF_GraphGetTensorNumDims(TF_Graph* graph, TF_Port port, TF_Status* status) { return -1; } - tensorflow::shape_inference::ShapeHandle shape = ic->output(port.index); + tensorflow::shape_inference::ShapeHandle shape = ic->output(output.index); // Unknown rank means the number of dimensions is -1. if (!ic->RankKnown(shape)) { @@ -834,9 +837,9 @@ int TF_GraphGetTensorNumDims(TF_Graph* graph, TF_Port port, TF_Status* status) { return ic->Rank(shape); } -void TF_GraphGetTensorShape(TF_Graph* graph, TF_Port port, int64_t* dims, +void TF_GraphGetTensorShape(TF_Graph* graph, TF_Output output, int64_t* dims, int num_dims, TF_Status* status) { - Node* node = &port.oper->node; + Node* node = &output.oper->node; mutex_lock l(graph->mu); tensorflow::shape_inference::InferenceContext* ic = @@ -847,7 +850,7 @@ void TF_GraphGetTensorShape(TF_Graph* graph, TF_Port port, int64_t* dims, return; } - tensorflow::shape_inference::ShapeHandle shape = ic->output(port.index); + tensorflow::shape_inference::ShapeHandle shape = ic->output(output.index); int rank = -1; if (ic->RankKnown(shape)) { @@ -891,11 +894,11 @@ void TF_SetDevice(TF_OperationDescription* desc, const char* device) { desc->node_builder.Device(device); } -void TF_AddInput(TF_OperationDescription* desc, TF_Port input) { +void TF_AddInput(TF_OperationDescription* desc, TF_Output input) { desc->node_builder.Input(&input.oper->node, input.index); } -void TF_AddInputList(TF_OperationDescription* desc, const TF_Port* inputs, +void TF_AddInputList(TF_OperationDescription* desc, const TF_Output* inputs, int num_inputs) { std::vector input_list; input_list.reserve(num_inputs); @@ -1165,7 +1168,7 @@ int TF_OperationNumOutputs(TF_Operation* oper) { return oper->node.num_outputs(); } -TF_DataType TF_OperationOutputType(TF_Port oper_out) { +TF_DataType TF_OperationOutputType(TF_Output oper_out) { return static_cast( oper_out.oper->node.output_type(oper_out.index)); } @@ -1188,7 +1191,7 @@ int TF_OperationNumInputs(TF_Operation* oper) { return oper->node.num_inputs(); } -TF_DataType TF_OperationInputType(TF_Port oper_in) { +TF_DataType TF_OperationInputType(TF_Input oper_in) { return static_cast(oper_in.oper->node.input_type(oper_in.index)); } @@ -1206,7 +1209,7 @@ int TF_OperationInputListLength(TF_Operation* oper, const char* arg_name, return iter->second.second - iter->second.first; } -TF_Port TF_OperationInput(TF_Port oper_in) { +TF_Output TF_OperationInput(TF_Input oper_in) { const tensorflow::Edge* edge; Status s = oper_in.oper->node.input_edge(oper_in.index, &edge); if (!s.ok()) { @@ -1216,7 +1219,7 @@ TF_Port TF_OperationInput(TF_Port oper_in) { return {ToOperation(edge->src()), edge->src_output()}; } -int TF_OperationOutputNumConsumers(TF_Port oper_out) { +int TF_OperationOutputNumConsumers(TF_Output oper_out) { int count = 0; for (const auto* edge : oper_out.oper->node.out_edges()) { if (edge->src_output() == oper_out.index) { @@ -1226,7 +1229,7 @@ int TF_OperationOutputNumConsumers(TF_Port oper_out) { return count; } -int TF_OperationOutputConsumers(TF_Port oper_out, TF_Port* consumers, +int TF_OperationOutputConsumers(TF_Output oper_out, TF_Input* consumers, int max_consumers) { int count = 0; for (const auto* edge : oper_out.oper->node.out_edges()) { @@ -1742,8 +1745,8 @@ static bool ExtendSessionGraphHelper(TF_Session* session, TF_Status* status) { } void TF_SessionRun(TF_Session* session, const TF_Buffer* run_options, - const TF_Port* inputs, TF_Tensor* const* input_values, - int ninputs, const TF_Port* outputs, + const TF_Output* inputs, TF_Tensor* const* input_values, + int ninputs, const TF_Output* outputs, TF_Tensor** output_values, int noutputs, const TF_Operation* const* target_opers, int ntargets, TF_Buffer* run_metadata, TF_Status* status) { @@ -1756,17 +1759,17 @@ void TF_SessionRun(TF_Session* session, const TF_Buffer* run_options, TF_Run_Setup(noutputs, output_values, status); - // Convert from TF_Port and TF_Tensor to a string and Tensor. + // Convert from TF_Output and TF_Tensor to a string and Tensor. std::vector> input_pairs(ninputs); if (!TF_Run_Inputs(input_values, &input_pairs, status)) return; for (int i = 0; i < ninputs; ++i) { - input_pairs[i].first = PortName(inputs[i]); + input_pairs[i].first = OutputName(inputs[i]); } - // Convert from TF_Port to string names. + // Convert from TF_Output to string names. std::vector output_names(noutputs); for (int i = 0; i < noutputs; ++i) { - output_names[i] = PortName(outputs[i]); + output_names[i] = OutputName(outputs[i]); } // Convert from TF_Operation* to string names. @@ -1781,8 +1784,8 @@ void TF_SessionRun(TF_Session* session, const TF_Buffer* run_options, status); } -void TF_SessionPRunSetup(TF_Session* session, const TF_Port* inputs, - int ninputs, const TF_Port* outputs, int noutputs, +void TF_SessionPRunSetup(TF_Session* session, const TF_Output* inputs, + int ninputs, const TF_Output* outputs, int noutputs, const TF_Operation* const* target_opers, int ntargets, const char** handle, TF_Status* status) { if (!ExtendSessionGraphHelper(session, status)) { @@ -1791,12 +1794,12 @@ void TF_SessionPRunSetup(TF_Session* session, const TF_Port* inputs, std::vector input_names(ninputs); for (int i = 0; i < ninputs; ++i) { - input_names[i] = PortName(inputs[i]); + input_names[i] = OutputName(inputs[i]); } std::vector output_names(noutputs); for (int i = 0; i < noutputs; ++i) { - output_names[i] = PortName(outputs[i]); + output_names[i] = OutputName(outputs[i]); } std::vector target_names(ntargets); @@ -1815,8 +1818,8 @@ void TF_SessionPRunSetup(TF_Session* session, const TF_Port* inputs, } void TF_SessionPRun(TF_Session* session, const char* handle, - const TF_Port* inputs, TF_Tensor* const* input_values, - int ninputs, const TF_Port* outputs, + const TF_Output* inputs, TF_Tensor* const* input_values, + int ninputs, const TF_Output* outputs, TF_Tensor** output_values, int noutputs, const TF_Operation* const* target_opers, int ntargets, TF_Status* status) { @@ -1829,17 +1832,17 @@ void TF_SessionPRun(TF_Session* session, const char* handle, TF_Run_Setup(noutputs, output_values, status); - // Convert from TF_Port and TF_Tensor to a string and Tensor. + // Convert from TF_Output and TF_Tensor to a string and Tensor. std::vector> input_pairs(ninputs); if (!TF_Run_Inputs(input_values, &input_pairs, status)) return; for (int i = 0; i < ninputs; ++i) { - input_pairs[i].first = PortName(inputs[i]); + input_pairs[i].first = OutputName(inputs[i]); } - // Convert from TF_Port to string names. + // Convert from TF_Output to string names. std::vector output_names(noutputs); for (int i = 0; i < noutputs; ++i) { - output_names[i] = PortName(outputs[i]); + output_names[i] = OutputName(outputs[i]); } // Convert from TF_Operation* to string names. diff --git a/tensorflow/c/c_api.h b/tensorflow/c/c_api.h index 3b969551e436a6..508140fc05d2b4 100644 --- a/tensorflow/c/c_api.h +++ b/tensorflow/c/c_api.h @@ -310,44 +310,49 @@ typedef struct TF_OperationDescription TF_OperationDescription; // invalidate old TF_Operation* pointers. typedef struct TF_Operation TF_Operation; -// Represents a specific input or output of an operation, e.g. to -// specify the specific output to pass as an input to a new op. -typedef struct TF_Port { +// Represents a specific input of an operation. +typedef struct TF_Input { TF_Operation* oper; - int index; // Specifies the index of the input or output within oper. -} TF_Port; + int index; // The index of the input within oper. +} TF_Input; -// Sets the shape of the Tensor referenced by `port` in `graph` to +// Represents a specific output of an operation. +typedef struct TF_Output { + TF_Operation* oper; + int index; // The index of the output within oper. +} TF_Output; + +// Sets the shape of the Tensor referenced by `output` in `graph` to // the shape described by `dims` and `num_dims`. // // If the number of dimensions is unknown, `num_dims` must be // set to -1 and dims can be null. If a dimension is unknown, // the corresponding entry in the `dims` array must be -1. // -// This does not overwrite the existing shape associated with `port`, +// This does not overwrite the existing shape associated with `output`, // but merges the input shape with the existing shape. For example, // setting a shape of [-1, 2] with an existing shape [2, -1] would set // a final shape of [2, 2] based on shape merging semantics. // // Returns an error into `status` if: -// * `port` is not in `graph`. +// * `output` is not in `graph`. // * An invalid shape is being set (e.g., the shape being set // is incompatible with the existing shape). -extern void TF_GraphSetTensorShape(TF_Graph* graph, TF_Port port, +extern void TF_GraphSetTensorShape(TF_Graph* graph, TF_Output output, const int64_t* dims, const int num_dims, TF_Status* status); -// Returns the number of dimensions of the Tensor referenced by `port` +// Returns the number of dimensions of the Tensor referenced by `output` // in `graph`. // // If the number of dimensions in the shape is unknown, returns -1. // // Returns an error into `status` if: -// * `port` is not in `graph`. -extern int TF_GraphGetTensorNumDims(TF_Graph* graph, TF_Port port, +// * `output` is not in `graph`. +extern int TF_GraphGetTensorNumDims(TF_Graph* graph, TF_Output output, TF_Status* status); -// Returns the shape of the Tensor referenced by `port` in `graph` +// Returns the shape of the Tensor referenced by `output` in `graph` // into `dims`. `dims` must be an array large enough to hold `num_dims` // entries (e.g., the return value of TF_GraphGetTensorNumDims). // @@ -357,10 +362,11 @@ extern int TF_GraphGetTensorNumDims(TF_Graph* graph, TF_Port port, // unknown dimension is represented by `-1`. // // Returns an error into `status` if: -// * `port` is not in `graph`. +// * `output` is not in `graph`. // * `num_dims` does not match the actual number of dimensions. -extern void TF_GraphGetTensorShape(TF_Graph* graph, TF_Port port, int64_t* dims, - int num_dims, TF_Status* status); +extern void TF_GraphGetTensorShape(TF_Graph* graph, TF_Output output, + int64_t* dims, int num_dims, + TF_Status* status); // Operation will only be added to *graph when TF_FinishOperation() is // called (assuming TF_FinishOperation() does not return an error). @@ -388,18 +394,18 @@ extern void TF_SetDevice(TF_OperationDescription* desc, const char* device); // it takes a list, even if you were to pass a list with a single // tensor), as in: // TF_OperationDescription* desc = TF_NewOperation(graph, "Concat", "c"); -// TF_Port concat_dim_input = {...}; +// TF_Output concat_dim_input = {...}; // TF_AddInput(desc, concat_dim_input); -// TF_Port values_inputs[5] = {{...}, ..., {...}}; +// TF_Output values_inputs[5] = {{...}, ..., {...}}; // TF_AddInputList(desc, values_inputs, 5); // For inputs that take a single tensor. -extern void TF_AddInput(TF_OperationDescription* desc, TF_Port input); +extern void TF_AddInput(TF_OperationDescription* desc, TF_Output input); // For inputs that take a list of tensors. -// inputs must point to TF_Port[num_inputs]. +// inputs must point to TF_Output[num_inputs]. extern void TF_AddInputList(TF_OperationDescription* desc, - const TF_Port* inputs, int num_inputs); + const TF_Output* inputs, int num_inputs); // Call once per control input to `desc`. extern void TF_AddControlInput(TF_OperationDescription* desc, @@ -511,26 +517,26 @@ extern const char* TF_OperationOpType(TF_Operation* oper); extern const char* TF_OperationDevice(TF_Operation* oper); extern int TF_OperationNumOutputs(TF_Operation* oper); -extern TF_DataType TF_OperationOutputType(TF_Port oper_out); +extern TF_DataType TF_OperationOutputType(TF_Output oper_out); extern int TF_OperationOutputListLength(TF_Operation* oper, const char* arg_name, TF_Status* status); extern int TF_OperationNumInputs(TF_Operation* oper); -extern TF_DataType TF_OperationInputType(TF_Port oper_in); +extern TF_DataType TF_OperationInputType(TF_Input oper_in); extern int TF_OperationInputListLength(TF_Operation* oper, const char* arg_name, TF_Status* status); // In this code: -// TF_Port producer = TF_OperationInput(consumer); +// TF_Output producer = TF_OperationInput(consumer); // There is an edge from producer.oper's output (given by // producer.index) to consumer.oper's input (given by consumer.index). -extern TF_Port TF_OperationInput(TF_Port oper_in); +extern TF_Output TF_OperationInput(TF_Input oper_in); // Get the number of current consumers of a specific output of an // operation. Note that this number can change when new operations // are added to the graph. -extern int TF_OperationOutputNumConsumers(TF_Port oper_out); +extern int TF_OperationOutputNumConsumers(TF_Output oper_out); // Get list of all current consumers of a specific output of an // operation. `consumers` must point to an array of length at least @@ -539,7 +545,7 @@ extern int TF_OperationOutputNumConsumers(TF_Port oper_out); // modification of the graph can increase the number of consumers of // an operation. Returns the number of output consumers (should match // TF_OperationOutputNumConsumers(oper_out)). -extern int TF_OperationOutputConsumers(TF_Port oper_out, TF_Port* consumers, +extern int TF_OperationOutputConsumers(TF_Output oper_out, TF_Input* consumers, int max_consumers); // Get the number of control inputs to an operation. @@ -866,10 +872,10 @@ extern void TF_SessionRun(TF_Session* session, // RunOptions const TF_Buffer* run_options, // Input tensors - const TF_Port* inputs, TF_Tensor* const* input_values, - int ninputs, + const TF_Output* inputs, + TF_Tensor* const* input_values, int ninputs, // Output tensors - const TF_Port* outputs, TF_Tensor** output_values, + const TF_Output* outputs, TF_Tensor** output_values, int noutputs, // Target operations const TF_Operation* const* target_opers, int ntargets, @@ -888,9 +894,9 @@ extern void TF_SessionRun(TF_Session* session, // NOTE: This is EXPERIMENTAL and subject to change. extern void TF_SessionPRunSetup(TF_Session*, // Input names - const TF_Port* inputs, int ninputs, + const TF_Output* inputs, int ninputs, // Output names - const TF_Port* outputs, int noutputs, + const TF_Output* outputs, int noutputs, // Target operations const TF_Operation* const* target_opers, int ntargets, @@ -904,10 +910,10 @@ extern void TF_SessionPRunSetup(TF_Session*, // NOTE: This is EXPERIMENTAL and subject to change. extern void TF_SessionPRun(TF_Session*, const char* handle, // Input tensors - const TF_Port* inputs, + const TF_Output* inputs, TF_Tensor* const* input_values, int ninputs, // Output tensors - const TF_Port* outputs, TF_Tensor** output_values, + const TF_Output* outputs, TF_Tensor** output_values, int noutputs, // Target operations const TF_Operation* const* target_opers, diff --git a/tensorflow/c/c_api_test.cc b/tensorflow/c/c_api_test.cc index ad0e6a7da8fa35..ca6165fff4beb7 100644 --- a/tensorflow/c/c_api_test.cc +++ b/tensorflow/c/c_api_test.cc @@ -273,14 +273,14 @@ TF_Operation* ScalarConst(int32 v, TF_Graph* graph, TF_Status* s) { TF_Operation* Add(TF_Operation* l, TF_Operation* r, TF_Graph* graph, TF_Status* s) { TF_OperationDescription* desc = TF_NewOperation(graph, "AddN", "add"); - TF_Port add_inputs[2] = {{l, 0}, {r, 0}}; + TF_Output add_inputs[2] = {{l, 0}, {r, 0}}; TF_AddInputList(desc, add_inputs, 2); return TF_FinishOperation(desc, s); } TF_Operation* Neg(TF_Operation* n, TF_Graph* graph, TF_Status* s) { TF_OperationDescription* desc = TF_NewOperation(graph, "Neg", "neg"); - TF_Port neg_input = {n, 0}; + TF_Output neg_input = {n, 0}; TF_AddInput(desc, neg_input); return TF_FinishOperation(desc, s); } @@ -401,7 +401,7 @@ TEST(CAPI, SetShape) { TF_Operation* feed = Placeholder(graph, s); ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); - TF_Port feed_out_0 = TF_Port{feed, 0}; + TF_Output feed_out_0 = TF_Output{feed, 0}; int num_dims; // Fetch the shape, it should be completely unknown. @@ -462,7 +462,7 @@ TEST(CAPI, SetShape) { // Test for a scalar. TF_Operation* three = ScalarConst(3, graph, s); ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); - TF_Port three_out_0 = TF_Port{three, 0}; + TF_Output three_out_0 = TF_Output{three, 0}; num_dims = TF_GraphGetTensorNumDims(graph, three_out_0, s); ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); @@ -488,11 +488,11 @@ TEST(CAPI, Graph) { EXPECT_EQ(string("Placeholder"), string(TF_OperationOpType(feed))); EXPECT_EQ(string(""), string(TF_OperationDevice(feed))); EXPECT_EQ(1, TF_OperationNumOutputs(feed)); - EXPECT_EQ(TF_INT32, TF_OperationOutputType(TF_Port{feed, 0})); + EXPECT_EQ(TF_INT32, TF_OperationOutputType(TF_Output{feed, 0})); EXPECT_EQ(1, TF_OperationOutputListLength(feed, "output", s)); ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); EXPECT_EQ(0, TF_OperationNumInputs(feed)); - EXPECT_EQ(0, TF_OperationOutputNumConsumers(TF_Port{feed, 0})); + EXPECT_EQ(0, TF_OperationOutputNumConsumers(TF_Output{feed, 0})); EXPECT_EQ(0, TF_OperationNumControlInputs(feed)); EXPECT_EQ(0, TF_OperationNumControlOutputs(feed)); @@ -521,21 +521,21 @@ TEST(CAPI, Graph) { EXPECT_EQ(string("AddN"), string(TF_OperationOpType(add))); EXPECT_EQ(string(""), string(TF_OperationDevice(add))); EXPECT_EQ(1, TF_OperationNumOutputs(add)); - EXPECT_EQ(TF_INT32, TF_OperationOutputType(TF_Port{add, 0})); + EXPECT_EQ(TF_INT32, TF_OperationOutputType(TF_Output{add, 0})); EXPECT_EQ(1, TF_OperationOutputListLength(add, "sum", s)); ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); EXPECT_EQ(2, TF_OperationNumInputs(add)); EXPECT_EQ(2, TF_OperationInputListLength(add, "inputs", s)); ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); - EXPECT_EQ(TF_INT32, TF_OperationInputType(TF_Port{add, 0})); - EXPECT_EQ(TF_INT32, TF_OperationInputType(TF_Port{add, 1})); - TF_Port add_in_0 = TF_OperationInput(TF_Port{add, 0}); + EXPECT_EQ(TF_INT32, TF_OperationInputType(TF_Input{add, 0})); + EXPECT_EQ(TF_INT32, TF_OperationInputType(TF_Input{add, 1})); + TF_Output add_in_0 = TF_OperationInput(TF_Input{add, 0}); EXPECT_EQ(feed, add_in_0.oper); EXPECT_EQ(0, add_in_0.index); - TF_Port add_in_1 = TF_OperationInput(TF_Port{add, 1}); + TF_Output add_in_1 = TF_OperationInput(TF_Input{add, 1}); EXPECT_EQ(three, add_in_1.oper); EXPECT_EQ(0, add_in_1.index); - EXPECT_EQ(0, TF_OperationOutputNumConsumers(TF_Port{add, 0})); + EXPECT_EQ(0, TF_OperationOutputNumConsumers(TF_Output{add, 0})); EXPECT_EQ(0, TF_OperationNumControlInputs(add)); EXPECT_EQ(0, TF_OperationNumControlOutputs(add)); @@ -545,16 +545,17 @@ TEST(CAPI, Graph) { EXPECT_EQ(attr_value.i(), 2); // Placeholder oper now has a consumer. - ASSERT_EQ(1, TF_OperationOutputNumConsumers(TF_Port{feed, 0})); - TF_Port feed_port; - EXPECT_EQ(1, TF_OperationOutputConsumers(TF_Port{feed, 0}, &feed_port, 1)); + ASSERT_EQ(1, TF_OperationOutputNumConsumers(TF_Output{feed, 0})); + TF_Input feed_port; + EXPECT_EQ(1, TF_OperationOutputConsumers(TF_Output{feed, 0}, &feed_port, 1)); EXPECT_EQ(add, feed_port.oper); EXPECT_EQ(0, feed_port.index); // The scalar const oper also has a consumer. - ASSERT_EQ(1, TF_OperationOutputNumConsumers(TF_Port{three, 0})); - TF_Port three_port; - EXPECT_EQ(1, TF_OperationOutputConsumers(TF_Port{three, 0}, &three_port, 1)); + ASSERT_EQ(1, TF_OperationOutputNumConsumers(TF_Output{three, 0})); + TF_Input three_port; + EXPECT_EQ(1, + TF_OperationOutputConsumers(TF_Output{three, 0}, &three_port, 1)); EXPECT_EQ(add, three_port.oper); EXPECT_EQ(1, three_port.index); @@ -713,7 +714,7 @@ class CSession { DeleteInputValues(); inputs_.clear(); for (const auto& p : inputs) { - inputs_.emplace_back(TF_Port{p.first, 0}); + inputs_.emplace_back(TF_Output{p.first, 0}); input_values_.emplace_back(p.second); } } @@ -722,7 +723,7 @@ class CSession { ResetOutputValues(); outputs_.clear(); for (TF_Operation* o : outputs) { - outputs_.emplace_back(TF_Port{o, 0}); + outputs_.emplace_back(TF_Output{o, 0}); } } @@ -741,11 +742,11 @@ class CSession { ResetOutputValues(); output_values_.resize(outputs_.size(), nullptr); - const TF_Port* inputs_ptr = inputs_.empty() ? nullptr : &inputs_[0]; + const TF_Output* inputs_ptr = inputs_.empty() ? nullptr : &inputs_[0]; TF_Tensor* const* input_values_ptr = input_values_.empty() ? nullptr : &input_values_[0]; - const TF_Port* outputs_ptr = outputs_.empty() ? nullptr : &outputs_[0]; + const TF_Output* outputs_ptr = outputs_.empty() ? nullptr : &outputs_[0]; TF_Tensor** output_values_ptr = output_values_.empty() ? nullptr : &output_values_[0]; @@ -788,9 +789,9 @@ class CSession { } TF_Session* session_; - std::vector inputs_; + std::vector inputs_; std::vector input_values_; - std::vector outputs_; + std::vector outputs_; std::vector output_values_; std::vector targets_; }; @@ -863,7 +864,7 @@ TEST(CAPI, ColocateWith) { ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); TF_OperationDescription* desc = TF_NewOperation(graph, "AddN", "add"); - TF_Port inputs[] = {{feed, 0}, {constant, 0}}; + TF_Output inputs[] = {{feed, 0}, {constant, 0}}; TF_AddInputList(desc, inputs, TF_ARRAYSIZE(inputs)); TF_ColocateWith(desc, feed); TF_Operation* add = TF_FinishOperation(desc, s); diff --git a/tensorflow/g3doc/how_tos/language_bindings/index.md b/tensorflow/g3doc/how_tos/language_bindings/index.md index 5b8a8c81462c53..b32c91354c2eb4 100644 --- a/tensorflow/g3doc/how_tos/language_bindings/index.md +++ b/tensorflow/g3doc/how_tos/language_bindings/index.md @@ -83,12 +83,12 @@ A language binding is expected to define the following classes: - `Output`: Represents one of the outputs of an operation in the graph. Has a `DataType` (and eventually a shape). May be passed as an input argument to a function for adding operations to a graph, or to a `Session`'s `Run()` - method to fetch that output as a tensor. Corresponds to a `TF_Port` in the C - API. + method to fetch that output as a tensor. Corresponds to a `TF_Output` in the + C API. - `Session`: Represents a client to a particular instance of the TensorFlow runtime. Its main job is to be constructed with a `Graph` and some options - and then field calls to `Run()` the graph. Corresponds to a - `TF_Session` in the C API. + and then field calls to `Run()` the graph. Corresponds to a `TF_Session` in + the C API. - `Tensor`: Represents an N-dimensional (rectangular) array with elements all the same `DataType`. Gets data into and out of a `Session`'s `Run()` call. Corresponds to a `TF_Tensor` in the C API. diff --git a/tensorflow/go/graph.go b/tensorflow/go/graph.go index b8bdd50503b8bb..2eb11946100c42 100644 --- a/tensorflow/go/graph.go +++ b/tensorflow/go/graph.go @@ -158,7 +158,7 @@ func (g *Graph) AddOperation(args OpSpec) (*Operation, error) { C.TF_AddInput(cdesc, in.c()) case OutputList: size := len(in) - list := make([]C.TF_Port, size) + list := make([]C.TF_Output, size) for i, v := range in { list[i] = v.c() } diff --git a/tensorflow/go/operation.go b/tensorflow/go/operation.go index e7986814d02eb3..eb8614653e1a3e 100644 --- a/tensorflow/go/operation.go +++ b/tensorflow/go/operation.go @@ -110,8 +110,8 @@ func (p Output) Shape() (shape []int64, err error) { return ret, nil } -func (p Output) c() C.TF_Port { - return C.TF_Port{oper: p.Op.c, index: C.int(p.Index)} +func (p Output) c() C.TF_Output { + return C.TF_Output{oper: p.Op.c, index: C.int(p.Index)} } func (p Output) canBeAnInput() {} diff --git a/tensorflow/go/session.go b/tensorflow/go/session.go index fc5e3ceb4fe39c..dd629441efacac 100644 --- a/tensorflow/go/session.go +++ b/tensorflow/go/session.go @@ -76,7 +76,7 @@ func (s *Session) Run(inputs map[Output]*Tensor, outputs []Output, targets []*Op s.mu.Unlock() defer s.wg.Done() - var inputPorts []C.TF_Port + var inputPorts []C.TF_Output var inputValues []*C.TF_Tensor if inputs != nil { for port, tensor := range inputs { @@ -85,7 +85,7 @@ func (s *Session) Run(inputs map[Output]*Tensor, outputs []Output, targets []*Op } } - var outputPorts []C.TF_Port + var outputPorts []C.TF_Output for _, port := range outputs { outputPorts = append(outputPorts, port.c()) } @@ -96,14 +96,14 @@ func (s *Session) Run(inputs map[Output]*Tensor, outputs []Output, targets []*Op } status := newStatus() - var inputPortsPtr *C.TF_Port + var inputPortsPtr *C.TF_Output var inputValuesPtr **C.TF_Tensor if len(inputPorts) > 0 { inputPortsPtr = &inputPorts[0] inputValuesPtr = &inputValues[0] } - var outputPortsPtr *C.TF_Port + var outputPortsPtr *C.TF_Output var outputValuesPtr **C.TF_Tensor if len(outputPorts) > 0 { outputPortsPtr = &outputPorts[0]