GCC Code Coverage Report


Directory: ./
File: src/phoenix_template_alloc_impl.h
Date: 2025-08-06 14:32:39
Exec Total Coverage
Lines: 21 38 55.3%
Functions: 14 14 100.0%
Branches: 6 19 31.6%

Line Branch Exec Source
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
12 ///Get the padding with respect to the number of elements of the tables
13 /** @param nbElement : number of elements of the table
14 * @return associated padding
15 */
16 template<typename T>
17 22 size_t phoenix_getPadding(size_t nbElement){
18 22 size_t regVecSizeType(phoenix_alignement_type<T>());
19 22 size_t padding = regVecSizeType - (nbElement % regVecSizeType);
20
2/2
✓ Branch 0 (3→4) taken 11 times.
✓ Branch 1 (3→5) taken 11 times.
22 if(padding == regVecSizeType){padding = 0lu;}
21 22 return padding;
22 }
23
24 ///Allocate a tensor
25 /** @param[out] padding : padding of the allocated tensor if it needs one
26 * @param[out] isAligned : true if the allocated tensor is aligned, false otherwise
27 * @param mode : allocation mode
28 * @param tabDim : table of the dimensions of the tensor
29 * @param nbDim : number of dimensions of the tensor
30 * @return allocated pointer or NULL on failure
31 */
32 template<typename T>
33 1 T * phoenix_template_alloc(size_t & padding, bool & isAligned, Phoenix::AllocMode mode, const size_t * tabDim, size_t nbDim){
34 1 padding = 0lu;
35 1 isAligned = false;
36
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→9) taken 1 times.
1 if(mode == Phoenix::NONE){
37 T * tabData = new T[phoenix_getFullSize(tabDim, nbDim)];
38 return tabData;
39
1/2
✓ Branch 0 (9→10) taken 1 times.
✗ Branch 1 (9→21) not taken.
1 }else if(mode == Phoenix::ALIGNED){
40 1 isAligned = true;
41 1 size_t alignementInByte(phoenix_alignement_in_bytes<T>());
42
1/2
✗ Branch 0 (11→12) not taken.
✓ Branch 1 (11→18) taken 1 times.
1 if(alignementInByte == 0lu){ //No alignement for this type
43 T * tabData = new T[phoenix_getFullSize(tabDim, nbDim)];
44 return tabData;
45 }else{
46 1 T * tabData = (T*)phoenix_allocAlignedTab(phoenix_getFullSize(tabDim, nbDim)*sizeof(T), alignementInByte);
47 1 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
67 ///Do a template allcoation of a type
68 /** @param nbValue : number of value to be allcoated
69 * @return allcated table
70 */
71 template<typename T>
72 1 T * phoenix_template_alloc_aligned1d(size_t nbValue){
73 1 size_t padding(0lu);
74 1 bool isAligned(false);
75
1/1
✓ Branch 0 (2→3) taken 1 times.
2 return phoenix_template_alloc<T>(padding, isAligned, Phoenix::ALIGNED, &nbValue, 1lu);
76 }
77
78 ///Alloc an aligned vector
79 /** @param alignedPtr : aligned pointor
80 * @param sizeOfVectorInT : size of the vector we want to allocate
81 * @param alignementInBytes : alignement of the vector we want to allocate, in bytes
82 *
83 * Usage :
84 * T* alignedVector = NULL;
85 * newAlignedTab(alignedVector, sizeOfVectorInT);
86 * ...
87 * Using of alignedVector pointor
88 * ...
89 * freeAlignedVector(alignedVector);
90 */
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
96 ///Check if the given pointer is aligned
97 /** @param ptr : pointer
98 * @return true if the given pointer is aligned, false otherwise
99 */
100 template<typename T>
101 1 bool phoenix_checkIsAligned(const T* ptr){
102 1 return (((size_t)ptr) % phoenix_alignement_in_bytes<T>()) == 0lu;
103 }
104
105 #endif
106
107