Skip to content

Commit b41b9da

Browse files
committed
GPU: Fix thread cluster offset count getting out of sync in case of buffer overflow in TPC compression kernel step1
1 parent 97df43f commit b41b9da

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.cxx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ GPUdii() void GPUTPCCompressionKernels::Thread<GPUTPCCompressionKernels::step1un
185185
GPUParam& GPUrestrict() param = processors.param;
186186
unsigned int* sortBuffer = smem.sortBuffer;
187187
for (int iSliceRow = iBlock; iSliceRow < GPUCA_NSLICES * GPUCA_ROW_COUNT; iSliceRow += nBlocks) {
188-
const int iSlice = iSliceRow / GPUCA_ROW_COUNT;
189-
const int iRow = iSliceRow % GPUCA_ROW_COUNT;
190-
const int idOffset = clusters->clusterOffset[iSlice][iRow];
191-
const int idOffsetOut = clusters->clusterOffset[iSlice][iRow] * compressor.mMaxClusterFactorBase1024 / 1024;
192-
const int idOffsetOutMax = ((const unsigned int*)clusters->clusterOffset[iSlice])[iRow + 1] * compressor.mMaxClusterFactorBase1024 / 1024; // Array out of bounds access is ok, since it goes to the correct nClustersTotal
188+
const unsigned int iSlice = iSliceRow / GPUCA_ROW_COUNT;
189+
const unsigned int iRow = iSliceRow % GPUCA_ROW_COUNT;
190+
const unsigned int idOffset = clusters->clusterOffset[iSlice][iRow];
191+
const unsigned int idOffsetOut = clusters->clusterOffset[iSlice][iRow] * compressor.mMaxClusterFactorBase1024 / 1024;
192+
const unsigned int idOffsetOutMax = ((const unsigned int*)clusters->clusterOffset[iSlice])[iRow + 1] * compressor.mMaxClusterFactorBase1024 / 1024; // Array out of bounds access is ok, since it goes to the correct nClustersTotal
193193
if (iThread == nThreads - 1) {
194194
smem.nCount = 0;
195195
}
@@ -250,6 +250,12 @@ GPUdii() void GPUTPCCompressionKernels::Thread<GPUTPCCompressionKernels::step1un
250250
}
251251

252252
unsigned int count = CAMath::Min(smem.nCount, (unsigned int)GPUCA_TPC_COMP_CHUNK_SIZE);
253+
if (idOffsetOut + totalCount + count > idOffsetOutMax) {
254+
if (iThread == nThreads - 1) {
255+
compressor.raiseError(GPUErrors::ERROR_COMPRESSION_ROW_HIT_OVERFLOW, iSlice * 1000 + iRow, idOffsetOut + totalCount + count, idOffsetOutMax);
256+
}
257+
break;
258+
}
253259
if (param.rec.tpc.compressionTypeMask & GPUSettings::CompressionDifferences) {
254260
if (param.rec.tpc.compressionSortOrder == GPUSettings::SortZPadTime) {
255261
CAAlgo::sortInBlock(sortBuffer, sortBuffer + count, GPUTPCCompressionKernels_Compare<GPUSettings::SortZPadTime>(clusters->clusters[iSlice][iRow]));
@@ -265,11 +271,6 @@ GPUdii() void GPUTPCCompressionKernels::Thread<GPUTPCCompressionKernels::step1un
265271

266272
for (unsigned int j = get_local_id(0); j < count; j += get_local_size(0)) {
267273
int outidx = idOffsetOut + totalCount + j;
268-
if (outidx >= idOffsetOutMax) {
269-
compressor.raiseError(GPUErrors::ERROR_COMPRESSION_ROW_HIT_OVERFLOW, iSlice * 1000 + iRow, outidx, idOffsetOutMax);
270-
count = 0;
271-
break;
272-
}
273274
const ClusterNative& GPUrestrict() orgCl = clusters->clusters[iSlice][iRow][sortBuffer[j]];
274275
unsigned int lastTime = 0;
275276
unsigned int lastPad = 0;

0 commit comments

Comments
 (0)