mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Return Out of Memory given Alloc Host Pointer fails
Related-to: LOCI-3550 Signed-off-by: Neil R Spruit <neil.r.spruit@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
338e376ca4
commit
54db9fddb7
@ -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<NEO::GraphicsAllocation>(alloc), NEO::AllocationUsage::TEMPORARY_ALLOCATION);
|
||||
} else if (alloc->getAllocationType() == NEO::AllocationType::EXTERNAL_HOST_PTR) {
|
||||
|
@ -527,6 +527,9 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::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<gfxCoreFamily>::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<gfxCoreFamily>::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<gfxCoreFamily>::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<gfxCoreFamily>::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<gfxCoreFamily>::getAlignedAll
|
||||
offset += reinterpret_cast<size_t>(ptr) - reinterpret_cast<size_t>(alloc->getUnderlyingBuffer());
|
||||
} else {
|
||||
alloc = getHostPtrAlloc(buffer, bufferSize, hostCopyAllowed);
|
||||
if (alloc == nullptr) {
|
||||
return {0u, 0, nullptr, false};
|
||||
}
|
||||
alignedPtr = static_cast<uintptr_t>(alignDown(alloc->getGpuAddress(), NEO::EncodeSurfaceState<GfxFamily>::getSurfaceBaseAddressAlignment()));
|
||||
if (alloc->getAllocationType() == NEO::AllocationType::EXTERNAL_HOST_PTR) {
|
||||
auto hostAllocCpuPtr = reinterpret_cast<uintptr_t>(alloc->getUnderlyingBuffer());
|
||||
@ -2225,6 +2241,9 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::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<gfxCoreFamily>::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<EventData[]> timestampsData = std::make_unique<EventData[]>(numEvents);
|
||||
@ -2288,6 +2310,9 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::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<uintptr_t>(pOffsetAllocationStruct.alloc->getGpuAddress());
|
||||
commandContainer.addToResidencyContainer(pOffsetAllocationStruct.alloc);
|
||||
builtinKernel = device->getBuiltinFunctionsLib()->getFunction(Builtin::QueryKernelTimestampsWithOffsets);
|
||||
@ -2666,6 +2691,9 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::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<uint64_t>(srcAllocationStruct.alignedAllocationPtr);
|
||||
@ -2709,6 +2737,9 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::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);
|
||||
|
||||
|
@ -34,7 +34,7 @@ class MockCommandListHw : public WhiteBox<::L0::CommandListCoreFamily<gfxCoreFam
|
||||
|
||||
AlignedAllocationData getAlignedAllocation(L0::Device *device, const void *buffer, uint64_t bufferSize, bool allowHostCopy) override {
|
||||
getAlignedAllocationCalledTimes++;
|
||||
if (buffer) {
|
||||
if (buffer && !failAlignedAlloc) {
|
||||
return {0, 0, &alignedAlloc, true};
|
||||
}
|
||||
return {0, 0, nullptr, false};
|
||||
@ -172,6 +172,7 @@ class MockCommandListHw : public WhiteBox<::L0::CommandListCoreFamily<gfxCoreFam
|
||||
uint32_t getAlignedAllocationCalledTimes = 0;
|
||||
bool failOnFirstCopy = false;
|
||||
bool useEvents = false;
|
||||
bool failAlignedAlloc = false;
|
||||
};
|
||||
|
||||
HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryCopyCalledWithNullDstPtrThenAppendMemoryCopyWithappendMemoryCopyReturnsError, IsAtLeastSkl) {
|
||||
@ -181,7 +182,7 @@ HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryCopyCalledWithNullDstPtrT
|
||||
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, givenCommandListWhenMemoryCopyCalledWithNullSrcPtrThenAppendMemoryCopyWithappendMemoryCopyReturnsError, IsAtLeastSkl) {
|
||||
@ -191,7 +192,7 @@ HWTEST2_F(CommandListAppend, givenCommandListWhenMemoryCopyCalledWithNullSrcPtrT
|
||||
void *dstPtr = reinterpret_cast<void *>(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<gfxCoreFamily> 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<gfxCoreFamily> cmdList;
|
||||
cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u);
|
||||
void *srcPtr = nullptr;
|
||||
void *dstPtr = reinterpret_cast<void *>(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<gfxCoreFamily> cmdList;
|
||||
cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u);
|
||||
void *srcPtr = reinterpret_cast<void *>(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<gfxCoreFamily> cmdList;
|
||||
cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u);
|
||||
void *dstPtr = reinterpret_cast<void *>(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<void *>(&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<gfxCoreFamily> 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<IGFX_SKYLAKE, IGFX_TIGERLAKE_LP>;
|
||||
|
||||
HWTEST2_F(CommandListAppend, givenCommandListWhenAppendImageCopyFromMemoryCalledWithNullSrcPtrThenAppendImageCopyFromMemoryReturnsError, ImageSupport) {
|
||||
MockCommandListHw<gfxCoreFamily> 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<WhiteBox<::L0::ImageCoreFamily<gfxCoreFamily>>>();
|
||||
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<gfxCoreFamily> 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<WhiteBox<::L0::ImageCoreFamily<gfxCoreFamily>>>();
|
||||
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<gfxCoreFamily> cmdList;
|
||||
cmdList.initialize(device, NEO::EngineGroupType::Copy, 0u);
|
||||
@ -1139,7 +1229,7 @@ class MockCommandListForRegionSize : public WhiteBox<::L0::CommandListCoreFamily
|
||||
MockCommandListForRegionSize() : WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>() {}
|
||||
|
||||
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<size_t> srcSize = {0, 0, 0};
|
||||
Vec3<size_t> dstSize = {0, 0, 0};
|
||||
NEO::MockGraphicsAllocation mockAllocationPtr = {0,
|
||||
AllocationType::INTERNAL_HOST_MEMORY,
|
||||
reinterpret_cast<void *>(0x1234),
|
||||
1,
|
||||
0u,
|
||||
MemoryPool::System4KBPages,
|
||||
MemoryManager::maxOsContextCount,
|
||||
0x1234};
|
||||
};
|
||||
HWTEST2_F(CommandListCreate, givenZeroAsPitchAndSlicePitchWhenMemoryCopyRegionCalledThenSizesEqualOffsetPlusCopySize, IsAtLeastSkl) {
|
||||
MockCommandListForRegionSize<gfxCoreFamily> cmdList;
|
||||
|
@ -159,6 +159,31 @@ HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenGetHostPtrAllocCalledThenCor
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
template <NEO::AllocationType AllocType>
|
||||
class DeviceHostPtrFailMock : public Mock<DeviceImp> {
|
||||
public:
|
||||
using Mock<L0::DeviceImp>::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<DeviceHostPtrFailMock<NEO::AllocationType::INTERNAL_HOST_MEMORY>>(device->getNEODevice(), execEnv);
|
||||
failDevice->neoDevice = device->getNEODevice();
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(failDevice.get(), NEO::EngineGroupType::Copy, 0u);
|
||||
|
||||
size_t cmdListHostPtrSize = MemoryConstants::pageSize;
|
||||
void *cmdListHostBuffer = reinterpret_cast<void *>(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<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy, 0u);
|
||||
|
@ -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 <GFXCORE_FAMILY gfxCoreFamily>
|
||||
class MockCommandListExtensionHw : public WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>> {
|
||||
public:
|
||||
MockCommandListExtensionHw() : WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>() {}
|
||||
MockCommandListExtensionHw(bool failOnFirst) : WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>(), 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_t> ©Size,
|
||||
size_t srcRowPitch, size_t srcSlicePitch,
|
||||
size_t dstRowPitch, size_t dstSlicePitch,
|
||||
const Vec3<size_t> &srcSize, const Vec3<size_t> &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<size_t> &srcOffsets, const Vec3<size_t> &dstOffsets,
|
||||
size_t srcRowPitch, size_t srcSlicePitch,
|
||||
size_t dstRowPitch, size_t dstSlicePitch,
|
||||
size_t bytesPerPixel, const Vec3<size_t> ©Size,
|
||||
const Vec3<size_t> &srcSize, const Vec3<size_t> &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<size_t> appendImageRegionCopySize = {0, 0, 0};
|
||||
Vec3<size_t> appendImageRegionSrcOrigin = {9, 9, 9};
|
||||
Vec3<size_t> appendImageRegionDstOrigin = {9, 9, 9};
|
||||
|
||||
void *alignedDataPtr = alignUp(mockAlignedAllocData, MemoryConstants::pageSize);
|
||||
|
||||
NEO::MockGraphicsAllocation alignedAlloc{alignedDataPtr, reinterpret_cast<uint64_t>(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<CommandListWaitOnMemFixture>;
|
||||
|
||||
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<gfxCoreFamily> 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<void *>(&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<gfxCoreFamily> 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<void *>(&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;
|
||||
|
Reference in New Issue
Block a user