Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
Allocators.h
1#pragma once
2
3#include <boost/pool/pool.hpp>
4
5#ifdef APRA_CUDA_ENABLED
6 #include "ApraPool.h"
7 #include "apra_cudamallochost_allocator.h"
8 #include "apra_cudamalloc_allocator.h"
9#endif
10
12{
13protected:
14 boost::pool<> buff_allocator;
15
16public:
19 {
20 buff_allocator.release_memory();
21 }
22 virtual void *allocateChunks(size_t n)
23 {
24 return buff_allocator.ordered_malloc(n);
25 }
26
27 virtual void freeChunks(void *MemPtr, size_t n)
28 {
29 buff_allocator.ordered_free(MemPtr, n);
30 }
31
32 virtual size_t getChunkSize()
33 {
34 return 1024;
35 }
36};
37
38#ifdef APRA_CUDA_ENABLED
39class HostPinnedAllocator : public HostAllocator
40{
41protected:
42 boost::pool<apra_cudamallochost_allocator> buff_pinned_allocator;
43
44public:
45 HostPinnedAllocator() : buff_pinned_allocator(1024) {};
46 ~HostPinnedAllocator()
47 {
48 buff_pinned_allocator.release_memory();
49 }
50 void *allocateChunks(size_t n)
51 {
52 return buff_pinned_allocator.ordered_malloc(n);
53 }
54 void freeChunks(void *MemPtr, size_t n)
55 {
56 buff_pinned_allocator.ordered_free(MemPtr, n);
57 }
58};
59
60class CudaDeviceAllocator : public HostAllocator
61{
62protected:
63 ApraPool<apra_cudamalloc_allocator> buff_cudadevice_allocator;
64
65public:
66 CudaDeviceAllocator() : buff_cudadevice_allocator(1024) {};
67 ~CudaDeviceAllocator()
68 {
69 buff_cudadevice_allocator.release_memory();
70 }
71 void *allocateChunks(size_t n)
72 {
73 return buff_cudadevice_allocator.ordered_malloc(n);
74 }
75 void freeChunks(void *MemPtr, size_t n)
76 {
77 buff_cudadevice_allocator.ordered_free(MemPtr, n);
78 }
79};
80#endif
Definition ApraPool.h:128
void ordered_free(void *ptr, const size_t n)
Definition ApraPool.h:378
bool release_memory()
Definition ApraPool.h:197
void * ordered_malloc(const size_t n)
Definition ApraPool.h:300
Definition Allocators.h:12
virtual size_t getChunkSize()
Definition Allocators.h:32
boost::pool buff_allocator
Definition Allocators.h:14
HostAllocator()
Definition Allocators.h:17
virtual void freeChunks(void *MemPtr, size_t n)
Definition Allocators.h:27
virtual void * allocateChunks(size_t n)
Definition Allocators.h:22
virtual ~HostAllocator()
Definition Allocators.h:18