21 #if !defined( BOLT_AMP_PARALLEL_ALLOC_H )
22 #define BOLT_AMP_PARALLEL_ALLOC_H
35 enum State {e_New, e_Created, e_Reserved};
36 PoolEntry() : _state(e_New), _dBuffer(NULL), _stagingBuffer(NULL) {};
39 concurrency::array<T> *_dBuffer;
40 concurrency::array<T> *_stagingBuffer;
43 PoolEntry &alloc(concurrency::accelerator_view av,
int size)
45 using namespace concurrency;
47 if (pool[0]._state == PoolEntry::e_New) {
48 pool[0]._state = PoolEntry::e_Reserved;
49 accelerator cpuAccelerator = accelerator(accelerator::cpu_accelerator);
50 pool[0]._stagingBuffer =
new array<T,1>(size, cpuAccelerator.default_view, av);
51 pool[0]._dBuffer =
new concurrency::array<T,1>(size, av);
52 }
else if ( pool[0]._state == PoolEntry::e_Reserved) {
53 throw(
"OclBufferpool[0] full!");
56 pool[0]._state = PoolEntry::e_Reserved;
61 concurrency::array<T,1> &alloc(
int size)
64 if (pool[0]._state == PoolEntry::e_New) {
65 pool[0]._state = PoolEntry::e_Reserved;
66 pool[0]._dBuffer =
new concurrency::array<T,1>(size);
67 }
else if ( pool[0]._state == PoolEntry::e_Reserved) {
68 throw(
"OclBufferpool[0] full!");
71 pool[0]._state = PoolEntry::e_Reserved;
72 return *(pool[0]._dBuffer);
78 assert (pool[0]._state == PoolEntry::e_Reserved);
79 pool[0]._state = PoolEntry::e_Created;
83 void free(PoolEntry &poolEntry)
86 assert (poolEntry._state == PoolEntry::e_Reserved);
87 poolEntry._state = PoolEntry::e_Created;