2020-03-06 11:09:57 +01:00
|
|
|
/*
|
2024-01-03 08:55:03 +00:00
|
|
|
* Copyright (C) 2020-2024 Intel Corporation
|
2020-03-06 11:09:57 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-03-18 22:21:57 -07:00
|
|
|
#include "level_zero/core/source/event/event.h"
|
2020-03-06 11:09:57 +01: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"
|
2023-01-02 09:56:45 +00:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
2020-04-02 11:28:38 +02:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2023-02-01 16:23:01 +00:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2020-03-06 11:09:57 +01:00
|
|
|
#include "shared/source/helpers/string.h"
|
2022-12-07 11:51:44 +00:00
|
|
|
#include "shared/source/memory_manager/allocation_properties.h"
|
2020-03-06 11:09:57 +01:00
|
|
|
#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-30 18:11:00 +00:00
|
|
|
#include "shared/source/utilities/wait_util.h"
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2021-06-04 18:01:05 -07:00
|
|
|
#include "level_zero/core/source/cmdlist/cmdlist.h"
|
2023-04-26 11:48:10 +00:00
|
|
|
#include "level_zero/core/source/cmdlist/cmdlist_imp.h"
|
2021-06-04 18:01:05 -07:00
|
|
|
#include "level_zero/core/source/cmdqueue/cmdqueue.h"
|
2021-04-12 22:00:23 +00:00
|
|
|
#include "level_zero/core/source/context/context_imp.h"
|
2020-03-18 22:21:57 -07:00
|
|
|
#include "level_zero/core/source/device/device.h"
|
|
|
|
|
#include "level_zero/core/source/device/device_imp.h"
|
2021-04-12 22:00:23 +00:00
|
|
|
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
2023-01-19 18:33:55 +00:00
|
|
|
#include "level_zero/core/source/event/event_impl.inl"
|
2023-02-02 03:54:41 +00:00
|
|
|
#include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h"
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2021-05-11 18:43:28 +00:00
|
|
|
#include <set>
|
2020-03-06 11:09:57 +01:00
|
|
|
|
|
|
|
|
namespace L0 {
|
2021-05-18 16:28:14 +00: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 *);
|
2024-01-11 17:18:16 +00:00
|
|
|
template Event *Event::create<uint64_t>(const EventDescriptor &, const ze_event_desc_t *, Device *);
|
|
|
|
|
template Event *Event::create<uint32_t>(const EventDescriptor &, const ze_event_desc_t *, Device *);
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
ze_result_t EventPool::initialize(DriverHandle *driver, Context *context, uint32_t numDevices, ze_device_handle_t *deviceHandles) {
|
2021-05-24 06:14:30 +00:00
|
|
|
this->context = static_cast<ContextImp *>(context);
|
|
|
|
|
|
2024-01-11 17:18:16 +00:00
|
|
|
const bool counterBased = (counterBasedFlags != 0);
|
|
|
|
|
|
2023-11-23 11:09:21 +00:00
|
|
|
if (isIpcPoolFlagSet() && counterBased) {
|
2023-11-17 10:22:58 +00:00
|
|
|
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 08:55:03 +00:00
|
|
|
constexpr uint32_t supportedCounterBasedFlags = ZE_EVENT_POOL_COUNTER_BASED_EXP_FLAG_IMMEDIATE | ZE_EVENT_POOL_COUNTER_BASED_EXP_FLAG_NON_IMMEDIATE;
|
|
|
|
|
if (counterBased && ((counterBasedFlags & supportedCounterBasedFlags) == 0)) {
|
|
|
|
|
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 13:09:40 +00:00
|
|
|
RootDeviceIndicesContainer rootDeviceIndices;
|
2020-10-13 17:23:09 -07:00
|
|
|
uint32_t maxRootDeviceIndex = 0u;
|
2022-10-27 11:40:44 +00:00
|
|
|
uint32_t currentNumDevices = numDevices;
|
2021-04-12 22:00:23 +00:00
|
|
|
|
2021-05-07 15:41:43 +00:00
|
|
|
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driver);
|
|
|
|
|
bool useDevicesFromApi = true;
|
2022-12-15 08:15:18 -08:00
|
|
|
this->isDeviceEventPoolAllocation = isEventPoolDeviceAllocationFlagSet();
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2021-05-07 15:41:43 +00:00
|
|
|
if (numDevices == 0) {
|
2022-10-27 11:40:44 +00:00
|
|
|
currentNumDevices = static_cast<uint32_t>(driverHandleImp->devices.size());
|
2021-05-07 15:41:43 +00:00
|
|
|
useDevicesFromApi = false;
|
|
|
|
|
}
|
2021-04-12 22:00:23 +00:00
|
|
|
|
2022-10-27 11:40:44 +00:00
|
|
|
for (uint32_t i = 0u; i < currentNumDevices; i++) {
|
2021-05-07 15:41:43 +00:00
|
|
|
Device *eventDevice = nullptr;
|
|
|
|
|
|
|
|
|
|
if (useDevicesFromApi) {
|
2023-01-16 17:12:02 +00:00
|
|
|
eventDevice = Device::fromHandle(deviceHandles[i]);
|
2021-05-07 15:41:43 +00:00
|
|
|
} else {
|
2021-04-12 22:00:23 +00:00
|
|
|
eventDevice = driverHandleImp->devices[i];
|
2021-05-07 15:41:43 +00:00
|
|
|
}
|
2021-04-12 22:00:23 +00:00
|
|
|
|
2021-05-07 15:41:43 +00:00
|
|
|
if (!eventDevice) {
|
2021-05-18 16:28:14 +00:00
|
|
|
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
2021-04-12 22:00:23 +00:00
|
|
|
}
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2021-05-07 15:41:43 +00:00
|
|
|
devices.push_back(eventDevice);
|
2023-06-12 13:52:45 +00:00
|
|
|
rootDeviceIndices.pushUnique(eventDevice->getNEODevice()->getRootDeviceIndex());
|
2021-05-07 15:41:43 +00:00
|
|
|
if (maxRootDeviceIndex < eventDevice->getNEODevice()->getRootDeviceIndex()) {
|
|
|
|
|
maxRootDeviceIndex = eventDevice->getNEODevice()->getRootDeviceIndex();
|
|
|
|
|
}
|
2023-03-24 21:26:48 +00:00
|
|
|
|
|
|
|
|
isImplicitScalingCapable |= eventDevice->isImplicitScalingCapable();
|
2021-04-12 22:00:23 +00:00
|
|
|
}
|
2021-02-25 09:38:48 +01:00
|
|
|
|
2022-12-20 04:30:24 +00:00
|
|
|
auto &rootDeviceEnvironment = getDevice()->getNEODevice()->getRootDeviceEnvironment();
|
|
|
|
|
auto &l0GfxCoreHelper = rootDeviceEnvironment.getHelper<L0GfxCoreHelper>();
|
2022-12-15 08:15:18 -08:00
|
|
|
this->isDeviceEventPoolAllocation |= l0GfxCoreHelper.alwaysAllocateEventInLocalMem();
|
2021-05-18 16:28:14 +00:00
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
initializeSizeParameters(numDevices, deviceHandles, *driverHandleImp, rootDeviceEnvironment);
|
2022-09-14 11:45:25 +00:00
|
|
|
|
2023-12-11 14:24:36 +00:00
|
|
|
NEO::AllocationType allocationType = isEventPoolTimestampFlagSet() ? NEO::AllocationType::timestampPacketTagBuffer
|
|
|
|
|
: NEO::AllocationType::bufferHostMemory;
|
2021-06-09 20:15:59 +00:00
|
|
|
if (this->devices.size() > 1) {
|
2022-12-15 08:15:18 -08:00
|
|
|
this->isDeviceEventPoolAllocation = false;
|
2021-06-09 20:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-15 08:15:18 -08:00
|
|
|
if (this->isDeviceEventPoolAllocation) {
|
2023-12-11 14:24:36 +00:00
|
|
|
allocationType = NEO::AllocationType::gpuTimestampDeviceBuffer;
|
2021-06-04 18:01:05 -07:00
|
|
|
}
|
2021-05-18 16:28:14 +00:00
|
|
|
|
2021-05-07 15:41:43 +00:00
|
|
|
eventPoolAllocations = std::make_unique<NEO::MultiGraphicsAllocation>(maxRootDeviceIndex);
|
|
|
|
|
|
2021-10-13 15:10:51 +00:00
|
|
|
bool allocatedMemory = false;
|
2021-05-07 15:41:43 +00:00
|
|
|
|
2023-02-20 12:51:01 +00:00
|
|
|
auto neoDevice = devices[0]->getNEODevice();
|
2022-12-15 08:15:18 -08:00
|
|
|
if (this->isDeviceEventPoolAllocation) {
|
2023-03-15 00:19:58 +00:00
|
|
|
this->isHostVisibleEventPoolAllocation = !(isEventPoolDeviceAllocationFlagSet());
|
2023-02-20 12:51:01 +00:00
|
|
|
NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), this->eventPoolSize, allocationType, neoDevice->getDeviceBitfield()};
|
2021-10-13 15:10:51 +00:00
|
|
|
allocationProperties.alignment = eventAlignment;
|
2021-05-07 15:41:43 +00:00
|
|
|
|
2022-11-10 02:57:51 +00:00
|
|
|
auto memoryManager = driver->getMemoryManager();
|
|
|
|
|
auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties);
|
2021-10-13 15:10:51 +00:00
|
|
|
if (graphicsAllocation) {
|
|
|
|
|
eventPoolAllocations->addAllocation(graphicsAllocation);
|
|
|
|
|
allocatedMemory = true;
|
2023-11-23 11:09:21 +00:00
|
|
|
if (isIpcPoolFlagSet()) {
|
2022-11-10 02:57:51 +00:00
|
|
|
uint64_t handle = 0;
|
|
|
|
|
this->isShareableEventMemory = (graphicsAllocation->peekInternalHandle(memoryManager, handle) == 0);
|
|
|
|
|
}
|
2021-10-13 15:10:51 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2023-03-15 00:19:58 +00:00
|
|
|
this->isHostVisibleEventPoolAllocation = true;
|
2022-10-27 11:40:44 +00:00
|
|
|
NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), this->eventPoolSize, allocationType, systemMemoryBitfield};
|
2021-10-13 15:10:51 +00:00
|
|
|
allocationProperties.alignment = eventAlignment;
|
|
|
|
|
|
2022-04-07 13:09:40 +00:00
|
|
|
eventPoolPtr = driver->getMemoryManager()->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices,
|
2021-10-13 15:10:51 +00:00
|
|
|
allocationProperties,
|
|
|
|
|
*eventPoolAllocations);
|
2023-11-23 11:09:21 +00:00
|
|
|
if (isIpcPoolFlagSet()) {
|
2024-03-25 14:44:36 +00:00
|
|
|
this->isShareableEventMemory = eventPoolAllocations->getDefaultGraphicsAllocation()->isShareableHostMemory();
|
2022-08-03 14:06:59 -07:00
|
|
|
}
|
2021-10-13 15:10:51 +00:00
|
|
|
allocatedMemory = (nullptr != eventPoolPtr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!allocatedMemory) {
|
2021-11-09 14:44:11 +00:00
|
|
|
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
2020-03-06 11:09:57 +01:00
|
|
|
}
|
2023-02-20 12:51:01 +00:00
|
|
|
if (neoDevice->getDefaultEngine().commandStreamReceiver->isTbxMode()) {
|
|
|
|
|
eventPoolAllocations->getDefaultGraphicsAllocation()->setWriteMemoryOnly(true);
|
|
|
|
|
}
|
2020-10-13 17:23:09 -07:00
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
EventPool::~EventPool() {
|
2021-05-18 16:28:14 +00:00
|
|
|
if (eventPoolAllocations) {
|
|
|
|
|
auto graphicsAllocations = eventPoolAllocations->getGraphicsAllocations();
|
|
|
|
|
auto memoryManager = devices[0]->getDriverHandle()->getMemoryManager();
|
|
|
|
|
for (auto gpuAllocation : graphicsAllocations) {
|
|
|
|
|
memoryManager->freeGraphicsMemory(gpuAllocation);
|
|
|
|
|
}
|
2020-10-13 17:23:09 -07:00
|
|
|
}
|
|
|
|
|
}
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
ze_result_t EventPool::destroy() {
|
2020-10-13 17:23:09 -07:00
|
|
|
delete this;
|
|
|
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
ze_result_t EventPool::createEvent(const ze_event_desc_t *desc, ze_event_handle_t *eventHandle) {
|
2020-10-13 17:23:09 -07:00
|
|
|
if (desc->index > (getNumEvents() - 1)) {
|
|
|
|
|
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
|
|
|
|
}
|
2021-05-18 16:28:14 +00:00
|
|
|
|
2022-12-02 15:24:50 +00:00
|
|
|
auto &l0GfxCoreHelper = getDevice()->getNEODevice()->getRootDeviceEnvironment().getHelper<L0GfxCoreHelper>();
|
2021-05-18 16:28:14 +00:00
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
*eventHandle = l0GfxCoreHelper.createEvent(this, desc, getDevice());
|
2020-10-13 17:23:09 -07:00
|
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2024-02-07 00:42:24 +00:00
|
|
|
ze_result_t EventPool::getContextHandle(ze_context_handle_t *phContext) {
|
|
|
|
|
*phContext = context->toHandle();
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ze_result_t EventPool::getFlags(ze_event_pool_flags_t *pFlags) {
|
|
|
|
|
*pFlags = eventPoolFlags;
|
|
|
|
|
|
|
|
|
|
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_KERNEL_MAPPED_TIMESTAMP) {
|
|
|
|
|
*pFlags &= ~ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
|
|
|
|
|
}
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
void EventPool::initializeSizeParameters(uint32_t numDevices, ze_device_handle_t *deviceHandles, DriverHandleImp &driver, const NEO::RootDeviceEnvironment &rootDeviceEnvironment) {
|
2022-12-20 04:30:24 +00:00
|
|
|
|
|
|
|
|
auto &l0GfxCoreHelper = rootDeviceEnvironment.getHelper<L0GfxCoreHelper>();
|
|
|
|
|
auto &gfxCoreHelper = rootDeviceEnvironment.getHelper<NEO::GfxCoreHelper>();
|
2022-10-27 11:40:44 +00:00
|
|
|
|
2022-12-08 12:22:35 +00:00
|
|
|
setEventAlignment(static_cast<uint32_t>(gfxCoreHelper.getTimestampPacketAllocatorAlignment()));
|
2022-10-27 11:40:44 +00:00
|
|
|
|
2022-12-20 04:30:24 +00:00
|
|
|
auto &hwInfo = *rootDeviceEnvironment.getHardwareInfo();
|
2022-12-02 15:24:50 +00:00
|
|
|
bool useDynamicEventPackets = l0GfxCoreHelper.useDynamicEventPacketsCount(hwInfo);
|
2022-10-27 11:40:44 +00:00
|
|
|
eventPackets = EventPacketsCount::eventPackets;
|
2022-12-13 18:50:36 +00:00
|
|
|
maxKernelCount = EventPacketsCount::maxKernelSplit;
|
2022-10-27 11:40:44 +00:00
|
|
|
if (useDynamicEventPackets) {
|
|
|
|
|
eventPackets = driver.getEventMaxPacketCount(numDevices, deviceHandles);
|
2022-12-13 18:50:36 +00:00
|
|
|
maxKernelCount = driver.getEventMaxKernelCount(numDevices, deviceHandles);
|
2022-10-27 11:40:44 +00:00
|
|
|
}
|
2022-12-08 12:22:35 +00:00
|
|
|
setEventSize(static_cast<uint32_t>(alignUp(eventPackets * gfxCoreHelper.getSingleTimestampPacketSize(), eventAlignment)));
|
2022-10-27 11:40:44 +00:00
|
|
|
|
|
|
|
|
eventPoolSize = alignUp<size_t>(this->numEvents * eventSize, MemoryConstants::pageSize64k);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
EventPool *EventPool::create(DriverHandle *driver, Context *context, uint32_t numDevices, ze_device_handle_t *deviceHandles, const ze_event_pool_desc_t *desc, ze_result_t &result) {
|
|
|
|
|
auto eventPool = std::make_unique<EventPool>(desc);
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
result = eventPool->initialize(driver, context, numDevices, deviceHandles);
|
2020-10-13 17:23:09 -07:00
|
|
|
if (result) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2021-05-18 16:28:14 +00:00
|
|
|
return eventPool.release();
|
2020-03-06 11:09:57 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-31 17:56:27 +00:00
|
|
|
void EventPool::setupDescriptorFlags(const ze_event_pool_desc_t *desc) {
|
|
|
|
|
eventPoolFlags = desc->flags;
|
|
|
|
|
|
|
|
|
|
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_KERNEL_MAPPED_TIMESTAMP) {
|
|
|
|
|
eventPoolFlags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-23 11:09:21 +00:00
|
|
|
this->isIpcPoolFlag = !!(eventPoolFlags & ZE_EVENT_POOL_FLAG_IPC);
|
|
|
|
|
|
2023-10-31 17:56:27 +00:00
|
|
|
auto pNext = reinterpret_cast<const ze_base_desc_t *>(desc->pNext);
|
|
|
|
|
|
|
|
|
|
if (pNext && pNext->stype == ZE_STRUCTURE_TYPE_COUNTER_BASED_EVENT_POOL_EXP_DESC) {
|
2024-01-03 08:55:03 +00:00
|
|
|
auto counterBasedDesc = reinterpret_cast<const ze_event_pool_counter_based_exp_desc_t *>(pNext);
|
|
|
|
|
counterBasedFlags = counterBasedDesc->flags;
|
2024-01-05 17:04:31 +00:00
|
|
|
if (counterBasedFlags == 0) {
|
|
|
|
|
counterBasedFlags = ZE_EVENT_POOL_COUNTER_BASED_EXP_FLAG_IMMEDIATE;
|
|
|
|
|
}
|
2023-10-31 17:56:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 17:12:02 +00:00
|
|
|
bool EventPool::isEventPoolTimestampFlagSet() const {
|
2023-11-30 08:32:25 +00:00
|
|
|
if (NEO::debugManager.flags.OverrideTimestampEvents.get() != -1) {
|
|
|
|
|
auto timestampOverride = !!NEO::debugManager.flags.OverrideTimestampEvents.get();
|
2023-01-16 15:30:27 +00:00
|
|
|
return timestampOverride;
|
|
|
|
|
}
|
|
|
|
|
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 18:33:55 +00:00
|
|
|
ze_result_t EventPool::closeIpcHandle() {
|
|
|
|
|
return this->destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ze_result_t EventPool::getIpcHandle(ze_ipc_event_pool_handle_t *ipcHandle) {
|
|
|
|
|
if (!this->isShareableEventMemory) {
|
|
|
|
|
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IpcEventPoolData &poolData = *reinterpret_cast<IpcEventPoolData *>(ipcHandle->data);
|
|
|
|
|
poolData = {};
|
|
|
|
|
poolData.numEvents = this->numEvents;
|
|
|
|
|
poolData.rootDeviceIndex = this->getDevice()->getRootDeviceIndex();
|
|
|
|
|
poolData.isDeviceEventPoolAllocation = this->isDeviceEventPoolAllocation;
|
|
|
|
|
poolData.isHostVisibleEventPoolAllocation = this->isHostVisibleEventPoolAllocation;
|
2023-03-24 21:26:48 +00:00
|
|
|
poolData.isImplicitScalingCapable = this->isImplicitScalingCapable;
|
2023-01-19 18:33:55 +00:00
|
|
|
poolData.maxEventPackets = this->getEventMaxPackets();
|
2023-02-08 02:24:29 +00:00
|
|
|
poolData.numDevices = static_cast<uint32_t>(this->devices.size());
|
2023-01-19 18:33:55 +00:00
|
|
|
|
2024-01-16 13:27:23 +00:00
|
|
|
auto memoryManager = this->context->getDriverHandle()->getMemoryManager();
|
|
|
|
|
auto allocation = this->eventPoolAllocations->getDefaultGraphicsAllocation();
|
|
|
|
|
if (int retCode = allocation->peekInternalHandle(memoryManager, poolData.handle); retCode != 0) {
|
|
|
|
|
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
memoryManager->registerIpcExportedAllocation(allocation);
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
2023-01-19 18:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ze_result_t EventPool::openEventPoolIpcHandle(const ze_ipc_event_pool_handle_t &ipcEventPoolHandle, ze_event_pool_handle_t *eventPoolHandle,
|
|
|
|
|
DriverHandleImp *driver, ContextImp *context, uint32_t numDevices, ze_device_handle_t *deviceHandles) {
|
|
|
|
|
const IpcEventPoolData &poolData = *reinterpret_cast<const IpcEventPoolData *>(ipcEventPoolHandle.data);
|
|
|
|
|
|
|
|
|
|
ze_event_pool_desc_t desc = {ZE_STRUCTURE_TYPE_EVENT_POOL_DESC};
|
|
|
|
|
desc.count = static_cast<uint32_t>(poolData.numEvents);
|
|
|
|
|
auto eventPool = std::make_unique<EventPool>(&desc);
|
|
|
|
|
eventPool->isDeviceEventPoolAllocation = poolData.isDeviceEventPoolAllocation;
|
|
|
|
|
eventPool->isHostVisibleEventPoolAllocation = poolData.isHostVisibleEventPoolAllocation;
|
2023-03-24 21:26:48 +00:00
|
|
|
eventPool->isImplicitScalingCapable = poolData.isImplicitScalingCapable;
|
2023-02-08 02:24:29 +00:00
|
|
|
ze_device_handle_t *deviceHandlesUsed = deviceHandles;
|
2023-01-19 18:33:55 +00:00
|
|
|
|
|
|
|
|
UNRECOVERABLE_IF(numDevices == 0);
|
|
|
|
|
auto device = Device::fromHandle(*deviceHandles);
|
|
|
|
|
auto neoDevice = device->getNEODevice();
|
|
|
|
|
NEO::osHandle osHandle = static_cast<NEO::osHandle>(poolData.handle);
|
|
|
|
|
|
2023-02-08 02:24:29 +00:00
|
|
|
if (poolData.numDevices == 1) {
|
|
|
|
|
for (uint32_t i = 0; i < numDevices; i++) {
|
|
|
|
|
auto deviceStruct = Device::fromHandle(deviceHandles[i]);
|
|
|
|
|
auto neoDeviceIteration = deviceStruct->getNEODevice();
|
|
|
|
|
if (neoDeviceIteration->getRootDeviceIndex() == poolData.rootDeviceIndex) {
|
|
|
|
|
*deviceHandlesUsed = deviceHandles[i];
|
|
|
|
|
neoDevice = neoDeviceIteration;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
numDevices = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eventPool->initializeSizeParameters(numDevices, deviceHandlesUsed, *driver, neoDevice->getRootDeviceEnvironment());
|
2023-01-19 18:33:55 +00:00
|
|
|
if (eventPool->getEventMaxPackets() != poolData.maxEventPackets) {
|
2023-11-30 08:32:25 +00:00
|
|
|
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(),
|
2023-01-19 18:33:55 +00:00
|
|
|
stderr,
|
|
|
|
|
"IPC handle max event packets %u does not match context devices max event packet %u\n",
|
|
|
|
|
poolData.maxEventPackets, eventPool->getEventMaxPackets());
|
|
|
|
|
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-11 14:24:36 +00:00
|
|
|
NEO::AllocationType allocationType = NEO::AllocationType::bufferHostMemory;
|
2023-01-19 18:33:55 +00:00
|
|
|
if (eventPool->isDeviceEventPoolAllocation) {
|
2023-12-11 14:24:36 +00:00
|
|
|
allocationType = NEO::AllocationType::gpuTimestampDeviceBuffer;
|
2023-01-19 18:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NEO::AllocationProperties unifiedMemoryProperties{poolData.rootDeviceIndex,
|
|
|
|
|
eventPool->getEventPoolSize(),
|
|
|
|
|
allocationType,
|
|
|
|
|
systemMemoryBitfield};
|
|
|
|
|
|
|
|
|
|
unifiedMemoryProperties.subDevicesBitfield = neoDevice->getDeviceBitfield();
|
|
|
|
|
auto memoryManager = driver->getMemoryManager();
|
|
|
|
|
NEO::GraphicsAllocation *alloc = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle,
|
|
|
|
|
unifiedMemoryProperties,
|
|
|
|
|
false,
|
|
|
|
|
eventPool->isHostVisibleEventPoolAllocation,
|
2023-05-04 01:40:52 +00:00
|
|
|
false,
|
|
|
|
|
nullptr);
|
2023-01-19 18:33:55 +00:00
|
|
|
|
|
|
|
|
if (alloc == nullptr) {
|
|
|
|
|
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 12:51:01 +00:00
|
|
|
if (neoDevice->getDefaultEngine().commandStreamReceiver->isTbxMode()) {
|
|
|
|
|
alloc->setWriteMemoryOnly(true);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 18:33:55 +00:00
|
|
|
eventPool->context = context;
|
|
|
|
|
eventPool->eventPoolAllocations =
|
|
|
|
|
std::make_unique<NEO::MultiGraphicsAllocation>(static_cast<uint32_t>(context->rootDeviceIndices.size()));
|
|
|
|
|
eventPool->eventPoolAllocations->addAllocation(alloc);
|
|
|
|
|
eventPool->eventPoolPtr = reinterpret_cast<void *>(alloc->getUnderlyingBuffer());
|
|
|
|
|
for (uint32_t i = 0; i < numDevices; i++) {
|
2023-02-08 02:24:29 +00:00
|
|
|
eventPool->devices.push_back(Device::fromHandle(deviceHandlesUsed[i]));
|
2023-01-19 18:33:55 +00:00
|
|
|
}
|
|
|
|
|
eventPool->isImportedIpcPool = true;
|
|
|
|
|
|
2023-02-08 02:24:29 +00:00
|
|
|
if (numDevices > 1) {
|
|
|
|
|
for (auto currDeviceIndex : context->rootDeviceIndices) {
|
|
|
|
|
if (currDeviceIndex == poolData.rootDeviceIndex) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-01-19 18:33:55 +00:00
|
|
|
|
2023-02-08 02:24:29 +00:00
|
|
|
unifiedMemoryProperties.rootDeviceIndex = currDeviceIndex;
|
|
|
|
|
unifiedMemoryProperties.flags.isUSMHostAllocation = true;
|
|
|
|
|
unifiedMemoryProperties.flags.forceSystemMemory = true;
|
|
|
|
|
unifiedMemoryProperties.flags.allocateMemory = false;
|
|
|
|
|
auto graphicsAllocation = memoryManager->createGraphicsAllocationFromExistingStorage(unifiedMemoryProperties,
|
|
|
|
|
eventPool->eventPoolPtr,
|
|
|
|
|
eventPool->getAllocation());
|
|
|
|
|
if (!graphicsAllocation) {
|
|
|
|
|
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
eventPool->eventPoolAllocations->addAllocation(graphicsAllocation);
|
2023-01-19 18:33:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*eventPoolHandle = eventPool.release();
|
|
|
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ze_result_t Event::destroy() {
|
|
|
|
|
delete this;
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 08:55:03 +00:00
|
|
|
void Event::enableCounterBasedMode(bool apiRequest, uint32_t flags) {
|
2023-12-19 10:42:58 +00:00
|
|
|
if (counterBasedMode == CounterBasedMode::initiallyDisabled) {
|
|
|
|
|
counterBasedMode = apiRequest ? CounterBasedMode::explicitlyEnabled : CounterBasedMode::implicitlyEnabled;
|
2024-01-03 08:55:03 +00:00
|
|
|
counterBasedFlags = flags;
|
2023-11-06 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Event::disableImplicitCounterBasedMode() {
|
|
|
|
|
if (isCounterBasedExplicitlyEnabled()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-19 10:42:58 +00:00
|
|
|
if (counterBasedMode == CounterBasedMode::implicitlyEnabled || counterBasedMode == CounterBasedMode::initiallyDisabled) {
|
|
|
|
|
counterBasedMode = CounterBasedMode::implicitlyDisabled;
|
2024-01-03 08:55:03 +00:00
|
|
|
counterBasedFlags = 0;
|
2023-11-28 18:07:06 +00:00
|
|
|
unsetInOrderExecInfo();
|
2023-11-06 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 09:24:14 +00:00
|
|
|
uint64_t Event::getGpuAddress(Device *device) const {
|
2024-02-16 11:03:25 +00:00
|
|
|
return getPoolAllocation(device)->getGpuAddress() + this->eventPoolOffset;
|
2023-01-12 09:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-16 11:03:25 +00:00
|
|
|
NEO::GraphicsAllocation *Event::getPoolAllocation(Device *device) const {
|
|
|
|
|
return this->eventPoolAllocation ? this->eventPoolAllocation->getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex()) : nullptr;
|
2023-01-12 09:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Event::setGpuStartTimestamp() {
|
|
|
|
|
if (isEventTimestampFlagSet()) {
|
|
|
|
|
this->device->getGlobalTimestamps(&cpuStartTimestamp, &gpuStartTimestamp);
|
|
|
|
|
cpuStartTimestamp = cpuStartTimestamp / this->device->getNEODevice()->getDeviceInfo().outProfilingTimerResolution;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Event::setGpuEndTimestamp() {
|
|
|
|
|
if (isEventTimestampFlagSet()) {
|
|
|
|
|
auto resolution = this->device->getNEODevice()->getDeviceInfo().outProfilingTimerResolution;
|
2023-01-11 07:06:00 +00:00
|
|
|
uint64_t cpuEndTimestamp = 0;
|
|
|
|
|
this->device->getNEODevice()->getOSTime()->getCpuTime(&cpuEndTimestamp);
|
|
|
|
|
cpuEndTimestamp = cpuEndTimestamp / resolution;
|
|
|
|
|
this->gpuEndTimestamp = gpuStartTimestamp + std::max<size_t>(1u, (cpuEndTimestamp - cpuStartTimestamp));
|
2023-01-12 09:24:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 12:57:43 +00:00
|
|
|
void *Event::getCompletionFieldHostAddress() const {
|
|
|
|
|
return ptrOffset(getHostAddress(), getCompletionFieldOffset());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Event::increaseKernelCount() {
|
|
|
|
|
kernelCount++;
|
|
|
|
|
UNRECOVERABLE_IF(kernelCount > maxKernelCount);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 09:24:14 +00:00
|
|
|
void Event::resetPackets(bool resetAllPackets) {
|
|
|
|
|
if (resetAllPackets) {
|
|
|
|
|
resetKernelCountAndPacketUsedCount();
|
|
|
|
|
}
|
|
|
|
|
cpuStartTimestamp = 0;
|
|
|
|
|
gpuStartTimestamp = 0;
|
|
|
|
|
gpuEndTimestamp = 0;
|
2023-04-27 14:11:10 +00:00
|
|
|
this->csrs.clear();
|
|
|
|
|
this->csrs.push_back(this->device->getNEODevice()->getDefaultEngine().commandStreamReceiver);
|
2023-01-12 09:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-26 16:43:07 +00:00
|
|
|
void Event::setIsCompleted() {
|
|
|
|
|
if (this->isCompleted.load() == STATE_CLEARED) {
|
|
|
|
|
this->isCompleted = STATE_SIGNALED;
|
|
|
|
|
}
|
2023-08-29 20:31:16 +00:00
|
|
|
unsetCmdQueue();
|
2023-04-26 16:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-11 12:10:56 +00:00
|
|
|
void Event::updateInOrderExecState(std::shared_ptr<NEO::InOrderExecInfo> &newInOrderExecInfo, uint64_t signalValue, uint32_t allocationOffset) {
|
2023-11-08 10:09:35 +00:00
|
|
|
resetCompletionStatus();
|
|
|
|
|
|
2023-09-27 14:02:30 +00:00
|
|
|
if (this->inOrderExecInfo.get() != newInOrderExecInfo.get()) {
|
|
|
|
|
inOrderExecInfo = newInOrderExecInfo;
|
2023-09-25 10:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-07 18:44:13 +00:00
|
|
|
inOrderExecSignalValue = signalValue;
|
2023-07-04 10:43:51 +00:00
|
|
|
inOrderAllocationOffset = allocationOffset;
|
2023-05-05 09:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-03 09:34:45 +00:00
|
|
|
uint64_t Event::getInOrderExecSignalValueWithSubmissionCounter() const {
|
2024-01-11 12:51:31 +00:00
|
|
|
uint64_t appendCounter = inOrderExecInfo.get() ? NEO::InOrderPatchCommandHelpers::getAppendCounterValue(*inOrderExecInfo) : 0;
|
|
|
|
|
return (inOrderExecSignalValue + appendCounter);
|
2023-09-29 13:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-22 16:38:44 +00:00
|
|
|
void Event::setLatestUsedCmdQueue(CommandQueue *newCmdQ) {
|
|
|
|
|
this->latestUsedCmdQueue = newCmdQ;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 20:31:16 +00:00
|
|
|
void Event::unsetCmdQueue() {
|
2023-09-25 07:58:39 +00:00
|
|
|
for (auto &csr : csrs) {
|
|
|
|
|
csr->unregisterClient(latestUsedCmdQueue);
|
2023-06-22 16:38:44 +00:00
|
|
|
}
|
2023-09-25 07:58:39 +00:00
|
|
|
|
2023-06-22 16:38:44 +00:00
|
|
|
latestUsedCmdQueue = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 08:35:07 +00:00
|
|
|
void Event::setReferenceTs(uint64_t currentCpuTimeStamp) {
|
|
|
|
|
const auto recalculate =
|
|
|
|
|
(currentCpuTimeStamp - referenceTs.cpuTimeinNS) > timestampRefreshIntervalInNanoSec;
|
|
|
|
|
if (referenceTs.cpuTimeinNS == 0 || recalculate) {
|
2023-10-18 10:00:43 +02:00
|
|
|
device->getNEODevice()->getOSTime()->getGpuCpuTime(&referenceTs);
|
2023-07-06 08:35:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-28 18:07:06 +00:00
|
|
|
void Event::unsetInOrderExecInfo() {
|
|
|
|
|
inOrderExecInfo.reset();
|
|
|
|
|
inOrderAllocationOffset = 0;
|
|
|
|
|
inOrderExecSignalValue = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 11:09:57 +01:00
|
|
|
} // namespace L0
|