Fix calculations for offseted addresses
Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
parent
798256ed61
commit
b32b5784c2
|
@ -55,13 +55,13 @@ NEO::GraphicsAllocation *CommandList::getAllocationFromHostPtrMap(const void *bu
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *CommandList::getHostPtrAlloc(const void *buffer, uint64_t bufferSize, size_t *offset) {
|
||||
NEO::GraphicsAllocation *CommandList::getHostPtrAlloc(const void *buffer, uint64_t bufferSize) {
|
||||
NEO::GraphicsAllocation *alloc = getAllocationFromHostPtrMap(buffer, bufferSize);
|
||||
if (alloc) {
|
||||
*offset += ptrDiff(buffer, alloc->getUnderlyingBuffer());
|
||||
return alloc;
|
||||
}
|
||||
alloc = device->allocateMemoryFromHostPtr(buffer, bufferSize);
|
||||
UNRECOVERABLE_IF(alloc == nullptr);
|
||||
hostPtrMap.insert(std::make_pair(buffer, alloc));
|
||||
return alloc;
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ struct CommandList : _ze_command_list_handle_t {
|
|||
bool indirectAllocationsAllowed = false;
|
||||
bool internalUsage = false;
|
||||
NEO::GraphicsAllocation *getAllocationFromHostPtrMap(const void *buffer, uint64_t bufferSize);
|
||||
NEO::GraphicsAllocation *getHostPtrAlloc(const void *buffer, uint64_t bufferSize, size_t *offset);
|
||||
NEO::GraphicsAllocation *getHostPtrAlloc(const void *buffer, uint64_t bufferSize);
|
||||
bool containsStatelessUncachedResource = false;
|
||||
};
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ struct CommandListCoreFamily : CommandListImp {
|
|||
void programThreadArbitrationPolicy(Device *device);
|
||||
|
||||
uint64_t getInputBufferSize(NEO::ImageType imageType, uint64_t bytesPerPixel, const ze_image_region_t *region);
|
||||
virtual AlignedAllocationData getAlignedAllocation(Device *device, const void *buffer, uint64_t bufferSize);
|
||||
MOCKABLE_VIRTUAL AlignedAllocationData getAlignedAllocation(Device *device, const void *buffer, uint64_t bufferSize);
|
||||
ze_result_t addEventsToCmdList(ze_event_handle_t hEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents);
|
||||
};
|
||||
|
||||
|
|
|
@ -1216,7 +1216,8 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendBlitFill(void *ptr,
|
|||
appendEventForProfiling(hEvent, true);
|
||||
NEO::GraphicsAllocation *gpuAllocation = device->getDriverHandle()->getDriverSystemMemoryAllocation(ptr,
|
||||
size,
|
||||
neoDevice->getRootDeviceIndex());
|
||||
neoDevice->getRootDeviceIndex(),
|
||||
nullptr);
|
||||
if (gpuAllocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
@ -1301,17 +1302,15 @@ inline AlignedAllocationData CommandListCoreFamily<gfxCoreFamily>::getAlignedAll
|
|||
|
||||
if (srcAllocFound == false) {
|
||||
alloc = device->getDriverHandle()->findHostPointerAllocation(ptr, static_cast<size_t>(bufferSize), device->getRootDeviceIndex());
|
||||
if (alloc != nullptr) {
|
||||
offset += ptrDiff(buffer, alloc->getUnderlyingBuffer());
|
||||
} else {
|
||||
alloc = getHostPtrAlloc(buffer, bufferSize, &offset);
|
||||
if (alloc == nullptr) {
|
||||
alloc = getHostPtrAlloc(buffer, bufferSize);
|
||||
}
|
||||
alignedPtr = static_cast<uintptr_t>(alignDown(alloc->getGpuAddress(), NEO::EncodeSurfaceState<GfxFamily>::getSurfaceBaseAddressAlignment()));
|
||||
|
||||
hostPointerNeedsFlush = true;
|
||||
} else {
|
||||
alloc = allocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
|
||||
alignedPtr = reinterpret_cast<uintptr_t>(ptr) - offset;
|
||||
alignedPtr = sourcePtr;
|
||||
|
||||
if (allocData->memoryType == InternalMemoryType::HOST_UNIFIED_MEMORY ||
|
||||
allocData->memoryType == InternalMemoryType::SHARED_UNIFIED_MEMORY) {
|
||||
|
|
|
@ -88,7 +88,11 @@ ze_result_t ContextImp::freeMem(const void *ptr) {
|
|||
ze_result_t ContextImp::makeMemoryResident(ze_device_handle_t hDevice, void *ptr, size_t size) {
|
||||
Device *device = L0::Device::fromHandle(hDevice);
|
||||
NEO::Device *neoDevice = device->getNEODevice();
|
||||
auto allocation = device->getDriverHandle()->getDriverSystemMemoryAllocation(ptr, size, neoDevice->getRootDeviceIndex());
|
||||
auto allocation = device->getDriverHandle()->getDriverSystemMemoryAllocation(
|
||||
ptr,
|
||||
size,
|
||||
neoDevice->getRootDeviceIndex(),
|
||||
nullptr);
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
@ -112,7 +116,11 @@ ze_result_t ContextImp::makeMemoryResident(ze_device_handle_t hDevice, void *ptr
|
|||
ze_result_t ContextImp::evictMemory(ze_device_handle_t hDevice, void *ptr, size_t size) {
|
||||
Device *device = L0::Device::fromHandle(hDevice);
|
||||
NEO::Device *neoDevice = device->getNEODevice();
|
||||
auto allocation = device->getDriverHandle()->getDriverSystemMemoryAllocation(ptr, size, neoDevice->getRootDeviceIndex());
|
||||
auto allocation = device->getDriverHandle()->getDriverSystemMemoryAllocation(
|
||||
ptr,
|
||||
size,
|
||||
neoDevice->getRootDeviceIndex(),
|
||||
nullptr);
|
||||
if (allocation == nullptr) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,10 @@ struct DriverHandle : _ze_driver_handle_t {
|
|||
virtual ze_result_t getHostPointerBaseAddress(void *ptr, void **baseAddress) = 0;
|
||||
|
||||
virtual NEO::GraphicsAllocation *findHostPointerAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) = 0;
|
||||
virtual NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) = 0;
|
||||
virtual NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr,
|
||||
size_t size,
|
||||
uint32_t rootDeviceIndex,
|
||||
uintptr_t *gpuAddress) = 0;
|
||||
|
||||
static DriverHandle *fromHandle(ze_driver_handle_t handle) { return static_cast<DriverHandle *>(handle); }
|
||||
inline ze_driver_handle_t toHandle() { return this; }
|
||||
|
|
|
@ -453,13 +453,27 @@ NEO::GraphicsAllocation *DriverHandleImp::findHostPointerAllocation(void *ptr, s
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
NEO::GraphicsAllocation *DriverHandleImp::getDriverSystemMemoryAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) {
|
||||
NEO::GraphicsAllocation *DriverHandleImp::getDriverSystemMemoryAllocation(void *ptr,
|
||||
size_t size,
|
||||
uint32_t rootDeviceIndex,
|
||||
uintptr_t *gpuAddress) {
|
||||
NEO::SvmAllocationData *allocData = nullptr;
|
||||
bool allocFound = findAllocationDataForRange(ptr, size, &allocData);
|
||||
if (allocFound) {
|
||||
if (gpuAddress != nullptr) {
|
||||
*gpuAddress = reinterpret_cast<uintptr_t>(ptr);
|
||||
}
|
||||
return allocData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
|
||||
}
|
||||
return findHostPointerAllocation(ptr, size, rootDeviceIndex);
|
||||
auto allocation = findHostPointerAllocation(ptr, size, rootDeviceIndex);
|
||||
if (allocation != nullptr) {
|
||||
if (gpuAddress != nullptr) {
|
||||
uintptr_t offset = reinterpret_cast<uintptr_t>(ptr) -
|
||||
reinterpret_cast<uintptr_t>(allocation->getUnderlyingBuffer());
|
||||
*gpuAddress = static_cast<uintptr_t>(allocation->getGpuAddress()) + offset;
|
||||
}
|
||||
}
|
||||
return allocation;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
|
|
@ -76,7 +76,10 @@ struct DriverHandleImp : public DriverHandle {
|
|||
ze_result_t getHostPointerBaseAddress(void *ptr, void **baseAddress) override;
|
||||
|
||||
virtual NEO::GraphicsAllocation *findHostPointerAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) override;
|
||||
virtual NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) override;
|
||||
virtual NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr,
|
||||
size_t size,
|
||||
uint32_t rootDeviceIndex,
|
||||
uintptr_t *gpuAddress) override;
|
||||
uint32_t parseAffinityMask(std::vector<std::unique_ptr<NEO::Device>> &neoDevices);
|
||||
void createHostPointerManager();
|
||||
|
||||
|
|
|
@ -524,11 +524,11 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi
|
|||
uintptr_t gpuAddress = 0u;
|
||||
NEO::GraphicsAllocation *alloc = module->getDevice()->getDriverHandle()->getDriverSystemMemoryAllocation(requestedAddress,
|
||||
1u,
|
||||
module->getDevice()->getRootDeviceIndex());
|
||||
module->getDevice()->getRootDeviceIndex(),
|
||||
&gpuAddress);
|
||||
if (nullptr == alloc) {
|
||||
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
gpuAddress = static_cast<uintptr_t>(alloc->getGpuAddress());
|
||||
return setArgBufferWithAlloc(argIndex, gpuAddress, alloc);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,9 +73,15 @@ struct Mock<DriverHandle> : public DriverHandleImp {
|
|||
NEO::GraphicsAllocation *findHostPointerAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) override {
|
||||
return nullptr;
|
||||
}
|
||||
NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) override {
|
||||
NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr,
|
||||
size_t size,
|
||||
uint32_t rootDeviceIndex,
|
||||
uintptr_t *gpuAddress) override {
|
||||
auto svmData = svmAllocsManager->getSVMAlloc(ptr);
|
||||
if (svmData != nullptr) {
|
||||
if (gpuAddress != nullptr) {
|
||||
*gpuAddress = reinterpret_cast<uintptr_t>(ptr);
|
||||
}
|
||||
return svmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -1042,117 +1042,5 @@ HWTEST2_F(CommandListCreate, givenNullEventWhenAppendEventAfterWalkerThenNothing
|
|||
EXPECT_EQ(commandList->commandContainer.getCommandStream()->getUsed(), usedBefore);
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenGettingAllocInRangeThenAllocFromMapReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = ptrOffset(cpuPtr, 0x10);
|
||||
auto newBufferSize = allocSize - 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_NE(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenSizeIsOutOfRangeThenNullPtrReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = ptrOffset(cpuPtr, 0x10);
|
||||
auto newBufferSize = allocSize + 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsOutOfRangeThenNullPtrReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = reinterpret_cast<const void *>(gpuAddress - 0x100);
|
||||
auto newBufferSize = allocSize - 0x200;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenGetHostPtrAllocCalledThenCorrectOffsetIsSet, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
size_t expectedOffset = 0x10;
|
||||
auto newBufferPtr = ptrOffset(cpuPtr, expectedOffset);
|
||||
auto newBufferSize = allocSize - 0x20;
|
||||
size_t offset = 0;
|
||||
auto newAlloc = commandList->getHostPtrAlloc(newBufferPtr, newBufferSize, &offset);
|
||||
EXPECT_NE(newAlloc, nullptr);
|
||||
EXPECT_EQ(offset, expectedOffset);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsInMapThenAllocationReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = cpuPtr;
|
||||
auto newBufferSize = allocSize - 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, &alloc);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsInMapButWithBiggerSizeThenNullPtrReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = cpuPtr;
|
||||
auto newBufferSize = allocSize + 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrLowerThanAnyInMapThenNullPtrReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = reinterpret_cast<const void *>(gpuAddress - 0x10);
|
||||
auto newBufferSize = allocSize - 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
#include "level_zero/core/source/image/image_hw.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_event.h"
|
||||
|
@ -1104,40 +1103,5 @@ HWTEST_F(CommandListCreate, GivenCommandListWhenUnalignedPtrThenLeftMiddleAndRig
|
|||
EXPECT_NE(cmdList.end(), itor);
|
||||
}
|
||||
|
||||
using HostPointerManagerCommandListTest = Test<HostPointerManagerFixure>;
|
||||
HWTEST2_F(HostPointerManagerCommandListTest,
|
||||
givenImportedHostPointerWhenAppendMemoryFillUsingHostPointerThenAppendFillUsingHostPointerAllocation,
|
||||
Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
|
||||
|
||||
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
|
||||
int pattern = 1;
|
||||
ret = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&pattern), sizeof(pattern), 64u, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
|
||||
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST2_F(HostPointerManagerCommandListTest,
|
||||
givenImportedHostPointerAndCopyEngineWhenAppendMemoryFillUsingHostPointerThenAppendFillUsingHostPointerAllocation,
|
||||
Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
|
||||
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
|
||||
int pattern = 1;
|
||||
ret = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&pattern), sizeof(pattern), 64u, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
|
||||
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
|
|
@ -9,11 +9,14 @@
|
|||
#include "test.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using Platforms = IsAtLeastProduct<IGFX_SKYLAKE>;
|
||||
|
||||
struct MemoryManagerCommandListCreateNegativeTest : public NEO::MockMemoryManager {
|
||||
MemoryManagerCommandListCreateNegativeTest(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
|
||||
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const NEO::AllocationProperties &properties) override {
|
||||
|
@ -80,5 +83,225 @@ TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandList
|
|||
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
|
||||
ASSERT_EQ(nullptr, commandList);
|
||||
}
|
||||
|
||||
using CommandListCreate = Test<DeviceFixture>;
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenGettingAllocInRangeThenAllocFromMapReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = ptrOffset(cpuPtr, 0x10);
|
||||
auto newBufferSize = allocSize - 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_NE(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenSizeIsOutOfRangeThenNullPtrReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = ptrOffset(cpuPtr, 0x10);
|
||||
auto newBufferSize = allocSize + 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsOutOfRangeThenNullPtrReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = reinterpret_cast<const void *>(gpuAddress - 0x100);
|
||||
auto newBufferSize = allocSize - 0x200;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenGetHostPtrAllocCalledThenCorrectOffsetIsSet, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
size_t expectedOffset = 0x10;
|
||||
auto newBufferPtr = ptrOffset(cpuPtr, expectedOffset);
|
||||
auto newBufferSize = allocSize - 0x20;
|
||||
auto newAlloc = commandList->getHostPtrAlloc(newBufferPtr, newBufferSize);
|
||||
EXPECT_NE(nullptr, newAlloc);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsInMapThenAllocationReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = cpuPtr;
|
||||
auto newBufferSize = allocSize - 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, &alloc);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrIsInMapButWithBiggerSizeThenNullPtrReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = cpuPtr;
|
||||
auto newBufferSize = allocSize + 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrLowerThanAnyInMapThenNullPtrReturned, Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
uint64_t gpuAddress = 0x1200;
|
||||
const void *cpuPtr = reinterpret_cast<const void *>(gpuAddress);
|
||||
size_t allocSize = 0x1000;
|
||||
NEO::MockGraphicsAllocation alloc(const_cast<void *>(cpuPtr), gpuAddress, allocSize);
|
||||
commandList->hostPtrMap.insert(std::make_pair(cpuPtr, &alloc));
|
||||
|
||||
auto newBufferPtr = reinterpret_cast<const void *>(gpuAddress - 0x10);
|
||||
auto newBufferSize = allocSize - 0x20;
|
||||
auto newAlloc = commandList->getAllocationFromHostPtrMap(newBufferPtr, newBufferSize);
|
||||
EXPECT_EQ(newAlloc, nullptr);
|
||||
commandList->hostPtrMap.clear();
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandListCreate,
|
||||
givenCmdListHostPointerUsedWhenGettingAlignedAllocationThenRetrieveProperOffsetAndAddress,
|
||||
Platforms) {
|
||||
auto commandList = std::make_unique<::L0::ult::CommandListCoreFamily<gfxCoreFamily>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
|
||||
|
||||
size_t cmdListHostPtrSize = MemoryConstants::pageSize;
|
||||
void *cmdListHostBuffer = device->getNEODevice()->getMemoryManager()->allocateSystemMemory(cmdListHostPtrSize, cmdListHostPtrSize);
|
||||
void *startMemory = cmdListHostBuffer;
|
||||
void *baseAddress = alignDown(startMemory, MemoryConstants::pageSize);
|
||||
size_t expectedOffset = ptrDiff(startMemory, baseAddress);
|
||||
|
||||
AlignedAllocationData outData = commandList->getAlignedAllocation(device, startMemory, cmdListHostPtrSize);
|
||||
ASSERT_NE(nullptr, outData.alloc);
|
||||
auto firstAlloc = outData.alloc;
|
||||
auto expectedGpuAddress = static_cast<uintptr_t>(alignDown(outData.alloc->getGpuAddress(), MemoryConstants::pageSize));
|
||||
EXPECT_EQ(startMemory, outData.alloc->getUnderlyingBuffer());
|
||||
EXPECT_EQ(expectedGpuAddress, outData.alignedAllocationPtr);
|
||||
EXPECT_EQ(expectedOffset, outData.offset);
|
||||
|
||||
size_t offset = 0x20u;
|
||||
void *offsetMemory = ptrOffset(startMemory, offset);
|
||||
expectedOffset = ptrDiff(offsetMemory, baseAddress);
|
||||
EXPECT_EQ(outData.offset + offset, expectedOffset);
|
||||
|
||||
outData = commandList->getAlignedAllocation(device, offsetMemory, 4u);
|
||||
ASSERT_NE(nullptr, outData.alloc);
|
||||
EXPECT_EQ(firstAlloc, outData.alloc);
|
||||
EXPECT_EQ(startMemory, outData.alloc->getUnderlyingBuffer());
|
||||
EXPECT_EQ(expectedGpuAddress, outData.alignedAllocationPtr);
|
||||
EXPECT_EQ(expectedOffset, outData.offset);
|
||||
|
||||
commandList->removeHostPtrAllocations();
|
||||
device->getNEODevice()->getMemoryManager()->freeSystemMemory(cmdListHostBuffer);
|
||||
}
|
||||
|
||||
using HostPointerManagerCommandListTest = Test<HostPointerManagerFixure>;
|
||||
HWTEST2_F(HostPointerManagerCommandListTest,
|
||||
givenImportedHostPointerWhenAppendMemoryFillUsingHostPointerThenAppendFillUsingHostPointerAllocation,
|
||||
Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
|
||||
|
||||
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
|
||||
int pattern = 1;
|
||||
ret = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&pattern), sizeof(pattern), 64u, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
|
||||
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST2_F(HostPointerManagerCommandListTest,
|
||||
givenImportedHostPointerAndCopyEngineWhenAppendMemoryFillUsingHostPointerThenAppendFillUsingHostPointerAllocation,
|
||||
Platforms) {
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::Copy);
|
||||
|
||||
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
|
||||
int pattern = 1;
|
||||
ret = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&pattern), sizeof(pattern), 64u, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
|
||||
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
}
|
||||
|
||||
HWTEST2_F(HostPointerManagerCommandListTest,
|
||||
givenHostPointerImportedWhenGettingAlignedAllocationThenRetrieveProperOffsetAndAddress,
|
||||
Platforms) {
|
||||
auto commandList = std::make_unique<::L0::ult::CommandListCoreFamily<gfxCoreFamily>>();
|
||||
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
|
||||
|
||||
size_t pointerSize = MemoryConstants::pageSize;
|
||||
size_t offset = 100;
|
||||
void *offsetPointer = ptrOffset(heapPointer, offset);
|
||||
|
||||
auto ret = hostDriverHandle->importExternalPointer(offsetPointer, offset);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
|
||||
auto hostAllocation = hostDriverHandle->findHostPointerAllocation(heapPointer, pointerSize, device->getRootDeviceIndex());
|
||||
ASSERT_NE(nullptr, hostAllocation);
|
||||
|
||||
AlignedAllocationData outData = commandList->getAlignedAllocation(device, heapPointer, pointerSize);
|
||||
auto expectedAlignedAddress = static_cast<uintptr_t>(hostAllocation->getGpuAddress());
|
||||
EXPECT_EQ(heapPointer, hostAllocation->getUnderlyingBuffer());
|
||||
EXPECT_EQ(expectedAlignedAddress, outData.alignedAllocationPtr);
|
||||
EXPECT_EQ(hostAllocation, outData.alloc);
|
||||
EXPECT_EQ(0u, outData.offset);
|
||||
|
||||
outData = commandList->getAlignedAllocation(device, offsetPointer, 2u);
|
||||
expectedAlignedAddress = static_cast<uintptr_t>(hostAllocation->getGpuAddress());
|
||||
EXPECT_EQ(heapPointer, hostAllocation->getUnderlyingBuffer());
|
||||
EXPECT_EQ(expectedAlignedAddress, outData.alignedAllocationPtr);
|
||||
EXPECT_EQ(hostAllocation, outData.alloc);
|
||||
EXPECT_EQ(offset, outData.offset);
|
||||
|
||||
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
|
|
@ -52,10 +52,40 @@ TEST_F(HostPointerManagerTest, givenNoHeapManagerThenReturnFeatureUnsupported) {
|
|||
result = hostDriverHandle->releaseImportedPointer(testPtr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result);
|
||||
|
||||
auto gfxAllocation = hostDriverHandle->getDriverSystemMemoryAllocation(testPtr, 1u, device->getRootDeviceIndex());
|
||||
auto gfxAllocation = hostDriverHandle->getDriverSystemMemoryAllocation(testPtr, 1u, device->getRootDeviceIndex(), nullptr);
|
||||
EXPECT_EQ(nullptr, gfxAllocation);
|
||||
}
|
||||
|
||||
TEST_F(HostPointerManagerTest, givenHostPointerImportedWhenGettingExistingAllocationThenRetrieveProperGpuAddress) {
|
||||
void *testPtr = heapPointer;
|
||||
|
||||
auto result = hostDriverHandle->importExternalPointer(testPtr, MemoryConstants::pageSize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
uintptr_t gpuAddress = 0u;
|
||||
auto gfxAllocation = hostDriverHandle->getDriverSystemMemoryAllocation(testPtr,
|
||||
1u,
|
||||
device->getRootDeviceIndex(),
|
||||
&gpuAddress);
|
||||
ASSERT_NE(nullptr, gfxAllocation);
|
||||
EXPECT_EQ(testPtr, gfxAllocation->getUnderlyingBuffer());
|
||||
EXPECT_EQ(static_cast<uintptr_t>(gfxAllocation->getGpuAddress()), gpuAddress);
|
||||
|
||||
size_t offset = 10u;
|
||||
testPtr = ptrOffset(testPtr, offset);
|
||||
gfxAllocation = hostDriverHandle->getDriverSystemMemoryAllocation(testPtr,
|
||||
1u,
|
||||
device->getRootDeviceIndex(),
|
||||
&gpuAddress);
|
||||
ASSERT_NE(nullptr, gfxAllocation);
|
||||
EXPECT_EQ(heapPointer, gfxAllocation->getUnderlyingBuffer());
|
||||
auto expectedGpuAddress = static_cast<uintptr_t>(gfxAllocation->getGpuAddress()) + offset;
|
||||
EXPECT_EQ(expectedGpuAddress, gpuAddress);
|
||||
|
||||
result = hostDriverHandle->releaseImportedPointer(heapPointer);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(HostPointerManagerTest, givenPointerRegisteredWhenSvmAllocationExistsThenRetrieveSvmFirst) {
|
||||
void *testPtr = heapPointer;
|
||||
|
||||
|
@ -77,7 +107,7 @@ TEST_F(HostPointerManagerTest, givenPointerRegisteredWhenSvmAllocationExistsThen
|
|||
auto result = hostDriverHandle->importExternalPointer(testPtr, MemoryConstants::pageSize);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
auto gfxAllocation = hostDriverHandle->getDriverSystemMemoryAllocation(usmBuffer, 1u, device->getRootDeviceIndex());
|
||||
auto gfxAllocation = hostDriverHandle->getDriverSystemMemoryAllocation(usmBuffer, 1u, device->getRootDeviceIndex(), nullptr);
|
||||
ASSERT_NE(nullptr, gfxAllocation);
|
||||
EXPECT_EQ(usmBuffer, gfxAllocation->getUnderlyingBuffer());
|
||||
|
||||
|
@ -88,6 +118,45 @@ TEST_F(HostPointerManagerTest, givenPointerRegisteredWhenSvmAllocationExistsThen
|
|||
hostDriverHandle->getMemoryManager()->freeSystemMemory(usmBuffer);
|
||||
}
|
||||
|
||||
TEST_F(HostPointerManagerTest, givenSvmAllocationExistsWhenGettingExistingAllocationThenRetrieveProperGpuAddress) {
|
||||
size_t usmSize = MemoryConstants::pageSize;
|
||||
void *usmBuffer = hostDriverHandle->getMemoryManager()->allocateSystemMemory(usmSize, usmSize);
|
||||
NEO::GraphicsAllocation *usmAllocation = hostDriverHandle->getMemoryManager()->allocateGraphicsMemoryWithProperties(
|
||||
{device->getRootDeviceIndex(), false, usmSize, NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, false, neoDevice->getDeviceBitfield()},
|
||||
usmBuffer);
|
||||
ASSERT_NE(nullptr, usmAllocation);
|
||||
|
||||
NEO::SvmAllocationData allocData(device->getRootDeviceIndex());
|
||||
allocData.gpuAllocations.addAllocation(usmAllocation);
|
||||
allocData.cpuAllocation = nullptr;
|
||||
allocData.size = usmSize;
|
||||
allocData.memoryType = InternalMemoryType::NOT_SPECIFIED;
|
||||
allocData.device = nullptr;
|
||||
hostDriverHandle->getSvmAllocsManager()->insertSVMAlloc(allocData);
|
||||
|
||||
uintptr_t gpuAddress = 0u;
|
||||
auto gfxAllocation = hostDriverHandle->getDriverSystemMemoryAllocation(usmBuffer,
|
||||
1u,
|
||||
device->getRootDeviceIndex(),
|
||||
&gpuAddress);
|
||||
ASSERT_NE(nullptr, gfxAllocation);
|
||||
EXPECT_EQ(usmBuffer, gfxAllocation->getUnderlyingBuffer());
|
||||
EXPECT_EQ(static_cast<uintptr_t>(gfxAllocation->getGpuAddress()), gpuAddress);
|
||||
|
||||
size_t offset = 10u;
|
||||
void *offsetUsmBuffer = ptrOffset(usmBuffer, offset);
|
||||
gfxAllocation = hostDriverHandle->getDriverSystemMemoryAllocation(offsetUsmBuffer,
|
||||
1u,
|
||||
device->getRootDeviceIndex(),
|
||||
&gpuAddress);
|
||||
ASSERT_NE(nullptr, gfxAllocation);
|
||||
EXPECT_EQ(usmBuffer, gfxAllocation->getUnderlyingBuffer());
|
||||
EXPECT_EQ(reinterpret_cast<uintptr_t>(offsetUsmBuffer), gpuAddress);
|
||||
|
||||
hostDriverHandle->getMemoryManager()->freeGraphicsMemory(usmAllocation);
|
||||
hostDriverHandle->getMemoryManager()->freeSystemMemory(usmBuffer);
|
||||
}
|
||||
|
||||
TEST_F(HostPointerManagerTest, WhenSizeIsZeroThenExpectInvalidArgument) {
|
||||
void *testPtr = heapPointer;
|
||||
|
||||
|
|
Loading…
Reference in New Issue