@@ -362,8 +362,6 @@ struct RecordReplayTy {
362
362
}
363
363
};
364
364
365
- static RecordReplayTy RecordReplay;
366
-
367
365
// Extract the mapping of host function pointers to device function pointers
368
366
// from the entry table. Functions marked as 'indirect' in OpenMP will have
369
367
// offloading entries generated for them which map the host's function pointer
@@ -473,7 +471,8 @@ GenericKernelTy::getKernelLaunchEnvironment(
473
471
// Ctor/Dtor have no arguments, replaying uses the original kernel launch
474
472
// environment. Older versions of the compiler do not generate a kernel
475
473
// launch environment.
476
- if (isCtorOrDtor () || RecordReplay.isReplaying () ||
474
+ if (isCtorOrDtor () ||
475
+ GenericDevice.Plugin .getRecordAndReplay ().isReplaying () ||
477
476
Version < OMP_KERNEL_ARG_MIN_VERSION_WITH_DYN_PTR)
478
477
return nullptr ;
479
478
@@ -562,6 +561,7 @@ Error GenericKernelTy::launch(GenericDeviceTy &GenericDevice, void **ArgPtrs,
562
561
563
562
// Record the kernel description after we modified the argument count and num
564
563
// blocks/threads.
564
+ RecordReplayTy &RecordReplay = GenericDevice.Plugin .getRecordAndReplay ();
565
565
if (RecordReplay.isRecording ()) {
566
566
RecordReplay.saveImage (getName (), getImage ());
567
567
RecordReplay.saveKernelInput (getName (), getImage ());
@@ -839,9 +839,6 @@ Error GenericDeviceTy::deinit(GenericPluginTy &Plugin) {
839
839
delete MemoryManager;
840
840
MemoryManager = nullptr ;
841
841
842
- if (RecordReplay.isRecordingOrReplaying ())
843
- RecordReplay.deinit ();
844
-
845
842
if (RPCServer)
846
843
if (auto Err = RPCServer->deinitDevice (*this ))
847
844
return Err;
@@ -858,6 +855,7 @@ Error GenericDeviceTy::deinit(GenericPluginTy &Plugin) {
858
855
859
856
return deinitImpl ();
860
857
}
858
+
861
859
Expected<DeviceImageTy *>
862
860
GenericDeviceTy::loadBinary (GenericPluginTy &Plugin,
863
861
const __tgt_device_image *InputTgtImage) {
@@ -892,7 +890,8 @@ GenericDeviceTy::loadBinary(GenericPluginTy &Plugin,
892
890
return std::move (Err);
893
891
894
892
// Setup the global device memory pool if needed.
895
- if (!RecordReplay.isReplaying () && shouldSetupDeviceMemoryPool ()) {
893
+ if (!Plugin.getRecordAndReplay ().isReplaying () &&
894
+ shouldSetupDeviceMemoryPool ()) {
896
895
uint64_t HeapSize;
897
896
auto SizeOrErr = getDeviceHeapSize (HeapSize);
898
897
if (SizeOrErr) {
@@ -1307,8 +1306,8 @@ Expected<void *> GenericDeviceTy::dataAlloc(int64_t Size, void *HostPtr,
1307
1306
TargetAllocTy Kind) {
1308
1307
void *Alloc = nullptr ;
1309
1308
1310
- if (RecordReplay .isRecordingOrReplaying ())
1311
- return RecordReplay .alloc (Size );
1309
+ if (Plugin. getRecordAndReplay () .isRecordingOrReplaying ())
1310
+ return Plugin. getRecordAndReplay () .alloc (Size );
1312
1311
1313
1312
switch (Kind) {
1314
1313
case TARGET_ALLOC_DEFAULT:
@@ -1344,7 +1343,7 @@ Expected<void *> GenericDeviceTy::dataAlloc(int64_t Size, void *HostPtr,
1344
1343
1345
1344
Error GenericDeviceTy::dataDelete (void *TgtPtr, TargetAllocTy Kind) {
1346
1345
// Free is a noop when recording or replaying.
1347
- if (RecordReplay .isRecordingOrReplaying ())
1346
+ if (Plugin. getRecordAndReplay () .isRecordingOrReplaying ())
1348
1347
return Plugin::success ();
1349
1348
1350
1349
int Res;
@@ -1396,6 +1395,7 @@ Error GenericDeviceTy::launchKernel(void *EntryPtr, void **ArgPtrs,
1396
1395
ptrdiff_t *ArgOffsets,
1397
1396
KernelArgsTy &KernelArgs,
1398
1397
__tgt_async_info *AsyncInfo) {
1398
+ RecordReplayTy &RecordReplay = Plugin.getRecordAndReplay ();
1399
1399
AsyncInfoWrapperTy AsyncInfoWrapper (
1400
1400
*this , RecordReplay.isRecordingOrReplaying () ? nullptr : AsyncInfo);
1401
1401
@@ -1495,6 +1495,9 @@ Error GenericPluginTy::init() {
1495
1495
RPCServer = new RPCServerTy (*this );
1496
1496
assert (RPCServer && " Invalid RPC server" );
1497
1497
1498
+ RecordReplay = new RecordReplayTy ();
1499
+ assert (RecordReplay && " Invalid Record and Replay handler" );
1500
+
1498
1501
return Plugin::success ();
1499
1502
}
1500
1503
@@ -1508,13 +1511,19 @@ Error GenericPluginTy::deinit() {
1508
1511
assert (!Devices[DeviceId] && " Device was not deinitialized" );
1509
1512
}
1510
1513
1514
+ if (RecordReplay && RecordReplay->isRecordingOrReplaying ())
1515
+ RecordReplay->deinit ();
1516
+
1511
1517
// There is no global handler if no device is available.
1512
1518
if (GlobalHandler)
1513
1519
delete GlobalHandler;
1514
1520
1515
1521
if (RPCServer)
1516
1522
delete RPCServer;
1517
1523
1524
+ if (RecordReplay)
1525
+ delete RecordReplay;
1526
+
1518
1527
// Perform last deinitializations on the plugin.
1519
1528
return deinitImpl ();
1520
1529
}
@@ -1630,12 +1639,12 @@ int32_t GenericPluginTy::initialize_record_replay(int32_t DeviceId,
1630
1639
isRecord ? RecordReplayTy::RRStatusTy::RRRecording
1631
1640
: RecordReplayTy::RRStatusTy::RRReplaying;
1632
1641
1633
- if (auto Err = RecordReplay. init (&Device, MemorySize, VAddr, Status,
1634
- SaveOutput, ReqPtrArgOffset)) {
1642
+ if (auto Err = RecordReplay-> init (&Device, MemorySize, VAddr, Status,
1643
+ SaveOutput, ReqPtrArgOffset)) {
1635
1644
REPORT (" WARNING RR did not intialize RR-properly with %lu bytes"
1636
1645
" (Error: %s)\n " ,
1637
1646
MemorySize, toString (std::move (Err)).data ());
1638
- RecordReplay. setStatus (RecordReplayTy::RRStatusTy::RRDeactivated);
1647
+ RecordReplay-> setStatus (RecordReplayTy::RRStatusTy::RRDeactivated);
1639
1648
1640
1649
if (!isRecord) {
1641
1650
return OFFLOAD_FAIL;
@@ -1984,8 +1993,8 @@ int32_t GenericPluginTy::get_global(__tgt_device_binary Binary, uint64_t Size,
1984
1993
assert (DevicePtr && " Invalid device global's address" );
1985
1994
1986
1995
// Save the loaded globals if we are recording.
1987
- if (RecordReplay .isRecording ())
1988
- RecordReplay .addEntry (Name, Size , *DevicePtr);
1996
+ if (getRecordAndReplay () .isRecording ())
1997
+ getRecordAndReplay () .addEntry (Name, Size , *DevicePtr);
1989
1998
1990
1999
return OFFLOAD_SUCCESS;
1991
2000
}
0 commit comments