Skip to content

[Offload] Make AMDGPU plugin handle empty allocation properly #142383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -420,7 +420,7 @@ struct AMDGPUMemoryManagerTy : public DeviceAllocatorTy {
assert(PtrStorage && "Invalid pointer storage");

*PtrStorage = MemoryManager->allocate(Size, nullptr);
if (*PtrStorage == nullptr)
if (Size && *PtrStorage == nullptr)
return Plugin::error(ErrorCode::OUT_OF_RESOURCES,
"failure to allocate from AMDGPU memory manager");

Expand All @@ -429,8 +429,6 @@ struct AMDGPUMemoryManagerTy : public DeviceAllocatorTy {

/// Release an allocation to be reused.
Error deallocate(void *Ptr) {
assert(Ptr && "Invalid pointer");

if (MemoryManager->free(Ptr))
return Plugin::error(ErrorCode::UNKNOWN,
"failure to deallocate from AMDGPU memory manager");
Expand Down Expand Up @@ -1204,7 +1202,6 @@ struct AMDGPUStreamTy {
ReleaseBufferArgsTy *Args = reinterpret_cast<ReleaseBufferArgsTy *>(Data);
assert(Args && "Invalid arguments");
assert(Args->MemoryManager && "Invalid memory manager");
assert(Args->Buffer && "Invalid buffer");

// Release the allocation to the memory manager.
return Args->MemoryManager->deallocate(Args->Buffer);
Expand Down
6 changes: 6 additions & 0 deletions offload/test/api/omp_device_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <omp.h>
#include <stdio.h>
#include <assert.h>

int main() {
const int N = 64;
Expand All @@ -24,4 +25,9 @@ int main() {
printf("PASS\n");

omp_free(device_ptr, llvm_omp_target_device_mem_alloc);

// Make sure this interface works.
void *ptr = omp_alloc(0, llvm_omp_target_device_mem_alloc);
assert(!ptr && "Ptr not (nullptr)");
omp_free(ptr, llvm_omp_target_device_mem_alloc);
}
Loading