DPC++ Runtime
Runtime libraries for oneAPI DPC++
usm_allocator.hpp
Go to the documentation of this file.
1 //===---------- usm_allocator.hpp - Allocator for USM memory --------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef USM_ALLOCATOR
10 #define USM_ALLOCATOR
11 
12 #include <memory>
13 
15 
16 // USM system memory allocation/deallocation interface.
17 class SystemMemory {
18 public:
19  virtual void *allocate(size_t size) = 0;
20  virtual void *allocate(size_t size, size_t aligned) = 0;
21  virtual void deallocate(void *ptr, bool OwnZeMemHandle) = 0;
22  virtual MemType getMemType() = 0;
23  virtual ~SystemMemory() = default;
24 };
25 
27 public:
28  // Keep it public since it needs to be accessed by the lower layer(Buckets)
29  class USMAllocImpl;
30 
31  USMAllocContext(std::unique_ptr<SystemMemory> memHandle);
33 
34  void *allocate(size_t size);
35  void *allocate(size_t size, size_t alignment);
36  void deallocate(void *ptr, bool OwnZeMemHandle);
37 
38 private:
39  std::unique_ptr<USMAllocImpl> pImpl;
40 };
41 
42 // Temporary interface to allow pooling to be reverted, i.e., no buffer support
43 bool enableBufferPooling();
44 
45 #endif
virtual void * allocate(size_t size, size_t aligned)=0
virtual void deallocate(void *ptr, bool OwnZeMemHandle)=0
virtual ~SystemMemory()=default
virtual void * allocate(size_t size)=0
virtual MemType getMemType()=0
void deallocate(void *ptr, bool OwnZeMemHandle)
USMAllocContext(std::unique_ptr< SystemMemory > memHandle)
void * allocate(size_t size)
bool enableBufferPooling()
MemType
@ All
@ SharedReadOnly
@ Host
@ Device
@ Shared