• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/function.h"
20 #include "tensorflow/core/framework/op_kernel.h"
21 
22 namespace tensorflow {
23 
24 static const char* const kArgOp = FunctionLibraryDefinition::kArgOp;
25 static const char* const kDeviceArgOp = FunctionLibraryDefinition::kDeviceArgOp;
26 static const char* const kRetOp = FunctionLibraryDefinition::kRetOp;
27 static const char* const kDeviceRetOp = FunctionLibraryDefinition::kDeviceRetOp;
28 
29 class ArgOp : public OpKernel {
30  public:
31   explicit ArgOp(OpKernelConstruction* ctx);
32 
33   void Compute(OpKernelContext* ctx) override;
34 
IsExpensive()35   bool IsExpensive() override { return false; }
36 
37  private:
38   int index_;
39   DataType dtype_;
40 
41   TF_DISALLOW_COPY_AND_ASSIGN(ArgOp);
42 };
43 
44 class RetvalOp : public OpKernel {
45  public:
46   explicit RetvalOp(OpKernelConstruction* ctx);
47 
48   void Compute(OpKernelContext* ctx) override;
49 
IsExpensive()50   bool IsExpensive() override { return false; }
51 
52  private:
53   int index_;
54   DataType dtype_;
55 
56   TF_DISALLOW_COPY_AND_ASSIGN(RetvalOp);
57 };
58 
59 class RemoteCallOp : public AsyncOpKernel {
60  public:
61   explicit RemoteCallOp(OpKernelConstruction* ctx);
62 
~RemoteCallOp()63   ~RemoteCallOp() override {}
64 
65   void ComputeAsync(OpKernelContext* ctx, DoneCallback done) override;
66 
67  private:
68   NameAttrList func_;
69   DataTypeVector input_dtypes_;
70   DataTypeVector output_dtypes_;
71 
72   mutex mu_;
73   typedef std::pair<string, FunctionLibraryRuntime*> FunctionTarget;
74   std::map<FunctionTarget, FunctionLibraryRuntime::Handle> handle_cache_
75       GUARDED_BY(mu_);
76 
77   TF_DISALLOW_COPY_AND_ASSIGN(RemoteCallOp);
78 };
79 
80 }  // namespace tensorflow
81 #endif  // TENSORFLOW_CORE_KERNELS_FUNCTION_OPS_H_
82