diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl index 80cdaeef8e..a463472e05 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl @@ -947,6 +947,11 @@ bool CommandListCoreFamilyImmediate::preferCopyThroughLockedPtr(C return false; } + if (((cpuMemCopyInfo.srcAllocData != nullptr) && (cpuMemCopyInfo.srcAllocData->isImportedAllocation)) || + ((cpuMemCopyInfo.dstAllocData != nullptr) && (cpuMemCopyInfo.dstAllocData->isImportedAllocation))) { + return false; + } + const TransferType transferType = getTransferType(cpuMemCopyInfo.dstAllocData, cpuMemCopyInfo.srcAllocData); const size_t transferThreshold = getTransferThreshold(transferType); diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index e5407de436..42806a72e6 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -676,6 +676,7 @@ void *DriverHandleImp::importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_fla allocDataTmp->size = alloc->getUnderlyingBufferSize(); allocDataTmp->memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY; allocDataTmp->device = neoDevice; + allocDataTmp->isImportedAllocation = true; allocDataTmp->setAllocId(this->getSvmAllocsManager()->allocationsCounter++); if (flags & ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED) { @@ -847,6 +848,7 @@ void *DriverHandleImp::importNTHandle(ze_device_handle_t hDevice, void *handle, allocData.memoryType = isHostIpcAllocation ? InternalMemoryType::HOST_UNIFIED_MEMORY : InternalMemoryType::DEVICE_UNIFIED_MEMORY; allocData.device = neoDevice; + allocData.isImportedAllocation = true; allocData.setAllocId(this->getSvmAllocsManager()->allocationsCounter++); this->getSvmAllocsManager()->insertSVMAlloc(allocData); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp index 9207c157b4..17cd33a73e 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp @@ -5,12 +5,14 @@ * */ +#include "shared/source/os_interface/os_interface.h" #include "shared/source/os_interface/product_helper.h" #include "shared/source/os_interface/sys_calls_common.h" #include "shared/test/common/cmd_parse/hw_parse.h" #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/libult/ult_command_stream_receiver.h" #include "shared/test/common/mocks/mock_command_stream_receiver.h" +#include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/mocks/mock_ostime.h" #include "shared/test/common/mocks/ult_device_factory.h" #include "shared/test/common/test_macros/hw_test.h" @@ -2039,6 +2041,56 @@ HWTEST2_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndUsmHostPtrWhen EXPECT_TRUE(cmdList.preferCopyThroughLockedPtr(cpuMemCopyInfo, 1, &event)); } +HWTEST2_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndIpcDevicePtrWhenPreferCopyThroughLockedPtrCalledForD2HThenReturnFalse, IsAtLeastSkl) { + MockCommandListImmediateHw cmdList; + cmdList.copyThroughLockedPtrEnabled = true; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface()); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique()); + + ze_ipc_mem_handle_t ipcHandle{}; + EXPECT_EQ(ZE_RESULT_SUCCESS, context->getIpcMemHandle(devicePtr, &ipcHandle)); + ze_ipc_memory_flag_t ipcFlags{}; + void *ipcDevicePtr = nullptr; + EXPECT_EQ(ZE_RESULT_SUCCESS, context->openIpcMemHandle(device->toHandle(), ipcHandle, ipcFlags, &ipcDevicePtr)); + EXPECT_NE(nullptr, ipcDevicePtr); + + CpuMemCopyInfo cpuMemCopyInfo(hostPtr, ipcDevicePtr, 1024); + auto srcFound = device->getDriverHandle()->findAllocationDataForRange(ipcDevicePtr, 1024, cpuMemCopyInfo.srcAllocData); + ASSERT_TRUE(srcFound); + auto dstFound = device->getDriverHandle()->findAllocationDataForRange(hostPtr, 1024, cpuMemCopyInfo.dstAllocData); + ASSERT_TRUE(dstFound); + EXPECT_FALSE(cmdList.preferCopyThroughLockedPtr(cpuMemCopyInfo, 0, nullptr)); + + EXPECT_EQ(ZE_RESULT_SUCCESS, context->closeIpcMemHandle(ipcDevicePtr)); +} + +HWTEST2_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndIpcDevicePtrWhenPreferCopyThroughLockedPtrCalledForH2DThenReturnFalse, IsAtLeastSkl) { + MockCommandListImmediateHw cmdList; + cmdList.copyThroughLockedPtrEnabled = true; + cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface()); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique()); + + ze_ipc_mem_handle_t ipcHandle{}; + EXPECT_EQ(ZE_RESULT_SUCCESS, context->getIpcMemHandle(devicePtr, &ipcHandle)); + ze_ipc_memory_flag_t ipcFlags{}; + void *ipcDevicePtr = nullptr; + EXPECT_EQ(ZE_RESULT_SUCCESS, context->openIpcMemHandle(device->toHandle(), ipcHandle, ipcFlags, &ipcDevicePtr)); + EXPECT_NE(nullptr, ipcDevicePtr); + + CpuMemCopyInfo cpuMemCopyInfo(ipcDevicePtr, hostPtr, 1024); + auto srcFound = device->getDriverHandle()->findAllocationDataForRange(hostPtr, 1024, cpuMemCopyInfo.srcAllocData); + ASSERT_TRUE(srcFound); + auto dstFound = device->getDriverHandle()->findAllocationDataForRange(ipcDevicePtr, 1024, cpuMemCopyInfo.dstAllocData); + ASSERT_TRUE(dstFound); + EXPECT_FALSE(cmdList.preferCopyThroughLockedPtr(cpuMemCopyInfo, 0, nullptr)); + + EXPECT_EQ(ZE_RESULT_SUCCESS, context->closeIpcMemHandle(ipcDevicePtr)); +} + HWTEST2_F(AppendMemoryLockedCopyTest, givenImmediateCommandListWhenIsSuitableUSMDeviceAllocThenReturnCorrectValue, IsAtLeastSkl) { MockCommandListImmediateHw cmdList; cmdList.copyThroughLockedPtrEnabled = true;