OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
PtrMemory.hpp
1/*
2 * PtrMemory.hpp
3 *
4 * Created on: Apr 15, 2015
5 * Author: Pietro Incardona
6 */
7
8#ifndef PTRMEMORY_HPP_
9#define PTRMEMORY_HPP_
10
11
32#include "config.h"
33#include "memory.hpp"
34#include <cstddef>
35#include <cstdint>
36#include <iostream>
37
38
39class PtrMemory : public memory
40{
42 size_t spm;
43
45 void * dm;
46
48 long int ref_cnt;
49
51 bool copyFromPointer(const void * ptr, size_t sz);
52
54 void setAlignment(size_t align);
55
56public:
57
59 bool copyDeviceToDevice(const PtrMemory & m);
60
62 virtual bool flush() {return true;};
64 virtual bool allocate(size_t sz);
66 virtual void destroy();
68 virtual bool copy(const memory & m);
70 virtual size_t size() const;
72 virtual bool resize(size_t sz);
74 virtual void * getPointer();
75
77 virtual const void * getPointer() const;
78
80 virtual void * getDevicePointer();
81
82
84 virtual void deviceToHost(){};
85
87 virtual void hostToDevice(){};
88
90 virtual void deviceToHost(size_t start, size_t stop) {};
91
93 virtual void hostToDevice(size_t start, size_t top) {};
94
99 virtual void fill(unsigned char c);
100
102 virtual void incRef()
103 {ref_cnt++;}
104
106 virtual void decRef()
107 {ref_cnt--;}
108
110 virtual long int ref()
111 {
112 return ref_cnt;
113 }
114
120 constexpr static bool isDeviceHostSame()
121 {
122 return true;
123 }
124
131 {
132 return true;
133 }
134
135 // Default constructor
136 PtrMemory():spm(0),dm(NULL),ref_cnt(0)
137 {
138 };
139
141 PtrMemory(void * ptr, size_t sz):spm(sz),dm(ptr),ref_cnt(0)
142 {
143 };
144
145 ~PtrMemory()
146 {
147 if(ref_cnt == 0)
148 destroy();
149 else
150 std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " destroying a live object" << "\n";
151 };
152};
153
154
155#endif /* PTRMEMORY_HPP_ */
This class give memory from a preallocated memory, memory destruction is not performed.
Definition PtrMemory.hpp:40
virtual void * getDevicePointer()
get a readable pointer with the data
virtual void destroy()
destroy memory
Definition PtrMemory.cpp:45
virtual void fill(unsigned char c)
fill memory with the selected byte
Definition PtrMemory.cpp:22
long int ref_cnt
Reference counter.
Definition PtrMemory.hpp:48
virtual bool flush()
flush the memory
Definition PtrMemory.hpp:62
PtrMemory(void *ptr, size_t sz)
Constructor, we choose a default alignment of 32 for avx.
virtual void hostToDevice(size_t start, size_t top)
Do nothing.
Definition PtrMemory.hpp:93
void * dm
Pointed memory.
Definition PtrMemory.hpp:45
virtual void decRef()
Decrement the reference counter.
size_t spm
Size of the pointed memory.
Definition PtrMemory.hpp:42
virtual void hostToDevice()
Do nothing.
Definition PtrMemory.hpp:87
virtual size_t size() const
the the size of the allocated memory
bool copyDeviceToDevice(const PtrMemory &m)
copy from same Heap to Heap
Definition PtrMemory.cpp:72
virtual long int ref()
Return the reference counter.
virtual void deviceToHost(size_t start, size_t stop)
Do nothing.
Definition PtrMemory.hpp:90
virtual void * getPointer()
get a readable pointer with the data
static constexpr bool isDeviceHostSame()
Return true if the device and the host pointer are the same.
virtual bool copy(const memory &m)
copy memory
Definition PtrMemory.cpp:92
bool isInitialized()
Allocated Memory is already initialized.
virtual void incRef()
Increment the reference counter.
void setAlignment(size_t align)
Set alignment the memory will be aligned with this number.
virtual void deviceToHost()
Do nothing.
Definition PtrMemory.hpp:84
bool copyFromPointer(const void *ptr, size_t sz)
copy from Pointer to Heap
Definition PtrMemory.cpp:54
virtual bool resize(size_t sz)
resize the memory allocated
this class is a functor for "for_each" algorithm