TensorFlow Serving C++ API Documentation
fake_thread_pool_factory.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_TEST_UTIL_FAKE_THREAD_POOL_FACTORY_H_
17 #define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_TEST_UTIL_FAKE_THREAD_POOL_FACTORY_H_
18 
19 #include <memory>
20 
21 #include "tensorflow/core/lib/core/status.h"
22 #include "tensorflow/core/platform/macros.h"
23 #include "tensorflow/core/platform/threadpool.h"
24 #include "tensorflow_serving/servables/tensorflow/test_util/fake_thread_pool_factory.pb.h"
25 #include "tensorflow_serving/servables/tensorflow/thread_pool_factory.h"
26 
27 namespace tensorflow {
28 namespace serving {
29 namespace test_util {
30 
31 // A fake ThreadPoolFactory that returns the given inter- and intra-op thread
32 // pools.
34  public:
35  static Status Create(const FakeThreadPoolFactoryConfig& config,
36  std::unique_ptr<ThreadPoolFactory>* result);
37 
38  explicit FakeThreadPoolFactory(const FakeThreadPoolFactoryConfig& config) {}
39  virtual ~FakeThreadPoolFactory() = default;
40 
41  virtual ScopedThreadPools GetThreadPools() {
42  return ScopedThreadPools(inter_op_thread_pool_, intra_op_thread_pool_);
43  }
44 
45  void SetInterOpThreadPool(
46  std::shared_ptr<thread::ThreadPoolInterface> thread_pool) {
47  inter_op_thread_pool_ = thread_pool;
48  }
49  void SetIntraOpThreadPool(
50  std::shared_ptr<thread::ThreadPoolInterface> thread_pool) {
51  intra_op_thread_pool_ = thread_pool;
52  }
53 
54  private:
55  std::shared_ptr<thread::ThreadPoolInterface> inter_op_thread_pool_;
56  std::shared_ptr<thread::ThreadPoolInterface> intra_op_thread_pool_;
57  TF_DISALLOW_COPY_AND_ASSIGN(FakeThreadPoolFactory);
58 };
59 
60 } // namespace test_util
61 } // namespace serving
62 } // namespace tensorflow
63 
64 #endif // TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_TEST_UTIL_FAKE_THREAD_POOL_FACTORY_H_