ASL 0.1.7
Advanced Simulation Library
Loading...
Searching...
No Matches
aclMemBlock.h
Go to the documentation of this file.
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;
36namespace 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;
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:
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
useful common utilities
unsigned int size
virtual cl::Buffer & getBuffer()
shared_ptr< void > map()
virtual void swapBuffers(MemBlock &a)
shared_ptr< cl::Buffer > buffer
Definition: aclMemBlock.h:42
MemBlock(unsigned int size, TypeID typeID, CommandQueue queue_)
MemBlock(unsigned int size, TypeID typeID, char *initArray, CommandQueue queue_)
friend void swapBuffers(MemBlock &a, MemBlock &b)
Definition: aclMemBlock.h:62
weak_ptr< void > region
Definition: aclMemBlock.h:43
Class interface for Buffer Memory Objects.
Definition: cl.hpp:3018
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
Advanced Computational Language.
Definition: acl.h:41
std::shared_ptr< cl::CommandQueue > CommandQueue
Definition: acl.h:51
std::shared_ptr< T > map(ElementData m)
Definition: aclMemBlock.h:68
TypeID
Definition: aclTypes.h:39
std::shared_ptr< MemBlock > ElementData
Definition: acl.h:48
const std::vector< std::string > TYPE
void swapBuffers(std::shared_ptr< Array< T > >a, std::shared_ptr< Array< T > > b)