PhoenixHardware
0.2.0
Tools to get hardware information
Toggle main menu visibility
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
10
#include "
phoenix_template_alloc.h
"
11
13
16
template
<
typename
T>
17
size_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
32
template
<
typename
T>
33
T *
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
71
template
<
typename
T>
72
T *
phoenix_template_alloc_aligned1d
(
size_t
nbValue){
73
size_t
padding(0lu);
74
bool
isAligned(
false
);
75
return
phoenix_template_alloc<T>
(padding, isAligned,
Phoenix::ALIGNED
, &nbValue, 1lu);
76
}
77
79
91
template
<
typename
T>
92
void
phoenix_newAlignedTab
(T* & alignedPtr,
size_t
sizeOfVectorInT){
93
alignedPtr = (T*)
phoenix_allocAlignedTab
(sizeOfVectorInT*
sizeof
(T),
phoenix_alignement_in_bytes<T>
());
94
}
95
97
100
template
<
typename
T>
101
bool
phoenix_checkIsAligned
(
const
T* ptr){
102
return
(((
size_t
)ptr) %
phoenix_alignement_in_bytes<T>
()) == 0lu;
103
}
104
105
#endif
106
Phoenix::AllocMode
AllocMode
Allocation mode of the PTensor.
Definition
phoenix_template_alloc.h:16
Phoenix::ALIGNED
@ ALIGNED
Definition
phoenix_template_alloc.h:18
Phoenix::PADDING
@ PADDING
Definition
phoenix_template_alloc.h:19
Phoenix::NONE
@ NONE
Definition
phoenix_template_alloc.h:17
phoenix_alignement_type
size_t phoenix_alignement_type()
Get the alignement by respect to the type.
Definition
phoenix_alignement_type_impl.h:16
phoenix_alignement_in_bytes
size_t phoenix_alignement_in_bytes()
Get the alignement in bytes by respect to the type.
Definition
phoenix_alignement_type_impl.h:24
phoenix_allocAlignedTab
void * phoenix_allocAlignedTab(size_t sizeOfVectorInBytes, size_t alignementInBytes)
Alloc an aligned vector.
Definition
phoenix_allocAlignedVector.cpp:35
phoenix_getFullSize
size_t phoenix_getFullSize(const size_t *tabDim, size_t nbDim)
Get the fulle size of the tensor.
Definition
phoenix_template_alloc.cpp:15
phoenix_template_alloc.h
phoenix_getPadding
size_t phoenix_getPadding(size_t nbElement)
Get the padding with respect to the number of elements of the tables.
Definition
phoenix_template_alloc_impl.h:17
phoenix_newAlignedTab
void phoenix_newAlignedTab(T *&alignedPtr, size_t sizeOfVectorInT)
Alloc an aligned vector.
Definition
phoenix_template_alloc_impl.h:92
phoenix_template_alloc_aligned1d
T * phoenix_template_alloc_aligned1d(size_t nbValue)
Do a template allcoation of a type.
Definition
phoenix_template_alloc_impl.h:72
phoenix_template_alloc
T * phoenix_template_alloc(size_t &padding, bool &isAligned, Phoenix::AllocMode mode, const size_t *tabDim, size_t nbDim)
Allocate a tensor.
Definition
phoenix_template_alloc_impl.h:33
phoenix_checkIsAligned
bool phoenix_checkIsAligned(const T *ptr)
Check if the given pointer is aligned.
Definition
phoenix_template_alloc_impl.h:101
src
phoenix_template_alloc_impl.h
Generated by
1.17.0