From 7a867cd98f53a1a53d01989af9b0f15a5ecbc274 Mon Sep 17 00:00:00 2001 From: Vladislav Sytchenko Date: Thu, 26 Mar 2020 12:42:55 -0400 Subject: [PATCH] (SWDEV-228782) The only requirment from hipMallocPitch() is that the returned pitch is aligned to the HW image pitch alignment. There is no restriction on the size of the allocation, since the memory might not be used for images. Change-Id: I97438e5fe4012ca4721b14b85f514dbac803c17c [ROCm/hip commit: a91b82f00e761875e735b0025645fc652149611b] --- projects/hip/vdi/hip_memory.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/projects/hip/vdi/hip_memory.cpp b/projects/hip/vdi/hip_memory.cpp index 2ffa356907..80710e0d13 100644 --- a/projects/hip/vdi/hip_memory.cpp +++ b/projects/hip/vdi/hip_memory.cpp @@ -358,17 +358,13 @@ hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t heigh amd::Device* device = hip::getCurrentDevice()->devices()[0]; - if ((width == 0) || (height == 0)) { - *ptr = nullptr; - return hipSuccess; - } - else if (!(device->info().image2DMaxWidth_ >= width && - device->info().image2DMaxHeight_ >= height ) || (ptr == nullptr)) { + if (ptr == nullptr) { return hipErrorInvalidValue; } - if (device->info().maxMemAllocSize_ < (width * height)) { - return hipErrorOutOfMemory; + if ((width == 0) || (height == 0)) { + *ptr = nullptr; + return hipSuccess; } const amd::Image::Format imageFormat(*image_format); @@ -376,6 +372,11 @@ hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t heigh *pitch = amd::alignUp(width * imageFormat.getElementSize(), device->info().imagePitchAlignment_); size_t sizeBytes = *pitch * height * depth; + + if (device->info().maxMemAllocSize_ < sizeBytes) { + return hipErrorOutOfMemory; + } + *ptr = amd::SvmBuffer::malloc(*hip::getCurrentDevice()->asContext(), 0, sizeBytes, device->info().memBaseAddrAlign_);