2020-03-06 18:09:57 +08:00
|
|
|
/*
|
2021-12-15 05:57:01 +08:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2020-03-06 18:09:57 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-03-19 13:21:57 +08:00
|
|
|
#include "level_zero/core/source/event/event.h"
|
2020-03-06 18:09:57 +08:00
|
|
|
|
|
|
|
#include "shared/source/command_stream/command_stream_receiver_hw.h"
|
|
|
|
#include "shared/source/command_stream/csr_definitions.h"
|
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
|
|
|
#include "shared/source/device/device.h"
|
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2020-04-02 17:28:38 +08:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2020-03-06 18:09:57 +08:00
|
|
|
#include "shared/source/helpers/string.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
|
|
|
#include "shared/source/memory_manager/memory_operations_handler.h"
|
|
|
|
#include "shared/source/utilities/cpuintrinsics.h"
|
2021-03-31 02:11:00 +08:00
|
|
|
#include "shared/source/utilities/wait_util.h"
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2021-06-05 09:01:05 +08:00
|
|
|
#include "level_zero/core/source/cmdlist/cmdlist.h"
|
|
|
|
#include "level_zero/core/source/cmdqueue/cmdqueue.h"
|
2021-04-13 06:00:23 +08:00
|
|
|
#include "level_zero/core/source/context/context_imp.h"
|
2020-03-19 13:21:57 +08:00
|
|
|
#include "level_zero/core/source/device/device.h"
|
|
|
|
#include "level_zero/core/source/device/device_imp.h"
|
2021-04-13 06:00:23 +08:00
|
|
|
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
2021-05-19 00:28:14 +08:00
|
|
|
#include "level_zero/core/source/hw_helpers/l0_hw_helper.h"
|
2020-03-06 18:09:57 +08:00
|
|
|
#include "level_zero/tools/source/metrics/metric.h"
|
|
|
|
|
2021-05-12 02:43:28 +08:00
|
|
|
#include <set>
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2021-05-19 00:28:14 +08:00
|
|
|
//
|
|
|
|
#include "level_zero/core/source/event/event_impl.inl"
|
|
|
|
|
2020-03-06 18:09:57 +08:00
|
|
|
namespace L0 {
|
2021-05-19 00:28:14 +08:00
|
|
|
template Event *Event::create<uint64_t>(EventPool *, const ze_event_desc_t *, Device *);
|
|
|
|
template Event *Event::create<uint32_t>(EventPool *, const ze_event_desc_t *, Device *);
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2021-05-19 00:28:14 +08:00
|
|
|
ze_result_t EventPoolImp::initialize(DriverHandle *driver, Context *context, uint32_t numDevices, ze_device_handle_t *phDevices) {
|
2021-05-24 14:14:30 +08:00
|
|
|
this->context = static_cast<ContextImp *>(context);
|
|
|
|
|
2022-04-07 21:09:40 +08:00
|
|
|
RootDeviceIndicesContainer rootDeviceIndices;
|
2020-10-14 08:23:09 +08:00
|
|
|
uint32_t maxRootDeviceIndex = 0u;
|
2021-04-13 06:00:23 +08:00
|
|
|
|
2021-05-07 23:41:43 +08:00
|
|
|
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driver);
|
|
|
|
bool useDevicesFromApi = true;
|
2021-06-10 04:15:59 +08:00
|
|
|
bool useDeviceAlloc = isEventPoolDeviceAllocationFlagSet();
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2021-05-07 23:41:43 +08:00
|
|
|
if (numDevices == 0) {
|
2021-04-13 06:00:23 +08:00
|
|
|
numDevices = static_cast<uint32_t>(driverHandleImp->devices.size());
|
2021-05-07 23:41:43 +08:00
|
|
|
useDevicesFromApi = false;
|
|
|
|
}
|
2021-04-13 06:00:23 +08:00
|
|
|
|
2021-05-07 23:41:43 +08:00
|
|
|
for (uint32_t i = 0u; i < numDevices; i++) {
|
|
|
|
Device *eventDevice = nullptr;
|
|
|
|
|
|
|
|
if (useDevicesFromApi) {
|
|
|
|
eventDevice = Device::fromHandle(phDevices[i]);
|
|
|
|
} else {
|
2021-04-13 06:00:23 +08:00
|
|
|
eventDevice = driverHandleImp->devices[i];
|
2021-05-07 23:41:43 +08:00
|
|
|
}
|
2021-04-13 06:00:23 +08:00
|
|
|
|
2021-05-07 23:41:43 +08:00
|
|
|
if (!eventDevice) {
|
2021-05-19 00:28:14 +08:00
|
|
|
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
2021-04-13 06:00:23 +08:00
|
|
|
}
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2021-05-07 23:41:43 +08:00
|
|
|
devices.push_back(eventDevice);
|
2022-04-07 21:09:40 +08:00
|
|
|
rootDeviceIndices.push_back(eventDevice->getNEODevice()->getRootDeviceIndex());
|
2021-05-07 23:41:43 +08:00
|
|
|
if (maxRootDeviceIndex < eventDevice->getNEODevice()->getRootDeviceIndex()) {
|
|
|
|
maxRootDeviceIndex = eventDevice->getNEODevice()->getRootDeviceIndex();
|
|
|
|
}
|
2021-04-13 06:00:23 +08:00
|
|
|
}
|
2022-04-07 21:09:40 +08:00
|
|
|
rootDeviceIndices.remove_duplicates();
|
2021-02-25 16:38:48 +08:00
|
|
|
|
2021-05-19 00:28:14 +08:00
|
|
|
auto &hwHelper = devices[0]->getHwHelper();
|
|
|
|
|
2022-09-14 19:45:25 +08:00
|
|
|
useDeviceAlloc |= L0HwHelper::get(getDevice()->getHwInfo().platform.eRenderCoreFamily).alwaysAllocateEventInLocalMem();
|
|
|
|
|
2021-05-19 00:28:14 +08:00
|
|
|
eventAlignment = static_cast<uint32_t>(hwHelper.getTimestampPacketAllocatorAlignment());
|
|
|
|
eventSize = static_cast<uint32_t>(alignUp(EventPacketsCount::eventPackets * hwHelper.getSingleTimestampPacketSize(), eventAlignment));
|
|
|
|
|
|
|
|
size_t alignedSize = alignUp<size_t>(numEvents * eventSize, MemoryConstants::pageSize64k);
|
2022-04-23 09:53:39 +08:00
|
|
|
NEO::AllocationType allocationType = isEventPoolTimestampFlagSet() ? NEO::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER
|
|
|
|
: NEO::AllocationType::BUFFER_HOST_MEMORY;
|
2021-06-10 04:15:59 +08:00
|
|
|
if (this->devices.size() > 1) {
|
|
|
|
useDeviceAlloc = false;
|
|
|
|
}
|
|
|
|
|
2022-02-26 06:35:37 +08:00
|
|
|
if (useDeviceAlloc) {
|
2022-02-04 21:59:01 +08:00
|
|
|
allocationType = NEO::AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER;
|
2021-06-05 09:01:05 +08:00
|
|
|
}
|
2021-05-19 00:28:14 +08:00
|
|
|
|
2021-05-07 23:41:43 +08:00
|
|
|
eventPoolAllocations = std::make_unique<NEO::MultiGraphicsAllocation>(maxRootDeviceIndex);
|
|
|
|
|
2021-10-13 23:10:51 +08:00
|
|
|
bool allocatedMemory = false;
|
2021-05-07 23:41:43 +08:00
|
|
|
|
2021-10-13 23:10:51 +08:00
|
|
|
if (useDeviceAlloc) {
|
|
|
|
NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), alignedSize, allocationType, devices[0]->getNEODevice()->getDeviceBitfield()};
|
|
|
|
allocationProperties.alignment = eventAlignment;
|
2022-08-04 05:06:59 +08:00
|
|
|
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_IPC) {
|
|
|
|
this->isShareableEventMemory = true;
|
|
|
|
}
|
2021-05-07 23:41:43 +08:00
|
|
|
|
2021-10-13 23:10:51 +08:00
|
|
|
auto graphicsAllocation = driver->getMemoryManager()->allocateGraphicsMemoryWithProperties(allocationProperties);
|
|
|
|
if (graphicsAllocation) {
|
|
|
|
eventPoolAllocations->addAllocation(graphicsAllocation);
|
|
|
|
allocatedMemory = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), alignedSize, allocationType, systemMemoryBitfield};
|
|
|
|
allocationProperties.alignment = eventAlignment;
|
|
|
|
|
2022-04-07 21:09:40 +08:00
|
|
|
eventPoolPtr = driver->getMemoryManager()->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices,
|
2021-10-13 23:10:51 +08:00
|
|
|
allocationProperties,
|
|
|
|
*eventPoolAllocations);
|
|
|
|
|
2022-08-04 05:06:59 +08:00
|
|
|
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_IPC) {
|
|
|
|
this->isShareableEventMemory = eventPoolAllocations->getDefaultGraphicsAllocation()->isShareableHostMemory;
|
|
|
|
}
|
|
|
|
|
2021-10-13 23:10:51 +08:00
|
|
|
allocatedMemory = (nullptr != eventPoolPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!allocatedMemory) {
|
2021-11-09 22:44:11 +08:00
|
|
|
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
2020-03-06 18:09:57 +08:00
|
|
|
}
|
2020-10-14 08:23:09 +08:00
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2020-10-14 08:23:09 +08:00
|
|
|
EventPoolImp::~EventPoolImp() {
|
2021-05-19 00:28:14 +08:00
|
|
|
if (eventPoolAllocations) {
|
|
|
|
auto graphicsAllocations = eventPoolAllocations->getGraphicsAllocations();
|
|
|
|
auto memoryManager = devices[0]->getDriverHandle()->getMemoryManager();
|
|
|
|
for (auto gpuAllocation : graphicsAllocations) {
|
|
|
|
memoryManager->freeGraphicsMemory(gpuAllocation);
|
|
|
|
}
|
2020-10-14 08:23:09 +08:00
|
|
|
}
|
|
|
|
}
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2020-10-14 08:23:09 +08:00
|
|
|
ze_result_t EventPoolImp::destroy() {
|
|
|
|
delete this;
|
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ze_result_t EventPoolImp::createEvent(const ze_event_desc_t *desc, ze_event_handle_t *phEvent) {
|
|
|
|
if (desc->index > (getNumEvents() - 1)) {
|
|
|
|
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
|
|
|
}
|
2021-05-19 00:28:14 +08:00
|
|
|
|
|
|
|
auto &l0HwHelper = L0HwHelper::get(getDevice()->getHwInfo().platform.eRenderCoreFamily);
|
|
|
|
|
|
|
|
*phEvent = l0HwHelper.createEvent(this, desc, getDevice());
|
2020-10-14 08:23:09 +08:00
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
2020-03-06 18:09:57 +08:00
|
|
|
|
|
|
|
ze_result_t Event::destroy() {
|
|
|
|
delete this;
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-11-09 22:44:11 +08:00
|
|
|
EventPool *EventPool::create(DriverHandle *driver, Context *context, uint32_t numDevices, ze_device_handle_t *phDevices, const ze_event_pool_desc_t *desc, ze_result_t &result) {
|
2021-05-19 00:28:14 +08:00
|
|
|
auto eventPool = std::make_unique<EventPoolImp>(desc);
|
2021-04-13 06:00:23 +08:00
|
|
|
if (!eventPool) {
|
2021-11-09 22:44:11 +08:00
|
|
|
result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
|
2021-04-13 06:00:23 +08:00
|
|
|
DEBUG_BREAK_IF(true);
|
2020-10-14 08:23:09 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2021-11-09 22:44:11 +08:00
|
|
|
result = eventPool->initialize(driver, context, numDevices, phDevices);
|
2020-10-14 08:23:09 +08:00
|
|
|
if (result) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-05-19 00:28:14 +08:00
|
|
|
return eventPool.release();
|
2020-03-06 18:09:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace L0
|