Fixed offset calculation for blit fill on imported non-usm allocation

Resolves: NEO-7379

Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
Milczarek, Slawomir
2022-10-03 22:14:55 +00:00
committed by Compute-Runtime-Automation
parent 65f7ff2027
commit e11bcb9882
3 changed files with 56 additions and 2 deletions

View File

@@ -265,6 +265,7 @@ struct CommandListCoreFamily : CommandListImp {
size_t estimateBufferSizeMultiTileBarrier(const NEO::HardwareInfo &hwInfo);
uint64_t getInputBufferSize(NEO::ImageType imageType, uint64_t bytesPerPixel, const ze_image_region_t *region);
MOCKABLE_VIRTUAL AlignedAllocationData getAlignedAllocation(Device *device, const void *buffer, uint64_t bufferSize, bool hostCopyAllowed);
size_t getAllocationOffsetForAppendBlitFill(void *ptr, NEO::GraphicsAllocation &gpuAllocation);
void addFlushRequiredCommand(bool flushOperationRequired, Event *signalEvent);
void handlePostSubmissionState();

View File

@@ -1755,7 +1755,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendBlitFill(void *ptr,
}
}
uint64_t offset = reinterpret_cast<uint64_t>(static_cast<uint64_t *>(ptr)) - static_cast<uint64_t>(gpuAllocation->getGpuAddress());
uint64_t offset = getAllocationOffsetForAppendBlitFill(ptr, *gpuAllocation);
commandContainer.addToResidencyContainer(gpuAllocation);
uint32_t patternToCommand[4] = {};
@@ -1902,6 +1902,17 @@ inline AlignedAllocationData CommandListCoreFamily<gfxCoreFamily>::getAlignedAll
return {alignedPtr, offset, alloc, hostPointerNeedsFlush};
}
template <GFXCORE_FAMILY gfxCoreFamily>
inline size_t CommandListCoreFamily<gfxCoreFamily>::getAllocationOffsetForAppendBlitFill(void *ptr, NEO::GraphicsAllocation &gpuAllocation) {
uint64_t offset;
if (gpuAllocation.getAllocationType() == NEO::AllocationType::EXTERNAL_HOST_PTR) {
offset = castToUint64(ptr) - castToUint64(gpuAllocation.getUnderlyingBuffer()) + gpuAllocation.getAllocationOffset();
} else {
offset = castToUint64(ptr) - gpuAllocation.getGpuAddress();
}
return offset;
}
template <GFXCORE_FAMILY gfxCoreFamily>
inline ze_result_t CommandListCoreFamily<gfxCoreFamily>::addEventsToCmdList(uint32_t numWaitEvents,
ze_event_handle_t *phWaitEvents) {

View File

@@ -23,7 +23,11 @@ namespace ult {
template <GFXCORE_FAMILY gfxCoreFamily>
class MockCommandListForMemFill : public WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>> {
public:
MockCommandListForMemFill() : WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>() {}
using BaseClass = WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>;
MockCommandListForMemFill() : BaseClass() {}
using BaseClass::getAllocationOffsetForAppendBlitFill;
AlignedAllocationData getAlignedAllocation(L0::Device *device, const void *buffer, uint64_t bufferSize, bool allowHostCopy) override {
return {0, 0, nullptr, true};
@@ -101,6 +105,44 @@ HWTEST2_F(AppendMemoryCopy, givenCopyOnlyCommandListWhenAppenBlitFillThenCopyBlt
device->setDriverHandle(driverHandle.get());
}
HWTEST2_F(AppendMemoryCopy,
givenExternalHostPointerAllocationWhenPassedToAppendBlitFillThenProgramDestinationAddressCorrectly,
IsAtLeastSkl) {
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
using XY_COLOR_BLT = typename GfxFamily::XY_COLOR_BLT;
L0::Device *device = driverHandle->devices[0];
size_t size = 1024;
auto hostPointer = std::make_unique<uint8_t[]>(size);
auto ret = driverHandle->importExternalPointer(hostPointer.get(), MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
auto gpuAllocation = device->getDriverHandle()->findHostPointerAllocation(hostPointer.get(), size, 0);
ASSERT_NE(nullptr, gpuAllocation);
EXPECT_EQ(NEO::AllocationType::EXTERNAL_HOST_PTR, gpuAllocation->getAllocationType());
MockCommandListForMemFill<gfxCoreFamily> commandList;
commandList.initialize(device, NEO::EngineGroupType::Copy, 0u);
uint32_t pattern = 1;
ze_result_t result = commandList.appendMemoryFill(hostPointer.get(), reinterpret_cast<void *>(&pattern), sizeof(pattern), size, nullptr, 0, nullptr);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandList.commandContainer.getCommandStream()->getCpuBase(), 0), commandList.commandContainer.getCommandStream()->getUsed()));
auto itor = find<XY_COLOR_BLT *>(cmdList.begin(), cmdList.end());
EXPECT_NE(cmdList.end(), itor);
auto cmd = genCmdCast<XY_COLOR_BLT *>(*itor);
uint64_t offset = commandList.getAllocationOffsetForAppendBlitFill(hostPointer.get(), *gpuAllocation);
EXPECT_EQ(cmd->getDestinationBaseAddress(), ptrOffset(gpuAllocation->getGpuAddress(), offset));
ret = driverHandle->releaseImportedPointer(hostPointer.get());
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(AppendMemoryCopy, givenCopyOnlyCommandListAndHostPointersWhenMemoryCopyCalledThenPipeControlWithDcFlushAddedIsNotAddedAfterBlitCopy, IsAtLeastSkl) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;