@@ -39,6 +39,7 @@ using namespace target;
39
39
using namespace plugin ;
40
40
41
41
// TODO: Fix any thread safety issues for multi-threaded kernel recording.
42
+ namespace llvm ::omp::target::plugin {
42
43
struct RecordReplayTy {
43
44
44
45
// Describes the state of the record replay mechanism.
@@ -358,8 +359,7 @@ struct RecordReplayTy {
358
359
}
359
360
}
360
361
};
361
-
362
- static RecordReplayTy RecordReplay;
362
+ } // namespace llvm::omp::target::plugin
363
363
364
364
// Extract the mapping of host function pointers to device function pointers
365
365
// from the entry table. Functions marked as 'indirect' in OpenMP will have
@@ -470,7 +470,7 @@ GenericKernelTy::getKernelLaunchEnvironment(
470
470
// Ctor/Dtor have no arguments, replaying uses the original kernel launch
471
471
// environment. Older versions of the compiler do not generate a kernel
472
472
// launch environment.
473
- if (RecordReplay .isReplaying () ||
473
+ if (GenericDevice. Plugin . getRecordReplay () .isReplaying () ||
474
474
Version < OMP_KERNEL_ARG_MIN_VERSION_WITH_DYN_PTR)
475
475
return nullptr ;
476
476
@@ -559,6 +559,7 @@ Error GenericKernelTy::launch(GenericDeviceTy &GenericDevice, void **ArgPtrs,
559
559
560
560
// Record the kernel description after we modified the argument count and num
561
561
// blocks/threads.
562
+ RecordReplayTy &RecordReplay = GenericDevice.Plugin .getRecordReplay ();
562
563
if (RecordReplay.isRecording ()) {
563
564
RecordReplay.saveImage (getName (), getImage ());
564
565
RecordReplay.saveKernelInput (getName (), getImage ());
@@ -833,6 +834,7 @@ Error GenericDeviceTy::deinit(GenericPluginTy &Plugin) {
833
834
delete MemoryManager;
834
835
MemoryManager = nullptr ;
835
836
837
+ RecordReplayTy &RecordReplay = Plugin.getRecordReplay ();
836
838
if (RecordReplay.isRecordingOrReplaying ())
837
839
RecordReplay.deinit ();
838
840
@@ -886,7 +888,8 @@ GenericDeviceTy::loadBinary(GenericPluginTy &Plugin,
886
888
return std::move (Err);
887
889
888
890
// Setup the global device memory pool if needed.
889
- if (!RecordReplay.isReplaying () && shouldSetupDeviceMemoryPool ()) {
891
+ if (!Plugin.getRecordReplay ().isReplaying () &&
892
+ shouldSetupDeviceMemoryPool ()) {
890
893
uint64_t HeapSize;
891
894
auto SizeOrErr = getDeviceHeapSize (HeapSize);
892
895
if (SizeOrErr) {
@@ -1301,8 +1304,8 @@ Expected<void *> GenericDeviceTy::dataAlloc(int64_t Size, void *HostPtr,
1301
1304
TargetAllocTy Kind) {
1302
1305
void *Alloc = nullptr ;
1303
1306
1304
- if (RecordReplay .isRecordingOrReplaying ())
1305
- return RecordReplay .alloc (Size );
1307
+ if (Plugin. getRecordReplay () .isRecordingOrReplaying ())
1308
+ return Plugin. getRecordReplay () .alloc (Size );
1306
1309
1307
1310
switch (Kind) {
1308
1311
case TARGET_ALLOC_DEFAULT:
@@ -1338,7 +1341,7 @@ Expected<void *> GenericDeviceTy::dataAlloc(int64_t Size, void *HostPtr,
1338
1341
1339
1342
Error GenericDeviceTy::dataDelete (void *TgtPtr, TargetAllocTy Kind) {
1340
1343
// Free is a noop when recording or replaying.
1341
- if (RecordReplay .isRecordingOrReplaying ())
1344
+ if (Plugin. getRecordReplay () .isRecordingOrReplaying ())
1342
1345
return Plugin::success ();
1343
1346
1344
1347
int Res;
@@ -1405,7 +1408,8 @@ Error GenericDeviceTy::launchKernel(void *EntryPtr, void **ArgPtrs,
1405
1408
KernelArgsTy &KernelArgs,
1406
1409
__tgt_async_info *AsyncInfo) {
1407
1410
AsyncInfoWrapperTy AsyncInfoWrapper (
1408
- *this , RecordReplay.isRecordingOrReplaying () ? nullptr : AsyncInfo);
1411
+ *this ,
1412
+ Plugin.getRecordReplay ().isRecordingOrReplaying () ? nullptr : AsyncInfo);
1409
1413
1410
1414
GenericKernelTy &GenericKernel =
1411
1415
*reinterpret_cast <GenericKernelTy *>(EntryPtr);
@@ -1416,6 +1420,7 @@ Error GenericDeviceTy::launchKernel(void *EntryPtr, void **ArgPtrs,
1416
1420
// 'finalize' here to guarantee next record-replay actions are in-sync
1417
1421
AsyncInfoWrapper.finalize (Err);
1418
1422
1423
+ RecordReplayTy &RecordReplay = Plugin.getRecordReplay ();
1419
1424
if (RecordReplay.isRecordingOrReplaying () &&
1420
1425
RecordReplay.isSaveOutputEnabled ())
1421
1426
RecordReplay.saveKernelOutputInfo (GenericKernel.getName ());
@@ -1503,6 +1508,9 @@ Error GenericPluginTy::init() {
1503
1508
RPCServer = new RPCServerTy (*this );
1504
1509
assert (RPCServer && " Invalid RPC server" );
1505
1510
1511
+ RecordReplay = new RecordReplayTy ();
1512
+ assert (RecordReplay && " Invalid RR interface" );
1513
+
1506
1514
return Plugin::success ();
1507
1515
}
1508
1516
@@ -1523,6 +1531,9 @@ Error GenericPluginTy::deinit() {
1523
1531
if (RPCServer)
1524
1532
delete RPCServer;
1525
1533
1534
+ if (RecordReplay)
1535
+ delete RecordReplay;
1536
+
1526
1537
// Perform last deinitializations on the plugin.
1527
1538
return deinitImpl ();
1528
1539
}
@@ -1633,12 +1644,12 @@ int32_t GenericPluginTy::initialize_record_replay(int32_t DeviceId,
1633
1644
isRecord ? RecordReplayTy::RRStatusTy::RRRecording
1634
1645
: RecordReplayTy::RRStatusTy::RRReplaying;
1635
1646
1636
- if (auto Err = RecordReplay. init (&Device, MemorySize, VAddr, Status,
1637
- SaveOutput, ReqPtrArgOffset)) {
1647
+ if (auto Err = RecordReplay-> init (&Device, MemorySize, VAddr, Status,
1648
+ SaveOutput, ReqPtrArgOffset)) {
1638
1649
REPORT (" WARNING RR did not intialize RR-properly with %lu bytes"
1639
1650
" (Error: %s)\n " ,
1640
1651
MemorySize, toString (std::move (Err)).data ());
1641
- RecordReplay. setStatus (RecordReplayTy::RRStatusTy::RRDeactivated);
1652
+ RecordReplay-> setStatus (RecordReplayTy::RRStatusTy::RRDeactivated);
1642
1653
1643
1654
if (!isRecord) {
1644
1655
return OFFLOAD_FAIL;
@@ -1982,6 +1993,7 @@ int32_t GenericPluginTy::get_global(__tgt_device_binary Binary, uint64_t Size,
1982
1993
assert (DevicePtr && " Invalid device global's address" );
1983
1994
1984
1995
// Save the loaded globals if we are recording.
1996
+ RecordReplayTy &RecordReplay = Device.Plugin .getRecordReplay ();
1985
1997
if (RecordReplay.isRecording ())
1986
1998
RecordReplay.addEntry (Name, Size , *DevicePtr);
1987
1999
0 commit comments