• 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 #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_SIMPLE_ALLOCATOR_H_
16 #define TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_SIMPLE_ALLOCATOR_H_
17 
18 #include <memory>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include "tensorflow/core/common_runtime/device/device_mem_allocator.h"
24 #include "tensorflow/core/platform/thread_annotations.h"
25 #include "tensorflow/core/platform/types.h"
26 #include "tensorflow/core/protobuf/config.pb.h"
27 
28 namespace tensorflow {
29 
30 class PluggableDeviceSimpleAllocator : public Allocator {
31  public:
32   explicit PluggableDeviceSimpleAllocator(DeviceMemAllocator* sub_allocator);
~PluggableDeviceSimpleAllocator()33   ~PluggableDeviceSimpleAllocator() override {}
34 
35   void* AllocateRaw(size_t alignment, size_t num_bytes) override;
36   void DeallocateRaw(void* ptr) override;
37 
TracksAllocationSizes()38   bool TracksAllocationSizes() const override { return false; }
Name()39   string Name() override { return "Simple allocator"; }
40   absl::optional<AllocatorStats> GetStats() override;
41 
GetMemoryType()42   AllocatorMemoryType GetMemoryType() const override {
43     return sub_allocator_->GetMemoryType();
44   }
45 
46  private:
47   TF_DISALLOW_COPY_AND_ASSIGN(PluggableDeviceSimpleAllocator);
48   std::unique_ptr<SubAllocator> sub_allocator_;
49 };
50 
51 }  // namespace tensorflow
52 
53 #endif  // TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_SIMPLE_ALLOCATOR_H_
54