TensorFlow Serving C++ API Documentation
prediction_service_impl.h
1 /* Copyright 2018 Google Inc. 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_SERVING_MODEL_SERVERS_PREDICTION_SERVICE_IMPL_H_
17 #define TENSORFLOW_SERVING_MODEL_SERVERS_PREDICTION_SERVICE_IMPL_H_
18 
19 #include "tensorflow_serving/apis/prediction_service.grpc.pb.h"
20 #include "tensorflow_serving/model_servers/prediction_service_util.h"
21 #include "tensorflow_serving/servables/tensorflow/predict_impl.h"
22 
23 namespace tensorflow {
24 namespace serving {
25 
26 class PredictionServiceImpl final : public PredictionService::Service {
27  public:
28  explicit PredictionServiceImpl(const PredictionServiceOptions& options)
29  : core_(options.server_core),
30  predictor_(new TensorflowPredictor(options.thread_pool_factory)),
31  enforce_session_run_timeout_(options.enforce_session_run_timeout),
32  thread_pool_factory_(options.thread_pool_factory) {}
33 
34  ::grpc::Status Predict(::grpc::ServerContext* context,
35  const PredictRequest* request,
36  PredictResponse* response) override;
37 
38  ::grpc::Status GetModelMetadata(::grpc::ServerContext* context,
39  const GetModelMetadataRequest* request,
40  GetModelMetadataResponse* response) override;
41 
42  ::grpc::Status Classify(::grpc::ServerContext* context,
43  const ClassificationRequest* request,
44  ClassificationResponse* response) override;
45 
46  ::grpc::Status Regress(::grpc::ServerContext* context,
47  const RegressionRequest* request,
48  RegressionResponse* response) override;
49 
50  ::grpc::Status MultiInference(::grpc::ServerContext* context,
51  const MultiInferenceRequest* request,
52  MultiInferenceResponse* response) override;
53 
54  private:
55  ServerCore* core_;
56  std::unique_ptr<TensorflowPredictor> predictor_;
57  const bool enforce_session_run_timeout_;
58  ThreadPoolFactory* thread_pool_factory_;
59 };
60 
61 } // namespace serving
62 } // namespace tensorflow
63 
64 #endif // TENSORFLOW_SERVING_MODEL_SERVERS_PREDICTION_SERVICE_IMPL_H_