1 | /* Copyright 2018 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 | #ifndef TENSORFLOW_CORE_KERNELS_FUNCTION_OPS_H_ |
17 | #define TENSORFLOW_CORE_KERNELS_FUNCTION_OPS_H_ |
18 | |
19 | #include "tensorflow/core/framework/full_type_util.h" |
20 | #include "tensorflow/core/framework/function.h" |
21 | #include "tensorflow/core/framework/op_kernel.h" |
22 | |
23 | namespace tensorflow { |
24 | |
25 | static const char* const kArgOp = FunctionLibraryDefinition::kArgOp; |
26 | static const char* const kDeviceArgOp = FunctionLibraryDefinition::kDeviceArgOp; |
27 | static const char* const kRetOp = FunctionLibraryDefinition::kRetOp; |
28 | static const char* const kDeviceRetOp = FunctionLibraryDefinition::kDeviceRetOp; |
29 | |
30 | class ArgOp : public OpKernel { |
31 | public: |
32 | explicit ArgOp(OpKernelConstruction* ctx); |
33 | |
34 | void Compute(OpKernelContext* ctx) override; |
35 | |
36 | bool IsExpensive() override { return false; } |
37 | |
38 | private: |
39 | int index_; |
40 | DataType dtype_; |
41 | |
42 | TF_DISALLOW_COPY_AND_ASSIGN(ArgOp); |
43 | }; |
44 | |
45 | class RetvalOp : public OpKernel { |
46 | public: |
47 | explicit RetvalOp(OpKernelConstruction* ctx); |
48 | |
49 | void Compute(OpKernelContext* ctx) override; |
50 | |
51 | bool IsExpensive() override { return false; } |
52 | |
53 | private: |
54 | int index_; |
55 | DataType dtype_; |
56 | |
57 | TF_DISALLOW_COPY_AND_ASSIGN(RetvalOp); |
58 | }; |
59 | |
60 | class RemoteCallOp : public AsyncOpKernel { |
61 | public: |
62 | explicit RemoteCallOp(OpKernelConstruction* ctx); |
63 | |
64 | ~RemoteCallOp() override {} |
65 | |
66 | void ComputeAsync(OpKernelContext* ctx, DoneCallback done) override; |
67 | |
68 | string TraceString(const OpKernelContext& ctx, bool verbose) const override; |
69 | |
70 | private: |
71 | NameAttrList func_; |
72 | DataTypeVector input_dtypes_; |
73 | DataTypeVector output_dtypes_; |
74 | // Note that in the future if all RemoteCall ops have full type |
75 | // information, the kernel will not need access to the "Tout" Attr and |
76 | // return_type_ will replace output_dtypes_. |
77 | FullTypeDef return_type_; |
78 | |
79 | mutex mu_; |
80 | typedef std::pair<string, FunctionLibraryRuntime*> FunctionTarget; |
81 | std::map<FunctionTarget, FunctionLibraryRuntime::Handle> handle_cache_ |
82 | TF_GUARDED_BY(mu_); |
83 | |
84 | TF_DISALLOW_COPY_AND_ASSIGN(RemoteCallOp); |
85 | }; |
86 | |
87 | } // namespace tensorflow |
88 | #endif // TENSORFLOW_CORE_KERNELS_FUNCTION_OPS_H_ |
89 |