| 1 |
/* |
| 2 |
* Advanced Simulation Library <http://asl.org.il> |
| 3 |
* |
| 4 |
* Copyright 2015 Avtech Scientific <http://avtechscientific.com> |
| 5 |
* |
| 6 |
* |
| 7 |
* This file is part of Advanced Simulation Library (ASL). |
| 8 |
* |
| 9 |
* ASL is free software: you can redistribute it and/or modify it |
| 10 |
* under the terms of the GNU Affero General Public License as |
| 11 |
* published by the Free Software Foundation, version 3 of the License. |
| 12 |
* |
| 13 |
* ASL is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Affero General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Affero General Public License |
| 19 |
* along with ASL. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
#ifndef ACLMEMBLOCK_H |
| 25 |
#define ACLMEMBLOCK_H |
| 26 |
|
| 27 |
#include "../aclStdIncludes.h" |
| 28 |
#include "../aclElementBase.h" |
| 29 |
#include "../aclUtilities.h" |
| 30 |
#include <aslUtilities.h> |
| 31 |
#include "../aclHardware.h" |
| 32 |
|
| 33 |
|
| 34 |
// using namespace asl; |
| 35 |
// using shared_ptr; |
| 36 |
namespace acl |
| 37 |
{ |
| 38 |
|
| 39 |
class MemBlock: public ElementBase |
| 40 |
{ |
| 41 |
protected: |
| 42 |
shared_ptr<cl::Buffer> buffer; //< pointer in gpu |
| 43 |
weak_ptr<void> region; |
| 44 |
MemBlock(); |
| 45 |
MemBlock(unsigned int size, TypeID typeID, CommandQueue queue_); |
| 46 |
MemBlock(unsigned int size, TypeID typeID, char *initArray, CommandQueue queue_); |
| 47 |
virtual void swapBuffers(MemBlock & a); |
| 48 |
public: |
| 49 |
virtual cl::Buffer &getBuffer(); |
| 50 |
shared_ptr<void> map(); |
| 51 |
friend inline void swapBuffers(MemBlock & a, MemBlock & b); |
| 52 |
}; |
| 53 |
|
| 54 |
typedef shared_ptr<MemBlock> ElementData; |
| 55 |
inline void swapBuffers(MemBlock & a, MemBlock & b); |
| 56 |
|
| 57 |
|
| 58 |
template<typename T> inline std::shared_ptr<T> map(ElementData m); |
| 59 |
|
| 60 |
// --------------------Implementation ----------------------- |
| 61 |
|
| 62 |
inline void swapBuffers(MemBlock & a, MemBlock & b) |
| 63 |
{ |
| 64 |
a.swapBuffers(b); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
template<typename T> inline std::shared_ptr<T> map(ElementData m) |
| 69 |
{ |
| 70 |
if (m->getTypeID() != typeToTypeID<T>()) |
| 71 |
asl::errorMessage ("map: there is attempt to cast pointer with type " + |
| 72 |
typeToStr<T>() + |
| 73 |
" for an element with type " + |
| 74 |
TYPE[m->getTypeID()]); |
| 75 |
return std::shared_ptr<T> (m->map(),(T*)m->map().get()); |
| 76 |
} |
| 77 |
} // namespace acl |
| 78 |
|
| 79 |
#endif // ACLVECTOR_H |