TensorFlow Serving C++ API Documentation
tfrt_saved_model_source_adapter.h
1 /* Copyright 2020 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_SERVABLES_TENSORFLOW_TFRT_SAVED_MODEL_SOURCE_ADAPTER_H_
17 #define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_TFRT_SAVED_MODEL_SOURCE_ADAPTER_H_
18 
19 #include "tensorflow/cc/saved_model/loader.h"
20 #include "tensorflow/core/lib/core/status.h"
21 #include "tensorflow/core/platform/macros.h"
22 #include "tensorflow_serving/core/simple_loader.h"
23 #include "tensorflow_serving/core/source_adapter.h"
24 #include "tensorflow_serving/core/storage_path.h"
25 #include "tensorflow_serving/servables/tensorflow/tfrt_saved_model_factory.h"
26 #include "tensorflow_serving/servables/tensorflow/tfrt_saved_model_source_adapter.pb.h"
27 #include "tensorflow_serving/servables/tensorflow/tfrt_servable.h"
28 
29 namespace tensorflow {
30 namespace serving {
31 
32 // A SourceAdapter that creates TfrtSavedModelServable Loaders from SavedModel
33 // paths. It keeps a TfrtSavedModelFactory as its state, which may house a batch
34 // scheduler that is shared across all of the SavedModel it emits.
36  : public UnarySourceAdapter<StoragePath, std::unique_ptr<Loader>> {
37  public:
38  static Status Create(const TfrtSavedModelSourceAdapterConfig& config,
39  std::unique_ptr<TfrtSavedModelSourceAdapter>* adapter);
40 
41  ~TfrtSavedModelSourceAdapter() override;
42 
43  private:
45 
47  std::unique_ptr<TfrtSavedModelFactory> factory);
48 
49  SimpleLoader<Servable>::CreatorVariant GetServableCreator(
50  std::shared_ptr<TfrtSavedModelFactory> factory,
51  const StoragePath& path) const;
52 
53  Status Convert(const StoragePath& path,
54  std::unique_ptr<Loader>* loader) override;
55 
56  // We use a shared ptr to share ownership with Loaders we emit, in case they
57  // outlive this object.
58  std::shared_ptr<TfrtSavedModelFactory> factory_;
59 
60  TF_DISALLOW_COPY_AND_ASSIGN(TfrtSavedModelSourceAdapter);
61 };
62 
63 } // namespace serving
64 } // namespace tensorflow
65 
66 #endif // TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_TFRT_SAVED_MODEL_SOURCE_ADAPTER_H_