• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 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_GPU_GPU_BFC_ALLOCATOR_H_
17 #define TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_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/common_runtime/gpu/gpu_virtual_mem_allocator.h"
27 #include "tensorflow/core/platform/thread_annotations.h"
28 #include "tensorflow/core/platform/types.h"
29 #include "tensorflow/core/protobuf/config.pb.h"
30 
31 namespace tensorflow {
32 
33 // A GPU memory allocator that implements a 'best-fit with coalescing'
34 // algorithm.
35 class GPUBFCAllocator : public BFCAllocator {
36  public:
37   GPUBFCAllocator(SubAllocator* sub_allocator, size_t total_memory,
38                   const string& name);
39   GPUBFCAllocator(SubAllocator* sub_allocator, size_t total_memory,
40                   const GPUOptions& gpu_options, const string& name);
~GPUBFCAllocator()41   ~GPUBFCAllocator() override {}
42 
43   TF_DISALLOW_COPY_AND_ASSIGN(GPUBFCAllocator);
44 
45  private:
46   static bool GetAllowGrowthValue(const GPUOptions& gpu_options);
47   static bool GetGarbageCollectionValue();
48 };
49 
50 }  // namespace tensorflow
51 
52 #endif  // TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_BFC_ALLOCATOR_H_
53