1 | /* Copyright 2017 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/framework/common_shape_fns.h" |
17 | #include "tensorflow/core/framework/op.h" |
18 | #include "tensorflow/core/framework/shape_inference.h" |
19 | #include "tensorflow/core/platform/errors.h" |
20 | |
21 | namespace tensorflow { |
22 | |
23 | using shape_inference::InferenceContext; |
24 | using shape_inference::ShapeHandle; |
25 | |
26 | REGISTER_OP("OutfeedEnqueue" ) |
27 | .Input("input: dtype" ) |
28 | .Attr("dtype: type" ) |
29 | .SetIsStateful() |
30 | .SetShapeFn(shape_inference::NoOutputs); |
31 | |
32 | REGISTER_OP("OutfeedEnqueueTuple" ) |
33 | .Input("inputs: dtypes" ) |
34 | .Attr("dtypes: list(type)" ) |
35 | .SetIsStateful() |
36 | .SetShapeFn(shape_inference::NoOutputs); |
37 | |
38 | REGISTER_OP("OutfeedDequeue" ) |
39 | .Output("output: dtype" ) |
40 | .Attr("dtype: type" ) |
41 | .Attr("shape: shape" ) |
42 | .Attr("device_ordinal: int = -1" ) |
43 | .SetIsStateful() |
44 | .SetShapeFn(shape_inference::ExplicitShape); |
45 | |
46 | REGISTER_OP("OutfeedDequeueTuple" ) |
47 | .Output("outputs: dtypes" ) |
48 | .Attr("dtypes: list(type)" ) |
49 | .Attr("shapes: list(shape)" ) |
50 | .Attr("device_ordinal: int = -1" ) |
51 | .SetIsStateful() |
52 | .SetShapeFn([](InferenceContext* c) { |
53 | std::vector<PartialTensorShape> shapes; |
54 | std::vector<DataType> dtypes; |
55 | TF_RETURN_IF_ERROR(c->GetAttr("shapes" , &shapes)); |
56 | TF_RETURN_IF_ERROR(c->GetAttr("dtypes" , &dtypes)); |
57 | if (shapes.size() != dtypes.size()) { |
58 | return errors::InvalidArgument( |
59 | "Incorrect number of output shapes specified" ); |
60 | } |
61 | for (int i = 0; i < shapes.size(); ++i) { |
62 | ShapeHandle out; |
63 | TF_RETURN_IF_ERROR(c->MakeShapeFromPartialTensorShape(shapes[i], &out)); |
64 | c->set_output(i, out); |
65 | } |
66 | return OkStatus(); |
67 | }); |
68 | |
69 | REGISTER_OP("OutfeedDequeueV2" ) |
70 | .Input("device_ordinal: int32" ) |
71 | .Output("output: dtype" ) |
72 | .Attr("dtype: type" ) |
73 | .Attr("shape: shape" ) |
74 | .SetIsStateful() |
75 | .SetShapeFn(shape_inference::ExplicitShape); |
76 | |
77 | REGISTER_OP("OutfeedDequeueTupleV2" ) |
78 | .Input("device_ordinal: int32" ) |
79 | .Output("outputs: dtypes" ) |
80 | .Attr("dtypes: list(type)" ) |
81 | .Attr("shapes: list(shape)" ) |
82 | .SetIsStateful() |
83 | .SetShapeFn([](InferenceContext* c) { |
84 | if (c->Rank(c->input(0)) != 0) { |
85 | return errors::InvalidArgument("device ordinal must be a scalar." ); |
86 | } |
87 | std::vector<PartialTensorShape> shapes; |
88 | std::vector<DataType> dtypes; |
89 | TF_RETURN_IF_ERROR(c->GetAttr("shapes" , &shapes)); |
90 | TF_RETURN_IF_ERROR(c->GetAttr("dtypes" , &dtypes)); |
91 | if (shapes.size() != dtypes.size()) { |
92 | return errors::InvalidArgument( |
93 | "Incorrect number of output shapes specified" ); |
94 | } |
95 | for (int i = 0; i < shapes.size(); ++i) { |
96 | ShapeHandle out; |
97 | TF_RETURN_IF_ERROR(c->MakeShapeFromPartialTensorShape(shapes[i], &out)); |
98 | c->set_output(i, out); |
99 | } |
100 | return OkStatus(); |
101 | }); |
102 | |
103 | } // namespace tensorflow |
104 | |