Home | History | Annotate | Download | only in rpc
      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_UTIL_RPC_RPC_FACTORY_H_
     17 #define TENSORFLOW_CORE_UTIL_RPC_RPC_FACTORY_H_
     18 
     19 #include "tensorflow/core/framework/op_kernel.h"
     20 #include "tensorflow/core/framework/tensor_types.h"
     21 
     22 namespace tensorflow {
     23 
     24 // Return the environment variable `key`.  If the variable is not set,
     25 // use the default value.  If it is set but could not be parsed,
     26 // return `false`.  Otherwise set `value` and return `true`.
     27 template <typename T>
     28 bool GetEnvVar(const char* key, const T& default_value, T* value);
     29 
     30 class RPCFactory {
     31  public:
     32   RPCFactory() {}
     33   virtual ~RPCFactory() {}
     34 
     35   // Asynchronously invokes methods `method_t` at addresses `address_t` with
     36   // request strings from `request_t`.  Any of these may be scalar
     37   // Tensors, in which case the operands are broadcasted.
     38   // Upon completion of all requests, `response_t` will be populated and the
     39   // `done` callback will be invoked.
     40   //
     41   // If `try_rpc` is `true`, then `status_message_t` and
     42   // `status_code_t` will be populated as well.
     43   //
     44   // If `try_rpc` is `false`, then `status_message_t` and
     45   // `status_code_t` are ignored (and may be nullptr).  Instead, the
     46   // status of any failed call will be propagated to the op.
     47   //
     48   // REQUIRES:
     49   //   - `response_t` is not null, and is a string Tensor with the same shape as
     50   //     `request_t`.
     51   //
     52   //   If `try_rpc` is `true`:
     53   //      - `status_code_t` and `status_message_t` are not null.
     54   //      - `status_code_t` is an int32 Tensor with the same shape as
     55   //        `request_t`.
     56   //      - `status_message_t` is a string Tensor with the same shape as
     57   //        `request_t`.
     58   virtual void Call(OpKernelContext* ctx, int64 num_elements,
     59                     const Tensor& address_t, const Tensor& method_t,
     60                     const Tensor& request_t, const bool try_rpc,
     61                     Tensor* response_t, Tensor* status_code_t,
     62                     Tensor* status_message_t,
     63                     AsyncOpKernel::DoneCallback done) = 0;
     64 
     65  private:
     66   TF_DISALLOW_COPY_AND_ASSIGN(RPCFactory);
     67 };
     68 
     69 }  // namespace tensorflow
     70 
     71 #endif  // TENSORFLOW_CORE_UTIL_RPC_RPC_FACTORY_H_
     72