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

Go to the source code of this file.

Namespaces

namespace  Phoenix
 

Macros

#define PHOENIX_AUTO_ALIGNED   Phoenix::ALIGNED
 
#define PHOENIX_AUTO_PADDING   Phoenix::PADDING
 

Enumerations

enum  Phoenix::AllocMode { Phoenix::NONE = 0 , Phoenix::ALIGNED = 1 , Phoenix::PADDING = 2 }
 Allocation mode of the PTensor. More...
 

Functions

void phoenix_copyShape (size_t *&destTabDim, const size_t *tabDim, size_t nbDim)
 Copy a shape of a tensor into an other.
 
void phoenix_copyShape (size_t *&destTabDim, size_t &destNbDim, const size_t *tabDim, size_t nbDim)
 Copy a shape of a tensor into an other.
 
size_t phoenix_getFullSize (const size_t *tabDim, size_t nbDim)
 Get the fulle size of the tensor.
 
template<typename T>
size_t phoenix_getPadding (size_t nbElement)
 Get the padding with respect to the number of elements of the tables.
 
bool phoenix_isSameShape (const size_t *tabDim1, size_t nbDim1, const size_t *tabDim2, size_t nbDim2)
 Say if two shapes are the same or not.
 
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.
 

Macro Definition Documentation

◆ PHOENIX_AUTO_ALIGNED

#define PHOENIX_AUTO_ALIGNED   Phoenix::ALIGNED

Definition at line 27 of file phoenix_template_alloc.h.

◆ PHOENIX_AUTO_PADDING

#define PHOENIX_AUTO_PADDING   Phoenix::PADDING

Definition at line 28 of file phoenix_template_alloc.h.

Function Documentation

◆ phoenix_copyShape() [1/2]

void phoenix_copyShape ( size_t *& destTabDim,
const size_t * tabDim,
size_t nbDim )

Copy a shape of a tensor into an other.

Parameters
[out]destTabDim: copy of the table of the size of each dimension
tabDim: table of the size of each dimension
nbDim: number of dimensions

Definition at line 28 of file phoenix_template_alloc.cpp.

28 {
29 if(destTabDim != NULL){
30 delete [] destTabDim;
31 destTabDim = NULL;
32 }
33 if(nbDim == 0lu || tabDim == NULL){
34 destTabDim = NULL;
35 return;
36 }
37 destTabDim = new size_t[nbDim];
38 memcpy(destTabDim, tabDim, nbDim*sizeof(size_t));
39}

Referenced by phoenix_copyShape().

+ Here is the caller graph for this function:

◆ phoenix_copyShape() [2/2]

void phoenix_copyShape ( size_t *& destTabDim,
size_t & destNbDim,
const size_t * tabDim,
size_t nbDim )

Copy a shape of a tensor into an other.

Parameters
[out]destTabDim: copy of the table of the size of each dimension
[out]destNbDim: copy of the number of dimensions
tabDim: table of the size of each dimension
nbDim: number of dimensions

Definition at line 47 of file phoenix_template_alloc.cpp.

47 {
48 destNbDim = nbDim;
49 phoenix_copyShape(destTabDim, tabDim, nbDim);
50}
void phoenix_copyShape(size_t *&destTabDim, const size_t *tabDim, size_t nbDim)
Copy a shape of a tensor into an other.

References phoenix_copyShape().

+ Here is the call graph for this function:

◆ phoenix_getFullSize()

size_t phoenix_getFullSize ( const size_t * tabDim,
size_t nbDim )

Get the fulle size of the tensor.

Parameters
tabDim: table of the dimensions of the tensor
nbDim: number of dimensions of the tensor
Returns
size of the tensor

Definition at line 15 of file phoenix_template_alloc.cpp.

15 {
16 size_t fullSize(1lu);
17 for(size_t i(0lu); i < nbDim; ++i){
18 fullSize *= tabDim[i];
19 }
20 return fullSize;
21}

Referenced by phoenix_template_alloc().

+ Here is the caller 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_isSameShape()

bool phoenix_isSameShape ( const size_t * tabDim1,
size_t nbDim1,
const size_t * tabDim2,
size_t nbDim2 )

Say if two shapes are the same or not.

Parameters
tabDim1: table of the size of each dimension
nbDim1: number of dimensions
tabDim2: table of the size of each dimension
nbDim2: number of dimensions
Returns
true if the shapes are equal, false otherwise

Definition at line 59 of file phoenix_template_alloc.cpp.

59 {
60 if(tabDim1 == NULL && tabDim2 == NULL){return true;}
61 if(nbDim1 != nbDim2 || tabDim1 == NULL || tabDim2 == NULL){return false;}
62 bool isSameSize(true);
63 size_t i(0lu);
64 while(isSameSize && i < nbDim1){
65 isSameSize = tabDim1[i] == tabDim2[i];
66 ++i;
67 }
68 return isSameSize;
69}

◆ 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}
size_t phoenix_alignement_in_bytes()
Get the alignement in bytes by respect to the type.
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: