Skip to content

Commit

Permalink
Fix uninitialised vars in memory-pool setup in offload runtime
Browse files Browse the repository at this point in the history
This patch fixes a bug in the AMDGPU offload plugin during initialisation of
memory pools.

The function preAllocateDeviceMemoryPool is called (only) from a location where
memory pool metadata structures have already been enumerated and initialised
(in initImpl, by calling initMemoryPools).  But it then calls
retrieveMemoryPools *again*, but does not go on to initialise the newly-created
duplicate metadata properly before using it, meaning some fields (Segment,
GlobalFlags) are left with uninitialised data.  That can lead to unpredictable
behaviour.

The fix is just to remove the "retrieval", i.e. allocation, of duplicate pool
metadata.

Change-Id: I7cd7e46c0f2c655a8007299595c553f33451ccb1
  • Loading branch information
jtb20 authored and ronlieb committed Oct 17, 2024
1 parent b1b5d57 commit 054b7e8
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions offload/plugins-nextgen/amdgpu/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4096,9 +4096,6 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
/// Allocate and zero initialize a small memory pool from the coarse grained
/// device memory of each device.
Error preAllocateDeviceMemoryPool() {
Error Err = retrieveAllMemoryPools();
if (Err)
return Plugin::error("Unable to retieve all memmory pools");

void *DevPtr;
for (AMDGPUMemoryPoolTy *MemoryPool : AllMemoryPools) {
Expand All @@ -4109,7 +4106,7 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
DevPtr = nullptr;
size_t PreAllocSize = hsa_utils::PER_DEVICE_PREALLOC_SIZE;

Err = MemoryPool->allocate(PreAllocSize, &DevPtr);
Error Err = MemoryPool->allocate(PreAllocSize, &DevPtr);
if (Err)
return Plugin::error("Device memory pool preallocation failed");

Expand Down

0 comments on commit 054b7e8

Please sign in to comment.