diff --git a/level_zero/core/source/cmdlist/cmdlist.cpp b/level_zero/core/source/cmdlist/cmdlist.cpp index 6ee9b45022..b37b87c0e1 100644 --- a/level_zero/core/source/cmdlist/cmdlist.cpp +++ b/level_zero/core/source/cmdlist/cmdlist.cpp @@ -89,7 +89,9 @@ NEO::GraphicsAllocation *CommandList::getHostPtrAlloc(const void *buffer, uint64 return alloc; } alloc = device->allocateMemoryFromHostPtr(buffer, bufferSize, hostCopyAllowed); - UNRECOVERABLE_IF(alloc == nullptr); + if (alloc == nullptr) { + return nullptr; + } if (this->storeExternalPtrAsTemporary()) { this->csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr(alloc), NEO::AllocationUsage::TEMPORARY_ALLOCATION); } else if (alloc->getAllocationType() == NEO::AllocationType::EXTERNAL_HOST_PTR) { diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index a54d406c6f..f300c5bddc 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -527,6 +527,9 @@ ze_result_t CommandListCoreFamily::appendImageCopyFromMemory(ze_i uint64_t bufferSize = getInputBufferSize(image->getImageInfo().imgDesc.imageType, bytesPerPixel, pDstRegion); auto allocationStruct = getAlignedAllocation(this->device, srcPtr, bufferSize, true); + if (allocationStruct.alloc == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } auto rowPitch = pDstRegion->width * bytesPerPixel; auto slicePitch = @@ -652,6 +655,9 @@ ze_result_t CommandListCoreFamily::appendImageCopyToMemory(void * uint64_t bufferSize = getInputBufferSize(image->getImageInfo().imgDesc.imageType, bytesPerPixel, pSrcRegion); auto allocationStruct = getAlignedAllocation(this->device, dstPtr, bufferSize, false); + if (allocationStruct.alloc == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } auto rowPitch = pSrcRegion->width * bytesPerPixel; auto slicePitch = @@ -1182,7 +1188,7 @@ ze_result_t CommandListCoreFamily::appendMemoryCopy(void *dstptr, auto srcAllocationStruct = getAlignedAllocation(this->device, srcptr, size, true); if (dstAllocationStruct.alloc == nullptr || srcAllocationStruct.alloc == nullptr) { - return ZE_RESULT_ERROR_UNKNOWN; + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; } if (size >= 4ull * MemoryConstants::gigaByte) { @@ -1342,6 +1348,10 @@ ze_result_t CommandListCoreFamily::appendMemoryCopyRegion(void *d signalEvent = Event::fromHandle(hSignalEvent); } + if (dstAllocationStruct.alloc == nullptr || srcAllocationStruct.alloc == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } + ze_result_t result = ZE_RESULT_SUCCESS; if (srcRegion->depth > 1) { result = isCopyOnly() ? appendMemoryCopyBlitRegion(srcAllocationStruct.alloc, dstAllocationStruct.alloc, srcAllocationStruct.offset, dstAllocationStruct.offset, *srcRegion, *dstRegion, {srcRegion->width, srcRegion->height, srcRegion->depth}, @@ -1595,6 +1605,9 @@ ze_result_t CommandListCoreFamily::appendMemoryFill(void *ptr, } auto dstAllocation = this->getAlignedAllocation(this->device, ptr, size, false); + if (dstAllocation.alloc == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } if (size >= 4ull * MemoryConstants::gigaByte) { isStateless = true; } @@ -1897,6 +1910,9 @@ inline AlignedAllocationData CommandListCoreFamily::getAlignedAll offset += reinterpret_cast(ptr) - reinterpret_cast(alloc->getUnderlyingBuffer()); } else { alloc = getHostPtrAlloc(buffer, bufferSize, hostCopyAllowed); + if (alloc == nullptr) { + return {0u, 0, nullptr, false}; + } alignedPtr = static_cast(alignDown(alloc->getGpuAddress(), NEO::EncodeSurfaceState::getSurfaceBaseAddressAlignment())); if (alloc->getAllocationType() == NEO::AllocationType::EXTERNAL_HOST_PTR) { auto hostAllocCpuPtr = reinterpret_cast(alloc->getUnderlyingBuffer()); @@ -2225,6 +2241,9 @@ ze_result_t CommandListCoreFamily::appendWriteGlobalTimestamp( appendSignalEventPostWalker(signalEvent); auto allocationStruct = getAlignedAllocation(this->device, dstptr, sizeof(uint64_t), false); + if (allocationStruct.alloc == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } commandContainer.addToResidencyContainer(allocationStruct.alloc); return ZE_RESULT_SUCCESS; @@ -2245,6 +2264,9 @@ ze_result_t CommandListCoreFamily::appendQueryKernelTimestamps( uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) { auto dstPtrAllocationStruct = getAlignedAllocation(this->device, dstptr, sizeof(ze_kernel_timestamp_result_t) * numEvents, false); + if (dstPtrAllocationStruct.alloc == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } commandContainer.addToResidencyContainer(dstPtrAllocationStruct.alloc); std::unique_ptr timestampsData = std::make_unique(numEvents); @@ -2288,6 +2310,9 @@ ze_result_t CommandListCoreFamily::appendQueryKernelTimestamps( builtinKernel->setArgumentValue(2u, sizeof(uint32_t), &useOnlyGlobalTimestamps); } else { auto pOffsetAllocationStruct = getAlignedAllocation(this->device, pOffsets, sizeof(size_t) * numEvents, false); + if (pOffsetAllocationStruct.alloc == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } auto offsetValPtr = static_cast(pOffsetAllocationStruct.alloc->getGpuAddress()); commandContainer.addToResidencyContainer(pOffsetAllocationStruct.alloc); builtinKernel = device->getBuiltinFunctionsLib()->getFunction(Builtin::QueryKernelTimestampsWithOffsets); @@ -2666,6 +2691,9 @@ ze_result_t CommandListCoreFamily::appendWaitOnMemory(void *desc, } auto srcAllocationStruct = getAlignedAllocation(this->device, ptr, sizeof(uint32_t), true); + if (srcAllocationStruct.alloc == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } UNRECOVERABLE_IF(srcAllocationStruct.alloc == nullptr); commandContainer.addToResidencyContainer(srcAllocationStruct.alloc); uint64_t gpuAddress = static_cast(srcAllocationStruct.alignedAllocationPtr); @@ -2709,6 +2737,9 @@ ze_result_t CommandListCoreFamily::appendWriteToMemory(void *desc size_t bufSize = sizeof(uint64_t); auto dstAllocationStruct = getAlignedAllocation(this->device, ptr, bufSize, false); + if (dstAllocationStruct.alloc == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } UNRECOVERABLE_IF(dstAllocationStruct.alloc == nullptr); commandContainer.addToResidencyContainer(dstAllocationStruct.alloc); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp index 614107da46..2ad50b929f 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp @@ -34,7 +34,7 @@ class MockCommandListHw : public WhiteBox<::L0::CommandListCoreFamily(0x2345); ze_result_t ret = cmdList.appendMemoryCopy(dstPtr, srcPtr, 0x1001, nullptr, 0, nullptr); EXPECT_GT(cmdList.getAlignedAllocationCalledTimes, 0u); - EXPECT_EQ(ret, ZE_RESULT_ERROR_UNKNOWN); + EXPECT_EQ(ret, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); } HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryCopyCalledWithNullSrcPtrAndDstPtrThenAppendMemoryCopyWithappendMemoryCopyReturnsError, IsAtLeastSkl) { @@ -201,7 +202,68 @@ HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryCopyCalledWithNullSrcPtrA void *dstPtr = nullptr; ze_result_t ret = cmdList.appendMemoryCopy(dstPtr, srcPtr, 0x1001, nullptr, 0, nullptr); EXPECT_GT(cmdList.getAlignedAllocationCalledTimes, 0u); - EXPECT_EQ(ret, ZE_RESULT_ERROR_UNKNOWN); + EXPECT_EQ(ret, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); +} + +HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryCopyRegionCalledWithNullSrcPtrAndDstPtrThenAppendMemoryCopyRegionReturnsError, IsAtLeastSkl) { + MockCommandListHw cmdList; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + void *srcPtr = nullptr; + void *dstPtr = nullptr; + ze_copy_region_t dstRegion = {}; + ze_copy_region_t srcRegion = {}; + ze_result_t ret = cmdList.appendMemoryCopyRegion(dstPtr, &dstRegion, 0, 0, srcPtr, &srcRegion, 0, 0, nullptr, 0, nullptr); + EXPECT_GT(cmdList.getAlignedAllocationCalledTimes, 0u); + EXPECT_EQ(ret, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); +} + +HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryCopyRegionCalledWithNullSrcPtrThenAppendMemoryCopyRegionReturnsError, IsAtLeastSkl) { + MockCommandListHw cmdList; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + void *srcPtr = nullptr; + void *dstPtr = reinterpret_cast(0x2345); + ze_copy_region_t dstRegion = {}; + ze_copy_region_t srcRegion = {}; + ze_result_t ret = cmdList.appendMemoryCopyRegion(dstPtr, &dstRegion, 0, 0, srcPtr, &srcRegion, 0, 0, nullptr, 0, nullptr); + EXPECT_GT(cmdList.getAlignedAllocationCalledTimes, 0u); + EXPECT_EQ(ret, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); +} + +HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryCopyRegionCalledWithNullDstPtrThenAppendMemoryCopyRegionReturnsError, IsAtLeastSkl) { + MockCommandListHw cmdList; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + void *srcPtr = reinterpret_cast(0x2345); + void *dstPtr = nullptr; + ze_copy_region_t dstRegion = {}; + ze_copy_region_t srcRegion = {}; + ze_result_t ret = cmdList.appendMemoryCopyRegion(dstPtr, &dstRegion, 0, 0, srcPtr, &srcRegion, 0, 0, nullptr, 0, nullptr); + EXPECT_GT(cmdList.getAlignedAllocationCalledTimes, 0u); + EXPECT_EQ(ret, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); +} + +HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryFillCalledWithNullDstPtrThenAppendMemoryFillReturnsError, IsAtLeastSkl) { + MockCommandListHw cmdList; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + void *dstPtr = reinterpret_cast(0x1234); + int pattern = 1; + cmdList.failAlignedAlloc = true; + auto result = driverHandle->importExternalPointer(dstPtr, MemoryConstants::pageSize); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + ze_result_t ret = cmdList.appendMemoryFill(dstPtr, reinterpret_cast(&pattern), sizeof(pattern), 0, nullptr, 0, nullptr); + EXPECT_GT(cmdList.getAlignedAllocationCalledTimes, 0u); + EXPECT_EQ(ret, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); + result = driverHandle->releaseImportedPointer(dstPtr); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); +} + +HWTEST2_F(CommandListAppend, givenCommandListWhenQueryKernelTimestampsCalledWithNullDstPtrThenAppendQueryKernelTimestampsReturnsError, IsAtLeastSkl) { + MockCommandListHw cmdList; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + void *dstPtr = nullptr; + ze_event_handle_t eventHandle = {}; + ze_result_t ret = cmdList.appendQueryKernelTimestamps(1u, &eventHandle, dstPtr, nullptr, nullptr, 1u, nullptr); + EXPECT_GT(cmdList.getAlignedAllocationCalledTimes, 0u); + EXPECT_EQ(ret, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); } HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryCopyCalledThenAppendMemoryCopyWithappendMemoryCopyKernelWithGACalled, IsAtLeastSkl) { @@ -660,6 +722,34 @@ HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyWithSignalEventScopeS using ImageSupport = IsWithinProducts; +HWTEST2_F(CommandListAppend, givenCommandListWhenAppendImageCopyFromMemoryCalledWithNullSrcPtrThenAppendImageCopyFromMemoryReturnsError, ImageSupport) { + MockCommandListHw cmdList; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + void *srcPtr = nullptr; + ze_image_desc_t zeDesc = {}; + zeDesc.stype = ZE_STRUCTURE_TYPE_IMAGE_DESC; + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + ze_image_region_t dstRegion = {4, 4, 4, 2, 2, 2}; + ze_result_t ret = cmdList.appendImageCopyFromMemory(imageHW->toHandle(), srcPtr, &dstRegion, nullptr, 0, nullptr); + EXPECT_GT(cmdList.getAlignedAllocationCalledTimes, 0u); + EXPECT_EQ(ret, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); +} + +HWTEST2_F(CommandListAppend, givenCommandListWhenAppendImageCopyToMemoryCalledWithNullDstPtrThenAppendImageCopyToMemoryReturnsError, ImageSupport) { + MockCommandListHw cmdList; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + void *dstPtr = nullptr; + ze_image_desc_t zeDesc = {}; + zeDesc.stype = ZE_STRUCTURE_TYPE_IMAGE_DESC; + auto imageHW = std::make_unique>>(); + imageHW->initialize(device, &zeDesc); + ze_image_region_t srcRegion = {4, 4, 4, 2, 2, 2}; + ze_result_t ret = cmdList.appendImageCopyToMemory(dstPtr, imageHW->toHandle(), &srcRegion, nullptr, 0, nullptr); + EXPECT_GT(cmdList.getAlignedAllocationCalledTimes, 0u); + EXPECT_EQ(ret, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); +} + HWTEST2_F(CommandListAppend, givenCopyCommandListWhenCopyFromMemoryToImageThenBlitImageCopyCalled, ImageSupport) { MockCommandListHw cmdList; cmdList.initialize(device, NEO::EngineGroupType::Copy, 0u); @@ -1139,7 +1229,7 @@ class MockCommandListForRegionSize : public WhiteBox<::L0::CommandListCoreFamily MockCommandListForRegionSize() : WhiteBox<::L0::CommandListCoreFamily>() {} AlignedAllocationData getAlignedAllocation(L0::Device *device, const void *buffer, uint64_t bufferSize, bool allowHostCopy) override { - return {0, 0, nullptr, true}; + return {0, 0, &mockAllocationPtr, true}; } ze_result_t appendMemoryCopyBlitRegion(NEO::GraphicsAllocation *srcAllocation, NEO::GraphicsAllocation *dstAllocation, @@ -1158,6 +1248,14 @@ class MockCommandListForRegionSize : public WhiteBox<::L0::CommandListCoreFamily } Vec3 srcSize = {0, 0, 0}; Vec3 dstSize = {0, 0, 0}; + NEO::MockGraphicsAllocation mockAllocationPtr = {0, + AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), + 1, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + 0x1234}; }; HWTEST2_F(CommandListCreate, givenZeroAsPitchAndSlicePitchWhenMemoryCopyRegionCalledThenSizesEqualOffsetPlusCopySize, IsAtLeastSkl) { MockCommandListForRegionSize cmdList; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp index a6de14d61c..fabfd69810 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp @@ -159,6 +159,31 @@ HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenGetHostPtrAllocCalledThenCor commandList->hostPtrMap.clear(); } +template +class DeviceHostPtrFailMock : public Mock { + public: + using Mock::Mock; + NEO::GraphicsAllocation *allocateMemoryFromHostPtr(const void *buffer, size_t size, bool hostCopyAllowed) override { + return nullptr; + } + const NEO::HardwareInfo &getHwInfo() const override { + return neoDevice->getHardwareInfo(); + } +}; + +HWTEST2_F(CommandListCreate, givenGetAlignedAllocationCalledWithInvalidPtrThenNullptrReturned, IsAtLeastSkl) { + auto failDevice = std::make_unique>(device->getNEODevice(), execEnv); + failDevice->neoDevice = device->getNEODevice(); + auto commandList = std::make_unique>>(); + commandList->initialize(failDevice.get(), NEO::EngineGroupType::Copy, 0u); + + size_t cmdListHostPtrSize = MemoryConstants::pageSize; + void *cmdListHostBuffer = reinterpret_cast(0x1234); + AlignedAllocationData outData = {}; + outData = commandList->getAlignedAllocation(device, cmdListHostBuffer, cmdListHostPtrSize, false); + EXPECT_EQ(nullptr, outData.alloc); +} + HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsInMapThenAllocationReturned, IsAtLeastSkl) { auto commandList = std::make_unique>>(); commandList->initialize(device, NEO::EngineGroupType::Copy, 0u); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_memory_extension.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_memory_extension.cpp index e6b44c2b28..1cd7100895 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_memory_extension.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_memory_extension.cpp @@ -7,6 +7,7 @@ #include "shared/test/common/cmd_parse/gen_cmd_parse.h" #include "shared/test/common/helpers/unit_test_helper.h" +#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/test_macros/hw_test.h" #include "level_zero/api/driver_experimental/public/zex_api.h" @@ -64,6 +65,154 @@ class CommandListWaitOnMemFixture : public DeviceFixture { void *ptr = nullptr; }; +template +class MockCommandListExtensionHw : public WhiteBox<::L0::CommandListCoreFamily> { + public: + MockCommandListExtensionHw() : WhiteBox<::L0::CommandListCoreFamily>() {} + MockCommandListExtensionHw(bool failOnFirst) : WhiteBox<::L0::CommandListCoreFamily>(), failOnFirstCopy(failOnFirst) {} + + AlignedAllocationData getAlignedAllocation(L0::Device *device, const void *buffer, uint64_t bufferSize, bool allowHostCopy) override { + getAlignedAllocationCalledTimes++; + if (buffer) { + return {0, 0, &alignedAlloc, true}; + } + return {0, 0, nullptr, false}; + } + + ze_result_t appendMemoryCopyKernelWithGA(void *dstPtr, + NEO::GraphicsAllocation *dstPtrAlloc, + uint64_t dstOffset, + void *srcPtr, + NEO::GraphicsAllocation *srcPtrAlloc, + uint64_t srcOffset, + uint64_t size, + uint64_t elementSize, + Builtin builtin, + Event *signalEvent, + bool isStateless, + CmdListKernelLaunchParams &launchParams) override { + appendMemoryCopyKernelWithGACalledTimes++; + if (isStateless) { + appendMemoryCopyKernelWithGAStatelessCalledTimes++; + } + if (signalEvent) { + useEvents = true; + } else { + useEvents = false; + } + if (failOnFirstCopy && + (appendMemoryCopyKernelWithGACalledTimes == 1 || appendMemoryCopyKernelWithGAStatelessCalledTimes == 1)) { + return ZE_RESULT_ERROR_UNKNOWN; + } + return ZE_RESULT_SUCCESS; + } + ze_result_t appendMemoryCopyBlit(uintptr_t dstPtr, + NEO::GraphicsAllocation *dstPtrAlloc, + uint64_t dstOffset, uintptr_t srcPtr, + NEO::GraphicsAllocation *srcPtrAlloc, + uint64_t srcOffset, + uint64_t size) override { + appendMemoryCopyBlitCalledTimes++; + if (failOnFirstCopy && appendMemoryCopyBlitCalledTimes == 1) { + return ZE_RESULT_ERROR_UNKNOWN; + } + return ZE_RESULT_SUCCESS; + } + + ze_result_t appendMemoryCopyBlitRegion(NEO::GraphicsAllocation *srcAllocation, + NEO::GraphicsAllocation *dstAllocation, + size_t srcOffset, + size_t dstOffset, + ze_copy_region_t srcRegion, + ze_copy_region_t dstRegion, const Vec3 ©Size, + size_t srcRowPitch, size_t srcSlicePitch, + size_t dstRowPitch, size_t dstSlicePitch, + const Vec3 &srcSize, const Vec3 &dstSize, + Event *signalEvent, + uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) override { + if (signalEvent) { + useEvents = true; + } else { + useEvents = false; + } + appendMemoryCopyBlitRegionCalledTimes++; + return ZE_RESULT_SUCCESS; + } + + ze_result_t appendMemoryCopyKernel2d(AlignedAllocationData *dstAlignedAllocation, AlignedAllocationData *srcAlignedAllocation, + Builtin builtin, const ze_copy_region_t *dstRegion, + uint32_t dstPitch, size_t dstOffset, + const ze_copy_region_t *srcRegion, uint32_t srcPitch, + size_t srcOffset, Event *signalEvent, + uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) override { + appendMemoryCopyKernel2dCalledTimes++; + return ZE_RESULT_SUCCESS; + } + + ze_result_t appendMemoryCopyKernel3d(AlignedAllocationData *dstAlignedAllocation, AlignedAllocationData *srcAlignedAllocation, + Builtin builtin, const ze_copy_region_t *dstRegion, + uint32_t dstPitch, uint32_t dstSlicePitch, size_t dstOffset, + const ze_copy_region_t *srcRegion, uint32_t srcPitch, + uint32_t srcSlicePitch, size_t srcOffset, + Event *signalEvent, uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) override { + appendMemoryCopyKernel3dCalledTimes++; + return ZE_RESULT_SUCCESS; + } + ze_result_t appendBlitFill(void *ptr, const void *pattern, + size_t patternSize, size_t size, + Event *signalEvent, uint32_t numWaitEvents, + ze_event_handle_t *phWaitEvents) override { + appendBlitFillCalledTimes++; + if (signalEvent) { + useEvents = true; + } else { + useEvents = false; + } + return ZE_RESULT_SUCCESS; + } + ze_result_t appendCopyImageBlit(NEO::GraphicsAllocation *src, + NEO::GraphicsAllocation *dst, + const Vec3 &srcOffsets, const Vec3 &dstOffsets, + size_t srcRowPitch, size_t srcSlicePitch, + size_t dstRowPitch, size_t dstSlicePitch, + size_t bytesPerPixel, const Vec3 ©Size, + const Vec3 &srcSize, const Vec3 &dstSize, + Event *signalEvent) override { + appendCopyImageBlitCalledTimes++; + appendImageRegionCopySize = copySize; + appendImageRegionSrcOrigin = srcOffsets; + appendImageRegionDstOrigin = dstOffsets; + if (signalEvent) { + useEvents = true; + } else { + useEvents = false; + } + return ZE_RESULT_SUCCESS; + } + uint8_t mockAlignedAllocData[2 * MemoryConstants::pageSize]{}; + + Vec3 appendImageRegionCopySize = {0, 0, 0}; + Vec3 appendImageRegionSrcOrigin = {9, 9, 9}; + Vec3 appendImageRegionDstOrigin = {9, 9, 9}; + + void *alignedDataPtr = alignUp(mockAlignedAllocData, MemoryConstants::pageSize); + + NEO::MockGraphicsAllocation alignedAlloc{alignedDataPtr, reinterpret_cast(alignedDataPtr), MemoryConstants::pageSize}; + + uint32_t appendMemoryCopyKernelWithGACalledTimes = 0; + uint32_t appendMemoryCopyKernelWithGAStatelessCalledTimes = 0; + uint32_t appendMemoryCopyBlitCalledTimes = 0; + uint32_t appendMemoryCopyBlitRegionCalledTimes = 0; + uint32_t appendMemoryCopyKernel2dCalledTimes = 0; + uint32_t appendMemoryCopyKernel3dCalledTimes = 0; + uint32_t appendBlitFillCalledTimes = 0; + uint32_t appendCopyImageBlitCalledTimes = 0; + uint32_t getAlignedAllocationCalledTimes = 0; + bool failOnFirstCopy = false; + bool useEvents = false; +}; + using CommandListAppendWaitOnMem = Test; HWTEST_F(CommandListAppendWaitOnMem, givenAppendWaitOnMemWithValidAddressAndDataAndNotEqualOpThenSemaphoreWaitProgrammedCorrectly) { @@ -91,6 +240,19 @@ HWTEST_F(CommandListAppendWaitOnMem, givenAppendWaitOnMemWithValidAddressAndData MI_SEMAPHORE_WAIT::WAIT_MODE::WAIT_MODE_POLLING_MODE); } +HWTEST2_F(CommandListAppendWaitOnMem, givenCommandListWaitOnMemoryCalledWithNullPtrThenAppendWaitOnMemoryReturnsError, IsAtLeastSkl) { + ze_result_t result = ZE_RESULT_SUCCESS; + MockCommandListExtensionHw cmdList; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + uint32_t waitMemData = 1u; + + zex_wait_on_mem_desc_t desc; + desc.actionFlag = ZEX_WAIT_ON_MEMORY_FLAG_NOT_EQUAL; + void *badPtr = nullptr; + result = cmdList.appendWaitOnMemory(reinterpret_cast(&desc), badPtr, waitMemData, nullptr); + EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, result); +} + HWTEST_F(CommandListAppendWaitOnMem, givenAppendWaitOnMemWithValidAddressAndDataAndEqualOpThenSemaphoreWaitProgrammedCorrectly) { using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; ze_result_t result = ZE_RESULT_SUCCESS; @@ -474,6 +636,19 @@ HWTEST_F(CommandListAppendWriteToMem, givenAppendWriteToMemWithNoScopeThenPipeCo } ASSERT_TRUE(postSyncFound); } + +HWTEST2_F(CommandListAppendWriteToMem, givenCommandListWriteToMemCalledWithNullPtrThenAppendWriteToMemoryReturnsError, IsAtLeastSkl) { + ze_result_t result = ZE_RESULT_SUCCESS; + MockCommandListExtensionHw cmdList; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + + zex_write_to_mem_desc_t desc = {}; + uint64_t data = 0xabc; + void *badPtr = nullptr; + result = cmdList.appendWriteToMemory(reinterpret_cast(&desc), badPtr, data); + EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, result); +} + HWTEST_F(CommandListAppendWriteToMem, givenAppendWriteToMemOnBcsWithNoScopeThenFlushDwEncodedCorrectly) { using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW; ze_result_t result = ZE_RESULT_SUCCESS;