TensorFlow Serving C++ API Documentation
load_servables_fast.h
1 /* Copyright 2016 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_CORE_LOAD_SERVABLES_FAST_H_
17 #define TENSORFLOW_SERVING_CORE_LOAD_SERVABLES_FAST_H_
18 
19 #include <functional>
20 #include <memory>
21 
22 #include "tensorflow/core/lib/core/status.h"
23 #include "tensorflow/core/platform/cpu_info.h"
24 #include "tensorflow_serving/core/aspired_versions_manager.h"
25 #include "tensorflow_serving/core/loader.h"
26 #include "tensorflow_serving/core/manager.h"
27 #include "tensorflow_serving/core/servable_state_monitor.h"
28 
29 namespace tensorflow {
30 namespace serving {
31 
32 // Connects 'source' to 'manager', and speeds up loading of the servables
33 // matching 'initial_servables'. The speeding up is accomplished by boosting the
34 // number of threads used for loading until the initial servables have been
35 // loaded, and then resetting it to the manager's originally configured value.
36 Status ConnectSourceWithFastInitialLoad(
37  AspiredVersionsManager* manager, Source<std::unique_ptr<Loader>>* source,
38  ServableStateMonitor* servable_state_monitor,
39  const std::vector<ServableRequest>& initial_servables,
40  uint32 num_threads = 4 * port::NumSchedulableCPUs());
41 
42 // Like ConnectSourceWithFastInitialLoad(), but with multiple sources.
43 Status ConnectSourcesWithFastInitialLoad(
44  AspiredVersionsManager* manager,
45  std::vector<Source<std::unique_ptr<Loader>>*> sources,
46  ServableStateMonitor* servable_state_monitor,
47  const std::vector<ServableRequest>& initial_servables,
48  uint32 num_threads = 4 * port::NumSchedulableCPUs());
49 
51 // Implementation detail. API readers may skip.
53 
54 namespace internal {
55 
56 Status ConnectSourcesWithFastInitialLoad(
57  AspiredVersionsManager* manager,
58  std::vector<Source<std::unique_ptr<Loader>>*> sources,
59  const std::function<Status()>& wait_until_loaded_fn, uint32 num_threads);
60 
61 uint32 GetManagerNumLoadThreads(AspiredVersionsManager* manager);
62 std::function<void(const uint32)> SetManagerNumLoadThreadsNotifier(
63  AspiredVersionsManager* manager);
64 
65 } // namespace internal
66 
67 } // namespace serving
68 } // namespace tensorflow
69 
70 #endif // TENSORFLOW_SERVING_CORE_LOAD_SERVABLES_FAST_H_