diff --git a/rocclr/device/rocm/rocdevice.cpp b/rocclr/device/rocm/rocdevice.cpp index 0b9bb784dc..9dea3d444d 100644 --- a/rocclr/device/rocm/rocdevice.cpp +++ b/rocclr/device/rocm/rocdevice.cpp @@ -2254,6 +2254,10 @@ void* Device::svmAlloc(amd::Context& context, size_t size, size_t alignment, cl_ } // if the device supports SVM FGS, return the committed CPU address directly. Memory* gpuMem = getRocMemory(mem); + if (gpuMem == nullptr) { + LogError("failed to create GPU memory from svm hidden buffer!"); + return nullptr; + } if (mem->getSvmPtr() != nullptr) { // add the information to context so that we can use it later. diff --git a/rocclr/device/rocm/rocmemory.cpp b/rocclr/device/rocm/rocmemory.cpp index c4d15c8bcd..9d1deb5d44 100644 --- a/rocclr/device/rocm/rocmemory.cpp +++ b/rocclr/device/rocm/rocmemory.cpp @@ -752,6 +752,9 @@ bool Buffer::create(bool alloc_local) { // AMD HMM path. Just allocate system memory and KFD will manage it deviceMemory_ = amd::Os::reserveMemory( 0, size(), amd::Os::pageSize(), amd::Os::MEM_PROT_RW); + if (deviceMemory_ == NULL) { + return false; + } amd::Os::commitMemory(deviceMemory_, size(), amd::Os::MEM_PROT_RW); // Currently HMM requires cirtain initial calls to mark sysmem allocation as // GPU accessible or prefetch memory into GPU diff --git a/rocclr/os/os_posix.cpp b/rocclr/os/os_posix.cpp index c6005afe5b..87c1ac3387 100644 --- a/rocclr/os/os_posix.cpp +++ b/rocclr/os/os_posix.cpp @@ -201,6 +201,10 @@ static inline int memProtToOsProt(Os::MemProt prot) { address Os::reserveMemory(address start, size_t size, size_t alignment, MemProt prot) { size = alignUp(size, pageSize()); + // check for invalid input size + if (size == 0) { + return NULL; + } alignment = std::max(pageSize(), alignUp(alignment, pageSize())); assert(isPowerOfTwo(alignment) && "not a power of 2");