Move methods from DriverHandle to Device

allocateMemoryFromHostPtr
allocateManagedMemoryFromHostPtr

add mock driver handle

Related-To: NEO-3691
Change-Id: Iee8a167e248871b3b5fc495bd79b3b5654fb1bbc
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-04-01 09:51:07 +02:00
committed by sys_ocldev
parent a7e4ad4eba
commit c294747979
13 changed files with 353 additions and 84 deletions

View File

@@ -51,9 +51,6 @@ struct DriverHandle : _ze_driver_handle_t {
ze_event_pool_handle_t *phEventPool) = 0;
virtual ze_result_t openEventPoolIpcHandle(ze_ipc_event_pool_handle_t hIpc, ze_event_pool_handle_t *phEventPool) = 0;
virtual ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) = 0;
virtual NEO::GraphicsAllocation *allocateManagedMemoryFromHostPtr(Device *device, void *buffer,
size_t size, struct CommandList *commandList) = 0;
virtual NEO::GraphicsAllocation *allocateMemoryFromHostPtr(Device *device, const void *buffer, size_t size) = 0;
virtual bool findAllocationDataForRange(const void *buffer,
size_t size,
NEO::SvmAllocationData **allocData) = 0;

View File

@@ -213,76 +213,6 @@ std::vector<NEO::SvmAllocationData *> DriverHandleImp::findAllocationsWithinRang
return allocDataArray;
}
NEO::GraphicsAllocation *DriverHandleImp::allocateManagedMemoryFromHostPtr(Device *device, void *buffer,
size_t size, struct CommandList *commandList) {
char *baseAddress = reinterpret_cast<char *>(buffer);
NEO::GraphicsAllocation *allocation = nullptr;
bool allocFound = false;
std::vector<NEO::SvmAllocationData *> allocDataArray = findAllocationsWithinRange(buffer, size, &allocFound);
if (allocFound) {
return allocDataArray[0]->gpuAllocation;
}
if (!allocDataArray.empty()) {
UNRECOVERABLE_IF(commandList == nullptr);
for (auto allocData : allocDataArray) {
allocation = allocData->gpuAllocation;
char *allocAddress = reinterpret_cast<char *>(allocation->getGpuAddress());
size_t allocSize = allocData->size;
device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->remove(*allocData);
memoryManager->freeGraphicsMemory(allocation);
commandList->eraseDeallocationContainerEntry(allocation);
commandList->eraseResidencyContainerEntry(allocation);
if (allocAddress < baseAddress) {
buffer = reinterpret_cast<void *>(allocAddress);
baseAddress += size;
size = ptrDiff(baseAddress, allocAddress);
baseAddress = reinterpret_cast<char *>(buffer);
} else {
allocAddress += allocSize;
baseAddress += size;
if (allocAddress > baseAddress) {
baseAddress = reinterpret_cast<char *>(buffer);
size = ptrDiff(allocAddress, baseAddress);
} else {
baseAddress = reinterpret_cast<char *>(buffer);
}
}
}
}
allocation = memoryManager->allocateGraphicsMemoryWithProperties(
{0u, false, size, NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, false},
buffer);
if (allocation == nullptr) {
return allocation;
}
NEO::SvmAllocationData allocData;
allocData.gpuAllocation = allocation;
allocData.cpuAllocation = nullptr;
allocData.size = size;
allocData.memoryType = InternalMemoryType::NOT_SPECIFIED;
allocData.device = nullptr;
svmAllocsManager->getSVMAllocs()->insert(allocData);
return allocation;
}
NEO::GraphicsAllocation *DriverHandleImp::allocateMemoryFromHostPtr(Device *device, const void *buffer, size_t size) {
NEO::AllocationProperties properties = {0u, false, size, NEO::GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, false};
properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true;
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties,
buffer);
UNRECOVERABLE_IF(allocation == nullptr);
return allocation;
}
ze_result_t DriverHandleImp::createEventPool(const ze_event_pool_desc_t *desc,
uint32_t numDevices,
ze_device_handle_t *phDevices,

View File

@@ -50,9 +50,6 @@ struct DriverHandleImp : public DriverHandle {
ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override;
NEO::SVMAllocsManager *getSvmAllocsManager() override;
ze_result_t initialize(std::vector<std::unique_ptr<NEO::Device>> devices);
NEO::GraphicsAllocation *allocateManagedMemoryFromHostPtr(Device *device, void *buffer,
size_t size, struct CommandList *commandList) override;
NEO::GraphicsAllocation *allocateMemoryFromHostPtr(Device *device, const void *buffer, size_t size) override;
bool findAllocationDataForRange(const void *buffer,
size_t size,
NEO::SvmAllocationData **allocData) override;