@@ -54,7 +54,7 @@ struct RecordReplayTy {
54
54
size_t MemorySize = 0 ;
55
55
size_t TotalSize = 0 ;
56
56
GenericDeviceTy *Device = nullptr ;
57
- std::mutex AllocationLock;
57
+ std::mutex AllocationLock{} ;
58
58
59
59
RRStatusTy Status = RRDeactivated;
60
60
bool ReplaySaveOutput = false ;
@@ -362,7 +362,10 @@ struct RecordReplayTy {
362
362
}
363
363
};
364
364
365
- static RecordReplayTy RecordReplay;
365
+ RecordReplayTy &getRecordReplay () {
366
+ static RecordReplayTy RecordReplay;
367
+ return RecordReplay;
368
+ }
366
369
367
370
// Extract the mapping of host function pointers to device function pointers
368
371
// from the entry table. Functions marked as 'indirect' in OpenMP will have
@@ -473,7 +476,7 @@ GenericKernelTy::getKernelLaunchEnvironment(
473
476
// Ctor/Dtor have no arguments, replaying uses the original kernel launch
474
477
// environment. Older versions of the compiler do not generate a kernel
475
478
// launch environment.
476
- if (isCtorOrDtor () || RecordReplay .isReplaying () ||
479
+ if (isCtorOrDtor () || getRecordReplay () .isReplaying () ||
477
480
Version < OMP_KERNEL_ARG_MIN_VERSION_WITH_DYN_PTR)
478
481
return nullptr ;
479
482
@@ -562,11 +565,12 @@ Error GenericKernelTy::launch(GenericDeviceTy &GenericDevice, void **ArgPtrs,
562
565
563
566
// Record the kernel description after we modified the argument count and num
564
567
// blocks/threads.
565
- if (RecordReplay.isRecording ()) {
566
- RecordReplay.saveImage (getName (), getImage ());
567
- RecordReplay.saveKernelInput (getName (), getImage ());
568
- RecordReplay.saveKernelDescr (getName (), Ptrs.data (), KernelArgs.NumArgs ,
569
- NumBlocks, NumThreads, KernelArgs.Tripcount );
568
+ if (getRecordReplay ().isRecording ()) {
569
+ getRecordReplay ().saveImage (getName (), getImage ());
570
+ getRecordReplay ().saveKernelInput (getName (), getImage ());
571
+ getRecordReplay ().saveKernelDescr (getName (), Ptrs.data (),
572
+ KernelArgs.NumArgs , NumBlocks, NumThreads,
573
+ KernelArgs.Tripcount );
570
574
}
571
575
572
576
if (auto Err =
@@ -839,8 +843,8 @@ Error GenericDeviceTy::deinit(GenericPluginTy &Plugin) {
839
843
delete MemoryManager;
840
844
MemoryManager = nullptr ;
841
845
842
- if (RecordReplay .isRecordingOrReplaying ())
843
- RecordReplay .deinit ();
846
+ if (getRecordReplay () .isRecordingOrReplaying ())
847
+ getRecordReplay () .deinit ();
844
848
845
849
if (RPCServer)
846
850
if (auto Err = RPCServer->deinitDevice (*this ))
@@ -892,7 +896,7 @@ GenericDeviceTy::loadBinary(GenericPluginTy &Plugin,
892
896
return std::move (Err);
893
897
894
898
// Setup the global device memory pool if needed.
895
- if (!RecordReplay .isReplaying () && shouldSetupDeviceMemoryPool ()) {
899
+ if (!getRecordReplay () .isReplaying () && shouldSetupDeviceMemoryPool ()) {
896
900
uint64_t HeapSize;
897
901
auto SizeOrErr = getDeviceHeapSize (HeapSize);
898
902
if (SizeOrErr) {
@@ -1307,8 +1311,8 @@ Expected<void *> GenericDeviceTy::dataAlloc(int64_t Size, void *HostPtr,
1307
1311
TargetAllocTy Kind) {
1308
1312
void *Alloc = nullptr ;
1309
1313
1310
- if (RecordReplay .isRecordingOrReplaying ())
1311
- return RecordReplay .alloc (Size);
1314
+ if (getRecordReplay () .isRecordingOrReplaying ())
1315
+ return getRecordReplay () .alloc (Size);
1312
1316
1313
1317
switch (Kind) {
1314
1318
case TARGET_ALLOC_DEFAULT:
@@ -1344,7 +1348,7 @@ Expected<void *> GenericDeviceTy::dataAlloc(int64_t Size, void *HostPtr,
1344
1348
1345
1349
Error GenericDeviceTy::dataDelete (void *TgtPtr, TargetAllocTy Kind) {
1346
1350
// Free is a noop when recording or replaying.
1347
- if (RecordReplay .isRecordingOrReplaying ())
1351
+ if (getRecordReplay () .isRecordingOrReplaying ())
1348
1352
return Plugin::success ();
1349
1353
1350
1354
int Res;
@@ -1397,7 +1401,7 @@ Error GenericDeviceTy::launchKernel(void *EntryPtr, void **ArgPtrs,
1397
1401
KernelArgsTy &KernelArgs,
1398
1402
__tgt_async_info *AsyncInfo) {
1399
1403
AsyncInfoWrapperTy AsyncInfoWrapper (
1400
- *this , RecordReplay .isRecordingOrReplaying () ? nullptr : AsyncInfo);
1404
+ *this , getRecordReplay () .isRecordingOrReplaying () ? nullptr : AsyncInfo);
1401
1405
1402
1406
GenericKernelTy &GenericKernel =
1403
1407
*reinterpret_cast <GenericKernelTy *>(EntryPtr);
@@ -1408,9 +1412,9 @@ Error GenericDeviceTy::launchKernel(void *EntryPtr, void **ArgPtrs,
1408
1412
// 'finalize' here to guarantee next record-replay actions are in-sync
1409
1413
AsyncInfoWrapper.finalize (Err);
1410
1414
1411
- if (RecordReplay .isRecordingOrReplaying () &&
1412
- RecordReplay .isSaveOutputEnabled ())
1413
- RecordReplay .saveKernelOutputInfo (GenericKernel.getName ());
1415
+ if (getRecordReplay () .isRecordingOrReplaying () &&
1416
+ getRecordReplay () .isSaveOutputEnabled ())
1417
+ getRecordReplay () .saveKernelOutputInfo (GenericKernel.getName ());
1414
1418
1415
1419
return Err;
1416
1420
}
@@ -1630,12 +1634,12 @@ int32_t GenericPluginTy::initialize_record_replay(int32_t DeviceId,
1630
1634
isRecord ? RecordReplayTy::RRStatusTy::RRRecording
1631
1635
: RecordReplayTy::RRStatusTy::RRReplaying;
1632
1636
1633
- if (auto Err = RecordReplay .init (&Device, MemorySize, VAddr, Status,
1634
- SaveOutput, ReqPtrArgOffset)) {
1637
+ if (auto Err = getRecordReplay () .init (&Device, MemorySize, VAddr, Status,
1638
+ SaveOutput, ReqPtrArgOffset)) {
1635
1639
REPORT (" WARNING RR did not intialize RR-properly with %lu bytes"
1636
1640
" (Error: %s)\n " ,
1637
1641
MemorySize, toString (std::move (Err)).data ());
1638
- RecordReplay .setStatus (RecordReplayTy::RRStatusTy::RRDeactivated);
1642
+ getRecordReplay () .setStatus (RecordReplayTy::RRStatusTy::RRDeactivated);
1639
1643
1640
1644
if (!isRecord) {
1641
1645
return OFFLOAD_FAIL;
@@ -1984,8 +1988,8 @@ int32_t GenericPluginTy::get_global(__tgt_device_binary Binary, uint64_t Size,
1984
1988
assert (DevicePtr && " Invalid device global's address" );
1985
1989
1986
1990
// Save the loaded globals if we are recording.
1987
- if (RecordReplay .isRecording ())
1988
- RecordReplay .addEntry (Name, Size, *DevicePtr);
1991
+ if (getRecordReplay () .isRecording ())
1992
+ getRecordReplay () .addEntry (Name, Size, *DevicePtr);
1989
1993
1990
1994
return OFFLOAD_SUCCESS;
1991
1995
}
0 commit comments