PhoenixHardware  0.2.0
Tools to get hardware information
Loading...
Searching...
No Matches
phoenix_template_alloc_impl.h
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#ifndef __PHOENIX_TEMPLATE_ALLOC_IMPL_H__
8#define __PHOENIX_TEMPLATE_ALLOC_IMPL_H__
9
11
13
16template<typename T>
17size_t phoenix_getPadding(size_t nbElement){
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}
23
25
32template<typename T>
33T * phoenix_template_alloc(size_t & padding, bool & isAligned, Phoenix::AllocMode mode, const size_t * tabDim, size_t nbDim){
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}
66
68
71template<typename T>
73 size_t padding(0lu);
74 bool isAligned(false);
75 return phoenix_template_alloc<T>(padding, isAligned, Phoenix::ALIGNED, &nbValue, 1lu);
76}
77
79
91template<typename T>
92void phoenix_newAlignedTab(T* & alignedPtr, size_t sizeOfVectorInT){
93 alignedPtr = (T*)phoenix_allocAlignedTab(sizeOfVectorInT*sizeof(T), phoenix_alignement_in_bytes<T>());
94}
95
97
100template<typename T>
101bool phoenix_checkIsAligned(const T* ptr){
102 return (((size_t)ptr) % phoenix_alignement_in_bytes<T>()) == 0lu;
103}
104
105#endif
106
AllocMode
Allocation mode of the PTensor.
size_t phoenix_alignement_type()
Get the alignement by respect to the type.
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.
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.
void phoenix_newAlignedTab(T *&alignedPtr, size_t sizeOfVectorInT)
Alloc an aligned vector.
T * phoenix_template_alloc_aligned1d(size_t nbValue)
Do a template allcoation of a type.
T * phoenix_template_alloc(size_t &padding, bool &isAligned, Phoenix::AllocMode mode, const size_t *tabDim, size_t nbDim)
Allocate a tensor.
bool phoenix_checkIsAligned(const T *ptr)
Check if the given pointer is aligned.