Home | History | Annotate | Download | only in distributed_runtime
      1 /* Copyright 2016 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_DISTRIBUTED_RUNTIME_MASTER_INTERFACE_H_
     17 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_MASTER_INTERFACE_H_
     18 
     19 #include "tensorflow/core/distributed_runtime/call_options.h"
     20 #include "tensorflow/core/distributed_runtime/message_wrappers.h"
     21 #include "tensorflow/core/lib/core/errors.h"
     22 #include "tensorflow/core/lib/core/status.h"
     23 #include "tensorflow/core/protobuf/master.pb.h"
     24 
     25 namespace tensorflow {
     26 
     27 // Abstract interface for communicating with the TensorFlow Master service.
     28 //
     29 // This interface supports both RPC-based master implementations, and
     30 // in-process master implementations that do not require an RPC
     31 // roundtrip.
     32 class MasterInterface {
     33  public:
     34   virtual ~MasterInterface() {}
     35   virtual Status CreateSession(CallOptions* call_options,
     36                                const CreateSessionRequest* request,
     37                                CreateSessionResponse* response) = 0;
     38 
     39   virtual Status ExtendSession(CallOptions* call_options,
     40                                const ExtendSessionRequest* request,
     41                                ExtendSessionResponse* response) = 0;
     42 
     43   virtual Status PartialRunSetup(CallOptions* call_options,
     44                                  const PartialRunSetupRequest* request,
     45                                  PartialRunSetupResponse* response) {
     46     return errors::Unimplemented("Partial run not implemented for this master");
     47   }
     48 
     49   virtual Status RunStep(CallOptions* call_options,
     50                          RunStepRequestWrapper* request,
     51                          MutableRunStepResponseWrapper* response) = 0;
     52 
     53   virtual Status RunStep(CallOptions* call_options,
     54                          const RunStepRequest* request,
     55                          RunStepResponse* response) {
     56     std::unique_ptr<RunStepRequestWrapper> wrapped_request(
     57         new ProtoRunStepRequest(request));
     58     std::unique_ptr<MutableRunStepResponseWrapper> wrapped_response(
     59         new NonOwnedProtoRunStepResponse(response));
     60     return RunStep(call_options, wrapped_request.get(), wrapped_response.get());
     61   }
     62 
     63   // Returns a request object for use in calls to
     64   // `RunStep()`. Ownership is transferred to the caller.
     65   //
     66   // The message returned from this method must only be used in a
     67   // `RunStep()` call on the same `MasterInterface` instance.
     68   virtual MutableRunStepRequestWrapper* CreateRunStepRequest() {
     69     return new MutableProtoRunStepRequest;
     70   }
     71 
     72   // Returns a response object for use in calls to
     73   // `RunStep()`. Ownership is transferred to the caller.
     74   //
     75   // The message returned from this method must only be used in a
     76   // `RunStep()` call on the same `MasterInterface` instance.
     77   virtual MutableRunStepResponseWrapper* CreateRunStepResponse() {
     78     return new OwnedProtoRunStepResponse;
     79   }
     80 
     81   virtual Status CloseSession(CallOptions* call_options,
     82                               const CloseSessionRequest* request,
     83                               CloseSessionResponse* response) = 0;
     84 
     85   virtual Status ListDevices(CallOptions* call_options,
     86                              const ListDevicesRequest* request,
     87                              ListDevicesResponse* response) = 0;
     88 
     89   virtual Status Reset(CallOptions* call_options, const ResetRequest* request,
     90                        ResetResponse* response) = 0;
     91 
     92  protected:
     93   // NOTE: This should only be called by implementations of this
     94   // interface whose CreateRunStepResponse() method returns a
     95   // proto-based wrappers for the RunStepResponse message.
     96   RunStepResponse* get_proto_from_wrapper(
     97       MutableRunStepResponseWrapper* wrapper) {
     98     return wrapper->get_proto();
     99   }
    100 };
    101 
    102 }  // namespace tensorflow
    103 
    104 #endif  // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_MASTER_INTERFACE_H_
    105