Skip to content

Commit fde54ec

Browse files
committed
GPU: allow standalone benchmark to work on macOS with Metal
1 parent 241b704 commit fde54ec

5 files changed

Lines changed: 29 additions & 15 deletions

File tree

‎GPU/GPUTracking/Base/GPUReconstructionTimeframe.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ int32_t GPUReconstructionTimeframe::LoadCreateTimeFrame(int32_t iEvent)
233233
return (2);
234234
}
235235

236-
int64_t nBunch = -DRIFT_TIME / config.bunchSpacing;
236+
int32_t nBunch = -DRIFT_TIME / config.bunchSpacing;
237237
int64_t lastBunch = config.timeFrameLen / config.bunchSpacing;
238238
int64_t lastTFBunch = lastBunch - DRIFT_TIME / config.bunchSpacing;
239239
int32_t nCollisions = 0, nBorderCollisions = 0, nTrainCollissions = 0, nMultipleCollisions = 0, nTrainMultipleCollisions = 0;
@@ -290,7 +290,7 @@ int32_t GPUReconstructionTimeframe::LoadCreateTimeFrame(int32_t iEvent)
290290
return (1);
291291
}
292292
nTotalClusters += nClusters;
293-
printf("Placing event %4d+%d (ID %4d) at z %7.3f (time %'dns) %s(collisions %4d, bunch %6ld, train %3d) (%'10d clusters, %'10d MC labels, %'10d track MC info)\n", nCollisions, nBorderCollisions, useEvent, shift, (int32_t)(nBunch * config.bunchSpacing), inTF ? " inside" : "outside",
293+
printf("Placing event %4d+%d (ID %4d) at z %7.3f (time %'dns) %s(collisions %4d, bunch %6d, train %3d) (%'10d clusters, %'10d MC labels, %'10d track MC info)\n", nCollisions, nBorderCollisions, useEvent, shift, (int32_t)(nBunch * config.bunchSpacing), inTF ? " inside" : "outside",
294294
nCollisions, nBunch, nTrain, nClusters, mChain->mIOPtrs.nMCLabelsTPC, mChain->mIOPtrs.nMCInfosTPC);
295295
nInBunchPileUp++;
296296
nCollisionsInTrain++;

‎GPU/GPUTracking/CMakeLists.txt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,7 @@ if(CPUDEVICE_ENABLED)
513513
endif()
514514

515515
if(ALIGPU_BUILD_TYPE STREQUAL "O2" OR ALIGPU_BUILD_TYPE STREQUAL "Standalone")
516-
if(NOT ${CMAKE_SYSTEM} MATCHES Darwin)
517-
add_subdirectory(Standalone/Benchmark)
518-
endif()
516+
add_subdirectory(Standalone/Benchmark)
519517
endif()
520518

521519
if(GPUCA_DETERMINISTIC_MODE GREATER_EQUAL ${GPUCA_DETERMINISTIC_MODE_MAP_GPU})

‎GPU/GPUTracking/Definitions/GPUSettingsList.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ AddOption(keepAllMemory, bool, false, "", 0, "Allocate all memory on both device
348348
AddOption(keepDisplayMemory, bool, false, "", 0, "Like keepAllMemory, but only for memory required for event display")
349349
AddOption(disableMemoryReuse, bool, false, "", 0, "Disable memory reusage (for debugging only)")
350350
AddOption(memoryAllocationStrategy, int8_t, 0, "", 0, "Memory Allocation Strategy (0 = auto, 1 = individual allocations, 2 = single global allocation)")
351-
AddOption(forceMemoryPoolSize, uint64_t, 1, "memSize", 0, "Force size of allocated GPU / page locked host memory (0 = disable, 1 / 2 = auto, other values set the size of the memory pool)", min(0ul))
352-
AddOption(forceHostMemoryPoolSize, uint64_t, 0, "hostMemSize", 0, "Force size of allocated host page locked host memory (overriding memSize)", min(0ul))
351+
AddOption(forceMemoryPoolSize, uint64_t, 1, "memSize", 0, "Force size of allocated GPU / page locked host memory (0 = disable, 1 / 2 = auto, other values set the size of the memory pool)", min(uint64_t(0)))
352+
AddOption(forceHostMemoryPoolSize, uint64_t, 0, "hostMemSize", 0, "Force size of allocated host page locked host memory (overriding memSize)", min(uint64_t(0)))
353353
AddOption(memoryScalingFactor, float, 1.f, "", 0, "Factor to apply to all memory scalers")
354354
AddOption(memoryScalingFuzz, uint64_t, 0, "", 0, "Fuzz the memoryScalingFactor (0 disable, 1 enable, >1 set seed", def(1))
355355
AddOption(tpcInputWithClusterRejection, uint8_t, 0, "", 0, "Indicate whether the TPC input is CTF data with cluster rejection, to tune buffer estimations")

‎GPU/GPUTracking/Definitions/GPUSettingsListStandalone.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ EndConfig()
4747
BeginConfig(GPUSettingsStandalone, configStandalone)
4848
AddOption(runGPU, uint8_t, 1, "", 'g', "Use GPU for processing", message("GPU processing enabled"), set(2))
4949
AddOptionSet(runGPU, uint8_t, 0, "", 'c', "Use CPU for processing", message("CPU enabled"))
50-
AddOption(gpuType, std::string, "AUTO", "", 0, "GPU type (CUDA / HIP / OCL / CPUDEVICE) or CPU or AUTO")
50+
AddOption(gpuType, std::string, "AUTO", "", 0, "GPU type (CUDA / HIP / OCL / METAL / CPUDEVICE) or CPU or AUTO")
5151
AddOption(runGPUforce, bool, true, "", 0, "Force usage of the specified GPU device type, no CPU fallback")
5252
AddOption(promptOnExit, bool, false, "", 0, "Prompt for keypress before exiting")
5353
AddOption(continueOnError, bool, false, "", 0, "Continue processing after an error")
@@ -64,8 +64,8 @@ AddOption(eventDisplay, int32_t, 0, "display", 'd', "Show standalone event displ
6464
AddOption(eventGenerator, bool, false, "", 0, "Run event generator")
6565
AddOption(cont, bool, false, "", 0, "Process continuous timeframe data, even if input is triggered")
6666
AddOption(setMaxTimeBin, int32_t, -2, "", 0, "maximum time bin of continuous data, 0 for triggered events, -1 for automatic continuous mode, -2 for automatic continuous / triggered")
67-
AddOption(outputcontrolmem, uint64_t, 0, "outputMemory", 0, "Use predefined output buffer of this size", min(0ul), message("Using %s bytes as output memory"))
68-
AddOption(inputcontrolmem, uint64_t, 0, "inputMemory", 0, "Use predefined input buffer of this size", min(0ul), message("Using %s bytes as input memory"))
67+
AddOption(outputcontrolmem, uint64_t, 0, "outputMemory", 0, "Use predefined output buffer of this size", min(uint64_t(0)), message("Using %s bytes as output memory"))
68+
AddOption(inputcontrolmem, uint64_t, 0, "inputMemory", 0, "Use predefined input buffer of this size", min(uint64_t(0)), message("Using %s bytes as input memory"))
6969
AddOption(cpuAffinity, int32_t, -1, "", 0, "Pin CPU affinity to this CPU core", min(-1))
7070
AddOption(fifoScheduler, bool, false, "", 0, "Use FIFO realtime scheduler", message("Setting FIFO scheduler: %s"))
7171
AddOption(fpe, int8_t, -1, "", 0, "Trap on floating point exceptions (-1 = if no ffast-math)")

‎GPU/GPUTracking/Standalone/Benchmark/standalone.cxx‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ int32_t ReadConfiguration(int argc, char** argv)
124124
setlocale(LC_ALL, "en_US.utf-8");
125125
setlocale(LC_NUMERIC, "en_US.utf-8");
126126
if (configStandalone.cpuAffinity != -1) {
127+
#ifdef __linux__
127128
cpu_set_t mask;
128129
CPU_ZERO(&mask);
129130
CPU_SET(configStandalone.cpuAffinity, &mask);
@@ -133,8 +134,13 @@ int32_t ReadConfiguration(int argc, char** argv)
133134
printf("Error setting CPU affinity\n");
134135
return 1;
135136
}
137+
#else
138+
printf("CPU affinity not supported on this platform\n");
139+
return 1;
140+
#endif
136141
}
137142
if (configStandalone.fifoScheduler) {
143+
#ifdef __linux__
138144
printf("Setting FIFO scheduler\n");
139145
sched_param param;
140146
sched_getparam(0, &param);
@@ -143,13 +149,21 @@ int32_t ReadConfiguration(int argc, char** argv)
143149
printf("Error setting scheduler\n");
144150
return 1;
145151
}
152+
#else
153+
printf("FIFO scheduler not supported on this platform\n");
154+
return 1;
155+
#endif
146156
}
147157
#ifdef __FAST_MATH__
148158
if (configStandalone.fpe == 1) {
149159
#else
150160
if (configStandalone.fpe) {
151161
#endif
162+
#ifdef __linux__
152163
feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
164+
#else
165+
printf("Trapping floating point exceptions not supported on this platform\n");
166+
#endif
153167
}
154168
bool detMode = false, noFTZMode = false;
155169
#ifdef GPUCA_DETERMINISTIC_MODE
@@ -655,7 +669,7 @@ int32_t LoadEvent(int32_t iEvent, int32_t x)
655669
return 0;
656670
}
657671

658-
void OutputStat(GPUChainTracking* t, int64_t* nTracksTotal = nullptr, int64_t* nClustersTotal = nullptr)
672+
void OutputStat(GPUChainTracking* t, size_t* nTracksTotal = nullptr, size_t* nClustersTotal = nullptr)
659673
{
660674
int32_t nTracks = 0;
661675
if (t->GetProcessingSettings().createO2Output) {
@@ -673,7 +687,7 @@ void OutputStat(GPUChainTracking* t, int64_t* nTracksTotal = nullptr, int64_t* n
673687
}
674688
}
675689

676-
int32_t RunBenchmark(GPUReconstruction* recUse, GPUChainTracking* chainTrackingUse, int32_t runs, int32_t iEvent, int64_t* nTracksTotal, int64_t* nClustersTotal, int32_t threadId = 0, HighResTimer* timerPipeline = nullptr)
690+
int32_t RunBenchmark(GPUReconstruction* recUse, GPUChainTracking* chainTrackingUse, int32_t runs, int32_t iEvent, size_t* nTracksTotal, size_t* nClustersTotal, int32_t threadId = 0, HighResTimer* timerPipeline = nullptr)
677691
{
678692
int32_t iRun = 0, iteration = 0;
679693
while ((iteration = nIteration.fetch_add(1)) < runs) {
@@ -907,8 +921,8 @@ int32_t main(int argc, char** argv)
907921
if (configStandalone.runs2 > 1) {
908922
printf("\nRUN2: %d\n", iRunOuter);
909923
}
910-
int64_t nTracksTotal = 0;
911-
int64_t nClustersTotal = 0;
924+
size_t nTracksTotal = 0;
925+
size_t nClustersTotal = 0;
912926
int32_t nEventsProcessed = 0;
913927

914928
if (configStandalone.noEvents) {
@@ -1010,7 +1024,7 @@ int32_t main(int argc, char** argv)
10101024
}
10111025
}
10121026
if (nEventsProcessed > 1) {
1013-
printf("Total: %ld clusters, %ld tracks\n", nClustersTotal, nTracksTotal);
1027+
printf("Total: %zu clusters, %zu tracks\n", nClustersTotal, nTracksTotal);
10141028
}
10151029
}
10161030

@@ -1021,7 +1035,9 @@ int32_t main(int argc, char** argv)
10211035

10221036
#ifndef _WIN32
10231037
if (configStandalone.proc.runQA && configStandalone.fpe) {
1038+
#ifdef __linux__
10241039
fedisableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
1040+
#endif
10251041
}
10261042
#endif
10271043

0 commit comments

Comments
 (0)