| 1 | /* |
| 2 | * memory.hpp |
| 3 | * |
| 4 | * Created on: Aug 8, 2014 |
| 5 | * Author: Pietro Incardona |
| 6 | */ |
| 7 | |
| 8 | /*! \brief This class is an interface |
| 9 | * |
| 10 | * This class is an interface to allocate memory |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef MEMORY_HPP_ |
| 15 | #define MEMORY_HPP_ |
| 16 | |
| 17 | typedef long int mem_id; |
| 18 | |
| 19 | #include "config.h" |
| 20 | #include <stddef.h> |
| 21 | |
| 22 | class memory |
| 23 | { |
| 24 | public: |
| 25 | |
| 26 | /*! \brief Flush the memory into the device |
| 27 | * |
| 28 | * |
| 29 | */ |
| 30 | virtual bool flush() = 0; |
| 31 | |
| 32 | /*! \brief allocate on device a buffer of |
| 33 | * |
| 34 | * Allocate on the device a buffer of memory |
| 35 | * |
| 36 | * \param sz the size of the buffer |
| 37 | * |
| 38 | */ |
| 39 | |
| 40 | virtual bool allocate(size_t sz) = 0; |
| 41 | |
| 42 | /*! \brief resize on device a buffer |
| 43 | * |
| 44 | * On the device resize |
| 45 | * |
| 46 | * \param sz the size the resized buffer |
| 47 | * |
| 48 | */ |
| 49 | virtual bool resize(size_t sz) = 0; |
| 50 | |
| 51 | /*! \brief Destroy the buffer on the device |
| 52 | * |
| 53 | * destroy the buffer on the device |
| 54 | * |
| 55 | */ |
| 56 | virtual void destroy() = 0; |
| 57 | |
| 58 | |
| 59 | /*! \brief Copy the memory from one device to another device |
| 60 | * |
| 61 | * \param m from where to copy |
| 62 | * |
| 63 | */ |
| 64 | virtual bool copy(const memory & m) = 0; |
| 65 | |
| 66 | /*! \brief get the size of the buffer |
| 67 | * |
| 68 | */ |
| 69 | |
| 70 | virtual size_t size() const = 0; |
| 71 | |
| 72 | /*! \brief return a data pointer |
| 73 | * |
| 74 | * return readable pointer with the data stored |
| 75 | * |
| 76 | */ |
| 77 | |
| 78 | virtual void * getPointer() = 0; |
| 79 | |
| 80 | /*! \brief return a data pointer |
| 81 | * |
| 82 | * return readable pointer with the data stored |
| 83 | * |
| 84 | */ |
| 85 | |
| 86 | virtual const void * getPointer() const = 0; |
| 87 | |
| 88 | /*! \brief destructor |
| 89 | * |
| 90 | * destructor |
| 91 | * |
| 92 | */ |
| 93 | virtual ~memory() {}; |
| 94 | |
| 95 | /*! \brief Increment the internal reference counter |
| 96 | * |
| 97 | * |
| 98 | */ |
| 99 | virtual void incRef() = 0; |
| 100 | |
| 101 | /*! \brief Decrement the internal reference counter |
| 102 | * |
| 103 | * |
| 104 | */ |
| 105 | virtual void decRef() = 0; |
| 106 | |
| 107 | /*! \brief Return the actual reference counter |
| 108 | * |
| 109 | * \return the reference counter |
| 110 | * |
| 111 | */ |
| 112 | virtual long int ref() = 0; |
| 113 | |
| 114 | /*! \brief Return if the actual memory that is going to be allocated is already initialized |
| 115 | * |
| 116 | * \return true if already initialized |
| 117 | * |
| 118 | */ |
| 119 | virtual bool isInitialized() = 0; |
| 120 | |
| 121 | /*! \brief Return the device pointer of the memory |
| 122 | * |
| 123 | * \return the device pointer |
| 124 | * |
| 125 | */ |
| 126 | virtual void * getDevicePointer() = 0; |
| 127 | |
| 128 | /*! \brief Copy the memory from device to host |
| 129 | * |
| 130 | * |
| 131 | */ |
| 132 | virtual void deviceToHost() = 0; |
| 133 | |
| 134 | /*! \brief Copy the memory from host to device |
| 135 | * |
| 136 | * |
| 137 | */ |
| 138 | virtual void hostToDevice() = 0; |
| 139 | |
| 140 | /*! \brief Copy the memory from host to device |
| 141 | * |
| 142 | * \param start |
| 143 | * \param stop |
| 144 | * |
| 145 | */ |
| 146 | virtual void hostToDevice(size_t start, size_t top) = 0; |
| 147 | |
| 148 | /*! \brief Copy the memory from device to host |
| 149 | * |
| 150 | * \param start from start |
| 151 | * \param stop to stop |
| 152 | * |
| 153 | */ |
| 154 | virtual void deviceToHost(size_t start, size_t stop) = 0; |
| 155 | |
| 156 | |
| 157 | /*! \brief Fill the buffer with a particular byte |
| 158 | * |
| 159 | * |
| 160 | */ |
| 161 | virtual void fill(unsigned char c) = 0; |
| 162 | |
| 163 | |
| 164 | }; |
| 165 | |
| 166 | #endif |
| 167 | |