PhoenixHardware  0.2.0
Tools to get hardware information
Loading...
Searching...
No Matches
phoenix_template_alloc_impl.h File Reference
+ Include dependency graph for phoenix_template_alloc_impl.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename T>
bool phoenix_checkIsAligned (const T *ptr)
 Check if the given pointer is aligned.
 
template<typename T>
size_t phoenix_getPadding (size_t nbElement)
 Get the padding with respect to the number of elements of the tables.
 
template<typename T>
void phoenix_newAlignedTab (T *&alignedPtr, size_t sizeOfVectorInT)
 Alloc an aligned vector.
 
template<typename T>
T * phoenix_template_alloc (size_t &padding, bool &isAligned, Phoenix::AllocMode mode, const size_t *tabDim, size_t nbDim)
 Allocate a tensor.
 
template<typename T>
T * phoenix_template_alloc_aligned1d (size_t nbValue)
 Do a template allcoation of a type.
 

Function Documentation

◆ phoenix_checkIsAligned()

template<typename T>
bool phoenix_checkIsAligned ( const T * ptr)

Check if the given pointer is aligned.

Parameters
ptr: pointer
Returns
true if the given pointer is aligned, false otherwise

Definition at line 101 of file phoenix_template_alloc_impl.h.

101 {
102 return (((size_t)ptr) % phoenix_alignement_in_bytes<T>()) == 0lu;
103}
size_t phoenix_alignement_in_bytes()
Get the alignement in bytes by respect to the type.

References phoenix_alignement_in_bytes().

+ Here is the call graph for this function:

◆ phoenix_getPadding()

template<typename T>
size_t phoenix_getPadding ( size_t nbElement)

Get the padding with respect to the number of elements of the tables.

Parameters
nbElement: number of elements of the table
Returns
associated padding

Definition at line 17 of file phoenix_template_alloc_impl.h.

17 {
18 size_t regVecSizeType(phoenix_alignement_type<T>());
19 size_t padding = regVecSizeType - (nbElement % regVecSizeType);
20 if(padding == regVecSizeType){padding = 0lu;}
21 return padding;
22}
size_t phoenix_alignement_type()
Get the alignement by respect to the type.

References phoenix_alignement_type().

Referenced by phoenix_template_alloc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ phoenix_newAlignedTab()

template<typename T>
void phoenix_newAlignedTab ( T *& alignedPtr,
size_t sizeOfVectorInT )

Alloc an aligned vector.

Parameters
alignedPtr: aligned pointor
sizeOfVectorInT: size of the vector we want to allocate
alignementInBytes: alignement of the vector we want to allocate, in bytes

Usage : T* alignedVector = NULL; newAlignedTab(alignedVector, sizeOfVectorInT); ... Using of alignedVector pointor ... freeAlignedVector(alignedVector);

Definition at line 92 of file phoenix_template_alloc_impl.h.

92 {
93 alignedPtr = (T*)phoenix_allocAlignedTab(sizeOfVectorInT*sizeof(T), phoenix_alignement_in_bytes<T>());
94}
void * phoenix_allocAlignedTab(size_t sizeOfVectorInBytes, size_t alignementInBytes)
Alloc an aligned vector.

References phoenix_alignement_in_bytes(), and phoenix_allocAlignedTab().

+ Here is the call graph for this function:

◆ phoenix_template_alloc()

template<typename T>
T * phoenix_template_alloc ( size_t & padding,
bool & isAligned,
Phoenix::AllocMode mode,
const size_t * tabDim,
size_t nbDim )

Allocate a tensor.

Parameters
[out]padding: padding of the allocated tensor if it needs one
[out]isAligned: true if the allocated tensor is aligned, false otherwise
mode: allocation mode
tabDim: table of the dimensions of the tensor
nbDim: number of dimensions of the tensor
Returns
allocated pointer or NULL on failure

Definition at line 33 of file phoenix_template_alloc_impl.h.

33 {
34 padding = 0lu;
35 isAligned = false;
36 if(mode == Phoenix::NONE){
37 T * tabData = new T[phoenix_getFullSize(tabDim, nbDim)];
38 return tabData;
39 }else if(mode == Phoenix::ALIGNED){
40 isAligned = true;
41 size_t alignementInByte(phoenix_alignement_in_bytes<T>());
42 if(alignementInByte == 0lu){ //No alignement for this type
43 T * tabData = new T[phoenix_getFullSize(tabDim, nbDim)];
44 return tabData;
45 }else{
46 T * tabData = (T*)phoenix_allocAlignedTab(phoenix_getFullSize(tabDim, nbDim)*sizeof(T), alignementInByte);
47 return tabData;
48 }
49 }else if(mode == Phoenix::PADDING){
50 isAligned = true;
51 size_t alignementInByte(phoenix_alignement_in_bytes<T>());
52 if(alignementInByte == 0lu){ //No alignement for this type
53 T * tabData = new T[phoenix_getFullSize(tabDim, nbDim)];
54 return tabData;
55 }else{
56 size_t fullSize(phoenix_getFullSize(tabDim, nbDim));
57 size_t nbCol(tabDim[nbDim - 1lu]);
58 size_t nbRow(fullSize/nbCol);
59 padding = phoenix_getPadding<T>(nbCol);
60 T * tabData = (T*)phoenix_allocAlignedTab((nbRow*(nbCol + padding))*sizeof(T), alignementInByte);
61 return tabData;
62 }
63 }
64 return NULL;
65}
size_t phoenix_getFullSize(const size_t *tabDim, size_t nbDim)
Get the fulle size of the tensor.
size_t phoenix_getPadding(size_t nbElement)
Get the padding with respect to the number of elements of the tables.

References Phoenix::ALIGNED, Phoenix::NONE, Phoenix::PADDING, phoenix_alignement_in_bytes(), phoenix_allocAlignedTab(), phoenix_getFullSize(), and phoenix_getPadding().

Referenced by phoenix_template_alloc_aligned1d().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ phoenix_template_alloc_aligned1d()

template<typename T>
T * phoenix_template_alloc_aligned1d ( size_t nbValue)

Do a template allcoation of a type.

Parameters
nbValue: number of value to be allcoated
Returns
allcated table

Definition at line 72 of file phoenix_template_alloc_impl.h.

72 {
73 size_t padding(0lu);
74 bool isAligned(false);
75 return phoenix_template_alloc<T>(padding, isAligned, Phoenix::ALIGNED, &nbValue, 1lu);
76}
T * phoenix_template_alloc(size_t &padding, bool &isAligned, Phoenix::AllocMode mode, const size_t *tabDim, size_t nbDim)
Allocate a tensor.

References Phoenix::ALIGNED, and phoenix_template_alloc().

Referenced by PAlignedAllocator< T >::allocate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: