Swarm-NG  1.1
swarm::CoalescedStructArray< Item, _Scalar, _CHUNK_SIZE > Struct Template Reference

Array of structures with coalecsed access. More...

#include <coalescedstructarray.hpp>

Public Types

typedef Item * PItem
 We may use a shared_ptr for PItem.
 

Public Member Functions

GENERIC CoalescedStructArray (PItem array, size_t block_count)
 CoalescedStructArray lets you allocate the memory for the array. More...
 
GENERIC Item & operator[] (const int &i)
 The core functionality: overlapping Items to allow transparent coalesced access. More...
 
GENERIC int block_count () const
 Number of blocks in this array. More...
 
GENERIC int size () const
 Number of items in the array: (block-count*CHUNK_SIZE)
 
GENERIC Item * get ()
 The raw pointer.
 
GENERIC Item * begin ()
 Begin pointer, it is a raw pointer. More...
 
GENERIC Item * end ()
 End pointer, it is a raw pointer. More...
 

Detailed Description

template<class Item, typename _Scalar = typename Item::scalar_t, int _CHUNK_SIZE = Item::CHUNK_SIZE>
struct swarm::CoalescedStructArray< Item, _Scalar, _CHUNK_SIZE >

Array of structures with coalecsed access.

It allows multiple threads access consecutive elements of a structure by grouping the structure elements together. However, it requires that all the elements of the structure should be of the same size.

The Item should provide CHUNK_SIZE and scalar_t for offset calculation

The Item should be designed with care. Item should be a struct where each of its members an array of scalar_t[CHUNK_SIZE]. That is the granularity level of the Item. The Item however, can have 2D arrays or other arrays. But the scalar_t[CHUNK_SIZE] is the smallest item. For example, an array of scalar_t[2*CHUNK_SIZE] and a 2D array of scalar_t[3][CHUNK_SIZE] are allowed. Item can contain other structs with the same granularity. The following example shows this feature: struct A { double _x[8]; double _y[8]; double _z[16]; double& z(const int& i){ return z[i*8]; } double& x(){ return _x[0]; } };

struct Item { typedef double scalar_t; static const int CHUNK_SIZE = 8; A _a[4]; double _f[8]; double _m[16]; double& m(const int& i){ return m[i*8]; } double& f(){ return _f[0]; } A& a(const int& i){ return a[i]; } }

The Item should also have accessors that return the first Item of the arrays and other items should not be accessible. Look at the example above.

Definition at line 92 of file coalescedstructarray.hpp.

Constructor & Destructor Documentation

template<class Item, typename _Scalar = typename Item::scalar_t, int _CHUNK_SIZE = Item::CHUNK_SIZE>
GENERIC swarm::CoalescedStructArray< Item, _Scalar, _CHUNK_SIZE >::CoalescedStructArray ( PItem  array,
size_t  block_count 
)
inline

CoalescedStructArray lets you allocate the memory for the array.

the second argument is called block_count because the real number of items in the array is block_count*CHUNK_SIZE, since there are CHUNK_SIZE items in each block. This constructor can be used as:

CoalescedStructArray&lt;Item&gt; arr(new Item[n], n);

Memory management is left to the user because CoalescedStructArray is meant to be used by GPU functions and memory management in that case is very complicated.

Definition at line 121 of file coalescedstructarray.hpp.

Member Function Documentation

template<class Item, typename _Scalar = typename Item::scalar_t, int _CHUNK_SIZE = Item::CHUNK_SIZE>
GENERIC Item* swarm::CoalescedStructArray< Item, _Scalar, _CHUNK_SIZE >::begin ( )
inline

Begin pointer, it is a raw pointer.

It should only be used for copying the whole array

Definition at line 167 of file coalescedstructarray.hpp.

Referenced by swarm::EnsembleAlloc< ENSEMBLE_CHUNK_SIZE, DeviceAllocator >::copyTo().

template<class Item, typename _Scalar = typename Item::scalar_t, int _CHUNK_SIZE = Item::CHUNK_SIZE>
GENERIC int swarm::CoalescedStructArray< Item, _Scalar, _CHUNK_SIZE >::block_count ( ) const
inline

Number of blocks in this array.

Definition at line 146 of file coalescedstructarray.hpp.

template<class Item, typename _Scalar = typename Item::scalar_t, int _CHUNK_SIZE = Item::CHUNK_SIZE>
GENERIC Item* swarm::CoalescedStructArray< Item, _Scalar, _CHUNK_SIZE >::end ( )
inline

End pointer, it is a raw pointer.

It should only be used for copying the whole array

Definition at line 175 of file coalescedstructarray.hpp.

template<class Item, typename _Scalar = typename Item::scalar_t, int _CHUNK_SIZE = Item::CHUNK_SIZE>
GENERIC Item& swarm::CoalescedStructArray< Item, _Scalar, _CHUNK_SIZE >::operator[] ( const int &  i)
inline

The core functionality: overlapping Items to allow transparent coalesced access.

To calculate the address of item i, i is divided by CHUNK_SIZE, the quotient is the block address and remainder is the offset into the item. For example, if the remainder is 3, it means that we want to access the 3rd item of all scalar_t[CHUNK_SIZE] arrays. The trick is to slide the pointers by that amount so the item that we want to access becomes the first item so we can use the default accessors on the item.

Definition at line 135 of file coalescedstructarray.hpp.


The documentation for this struct was generated from the following file: