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
SystemMemory::allocate
virtual void * allocate(size_t size)=0
SystemMemory
Definition: usm_allocator.hpp:17
MemType
MemType
Definition: usm_allocator.hpp:14
SystemMemory::~SystemMemory
virtual ~SystemMemory()=default
USMAllocContext::USMAllocContext
USMAllocContext(std::unique_ptr< SystemMemory > memHandle)
Definition: usm_allocator.cpp:1052
USMAllocContext::allocate
void * allocate(size_t size)
Definition: usm_allocator.cpp:1055
Shared
@ Shared
Definition: usm_allocator.hpp:14
USMAllocContext::USMAllocImpl
Definition: usm_allocator.cpp:534
SystemMemory::deallocate
virtual void deallocate(void *ptr, bool OwnZeMemHandle)=0
USMAllocContext::deallocate
void deallocate(void *ptr, bool OwnZeMemHandle)
Definition: usm_allocator.cpp:1083
Device
@ Device
Definition: usm_allocator.hpp:14
Host
@ Host
Definition: usm_allocator.hpp:14
USMAllocContext::~USMAllocContext
~USMAllocContext()
Definition: usm_allocator.cpp:1102
SystemMemory::getMemType
virtual MemType getMemType()=0
USMAllocContext
Definition: usm_allocator.hpp:26
All
@ All
Definition: usm_allocator.hpp:14
enableBufferPooling
bool enableBufferPooling()
Definition: usm_allocator.cpp:1134
SharedReadOnly
@ SharedReadOnly
Definition: usm_allocator.hpp:14