Simplify creating EventPool allocation

Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski
2021-05-07 15:41:43 +00:00
committed by Compute-Runtime-Automation
parent 5cbb822c3c
commit cffac84a3b
3 changed files with 29 additions and 64 deletions

View File

@ -36,78 +36,48 @@ ze_result_t EventPoolImp::initialize(DriverHandle *driver, Context *context, uin
uint32_t maxRootDeviceIndex = 0u; uint32_t maxRootDeviceIndex = 0u;
void *eventPoolPtr = nullptr; void *eventPoolPtr = nullptr;
ContextImp *contextImp = static_cast<ContextImp *>(context);
size_t alignedSize = alignUp<size_t>(numEvents * eventSize, MemoryConstants::pageSize64k); size_t alignedSize = alignUp<size_t>(numEvents * eventSize, MemoryConstants::pageSize64k);
NEO::GraphicsAllocation::AllocationType allocationType = isEventPoolUsedForTimestamp ? NEO::GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER NEO::GraphicsAllocation::AllocationType allocationType = isEventPoolUsedForTimestamp ? NEO::GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER
: NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; : NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
if (numDevices != 0) { DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driver);
for (uint32_t i = 0u; i < numDevices; i++) { bool useDevicesFromApi = true;
ze_device_handle_t hDevice = phDevices[i];
auto eventDevice = Device::fromHandle(hDevice);
if (eventDevice == nullptr) {
continue;
}
this->devices.push_back(eventDevice);
rootDeviceIndices.push_back(eventDevice->getNEODevice()->getRootDeviceIndex());
if (maxRootDeviceIndex < eventDevice->getNEODevice()->getRootDeviceIndex()) {
maxRootDeviceIndex = eventDevice->getNEODevice()->getRootDeviceIndex();
}
}
uint32_t rootDeviceIndex = rootDeviceIndices.at(0); if (numDevices == 0) {
auto deviceBitfield = devices[0]->getNEODevice()->getDeviceBitfield();
NEO::AllocationProperties unifiedMemoryProperties{rootDeviceIndex,
true,
alignedSize,
allocationType,
deviceBitfield.count() > 1,
deviceBitfield.count() > 1,
deviceBitfield};
unifiedMemoryProperties.alignment = eventAlignment;
eventPoolAllocations = new NEO::MultiGraphicsAllocation(maxRootDeviceIndex);
eventPoolPtr = driver->getMemoryManager()->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices,
unifiedMemoryProperties,
*eventPoolAllocations);
} else {
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driver);
numDevices = static_cast<uint32_t>(driverHandleImp->devices.size()); numDevices = static_cast<uint32_t>(driverHandleImp->devices.size());
useDevicesFromApi = false;
}
for (uint32_t i = 0u; i < numDevices; i++) { for (uint32_t i = 0u; i < numDevices; i++) {
Device *eventDevice = nullptr; Device *eventDevice = nullptr;
if (useDevicesFromApi) {
eventDevice = Device::fromHandle(phDevices[i]);
} else {
eventDevice = driverHandleImp->devices[i]; eventDevice = driverHandleImp->devices[i];
this->devices.push_back(eventDevice);
rootDeviceIndices.push_back(eventDevice->getNEODevice()->getRootDeviceIndex());
if (maxRootDeviceIndex < eventDevice->getNEODevice()->getRootDeviceIndex()) {
maxRootDeviceIndex = eventDevice->getNEODevice()->getRootDeviceIndex();
}
} }
uint32_t rootDeviceIndex = rootDeviceIndices.at(0); if (!eventDevice) {
auto &deviceBitfield = contextImp->deviceBitfields.at(rootDeviceIndex); continue;
}
NEO::AllocationProperties unifiedMemoryProperties{rootDeviceIndex, devices.push_back(eventDevice);
true, rootDeviceIndices.push_back(eventDevice->getNEODevice()->getRootDeviceIndex());
alignedSize, if (maxRootDeviceIndex < eventDevice->getNEODevice()->getRootDeviceIndex()) {
allocationType, maxRootDeviceIndex = eventDevice->getNEODevice()->getRootDeviceIndex();
false, }
(deviceBitfield.count() > 1) && driverHandleImp->svmAllocsManager->getMultiOsContextSupport(),
deviceBitfield};
unifiedMemoryProperties.flags.isUSMHostAllocation = true;
unifiedMemoryProperties.flags.isUSMDeviceAllocation = false;
unifiedMemoryProperties.alignment = eventAlignment;
eventPoolAllocations = new NEO::MultiGraphicsAllocation(maxRootDeviceIndex);
eventPoolPtr = driver->getMemoryManager()->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices,
unifiedMemoryProperties,
*eventPoolAllocations);
} }
eventPoolAllocations = std::make_unique<NEO::MultiGraphicsAllocation>(maxRootDeviceIndex);
NEO::AllocationProperties allocationProperties{rootDeviceIndices.at(0), alignedSize, allocationType, systemMemoryBitfield};
allocationProperties.alignment = eventAlignment;
eventPoolPtr = driver->getMemoryManager()->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices,
allocationProperties,
*eventPoolAllocations);
if (!eventPoolPtr) { if (!eventPoolPtr) {
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
} }
@ -120,8 +90,6 @@ EventPoolImp::~EventPoolImp() {
for (auto gpuAllocation : graphicsAllocations) { for (auto gpuAllocation : graphicsAllocations) {
memoryManager->freeGraphicsMemory(gpuAllocation); memoryManager->freeGraphicsMemory(gpuAllocation);
} }
delete eventPoolAllocations;
eventPoolAllocations = nullptr;
} }
ze_result_t EventPoolImp::getIpcHandle(ze_ipc_event_pool_handle_t *pIpcHandle) { ze_result_t EventPoolImp::getIpcHandle(ze_ipc_event_pool_handle_t *pIpcHandle) {

View File

@ -133,7 +133,7 @@ struct EventPool : _ze_event_pool_handle_t {
bool isEventPoolUsedForTimestamp = false; bool isEventPoolUsedForTimestamp = false;
protected: protected:
NEO::MultiGraphicsAllocation *eventPoolAllocations = nullptr; std::unique_ptr<NEO::MultiGraphicsAllocation> eventPoolAllocations;
}; };
struct EventPoolImp : public EventPool { struct EventPoolImp : public EventPool {

View File

@ -139,9 +139,6 @@ class SVMAllocsManager {
void *createUnifiedAllocationWithDeviceStorage(size_t size, const SvmAllocationProperties &svmProperties, const UnifiedMemoryProperties &unifiedMemoryProperties); void *createUnifiedAllocationWithDeviceStorage(size_t size, const SvmAllocationProperties &svmProperties, const UnifiedMemoryProperties &unifiedMemoryProperties);
void freeSvmAllocationWithDeviceStorage(SvmAllocationData *svmData); void freeSvmAllocationWithDeviceStorage(SvmAllocationData *svmData);
bool hasHostAllocations(); bool hasHostAllocations();
bool getMultiOsContextSupport() {
return multiOsContextSupport;
}
protected: protected:
void *createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties, void *createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties,