TensorFlow Serving C++ API Documentation
server_init.cc
1 /* Copyright 2022 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 #include "tensorflow_serving/model_servers/server_init.h"
17 
18 #include <memory>
19 
20 #include "absl/log/log.h"
21 #include "absl/strings/string_view.h"
22 #include "tensorflow_serving/model_servers/http_rest_api_handler.h"
23 #include "tensorflow_serving/model_servers/platform_config_util.h"
24 #include "tensorflow_serving/model_servers/prediction_service_impl.h"
25 #include "tensorflow_serving/servables/tensorflow/saved_model_bundle_source_adapter.h"
26 
27 namespace tensorflow {
28 namespace serving {
29 namespace init {
30 
31 Status SetupPlatformConfigMapForTensorFlowImpl(
32  const SessionBundleConfig& session_bundle_config,
33  PlatformConfigMap& platform_config_map) {
34  platform_config_map =
35  CreateTensorFlowPlatformConfigMap(session_bundle_config);
36  return absl::OkStatus();
37 }
38 
39 Status UpdatePlatformConfigMapForTensorFlowImpl(
40  PlatformConfigMap& platform_config_map) {
41  return absl::OkStatus();
42 }
43 
44 std::unique_ptr<HttpRestApiHandlerBase> CreateHttpRestApiHandlerImpl(
45  int timeout_in_ms, ServerCore* core) {
46  return absl::make_unique<HttpRestApiHandler>(timeout_in_ms, core);
47 }
48 
49 std::unique_ptr<PredictionService::Service> CreatePredictionServiceImpl(
50  const PredictionServiceOptions& options) {
51  return absl::make_unique<PredictionServiceImpl>(options);
52 }
53 
54 void TensorflowServingFunctionRegistration::Register(
55  absl::string_view type,
56  SetupPlatformConfigMapForTensorFlowFnType setup_platform_config_map_func,
57  UpdatePlatformConfigMapForTensorFlowFnType update_platform_config_map_func,
58  CreateHttpRestApiHandlerFnType create_http_rest_api_handler_func,
59  CreatePredictionServiceFnType create_prediction_service_func) {
60  VLOG(1) << "Registering serving functions for " << type;
61  registration_type_ = type;
62  setup_platform_config_map_ = setup_platform_config_map_func;
63  update_platform_config_map_ = update_platform_config_map_func;
64  create_http_rest_api_handler_ = create_http_rest_api_handler_func;
65  create_prediction_service_ = create_prediction_service_func;
66 }
67 
68 } // namespace init
69 } // namespace serving
70 } // namespace tensorflow