mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Fix don't store internal host mem in hostPtrMap
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
0d68c55198
commit
f9307bb20e
@@ -80,8 +80,10 @@ NEO::GraphicsAllocation *CommandList::getHostPtrAlloc(const void *buffer, uint64
|
||||
UNRECOVERABLE_IF(alloc == nullptr);
|
||||
if (this->cmdListType == CommandListType::TYPE_IMMEDIATE && this->isFlushTaskSubmissionEnabled) {
|
||||
this->csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr<NEO::GraphicsAllocation>(alloc), NEO::AllocationUsage::TEMPORARY_ALLOCATION);
|
||||
} else {
|
||||
} else if (alloc->getAllocationType() == NEO::AllocationType::EXTERNAL_HOST_PTR) {
|
||||
hostPtrMap.insert(std::make_pair(buffer, alloc));
|
||||
} else {
|
||||
commandContainer.getDeallocationContainer().push_back(alloc);
|
||||
}
|
||||
return alloc;
|
||||
}
|
||||
|
||||
@@ -1757,10 +1757,12 @@ inline AlignedAllocationData CommandListCoreFamily<gfxCoreFamily>::getAlignedAll
|
||||
} else {
|
||||
alloc = getHostPtrAlloc(buffer, bufferSize, hostCopyAllowed);
|
||||
alignedPtr = static_cast<uintptr_t>(alignDown(alloc->getGpuAddress(), NEO::EncodeSurfaceState<GfxFamily>::getSurfaceBaseAddressAlignment()));
|
||||
auto hostAllocCpuPtr = reinterpret_cast<uintptr_t>(alloc->getUnderlyingBuffer());
|
||||
hostAllocCpuPtr = alignDown(hostAllocCpuPtr, NEO::EncodeSurfaceState<GfxFamily>::getSurfaceBaseAddressAlignment());
|
||||
auto allignedPtrOffset = sourcePtr - hostAllocCpuPtr;
|
||||
alignedPtr = ptrOffset(alignedPtr, allignedPtrOffset);
|
||||
if (alloc->getAllocationType() == NEO::AllocationType::EXTERNAL_HOST_PTR) {
|
||||
auto hostAllocCpuPtr = reinterpret_cast<uintptr_t>(alloc->getUnderlyingBuffer());
|
||||
hostAllocCpuPtr = alignDown(hostAllocCpuPtr, NEO::EncodeSurfaceState<GfxFamily>::getSurfaceBaseAddressAlignment());
|
||||
auto allignedPtrOffset = sourcePtr - hostAllocCpuPtr;
|
||||
alignedPtr = ptrOffset(alignedPtr, allignedPtrOffset);
|
||||
}
|
||||
}
|
||||
|
||||
hostPointerNeedsFlush = true;
|
||||
|
||||
@@ -1287,5 +1287,76 @@ HWTEST2_F(CommandListCreate, givenNonEmptyCommandsToPatchWhenClearCommandsToPatc
|
||||
EXPECT_TRUE(pCommandList->commandsToPatch.empty());
|
||||
}
|
||||
|
||||
template <NEO::AllocationType AllocType>
|
||||
class MyDeviceMock : public Mock<Device> {
|
||||
public:
|
||||
NEO::GraphicsAllocation *allocateMemoryFromHostPtr(const void *buffer, size_t size, bool hostCopyAllowed) override {
|
||||
auto alloc = std::make_unique<NEO::MockGraphicsAllocation>(const_cast<void *>(buffer), reinterpret_cast<uintptr_t>(buffer), size);
|
||||
alloc->allocationType = AllocType;
|
||||
return alloc.release();
|
||||
}
|
||||
const NEO::HardwareInfo &getHwInfo() const override {
|
||||
return neoDevice->getHardwareInfo();
|
||||
}
|
||||
};
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostPtrAllocAllocWhenInternalMemCreatedThenNewAllocAddedToDealocationContainer, IsAtLeastSkl) {
|
||||
auto myDevice = std::make_unique<MyDeviceMock<NEO::AllocationType::INTERNAL_HOST_MEMORY>>();
|
||||
myDevice->neoDevice = device->getNEODevice();
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(myDevice.get(), NEO::EngineGroupType::Copy, 0u);
|
||||
auto buffer = std::make_unique<uint8_t>(0x100);
|
||||
|
||||
auto deallocationSize = commandList->commandContainer.getDeallocationContainer().size();
|
||||
auto alloc = commandList->getHostPtrAlloc(buffer.get(), 0x80, true);
|
||||
EXPECT_EQ(deallocationSize + 1, commandList->commandContainer.getDeallocationContainer().size());
|
||||
EXPECT_NE(alloc, nullptr);
|
||||
driverHandle.get()->getMemoryManager()->freeGraphicsMemory(alloc);
|
||||
commandList->commandContainer.getDeallocationContainer().clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostPtrAllocAllocWhenExternalMemCreatedThenNewAllocAddedToHostPtrMap, IsAtLeastSkl) {
|
||||
auto myDevice = std::make_unique<MyDeviceMock<NEO::AllocationType::EXTERNAL_HOST_PTR>>();
|
||||
myDevice->neoDevice = device->getNEODevice();
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(myDevice.get(), NEO::EngineGroupType::Copy, 0u);
|
||||
auto buffer = std::make_unique<uint8_t>(0x100);
|
||||
|
||||
auto hostPtrMapSize = commandList->getHostPtrMap().size();
|
||||
auto alloc = commandList->getHostPtrAlloc(buffer.get(), 0x100, true);
|
||||
EXPECT_EQ(hostPtrMapSize + 1, commandList->getHostPtrMap().size());
|
||||
EXPECT_NE(alloc, nullptr);
|
||||
driverHandle.get()->getMemoryManager()->freeGraphicsMemory(alloc);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenGetAlignedAllocationWhenInternalMemWithinDifferentAllocThenReturnNewAlloc, IsAtLeastSkl) {
|
||||
auto myDevice = std::make_unique<MyDeviceMock<NEO::AllocationType::INTERNAL_HOST_MEMORY>>();
|
||||
myDevice->neoDevice = device->getNEODevice();
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(myDevice.get(), NEO::EngineGroupType::Copy, 0u);
|
||||
auto buffer = std::make_unique<uint8_t>(0x100);
|
||||
|
||||
auto outData1 = commandList->getAlignedAllocation(device, buffer.get(), 0x100, true);
|
||||
auto outData2 = commandList->getAlignedAllocation(device, &buffer.get()[5], 0x1, true);
|
||||
EXPECT_NE(outData1.alloc, outData2.alloc);
|
||||
driverHandle.get()->getMemoryManager()->freeGraphicsMemory(outData1.alloc);
|
||||
driverHandle.get()->getMemoryManager()->freeGraphicsMemory(outData2.alloc);
|
||||
commandList->commandContainer.getDeallocationContainer().clear();
|
||||
}
|
||||
HWTEST2_F(CommandListCreate, givenGetAlignedAllocationWhenExternalMemWithinDifferentAllocThenReturnPreviouslyAllocatedMem, IsAtLeastSkl) {
|
||||
auto myDevice = std::make_unique<MyDeviceMock<NEO::AllocationType::EXTERNAL_HOST_PTR>>();
|
||||
myDevice->neoDevice = device->getNEODevice();
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(myDevice.get(), NEO::EngineGroupType::Copy, 0u);
|
||||
auto buffer = std::make_unique<uint8_t>(0x100);
|
||||
|
||||
auto outData1 = commandList->getAlignedAllocation(device, buffer.get(), 0x100, true);
|
||||
auto outData2 = commandList->getAlignedAllocation(device, &buffer.get()[5], 0x1, true);
|
||||
EXPECT_EQ(outData1.alloc, outData2.alloc);
|
||||
driverHandle.get()->getMemoryManager()->freeGraphicsMemory(outData1.alloc);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
Reference in New Issue
Block a user