• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 The TensorFlow Authors. 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_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_PLUGGABLE_DEVICE_BFC_ALLOCATOR_H_
17 #define TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_PLUGGABLE_DEVICE_BFC_ALLOCATOR_H_
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include "tensorflow/core/common_runtime/bfc_allocator.h"
25 #include "tensorflow/core/common_runtime/device/device_mem_allocator.h"
26 #include "tensorflow/core/platform/thread_annotations.h"
27 #include "tensorflow/core/platform/types.h"
28 #include "tensorflow/core/protobuf/config.pb.h"
29 
30 namespace tensorflow {
31 
32 // A PluggableDevice memory allocator that implements a 'best-fit with
33 // coalescing' algorithm
34 class PluggableDeviceBFCAllocator : public BFCAllocator {
35  public:
36   PluggableDeviceBFCAllocator(DeviceMemAllocator* sub_allocator,
37                               size_t total_memory, const string& name,
38                               bool force_memory_growth_requested);
39   PluggableDeviceBFCAllocator(DeviceMemAllocator* sub_allocator,
40                               size_t total_memory,
41                               const GPUOptions& gpu_options, const string& name,
42                               bool force_memory_growth_requested);
~PluggableDeviceBFCAllocator()43   ~PluggableDeviceBFCAllocator() override {}
44 
45   TF_DISALLOW_COPY_AND_ASSIGN(PluggableDeviceBFCAllocator);
46 
47  private:
48   static bool GetAllowGrowthValue(const GPUOptions& gpu_options,
49                                   bool force_memory_growth_requested);
50   static bool GetGarbageCollectionValue();
51 };
52 
53 }  // namespace tensorflow
54 
55 #endif  // TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_PLUGGABLE_DEVICE_BFC_ALLOCATOR_H_
56