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

@@ -720,7 +720,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemoryCopyRegion(void *d
bool hostPointerNeedsFlush = false;
bool dstAllocFound = device->getDriverHandle()->findAllocationDataForRange(alignedDstPtr, dstSize, &allocData);
if (dstAllocFound == false) {
auto dstAlloc = device->getDriverHandle()->allocateManagedMemoryFromHostPtr(device, alignedDstPtr, dstSize, this);
auto dstAlloc = device->allocateManagedMemoryFromHostPtr(alignedDstPtr, dstSize, this);
commandContainer.getDeallocationContainer().push_back(dstAlloc);
hostPointerNeedsFlush = true;
} else {
@@ -733,7 +733,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemoryCopyRegion(void *d
bool srcAllocFound = device->getDriverHandle()->findAllocationDataForRange(alignedSrcPtr,
srcSize, nullptr);
if (srcAllocFound == false) {
auto srcAlloc = device->getDriverHandle()->allocateManagedMemoryFromHostPtr(device, alignedSrcPtr, dstSize, this);
auto srcAlloc = device->allocateManagedMemoryFromHostPtr(alignedSrcPtr, dstSize, this);
commandContainer.getDeallocationContainer().push_back(srcAlloc);
}
@@ -937,9 +937,8 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemoryFill(void *ptr,
} else {
builtinFunction = device->getBuiltinFunctionsLib()->getFunction(Builtin::FillBufferSSHOffset);
auto patternAlloc = device->getDriverHandle()->allocateManagedMemoryFromHostPtr(device,
reinterpret_cast<void *>(srcPtr),
srcOffset + patternSize, this);
auto patternAlloc = device->allocateManagedMemoryFromHostPtr(reinterpret_cast<void *>(srcPtr),
srcOffset + patternSize, this);
if (patternAlloc == nullptr) {
DEBUG_BREAK_IF(true);
return ZE_RESULT_ERROR_UNKNOWN;
@@ -1047,7 +1046,7 @@ inline AlignedAllocationData CommandListCoreFamily<gfxCoreFamily>::getAlignedAll
bool hostPointerNeedsFlush = false;
if (srcAllocFound == false) {
alloc = device->getDriverHandle()->allocateMemoryFromHostPtr(device, buffer, bufferSize);
alloc = device->allocateMemoryFromHostPtr(buffer, bufferSize);
hostPtrMap.insert(std::make_pair(buffer, alloc));
alignedPtr = static_cast<uintptr_t>(alloc->getGpuAddress() - offset);

View File

@@ -116,6 +116,11 @@ struct Device : _ze_device_handle_t {
return getNEODevice() ? reinterpret_cast<NEO::SourceLevelDebugger *>(getNEODevice()->getDebugger()) : nullptr;
}
virtual NEO::GraphicsAllocation *getDebugSurface() const = 0;
virtual NEO::GraphicsAllocation *allocateManagedMemoryFromHostPtr(void *buffer,
size_t size, struct CommandList *commandList) = 0;
virtual NEO::GraphicsAllocation *allocateMemoryFromHostPtr(const void *buffer, size_t size) = 0;
};
} // namespace L0

View File

@@ -462,8 +462,8 @@ ze_result_t DeviceImp::registerCLMemory(cl_context context, cl_mem mem, void **p
NEO::GraphicsAllocation *graphicsAllocation = memObj->getGraphicsAllocation();
DEBUG_BREAK_IF(graphicsAllocation == nullptr);
auto allocation = getDriverHandle()->allocateManagedMemoryFromHostPtr(
this, graphicsAllocation->getUnderlyingBuffer(),
auto allocation = allocateManagedMemoryFromHostPtr(
graphicsAllocation->getUnderlyingBuffer(),
graphicsAllocation->getUnderlyingBufferSize(), nullptr);
*ptr = allocation->getUnderlyingBuffer();
@@ -622,4 +622,74 @@ const NEO::DeviceInfo &DeviceImp::getDeviceInfo() const {
NEO::Device *DeviceImp::getNEODevice() {
return neoDevice;
}
NEO::GraphicsAllocation *DeviceImp::allocateManagedMemoryFromHostPtr(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 = driverHandle->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;
driverHandle->getSvmAllocsManager()->getSVMAllocs()->remove(*allocData);
neoDevice->getMemoryManager()->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 = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
{getRootDeviceIndex(), 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;
driverHandle->getSvmAllocsManager()->getSVMAllocs()->insert(allocData);
return allocation;
}
NEO::GraphicsAllocation *DeviceImp::allocateMemoryFromHostPtr(const void *buffer, size_t size) {
NEO::AllocationProperties properties = {getRootDeviceIndex(), false, size, NEO::GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, false};
properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true;
auto allocation = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties,
buffer);
UNRECOVERABLE_IF(allocation == nullptr);
return allocation;
}
} // namespace L0

View File

@@ -80,6 +80,8 @@ struct DeviceImp : public Device {
NEO::GraphicsAllocation *getDebugSurface() const override { return debugSurface; }
void setDebugSurface(NEO::GraphicsAllocation *debugSurface) { this->debugSurface = debugSurface; };
~DeviceImp() override;
NEO::GraphicsAllocation *allocateManagedMemoryFromHostPtr(void *buffer, size_t size, struct CommandList *commandList) override;
NEO::GraphicsAllocation *allocateMemoryFromHostPtr(const void *buffer, size_t size) override;
NEO::Device *neoDevice = nullptr;
bool isSubdevice = false;

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;