Skip to content

Commit 3b23e9a

Browse files
committed
TPCFastTransform: Do not pollute the global namespace
1 parent 73d9a50 commit 3b23e9a

File tree

4 files changed

+73
-75
lines changed

4 files changed

+73
-75
lines changed

Detectors/Base/src/MatLayerCyl.cxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void MatLayerCyl::initSegmentation(float rMin, float rMax, float zHalfSpan, int
8383
//
8484
int offs = 0;
8585

86-
o2::gpu::resizeArray(mPhiBin2Slice, 0, nphi, reinterpret_cast<short*>(mFlatBufferPtr + offs));
86+
o2::gpu::FlatObject::FlatObject::resizeArray(mPhiBin2Slice, 0, nphi, reinterpret_cast<short*>(mFlatBufferPtr + offs));
8787
mNPhiSlices = mNPhiBins = nphi;
8888

8989
for (int i = nphi; i--;) {
@@ -92,18 +92,18 @@ void MatLayerCyl::initSegmentation(float rMin, float rMax, float zHalfSpan, int
9292

9393
offs = alignSize(offs + nphi * sizeof(short), getBufferAlignmentBytes()); // account for alignment
9494

95-
o2::gpu::resizeArray(mSliceCos, 0, nphi, reinterpret_cast<float*>(mFlatBufferPtr + offs)); // in the beginning nslice = nphi
95+
o2::gpu::FlatObject::resizeArray(mSliceCos, 0, nphi, reinterpret_cast<float*>(mFlatBufferPtr + offs)); // in the beginning nslice = nphi
9696
offs = alignSize(offs + nphi * sizeof(float), getBufferAlignmentBytes()); // account for alignment
9797

98-
o2::gpu::resizeArray(mSliceSin, 0, nphi, reinterpret_cast<float*>(mFlatBufferPtr + offs)); // in the beginning nslice = nphi
98+
o2::gpu::FlatObject::resizeArray(mSliceSin, 0, nphi, reinterpret_cast<float*>(mFlatBufferPtr + offs)); // in the beginning nslice = nphi
9999
offs = alignSize(offs + nphi * sizeof(float), getBufferAlignmentBytes()); // account for alignment
100100

101101
for (int i = nphi; i--;) {
102102
mSliceCos[i] = o2::math_utils::cos(getPhiBinMin(i));
103103
mSliceSin[i] = o2::math_utils::sin(getPhiBinMin(i));
104104
}
105105

106-
o2::gpu::resizeArray(mCells, 0, getNCells(), reinterpret_cast<MatCell*>(mFlatBufferPtr + offs));
106+
o2::gpu::FlatObject::resizeArray(mCells, 0, getNCells(), reinterpret_cast<MatCell*>(mFlatBufferPtr + offs));
107107

108108
mConstructionMask = InProgress;
109109
}
@@ -245,10 +245,10 @@ void MatLayerCyl::optimizePhiSlices(float maxRelDiff)
245245
// mSliceCos pointer does not change, but sliceSin needs to be relocated
246246
auto offs = alignSize(newSl * sizeof(float), getBufferAlignmentBytes());
247247
char* dst = ((char*)mSliceCos) + offs; // account for alignment
248-
o2::gpu::resizeArray(mSliceSin, getNPhiBins(), newSl, reinterpret_cast<float*>(dst));
248+
o2::gpu::FlatObject::resizeArray(mSliceSin, getNPhiBins(), newSl, reinterpret_cast<float*>(dst));
249249
// adjust mCells array
250250
dst = ((char*)mSliceSin) + offs; // account for alignment
251-
o2::gpu::resizeArray(mCells, getNPhiBins() * getNZBins(), newSl * getNZBins(), reinterpret_cast<MatCell*>(dst));
251+
o2::gpu::FlatObject::resizeArray(mCells, getNPhiBins() * getNZBins(), newSl * getNZBins(), reinterpret_cast<MatCell*>(dst));
252252
mFlatBufferSize = estimateFlatBufferSize();
253253
LOG(info) << "Updated Nslices = " << getNPhiSlices();
254254
}
@@ -313,7 +313,7 @@ void MatLayerCyl::flatten(char* newPtr)
313313
// make object flat: move all content to single internally allocated buffer
314314
assert(mConstructionMask == InProgress);
315315
fixPointers(mFlatBufferPtr, newPtr);
316-
auto old = o2::gpu::resizeArray(mFlatBufferPtr, getFlatBufferSize(), getFlatBufferSize(), newPtr);
316+
auto old = o2::gpu::FlatObject::resizeArray(mFlatBufferPtr, getFlatBufferSize(), getFlatBufferSize(), newPtr);
317317
delete[] old;
318318
mFlatBufferContainer = nullptr;
319319
mConstructionMask = Constructed;

Detectors/Base/src/MatLayerCylSet.cxx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void MatLayerCylSet::addLayer(float rmin, float rmax, float zmax, float dz, floa
3939
if (!nlr) {
4040
// book local storage
4141
auto sz = sizeof(MatLayerCylSetLayout);
42-
o2::gpu::resizeArray(mFlatBufferContainer, 0, sz);
42+
o2::gpu::FlatObject::resizeArray(mFlatBufferContainer, 0, sz);
4343
mFlatBufferPtr = mFlatBufferContainer;
4444
mFlatBufferSize = sz;
4545
//--------------????
@@ -53,7 +53,7 @@ void MatLayerCylSet::addLayer(float rmin, float rmax, float zmax, float dz, floa
5353
LOG(fatal) << "new layer overlaps with layer " << il;
5454
}
5555
}
56-
auto* oldLayers = o2::gpu::resizeArray(get()->mLayers, nlr, nlr + 1);
56+
auto* oldLayers = o2::gpu::FlatObject::resizeArray(get()->mLayers, nlr, nlr + 1);
5757
// dynamyc buffers of old layers were used in new ones, detach them
5858
for (int i = nlr; i--;) {
5959
oldLayers[i].clearInternalBufferPtr();
@@ -98,8 +98,8 @@ void MatLayerCylSet::finalizeStructures()
9898
assert(mConstructionMask == InProgress);
9999
int nlr = getNLayers();
100100
int nR2Int = 2 * (nlr + 1);
101-
o2::gpu::resizeArray(get()->mR2Intervals, 0, nR2Int);
102-
o2::gpu::resizeArray(get()->mInterval2LrID, 0, nR2Int);
101+
o2::gpu::FlatObject::resizeArray(get()->mR2Intervals, 0, nR2Int);
102+
o2::gpu::FlatObject::resizeArray(get()->mInterval2LrID, 0, nR2Int);
103103
get()->mR2Intervals[0] = get()->mRMin2;
104104
get()->mR2Intervals[1] = get()->mRMax2;
105105
get()->mInterval2LrID[0] = 0;
@@ -116,8 +116,8 @@ void MatLayerCylSet::finalizeStructures()
116116
get()->mInterval2LrID[nRIntervals] = i;
117117
get()->mR2Intervals[++nRIntervals] = lr.getRMax2();
118118
}
119-
delete[] o2::gpu::resizeArray(get()->mInterval2LrID, nR2Int, nRIntervals); // rebook with precise size
120-
delete[] o2::gpu::resizeArray(get()->mR2Intervals, nR2Int, ++nRIntervals); // rebook with precise size
119+
delete[] o2::gpu::FlatObject::resizeArray(get()->mInterval2LrID, nR2Int, nRIntervals); // rebook with precise size
120+
delete[] o2::gpu::FlatObject::resizeArray(get()->mR2Intervals, nR2Int, ++nRIntervals); // rebook with precise size
121121
//
122122
}
123123

@@ -508,14 +508,14 @@ void MatLayerCylSet::flatten()
508508

509509
int sz = estimateFlatBufferSize();
510510
// create new internal buffer with total size and copy data
511-
delete[] o2::gpu::resizeArray(mFlatBufferContainer, mFlatBufferSize, sz);
511+
delete[] o2::gpu::FlatObject::resizeArray(mFlatBufferContainer, mFlatBufferSize, sz);
512512
mFlatBufferPtr = mFlatBufferContainer;
513513
mFlatBufferSize = sz;
514514
int nLr = getNLayers();
515515

516516
auto offs = alignSize(sizeof(MatLayerCylSetLayout), getBufferAlignmentBytes()); // account for the alignment
517517
// move array of layer pointers to the flat array
518-
auto* oldLayers = o2::gpu::resizeArray(get()->mLayers, nLr, nLr, (MatLayerCyl*)(mFlatBufferPtr + offs));
518+
auto* oldLayers = o2::gpu::FlatObject::resizeArray(get()->mLayers, nLr, nLr, (MatLayerCyl*)(mFlatBufferPtr + offs));
519519
// dynamyc buffers of old layers were used in new ones, detach them
520520
for (int i = nLr; i--;) {
521521
oldLayers[i].clearInternalBufferPtr();
@@ -524,11 +524,11 @@ void MatLayerCylSet::flatten()
524524
offs = alignSize(offs + nLr * sizeof(MatLayerCyl), MatLayerCyl::getClassAlignmentBytes()); // account for the alignment
525525

526526
// move array of R2 boundaries to the flat array
527-
delete[] o2::gpu::resizeArray(get()->mR2Intervals, nLr + 1, nLr + 1, (float*)(mFlatBufferPtr + offs));
527+
delete[] o2::gpu::FlatObject::resizeArray(get()->mR2Intervals, nLr + 1, nLr + 1, (float*)(mFlatBufferPtr + offs));
528528
offs = alignSize(offs + (nLr + 1) * sizeof(float), getBufferAlignmentBytes()); // account for the alignment
529529

530530
// move array of R2 boundaries to the flat array
531-
delete[] o2::gpu::resizeArray(get()->mInterval2LrID, nLr, nLr, (int*)(mFlatBufferPtr + offs));
531+
delete[] o2::gpu::FlatObject::resizeArray(get()->mInterval2LrID, nLr, nLr, (int*)(mFlatBufferPtr + offs));
532532
offs = alignSize(offs + nLr * sizeof(int), getBufferAlignmentBytes()); // account for the alignment
533533

534534
for (int il = 0; il < nLr; il++) {

GPU/TPCFastTransformation/TPCFastTransform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class TPCFastTransform : public FlatObject
115115
}
116116

117117
/// Destructor
118-
#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
118+
#if !defined(GPUCA_GPUCODE)
119119
~TPCFastTransform()
120120
{
121121
delete mCorrectionSlow;

GPU/Utils/FlatObject.h

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -115,63 +115,6 @@ namespace gpu
115115
/// before the transport. The object will be ready-to-use right after the porting.
116116
///
117117

118-
#ifndef GPUCA_GPUCODE // code invisible on GPU
119-
120-
template <typename T>
121-
T* resizeArray(T*& ptr, int32_t oldSize, int32_t newSize, T* newPtr = nullptr)
122-
{
123-
// Resize array pointed by ptr. T must be a POD class.
124-
// If the non-null newPtr is provided, use it instead of allocating a new one.
125-
// In this case it is up to the user to ensure that it has at least newSize slots allocated.
126-
// Return original array pointer, so that the user can manage previously allocate memory
127-
if (oldSize < 0) {
128-
oldSize = 0;
129-
}
130-
if (newSize > 0) {
131-
if (!newPtr) {
132-
newPtr = new T[newSize];
133-
}
134-
int32_t mcp = std::min(newSize, oldSize);
135-
if (mcp) {
136-
assert(ptr);
137-
std::memmove(newPtr, ptr, mcp * sizeof(T));
138-
}
139-
if (newSize > oldSize) {
140-
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T));
141-
}
142-
}
143-
T* oldPtr = ptr;
144-
ptr = newPtr;
145-
return oldPtr;
146-
}
147-
148-
template <typename T>
149-
T** resizeArray(T**& ptr, int32_t oldSize, int32_t newSize, T** newPtr = nullptr)
150-
{
151-
// Resize array of pointers pointed by ptr.
152-
// If the non-null newPtr is provided, use it instead of allocating a new one.
153-
// In this case it is up to the user to ensure that it has at least newSize slots allocated.
154-
// Return original array pointer, so that the user can manage previously allocate memory
155-
if (oldSize < 0) {
156-
oldSize = 0;
157-
}
158-
if (newSize > 0) {
159-
if (!newPtr) {
160-
newPtr = new T*[newSize];
161-
}
162-
int32_t mcp = std::min(newSize, oldSize);
163-
std::memmove(newPtr, ptr, mcp * sizeof(T*));
164-
if (newSize > oldSize) {
165-
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T*));
166-
}
167-
}
168-
T** oldPtr = ptr;
169-
ptr = newPtr;
170-
return oldPtr;
171-
}
172-
173-
#endif //! GPUCA_GPUCODE
174-
175118
class FlatObject
176119
{
177120
public:
@@ -187,6 +130,61 @@ class FlatObject
187130
FlatObject() = delete;
188131
#endif
189132

133+
#ifndef GPUCA_GPUCODE // code invisible on GPU
134+
template <typename T>
135+
T* resizeArray(T*& ptr, int32_t oldSize, int32_t newSize, T* newPtr = nullptr)
136+
{
137+
// Resize array pointed by ptr. T must be a POD class.
138+
// If the non-null newPtr is provided, use it instead of allocating a new one.
139+
// In this case it is up to the user to ensure that it has at least newSize slots allocated.
140+
// Return original array pointer, so that the user can manage previously allocate memory
141+
if (oldSize < 0) {
142+
oldSize = 0;
143+
}
144+
if (newSize > 0) {
145+
if (!newPtr) {
146+
newPtr = new T[newSize];
147+
}
148+
int32_t mcp = std::min(newSize, oldSize);
149+
if (mcp) {
150+
assert(ptr);
151+
std::memmove(newPtr, ptr, mcp * sizeof(T));
152+
}
153+
if (newSize > oldSize) {
154+
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T));
155+
}
156+
}
157+
T* oldPtr = ptr;
158+
ptr = newPtr;
159+
return oldPtr;
160+
}
161+
162+
template <typename T>
163+
T** resizeArray(T**& ptr, int32_t oldSize, int32_t newSize, T** newPtr = nullptr)
164+
{
165+
// Resize array of pointers pointed by ptr.
166+
// If the non-null newPtr is provided, use it instead of allocating a new one.
167+
// In this case it is up to the user to ensure that it has at least newSize slots allocated.
168+
// Return original array pointer, so that the user can manage previously allocate memory
169+
if (oldSize < 0) {
170+
oldSize = 0;
171+
}
172+
if (newSize > 0) {
173+
if (!newPtr) {
174+
newPtr = new T*[newSize];
175+
}
176+
int32_t mcp = std::min(newSize, oldSize);
177+
std::memmove(newPtr, ptr, mcp * sizeof(T*));
178+
if (newSize > oldSize) {
179+
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T*));
180+
}
181+
}
182+
T** oldPtr = ptr;
183+
ptr = newPtr;
184+
return oldPtr;
185+
}
186+
#endif //! GPUCA_GPUCODE
187+
190188
protected:
191189
/// _____________ Memory alignment __________________________
192190

0 commit comments

Comments
 (0)