fix: extract checks for imported allocations

Related-To: NEO-16868

Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
Szymon Morek
2025-12-02 10:52:20 +00:00
committed by Compute-Runtime-Automation
parent f0295adeb3
commit cf9d9df8a9
5 changed files with 35 additions and 35 deletions

View File

@@ -262,6 +262,7 @@ struct CommandListCoreFamilyImmediate : public CommandListCoreFamily<gfxCoreFami
size_t estimateAdditionalSizeAppendRegularCommandLists(uint32_t numCommandLists, ze_command_list_handle_t *phCommandLists);
void setupFlagsForBcsSplit(CmdListMemoryCopyParams &memoryCopyParams, bool &hasStallingCmds, bool &copyOffloadFlush, const void *srcPtr, void *dstPtr, size_t srcSize, size_t dstSize);
void tryResetKernelWithAssertFlag();
void obtainAllocData(CpuMemCopyInfo &cpuMemCopyInfo);
MOCKABLE_VIRTUAL void checkAssert();
ComputeFlushMethodType computeFlushMethod = nullptr;

View File

@@ -689,8 +689,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendMemoryCopy(
ze_result_t ret;
CpuMemCopyInfo cpuMemCopyInfo(dstptr, const_cast<void *>(srcptr), size);
this->device->getDriverHandle()->findAllocationDataForRange(const_cast<void *>(srcptr), size, cpuMemCopyInfo.srcAllocData);
this->device->getDriverHandle()->findAllocationDataForRange(dstptr, size, cpuMemCopyInfo.dstAllocData);
this->obtainAllocData(cpuMemCopyInfo);
if (preferCopyThroughLockedPtr(cpuMemCopyInfo, numWaitEvents, phWaitEvents)) {
ret = performCpuMemcpy(cpuMemCopyInfo, hSignalEvent, numWaitEvents, phWaitEvents);
if (ret == ZE_RESULT_SUCCESS || ret == ZE_RESULT_ERROR_DEVICE_LOST) {
@@ -1368,15 +1367,6 @@ bool CommandListCoreFamilyImmediate<gfxCoreFamily>::preferCopyThroughLockedPtr(C
return false;
}
if (cpuMemCopyInfo.srcAllocData == nullptr) {
auto hostAlloc = this->getDevice()->getDriverHandle()->findHostPointerAllocation(cpuMemCopyInfo.srcPtr, cpuMemCopyInfo.size, this->getDevice()->getRootDeviceIndex());
cpuMemCopyInfo.srcIsImportedHostPtr = hostAlloc != nullptr;
}
if (cpuMemCopyInfo.dstAllocData == nullptr) {
auto hostAlloc = this->getDevice()->getDriverHandle()->findHostPointerAllocation(cpuMemCopyInfo.dstPtr, cpuMemCopyInfo.size, this->getDevice()->getRootDeviceIndex());
cpuMemCopyInfo.dstIsImportedHostPtr = hostAlloc != nullptr;
}
const TransferType transferType = getTransferType(cpuMemCopyInfo);
const size_t transferThreshold = getTransferThreshold(transferType);
@@ -1999,4 +1989,18 @@ bool CommandListCoreFamilyImmediate<gfxCoreFamily>::handleRelaxedOrderingSignali
return false;
}
template <GFXCORE_FAMILY gfxCoreFamily>
void CommandListCoreFamilyImmediate<gfxCoreFamily>::obtainAllocData(CpuMemCopyInfo &cpuMemCopyInfo) {
this->device->getDriverHandle()->findAllocationDataForRange(const_cast<void *>(cpuMemCopyInfo.srcPtr), cpuMemCopyInfo.size, cpuMemCopyInfo.srcAllocData);
this->device->getDriverHandle()->findAllocationDataForRange(cpuMemCopyInfo.dstPtr, cpuMemCopyInfo.size, cpuMemCopyInfo.dstAllocData);
if (cpuMemCopyInfo.srcAllocData == nullptr) {
auto hostAlloc = this->getDevice()->getDriverHandle()->findHostPointerAllocation(cpuMemCopyInfo.srcPtr, cpuMemCopyInfo.size, this->getDevice()->getRootDeviceIndex());
cpuMemCopyInfo.srcIsImportedHostPtr = hostAlloc != nullptr;
}
if (cpuMemCopyInfo.dstAllocData == nullptr) {
auto hostAlloc = this->getDevice()->getDriverHandle()->findHostPointerAllocation(cpuMemCopyInfo.dstPtr, cpuMemCopyInfo.size, this->getDevice()->getRootDeviceIndex());
cpuMemCopyInfo.dstIsImportedHostPtr = hostAlloc != nullptr;
}
}
} // namespace L0

View File

@@ -788,6 +788,7 @@ class MockCommandListImmediateHw : public WhiteBox<::L0::CommandListCoreFamilyIm
using BaseClass::isSmallBarConfigPresent;
using BaseClass::isSyncModeQueue;
using BaseClass::isTbxMode;
using BaseClass::obtainAllocData;
using BaseClass::setupFillKernelArguments;
ze_result_t executeCommandListImmediateWithFlushTask(bool performMigration, bool hasStallingCmds, bool hasRelaxedOrderingDependencies, NEO::AppendOperations appendOperation,

View File

@@ -83,14 +83,12 @@ HWTEST_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndImportedHostPtr
std::array<size_t, 4> sizes = {1, 256, 4096, sz};
for (size_t i = 0; i < sizes.size(); i++) {
CpuMemCopyInfo copyInfoDeviceUsmToHostUsm(hostPtr, devicePtr, sizes[i]);
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(devicePtr, sizes[i], copyInfoDeviceUsmToHostUsm.srcAllocData));
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(hostPtr, sizes[i], copyInfoDeviceUsmToHostUsm.dstAllocData));
cmdList.obtainAllocData(copyInfoDeviceUsmToHostUsm);
EXPECT_NE(nullptr, copyInfoDeviceUsmToHostUsm.srcAllocData);
EXPECT_NE(nullptr, copyInfoDeviceUsmToHostUsm.dstAllocData);
CpuMemCopyInfo copyInfoDeviceUsmToHostImported(importedPtr, devicePtr, sizes[i]);
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(devicePtr, sizes[i], copyInfoDeviceUsmToHostImported.srcAllocData));
EXPECT_FALSE(device->getDriverHandle()->findAllocationDataForRange(importedPtr, sizes[i], copyInfoDeviceUsmToHostImported.dstAllocData));
cmdList.obtainAllocData(copyInfoDeviceUsmToHostImported);
EXPECT_NE(nullptr, copyInfoDeviceUsmToHostImported.srcAllocData);
EXPECT_EQ(nullptr, copyInfoDeviceUsmToHostImported.dstAllocData);
@@ -98,14 +96,12 @@ HWTEST_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndImportedHostPtr
EXPECT_TRUE(copyInfoDeviceUsmToHostImported.dstIsImportedHostPtr);
CpuMemCopyInfo copyInfoHostUsmToDeviceUsm(devicePtr, hostPtr, sizes[i]);
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(hostPtr, sizes[i], copyInfoHostUsmToDeviceUsm.srcAllocData));
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(devicePtr, sizes[i], copyInfoHostUsmToDeviceUsm.dstAllocData));
cmdList.obtainAllocData(copyInfoHostUsmToDeviceUsm);
EXPECT_NE(nullptr, copyInfoHostUsmToDeviceUsm.srcAllocData);
EXPECT_NE(nullptr, copyInfoHostUsmToDeviceUsm.dstAllocData);
CpuMemCopyInfo copyInfoHostImportedToDeviceUsm(devicePtr, importedPtr, sizes[i]);
EXPECT_FALSE(device->getDriverHandle()->findAllocationDataForRange(importedPtr, sizes[i], copyInfoHostImportedToDeviceUsm.srcAllocData));
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(devicePtr, sizes[i], copyInfoHostImportedToDeviceUsm.dstAllocData));
cmdList.obtainAllocData(copyInfoHostImportedToDeviceUsm);
EXPECT_EQ(nullptr, copyInfoHostImportedToDeviceUsm.srcAllocData);
EXPECT_NE(nullptr, copyInfoHostImportedToDeviceUsm.dstAllocData);
@@ -113,13 +109,13 @@ HWTEST_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndImportedHostPtr
EXPECT_TRUE(copyInfoHostImportedToDeviceUsm.srcIsImportedHostPtr);
CpuMemCopyInfo copyInfoSharedUsmToHostUsm(hostPtr, sharedPtr, sizes[i]);
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(sharedPtr, sizes[i], copyInfoSharedUsmToHostUsm.srcAllocData));
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(hostPtr, sizes[i], copyInfoSharedUsmToHostUsm.dstAllocData));
cmdList.obtainAllocData(copyInfoSharedUsmToHostUsm);
EXPECT_NE(nullptr, copyInfoSharedUsmToHostUsm.srcAllocData);
EXPECT_NE(nullptr, copyInfoSharedUsmToHostUsm.dstAllocData);
CpuMemCopyInfo copyInfoSharedUsmToHostImported(importedPtr, sharedPtr, sizes[i]);
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(sharedPtr, sizes[i], copyInfoSharedUsmToHostImported.srcAllocData));
cmdList.obtainAllocData(copyInfoSharedUsmToHostImported);
EXPECT_NE(nullptr, copyInfoSharedUsmToHostImported.srcAllocData);
EXPECT_FALSE(device->getDriverHandle()->findAllocationDataForRange(importedPtr, sizes[i], copyInfoSharedUsmToHostImported.dstAllocData));
EXPECT_NE(nullptr, copyInfoSharedUsmToHostImported.srcAllocData);
EXPECT_EQ(nullptr, copyInfoSharedUsmToHostImported.dstAllocData);
@@ -128,14 +124,12 @@ HWTEST_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndImportedHostPtr
EXPECT_TRUE(copyInfoSharedUsmToHostImported.dstIsImportedHostPtr);
CpuMemCopyInfo copyInfoHostUsmToSharedUsm(sharedPtr, hostPtr, sizes[i]);
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(hostPtr, sizes[i], copyInfoHostUsmToSharedUsm.srcAllocData));
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(sharedPtr, sizes[i], copyInfoHostUsmToSharedUsm.dstAllocData));
cmdList.obtainAllocData(copyInfoHostUsmToSharedUsm);
EXPECT_NE(nullptr, copyInfoHostUsmToSharedUsm.srcAllocData);
EXPECT_NE(nullptr, copyInfoHostUsmToSharedUsm.dstAllocData);
CpuMemCopyInfo copyInfoHostImportedToSharedUsm(sharedPtr, importedPtr, sizes[i]);
EXPECT_FALSE(device->getDriverHandle()->findAllocationDataForRange(importedPtr, sizes[i], copyInfoHostImportedToSharedUsm.srcAllocData));
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(sharedPtr, sizes[i], copyInfoHostImportedToSharedUsm.dstAllocData));
cmdList.obtainAllocData(copyInfoHostImportedToSharedUsm);
EXPECT_EQ(nullptr, copyInfoHostImportedToSharedUsm.srcAllocData);
EXPECT_NE(nullptr, copyInfoHostImportedToSharedUsm.dstAllocData);
@@ -143,14 +137,14 @@ HWTEST_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndImportedHostPtr
EXPECT_TRUE(copyInfoHostImportedToSharedUsm.srcIsImportedHostPtr);
CpuMemCopyInfo copyInfoHostUsmToHostUsm(hostPtr, hostPtr, sizes[i]);
cmdList.obtainAllocData(copyInfoHostUsmToHostUsm);
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(hostPtr, sizes[i], copyInfoHostUsmToHostUsm.srcAllocData));
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(hostPtr, sizes[i], copyInfoHostUsmToHostUsm.dstAllocData));
EXPECT_NE(nullptr, copyInfoHostUsmToHostUsm.srcAllocData);
EXPECT_NE(nullptr, copyInfoHostUsmToHostUsm.dstAllocData);
CpuMemCopyInfo copyInfoHostUsmToHostImported(importedPtr, hostPtr, sizes[i]);
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(hostPtr, sizes[i], copyInfoHostUsmToHostImported.srcAllocData));
EXPECT_FALSE(device->getDriverHandle()->findAllocationDataForRange(importedPtr, sizes[i], copyInfoHostUsmToHostImported.dstAllocData));
cmdList.obtainAllocData(copyInfoHostUsmToHostImported);
EXPECT_NE(nullptr, copyInfoHostUsmToHostImported.srcAllocData);
EXPECT_EQ(nullptr, copyInfoHostUsmToHostImported.dstAllocData);
@@ -158,8 +152,7 @@ HWTEST_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndImportedHostPtr
EXPECT_TRUE(copyInfoHostUsmToHostImported.dstIsImportedHostPtr);
CpuMemCopyInfo copyInfoHostImportedToHostUsm(hostPtr, importedPtr, sizes[i]);
EXPECT_FALSE(device->getDriverHandle()->findAllocationDataForRange(importedPtr, sizes[i], copyInfoHostImportedToHostUsm.srcAllocData));
EXPECT_TRUE(device->getDriverHandle()->findAllocationDataForRange(hostPtr, sizes[i], copyInfoHostImportedToHostUsm.dstAllocData));
cmdList.obtainAllocData(copyInfoHostImportedToHostUsm);
EXPECT_EQ(nullptr, copyInfoHostImportedToHostUsm.srcAllocData);
EXPECT_NE(nullptr, copyInfoHostImportedToHostUsm.dstAllocData);
@@ -167,8 +160,7 @@ HWTEST_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndImportedHostPtr
EXPECT_TRUE(copyInfoHostImportedToHostUsm.srcIsImportedHostPtr);
CpuMemCopyInfo copyInfoHostImportedToHostImported(importedPtr, importedPtr, sizes[i]);
EXPECT_FALSE(device->getDriverHandle()->findAllocationDataForRange(importedPtr, sizes[i], copyInfoHostImportedToHostImported.srcAllocData));
EXPECT_FALSE(device->getDriverHandle()->findAllocationDataForRange(importedPtr, sizes[i], copyInfoHostImportedToHostImported.dstAllocData));
cmdList.obtainAllocData(copyInfoHostImportedToHostImported);
EXPECT_EQ(nullptr, copyInfoHostImportedToHostImported.srcAllocData);
EXPECT_EQ(nullptr, copyInfoHostImportedToHostImported.dstAllocData);

View File

@@ -1576,13 +1576,15 @@ HWTEST_F(StagingBuffersFixture, givenAppendMemoryCopyWithImportedDstAllocationTh
cmdList.cmdQImmediate = queue.get();
cmdList.initialize(device, NEO::EngineGroupType::compute, 0u);
size_t dst[size] = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->importExternalPointer(&dst, size));
auto res = cmdList.appendMemoryCopy(&dst, usmDevice, size, nullptr, 0, nullptr, copyParams);
auto dst = alignedMalloc(size, MemoryConstants::cacheLineSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->importExternalPointer(dst, size));
auto res = cmdList.appendMemoryCopy(dst, usmDevice, size, nullptr, 0, nullptr, copyParams);
ASSERT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_EQ(1u, cmdList.appendMemoryCopyKernelWithGACalledCount);
EXPECT_TRUE(cmdList.getCsr(false)->getInternalAllocationStorage()->getTemporaryAllocations().peekIsEmpty());
driverHandle->releaseImportedPointer(dst);
alignedFree(dst);
}
HWTEST_F(StagingBuffersFixture, givenAppendMemoryCopyWithImportedAllocationThenDontUseStaging) {