Skip to content

Commit c4d4de7

Browse files
committed
GPU: Add memoryScaling fuzzing debug option
1 parent 0386f65 commit c4d4de7

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

GPU/GPUTracking/Base/GPUReconstruction.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ int32_t GPUReconstruction::InitPhaseBeforeDevice()
304304
mProcessingSettings->rtc.optConstexpr = false;
305305
}
306306

307-
mMemoryScalers->factor = GetProcessingSettings().memoryScalingFactor;
307+
mMemoryScalers->scalingFactor = GetProcessingSettings().memoryScalingFactor;
308308
mMemoryScalers->conservative = GetProcessingSettings().conservativeMemoryEstimate;
309309
mMemoryScalers->returnMaxVal = GetProcessingSettings().forceMaxMemScalers != 0;
310310
if (GetProcessingSettings().forceMaxMemScalers > 1) {

GPU/GPUTracking/Base/GPUReconstructionCPU.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ int32_t GPUReconstructionCPU::ExitDevice()
216216
int32_t GPUReconstructionCPU::RunChains()
217217
{
218218
mMemoryScalers->temporaryFactor = 1.;
219+
if (GetProcessingSettings().memoryScalingFuzz) {
220+
static std::mt19937 rng;
221+
static std::uniform_int_distribution<uint64_t> dist(0, 1000000);
222+
uint64_t fuzzFactor = GetProcessingSettings().memoryScalingFuzz == 1 ? dist(rng) : GetProcessingSettings().memoryScalingFuzz;
223+
GPUInfo("Fuzzing memory scaling factor with %lu", fuzzFactor);
224+
mMemoryScalers->fuzzScalingFactor(fuzzFactor);
225+
}
226+
219227
mStatNEvents++;
220228
mNEventsProcessed++;
221229

GPU/GPUTracking/DataTypes/GPUMemorySizeScalers.cxx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "GPUMemorySizeScalers.h"
1616
#include "GPULogging.h"
1717

18+
#include <random>
19+
1820
using namespace o2::gpu;
1921

2022
void GPUMemorySizeScalers::rescaleMaxMem(size_t newAvailableMemory)
@@ -36,3 +38,27 @@ void GPUMemorySizeScalers::rescaleMaxMem(size_t newAvailableMemory)
3638
tpcMaxMergedTrackHits = (double)tmp.tpcMaxMergedTrackHits * scaleFactor;
3739
availableMemory = newAvailableMemory;
3840
}
41+
42+
double GPUMemorySizeScalers::getScalingFactor()
43+
{
44+
if (!doFuzzing) {
45+
return scalingFactor;
46+
}
47+
static std::uniform_int_distribution<uint32_t> dist(0, 1000000);
48+
static std::mt19937 rng;
49+
if (fuzzSeed) {
50+
rng = std::mt19937(fuzzSeed);
51+
fuzzLimit = dist(rng) / 10;
52+
fuzzSeed = 0;
53+
}
54+
if (dist(rng) > fuzzLimit) {
55+
return scalingFactor;
56+
}
57+
return scalingFactor * 0.000001 * dist(rng);
58+
}
59+
60+
void GPUMemorySizeScalers::fuzzScalingFactor(uint64_t seed)
61+
{
62+
fuzzSeed = seed;
63+
doFuzzing = true;
64+
}

GPU/GPUTracking/DataTypes/GPUMemorySizeScalers.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ struct GPUMemorySizeScalers {
2828
size_t nITSTracks = 0;
2929

3030
// General scaling factor
31-
double factor = 1;
31+
double scalingFactor = 1;
32+
uint64_t fuzzSeed = 0;
33+
uint64_t fuzzLimit = 0;
3234
double temporaryFactor = 1;
3335
bool conservative = 0;
3436

@@ -64,11 +66,14 @@ struct GPUMemorySizeScalers {
6466
size_t tpcMaxMergedTrackHits = 200000000;
6567
size_t availableMemory = 20500000000;
6668
bool returnMaxVal = false;
69+
bool doFuzzing = false;
6770

6871
void rescaleMaxMem(size_t newAvailableMemory);
72+
double getScalingFactor();
73+
void fuzzScalingFactor(uint64_t seed);
6974
inline size_t getValue(size_t maxVal, size_t val)
7075
{
71-
return returnMaxVal ? maxVal : (std::min<size_t>(maxVal, offset + val) * factor * temporaryFactor);
76+
return returnMaxVal ? maxVal : (std::min<size_t>(maxVal, offset + val) * (doFuzzing == 0 ? scalingFactor : getScalingFactor()) * temporaryFactor);
7277
}
7378

7479
inline size_t NTPCPeaks(size_t tpcDigits, bool perSector = false) { return getValue(perSector ? tpcMaxPeaks : (GPUCA_NSECTORS * tpcMaxPeaks), hitOffset + tpcDigits * tpcPeaksPerDigit); }
@@ -81,7 +86,7 @@ struct GPUMemorySizeScalers {
8186
inline size_t NTPCSectorTrackHits(size_t tpcHits, uint8_t withRejection = 0) { return getValue(tpcMaxSectorTrackHits, tpcHits * (withRejection ? tpcSectorTrackHitsPerHitWithRejection : tpcSectorTrackHitsPerHit)); }
8287
inline size_t NTPCMergedTracks(size_t tpcSectorTracks) { return getValue(tpcMaxMergedTracks, tpcSectorTracks * (conservative ? 1.0 : tpcMergedTrackPerSectorTrack)); }
8388
inline size_t NTPCMergedTrackHits(size_t tpcSectorTrackHitss) { return getValue(tpcMaxMergedTrackHits, tpcSectorTrackHitss * tpcMergedTrackHitPerSectorHit); }
84-
inline size_t NTPCUnattachedHitsBase1024(int32_t type) { return (returnMaxVal || conservative) ? 1024 : std::min<size_t>(1024, tpcCompressedUnattachedHitsBase1024[type] * factor * temporaryFactor); }
89+
inline size_t NTPCUnattachedHitsBase1024(int32_t type) { return (returnMaxVal || conservative) ? 1024 : std::min<size_t>(1024, tpcCompressedUnattachedHitsBase1024[type] * (doFuzzing == 0 ? scalingFactor : getScalingFactor()) * temporaryFactor); }
8590
};
8691

8792
} // namespace o2::gpu

GPU/GPUTracking/Definitions/GPUSettingsList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ AddOption(memoryAllocationStrategy, int8_t, 0, "", 0, "Memory Allocation Strageg
312312
AddOption(forceMemoryPoolSize, uint64_t, 1, "memSize", 0, "Force size of allocated GPU / page locked host memory", min(0ul))
313313
AddOption(forceHostMemoryPoolSize, uint64_t, 0, "hostMemSize", 0, "Force size of allocated host page locked host memory (overriding memSize)", min(0ul))
314314
AddOption(memoryScalingFactor, float, 1.f, "", 0, "Factor to apply to all memory scalers")
315+
AddOption(memoryScalingFuzz, uint64_t, 0, "", 0, "Fuzz the memoryScalingFactor (0 disable, 1 enable, >1 set seed", def(1))
315316
AddOption(conservativeMemoryEstimate, bool, false, "", 0, "Use some more conservative defaults for larger buffers during TPC processing")
316317
AddOption(tpcInputWithClusterRejection, uint8_t, 0, "", 0, "Indicate whether the TPC input is CTF data with cluster rejection, to tune buffer estimations")
317318
AddOption(forceMaxMemScalers, uint64_t, 0, "", 0, "Force using the maximum values for all buffers, Set a value n > 1 to rescale all maximums to a memory size of n")

GPU/GPUTracking/Interface/GPUO2Interface.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int32_t GPUO2Interface::Initialize(const GPUO2InterfaceConfiguration& config)
110110
return (1);
111111
}
112112
if (!mCtx[i].mRec->IsGPU() && mCtx[i].mRec->GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL) {
113-
mCtx[i].mRec->MemoryScalers()->factor *= 2;
113+
mCtx[i].mRec->MemoryScalers()->scalingFactor *= 2;
114114
}
115115
}
116116
if (mConfig->configProcessing.doublePipeline) {

0 commit comments

Comments
 (0)