@@ -371,7 +371,8 @@ struct AMDGPUMemoryPoolTy {
371
371
struct AMDGPUMemoryManagerTy : public DeviceAllocatorTy {
372
372
373
373
// / Create an empty memory manager.
374
- AMDGPUMemoryManagerTy () : MemoryPool(nullptr ), MemoryManager(nullptr ) {}
374
+ AMDGPUMemoryManagerTy (AMDGPUPluginTy &Plugin)
375
+ : Plugin(Plugin), MemoryPool(nullptr ), MemoryManager(nullptr ) {}
375
376
376
377
// / Initialize the memory manager from a memory pool.
377
378
Error init (AMDGPUMemoryPoolTy &MemoryPool) {
@@ -429,6 +430,9 @@ struct AMDGPUMemoryManagerTy : public DeviceAllocatorTy {
429
430
return OFFLOAD_SUCCESS;
430
431
}
431
432
433
+ // / The underlying plugin that owns this memory manager.
434
+ AMDGPUPluginTy &Plugin;
435
+
432
436
// / The memory pool used to allocate memory.
433
437
AMDGPUMemoryPoolTy *MemoryPool;
434
438
@@ -1744,9 +1748,10 @@ struct AMDGenericDeviceTy {
1744
1748
// / HSA host agent. We aggregate all its resources into the same instance.
1745
1749
struct AMDHostDeviceTy : public AMDGenericDeviceTy {
1746
1750
// / Create a host device from an array of host agents.
1747
- AMDHostDeviceTy (const llvm::SmallVector<hsa_agent_t > &HostAgents)
1748
- : AMDGenericDeviceTy(), Agents(HostAgents), ArgsMemoryManager(),
1749
- PinnedMemoryManager () {
1751
+ AMDHostDeviceTy (AMDGPUPluginTy &Plugin,
1752
+ const llvm::SmallVector<hsa_agent_t > &HostAgents)
1753
+ : AMDGenericDeviceTy(), Agents(HostAgents), ArgsMemoryManager(Plugin),
1754
+ PinnedMemoryManager (Plugin) {
1750
1755
assert (HostAgents.size () && " No host agent found" );
1751
1756
}
1752
1757
@@ -1840,9 +1845,10 @@ struct AMDHostDeviceTy : public AMDGenericDeviceTy {
1840
1845
// / generic device class.
1841
1846
struct AMDGPUDeviceTy : public GenericDeviceTy , AMDGenericDeviceTy {
1842
1847
// Create an AMDGPU device with a device id and default AMDGPU grid values.
1843
- AMDGPUDeviceTy (int32_t DeviceId, int32_t NumDevices,
1848
+ AMDGPUDeviceTy (GenericPluginTy &Plugin, int32_t DeviceId, int32_t NumDevices,
1844
1849
AMDHostDeviceTy &HostDevice, hsa_agent_t Agent)
1845
- : GenericDeviceTy(DeviceId, NumDevices, {0 }), AMDGenericDeviceTy(),
1850
+ : GenericDeviceTy(Plugin, DeviceId, NumDevices, {0 }),
1851
+ AMDGenericDeviceTy (),
1846
1852
OMPX_NumQueues (" LIBOMPTARGET_AMDGPU_NUM_HSA_QUEUES" , 4 ),
1847
1853
OMPX_QueueSize (" LIBOMPTARGET_AMDGPU_HSA_QUEUE_SIZE" , 512 ),
1848
1854
OMPX_DefaultTeamsPerCU (" LIBOMPTARGET_AMDGPU_TEAMS_PER_CU" , 4 ),
@@ -2088,7 +2094,7 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
2088
2094
// / Allocate and construct an AMDGPU kernel.
2089
2095
Expected<GenericKernelTy &> constructKernel (const char *Name) override {
2090
2096
// Allocate and construct the AMDGPU kernel.
2091
- AMDGPUKernelTy *AMDGPUKernel = PluginTy::get () .allocate <AMDGPUKernelTy>();
2097
+ AMDGPUKernelTy *AMDGPUKernel = Plugin .allocate <AMDGPUKernelTy>();
2092
2098
if (!AMDGPUKernel)
2093
2099
return Plugin::error (" Failed to allocate memory for AMDGPU kernel" );
2094
2100
@@ -2138,8 +2144,7 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
2138
2144
Expected<DeviceImageTy *> loadBinaryImpl (const __tgt_device_image *TgtImage,
2139
2145
int32_t ImageId) override {
2140
2146
// Allocate and initialize the image object.
2141
- AMDGPUDeviceImageTy *AMDImage =
2142
- PluginTy::get ().allocate <AMDGPUDeviceImageTy>();
2147
+ AMDGPUDeviceImageTy *AMDImage = Plugin.allocate <AMDGPUDeviceImageTy>();
2143
2148
new (AMDImage) AMDGPUDeviceImageTy (ImageId, *this , TgtImage);
2144
2149
2145
2150
// Load the HSA executable.
@@ -2697,7 +2702,7 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
2697
2702
}
2698
2703
Error setDeviceHeapSize (uint64_t Value) override {
2699
2704
for (DeviceImageTy *Image : LoadedImages)
2700
- if (auto Err = setupDeviceMemoryPool (PluginTy::get () , *Image, Value))
2705
+ if (auto Err = setupDeviceMemoryPool (Plugin , *Image, Value))
2701
2706
return Err;
2702
2707
DeviceMemoryPoolSize = Value;
2703
2708
return Plugin::success ();
@@ -2737,7 +2742,7 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
2737
2742
return utils::iterateAgentMemoryPools (
2738
2743
Agent, [&](hsa_amd_memory_pool_t HSAMemoryPool) {
2739
2744
AMDGPUMemoryPoolTy *MemoryPool =
2740
- PluginTy::get () .allocate <AMDGPUMemoryPoolTy>();
2745
+ Plugin .allocate <AMDGPUMemoryPoolTy>();
2741
2746
new (MemoryPool) AMDGPUMemoryPoolTy (HSAMemoryPool);
2742
2747
AllMemoryPools.push_back (MemoryPool);
2743
2748
return HSA_STATUS_SUCCESS;
@@ -3090,7 +3095,7 @@ struct AMDGPUPluginTy final : public GenericPluginTy {
3090
3095
3091
3096
// Initialize the host device using host agents.
3092
3097
HostDevice = allocate<AMDHostDeviceTy>();
3093
- new (HostDevice) AMDHostDeviceTy (HostAgents);
3098
+ new (HostDevice) AMDHostDeviceTy (* this , HostAgents);
3094
3099
3095
3100
// Setup the memory pools of available for the host.
3096
3101
if (auto Err = HostDevice->init ())
@@ -3116,8 +3121,9 @@ struct AMDGPUPluginTy final : public GenericPluginTy {
3116
3121
}
3117
3122
3118
3123
// / Creates an AMDGPU device.
3119
- GenericDeviceTy *createDevice (int32_t DeviceId, int32_t NumDevices) override {
3120
- return new AMDGPUDeviceTy (DeviceId, NumDevices, getHostDevice (),
3124
+ GenericDeviceTy *createDevice (GenericPluginTy &Plugin, int32_t DeviceId,
3125
+ int32_t NumDevices) override {
3126
+ return new AMDGPUDeviceTy (Plugin, DeviceId, NumDevices, getHostDevice (),
3121
3127
getKernelAgent (DeviceId));
3122
3128
}
3123
3129
@@ -3248,7 +3254,9 @@ Error AMDGPUKernelTy::launchImpl(GenericDeviceTy &GenericDevice,
3248
3254
// 56 bytes per allocation.
3249
3255
uint32_t AllArgsSize = KernelArgsSize + ImplicitArgsSize;
3250
3256
3251
- AMDHostDeviceTy &HostDevice = PluginTy::get<AMDGPUPluginTy>().getHostDevice ();
3257
+ AMDGPUPluginTy &AMDGPUPlugin =
3258
+ static_cast <AMDGPUPluginTy &>(GenericDevice.Plugin );
3259
+ AMDHostDeviceTy &HostDevice = AMDGPUPlugin.getHostDevice ();
3252
3260
AMDGPUMemoryManagerTy &ArgsMemoryManager = HostDevice.getArgsMemoryManager ();
3253
3261
3254
3262
void *AllArgs = nullptr ;
@@ -3385,7 +3393,7 @@ void *AMDGPUMemoryManagerTy::allocate(size_t Size, void *HstPtr,
3385
3393
}
3386
3394
assert (Ptr && " Invalid pointer" );
3387
3395
3388
- auto &KernelAgents = PluginTy::get<AMDGPUPluginTy>() .getKernelAgents ();
3396
+ auto &KernelAgents = Plugin .getKernelAgents ();
3389
3397
3390
3398
// Allow all kernel agents to access the allocation.
3391
3399
if (auto Err = MemoryPool->enableAccess (Ptr, Size, KernelAgents)) {
@@ -3428,7 +3436,8 @@ void *AMDGPUDeviceTy::allocate(size_t Size, void *, TargetAllocTy Kind) {
3428
3436
}
3429
3437
3430
3438
if (Alloc) {
3431
- auto &KernelAgents = PluginTy::get<AMDGPUPluginTy>().getKernelAgents ();
3439
+ auto &KernelAgents =
3440
+ static_cast <AMDGPUPluginTy &>(Plugin).getKernelAgents ();
3432
3441
// Inherently necessary for host or shared allocations
3433
3442
// Also enabled for device memory to allow device to device memcpy
3434
3443
0 commit comments