2020-03-06 18:09:57 +08:00
|
|
|
/*
|
2024-01-03 16:55:03 +08:00
|
|
|
* Copyright (C) 2020-2024 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"
|
2023-01-02 17:56:45 +08:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
2020-04-02 17:28:38 +08:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2023-02-02 00:23:01 +08:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2020-03-06 18:09:57 +08:00
|
|
|
#include "shared/source/helpers/string.h"
|
2022-12-07 19:51:44 +08:00
|
|
|
#include "shared/source/memory_manager/allocation_properties.h"
|
2020-03-06 18:09:57 +08: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-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"
|
2023-04-26 19:48:10 +08:00
|
|
|
#include "level_zero/core/source/cmdlist/cmdlist_imp.h"
|
2021-06-05 09:01:05 +08:00
|
|
|
#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"
|
2023-01-20 02:33:55 +08:00
|
|
|
#include "level_zero/core/source/event/event_impl.inl"
|
2023-02-02 11:54:41 +08:00
|
|
|
#include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h"
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2021-05-12 02:43:28 +08:00
|
|
|
#include <set>
|
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 *);
|
2024-01-12 01:18:16 +08: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 18:09:57 +08:00
|
|
|
|
2024-07-19 23:15:04 +08:00
|
|
|
Event::~Event() {
|
|
|
|
resetInOrderTimestampNode(nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-17 01:12:02 +08:00
|
|
|
ze_result_t EventPool::initialize(DriverHandle *driver, Context *context, uint32_t numDevices, ze_device_handle_t *deviceHandles) {
|
2021-05-24 14:14:30 +08:00
|
|
|
this->context = static_cast<ContextImp *>(context);
|
|
|
|
|
2024-01-12 01:18:16 +08:00
|
|
|
const bool counterBased = (counterBasedFlags != 0);
|
|
|
|
|
2023-11-23 19:09:21 +08:00
|
|
|
if (isIpcPoolFlagSet() && counterBased) {
|
2023-11-17 18:22:58 +08:00
|
|
|
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
|
|
|
}
|
|
|
|
|
2024-01-03 16:55:03 +08: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 21:09:40 +08:00
|
|
|
RootDeviceIndicesContainer rootDeviceIndices;
|
2020-10-14 08:23:09 +08:00
|
|
|
uint32_t maxRootDeviceIndex = 0u;
|
2022-10-27 19:40:44 +08:00
|
|
|
uint32_t currentNumDevices = numDevices;
|
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;
|
2022-12-16 00:15:18 +08:00
|
|
|
this->isDeviceEventPoolAllocation = isEventPoolDeviceAllocationFlagSet();
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2021-05-07 23:41:43 +08:00
|
|
|
if (numDevices == 0) {
|
2022-10-27 19:40:44 +08:00
|
|
|
currentNumDevices = 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
|
|
|
|
2022-10-27 19:40:44 +08:00
|
|
|
for (uint32_t i = 0u; i < currentNumDevices; i++) {
|
2021-05-07 23:41:43 +08:00
|
|
|
Device *eventDevice = nullptr;
|
|
|
|
|
|
|
|
if (useDevicesFromApi) {
|
2023-01-17 01:12:02 +08:00
|
|
|
eventDevice = Device::fromHandle(deviceHandles[i]);
|
2021-05-07 23:41:43 +08:00
|
|
|
} 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);
|
2023-06-12 21:52:45 +08:00
|
|
|
rootDeviceIndices.pushUnique(eventDevice->getNEODevice()->getRootDeviceIndex());
|
2021-05-07 23:41:43 +08:00
|
|
|
if (maxRootDeviceIndex < eventDevice->getNEODevice()->getRootDeviceIndex()) {
|
|
|
|
maxRootDeviceIndex = eventDevice->getNEODevice()->getRootDeviceIndex();
|
|
|
|
}
|
2023-03-25 05:26:48 +08:00
|
|
|
|
|
|
|
isImplicitScalingCapable |= eventDevice->isImplicitScalingCapable();
|
2021-04-13 06:00:23 +08:00
|
|
|
}
|
2021-02-25 16:38:48 +08:00
|
|
|
|
2022-12-20 12:30:24 +08:00
|
|
|
auto &rootDeviceEnvironment = getDevice()->getNEODevice()->getRootDeviceEnvironment();
|
|
|
|
auto &l0GfxCoreHelper = rootDeviceEnvironment.getHelper<L0GfxCoreHelper>();
|
2022-12-16 00:15:18 +08:00
|
|
|
this->isDeviceEventPoolAllocation |= l0GfxCoreHelper.alwaysAllocateEventInLocalMem();
|
2021-05-19 00:28:14 +08:00
|
|
|
|
2023-01-17 01:12:02 +08:00
|
|
|
initializeSizeParameters(numDevices, deviceHandles, *driverHandleImp, rootDeviceEnvironment);
|
2022-09-14 19:45:25 +08:00
|
|
|
|
2023-12-11 22:24:36 +08:00
|
|
|
NEO::AllocationType allocationType = isEventPoolTimestampFlagSet() ? NEO::AllocationType::timestampPacketTagBuffer
|
|
|
|
: NEO::AllocationType::bufferHostMemory;
|
2021-06-10 04:15:59 +08:00
|
|
|
if (this->devices.size() > 1) {
|
2022-12-16 00:15:18 +08:00
|
|
|
this->isDeviceEventPoolAllocation = false;
|
2021-06-10 04:15:59 +08:00
|
|
|
}
|
|
|
|
|
2022-12-16 00:15:18 +08:00
|
|
|
if (this->isDeviceEventPoolAllocation) {
|
2023-12-11 22:24:36 +08:00
|
|
|
allocationType = NEO::AllocationType::gpuTimestampDeviceBuffer;
|
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
|
|
|
|
2023-02-20 20:51:01 +08:00
|
|
|
auto neoDevice = devices[0]->getNEODevice();
|
2022-12-16 00:15:18 +08:00
|
|
|
if (this->isDeviceEventPoolAllocation) {
|
2023-03-15 08:19:58 +08:00
|
|
|
this->isHostVisibleEventPoolAllocation = !(isEventPoolDeviceAllocationFlagSet());
|
2023-02-20 20:51:01 +08:00
|
|
|
NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), this->eventPoolSize, allocationType, neoDevice->getDeviceBitfield()};
|
2021-10-13 23:10:51 +08:00
|
|
|
allocationProperties.alignment = eventAlignment;
|
2021-05-07 23:41:43 +08:00
|
|
|
|
2022-11-10 10:57:51 +08:00
|
|
|
auto memoryManager = driver->getMemoryManager();
|
|
|
|
auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties);
|
2021-10-13 23:10:51 +08:00
|
|
|
if (graphicsAllocation) {
|
|
|
|
eventPoolAllocations->addAllocation(graphicsAllocation);
|
|
|
|
allocatedMemory = true;
|
2023-11-23 19:09:21 +08:00
|
|
|
if (isIpcPoolFlagSet()) {
|
2022-11-10 10:57:51 +08:00
|
|
|
uint64_t handle = 0;
|
|
|
|
this->isShareableEventMemory = (graphicsAllocation->peekInternalHandle(memoryManager, handle) == 0);
|
|
|
|
}
|
2021-10-13 23:10:51 +08:00
|
|
|
}
|
|
|
|
} else {
|
2023-03-15 08:19:58 +08:00
|
|
|
this->isHostVisibleEventPoolAllocation = true;
|
2022-10-27 19:40:44 +08:00
|
|
|
NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), this->eventPoolSize, allocationType, systemMemoryBitfield};
|
2021-10-13 23:10:51 +08:00
|
|
|
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);
|
2023-11-23 19:09:21 +08:00
|
|
|
if (isIpcPoolFlagSet()) {
|
2024-03-25 22:44:36 +08:00
|
|
|
this->isShareableEventMemory = eventPoolAllocations->getDefaultGraphicsAllocation()->isShareableHostMemory();
|
2022-08-04 05:06:59 +08:00
|
|
|
}
|
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
|
|
|
}
|
2023-02-20 20:51:01 +08:00
|
|
|
if (neoDevice->getDefaultEngine().commandStreamReceiver->isTbxMode()) {
|
|
|
|
eventPoolAllocations->getDefaultGraphicsAllocation()->setWriteMemoryOnly(true);
|
|
|
|
}
|
2020-10-14 08:23:09 +08:00
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2023-01-17 01:12:02 +08:00
|
|
|
EventPool::~EventPool() {
|
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
|
|
|
|
2023-01-17 01:12:02 +08:00
|
|
|
ze_result_t EventPool::destroy() {
|
2020-10-14 08:23:09 +08:00
|
|
|
delete this;
|
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2023-01-17 01:12:02 +08:00
|
|
|
ze_result_t EventPool::createEvent(const ze_event_desc_t *desc, ze_event_handle_t *eventHandle) {
|
2020-10-14 08:23:09 +08:00
|
|
|
if (desc->index > (getNumEvents() - 1)) {
|
|
|
|
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
|
|
|
}
|
2021-05-19 00:28:14 +08:00
|
|
|
|
2022-12-02 23:24:50 +08:00
|
|
|
auto &l0GfxCoreHelper = getDevice()->getNEODevice()->getRootDeviceEnvironment().getHelper<L0GfxCoreHelper>();
|
2021-05-19 00:28:14 +08:00
|
|
|
|
2023-01-17 01:12:02 +08:00
|
|
|
*eventHandle = l0GfxCoreHelper.createEvent(this, desc, getDevice());
|
2020-10-14 08:23:09 +08:00
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2024-02-07 08:42:24 +08: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-17 01:12:02 +08:00
|
|
|
void EventPool::initializeSizeParameters(uint32_t numDevices, ze_device_handle_t *deviceHandles, DriverHandleImp &driver, const NEO::RootDeviceEnvironment &rootDeviceEnvironment) {
|
2022-12-20 12:30:24 +08:00
|
|
|
|
|
|
|
auto &l0GfxCoreHelper = rootDeviceEnvironment.getHelper<L0GfxCoreHelper>();
|
|
|
|
auto &gfxCoreHelper = rootDeviceEnvironment.getHelper<NEO::GfxCoreHelper>();
|
2022-10-27 19:40:44 +08:00
|
|
|
|
2022-12-08 20:22:35 +08:00
|
|
|
setEventAlignment(static_cast<uint32_t>(gfxCoreHelper.getTimestampPacketAllocatorAlignment()));
|
2022-10-27 19:40:44 +08:00
|
|
|
|
2022-12-20 12:30:24 +08:00
|
|
|
auto &hwInfo = *rootDeviceEnvironment.getHardwareInfo();
|
2022-12-02 23:24:50 +08:00
|
|
|
bool useDynamicEventPackets = l0GfxCoreHelper.useDynamicEventPacketsCount(hwInfo);
|
2022-10-27 19:40:44 +08:00
|
|
|
eventPackets = EventPacketsCount::eventPackets;
|
2022-12-14 02:50:36 +08:00
|
|
|
maxKernelCount = EventPacketsCount::maxKernelSplit;
|
2022-10-27 19:40:44 +08:00
|
|
|
if (useDynamicEventPackets) {
|
|
|
|
eventPackets = driver.getEventMaxPacketCount(numDevices, deviceHandles);
|
2022-12-14 02:50:36 +08:00
|
|
|
maxKernelCount = driver.getEventMaxKernelCount(numDevices, deviceHandles);
|
2022-10-27 19:40:44 +08:00
|
|
|
}
|
2022-12-08 20:22:35 +08:00
|
|
|
setEventSize(static_cast<uint32_t>(alignUp(eventPackets * gfxCoreHelper.getSingleTimestampPacketSize(), eventAlignment)));
|
2022-10-27 19:40:44 +08:00
|
|
|
|
|
|
|
eventPoolSize = alignUp<size_t>(this->numEvents * eventSize, MemoryConstants::pageSize64k);
|
|
|
|
}
|
|
|
|
|
2023-01-17 01:12:02 +08: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 18:09:57 +08:00
|
|
|
|
2023-01-17 01:12:02 +08:00
|
|
|
result = eventPool->initialize(driver, context, numDevices, deviceHandles);
|
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
|
|
|
}
|
|
|
|
|
2023-11-01 01:56:27 +08: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 19:09:21 +08:00
|
|
|
this->isIpcPoolFlag = !!(eventPoolFlags & ZE_EVENT_POOL_FLAG_IPC);
|
|
|
|
|
2023-11-01 01:56:27 +08: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 16:55:03 +08:00
|
|
|
auto counterBasedDesc = reinterpret_cast<const ze_event_pool_counter_based_exp_desc_t *>(pNext);
|
|
|
|
counterBasedFlags = counterBasedDesc->flags;
|
2024-01-06 01:04:31 +08:00
|
|
|
if (counterBasedFlags == 0) {
|
|
|
|
counterBasedFlags = ZE_EVENT_POOL_COUNTER_BASED_EXP_FLAG_IMMEDIATE;
|
|
|
|
}
|
2023-11-01 01:56:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 01:12:02 +08:00
|
|
|
bool EventPool::isEventPoolTimestampFlagSet() const {
|
2023-11-30 16:32:25 +08:00
|
|
|
if (NEO::debugManager.flags.OverrideTimestampEvents.get() != -1) {
|
|
|
|
auto timestampOverride = !!NEO::debugManager.flags.OverrideTimestampEvents.get();
|
2023-01-16 23:30:27 +08:00
|
|
|
return timestampOverride;
|
|
|
|
}
|
|
|
|
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-01-20 02:33:55 +08: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-25 05:26:48 +08:00
|
|
|
poolData.isImplicitScalingCapable = this->isImplicitScalingCapable;
|
2023-01-20 02:33:55 +08:00
|
|
|
poolData.maxEventPackets = this->getEventMaxPackets();
|
2023-02-08 10:24:29 +08:00
|
|
|
poolData.numDevices = static_cast<uint32_t>(this->devices.size());
|
2023-01-20 02:33:55 +08:00
|
|
|
|
2024-01-16 21:27:23 +08: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-20 02:33:55 +08: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-25 05:26:48 +08:00
|
|
|
eventPool->isImplicitScalingCapable = poolData.isImplicitScalingCapable;
|
2023-02-08 10:24:29 +08:00
|
|
|
ze_device_handle_t *deviceHandlesUsed = deviceHandles;
|
2023-01-20 02:33:55 +08:00
|
|
|
|
|
|
|
UNRECOVERABLE_IF(numDevices == 0);
|
|
|
|
auto device = Device::fromHandle(*deviceHandles);
|
|
|
|
auto neoDevice = device->getNEODevice();
|
2024-06-07 00:56:16 +08:00
|
|
|
NEO::MemoryManager::OsHandleData osHandleData{poolData.handle};
|
2023-01-20 02:33:55 +08:00
|
|
|
|
2023-02-08 10:24:29 +08: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-20 02:33:55 +08:00
|
|
|
if (eventPool->getEventMaxPackets() != poolData.maxEventPackets) {
|
2023-11-30 16:32:25 +08:00
|
|
|
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(),
|
2023-01-20 02:33:55 +08: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 22:24:36 +08:00
|
|
|
NEO::AllocationType allocationType = NEO::AllocationType::bufferHostMemory;
|
2023-01-20 02:33:55 +08:00
|
|
|
if (eventPool->isDeviceEventPoolAllocation) {
|
2023-12-11 22:24:36 +08:00
|
|
|
allocationType = NEO::AllocationType::gpuTimestampDeviceBuffer;
|
2023-01-20 02:33:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NEO::AllocationProperties unifiedMemoryProperties{poolData.rootDeviceIndex,
|
|
|
|
eventPool->getEventPoolSize(),
|
|
|
|
allocationType,
|
|
|
|
systemMemoryBitfield};
|
|
|
|
|
|
|
|
unifiedMemoryProperties.subDevicesBitfield = neoDevice->getDeviceBitfield();
|
|
|
|
auto memoryManager = driver->getMemoryManager();
|
2024-06-07 00:56:16 +08:00
|
|
|
NEO::GraphicsAllocation *alloc = memoryManager->createGraphicsAllocationFromSharedHandle(osHandleData,
|
2023-01-20 02:33:55 +08:00
|
|
|
unifiedMemoryProperties,
|
|
|
|
false,
|
|
|
|
eventPool->isHostVisibleEventPoolAllocation,
|
2023-05-04 09:40:52 +08:00
|
|
|
false,
|
|
|
|
nullptr);
|
2023-01-20 02:33:55 +08:00
|
|
|
|
|
|
|
if (alloc == nullptr) {
|
|
|
|
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
|
|
|
}
|
|
|
|
|
2023-02-20 20:51:01 +08:00
|
|
|
if (neoDevice->getDefaultEngine().commandStreamReceiver->isTbxMode()) {
|
|
|
|
alloc->setWriteMemoryOnly(true);
|
|
|
|
}
|
|
|
|
|
2023-01-20 02:33:55 +08: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 10:24:29 +08:00
|
|
|
eventPool->devices.push_back(Device::fromHandle(deviceHandlesUsed[i]));
|
2023-01-20 02:33:55 +08:00
|
|
|
}
|
|
|
|
eventPool->isImportedIpcPool = true;
|
|
|
|
|
2023-02-08 10:24:29 +08:00
|
|
|
if (numDevices > 1) {
|
|
|
|
for (auto currDeviceIndex : context->rootDeviceIndices) {
|
|
|
|
if (currDeviceIndex == poolData.rootDeviceIndex) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-20 02:33:55 +08:00
|
|
|
|
2023-02-08 10:24:29 +08: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-20 02:33:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*eventPoolHandle = eventPool.release();
|
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ze_result_t Event::destroy() {
|
|
|
|
delete this;
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2024-01-03 16:55:03 +08:00
|
|
|
void Event::enableCounterBasedMode(bool apiRequest, uint32_t flags) {
|
2023-12-19 18:42:58 +08:00
|
|
|
if (counterBasedMode == CounterBasedMode::initiallyDisabled) {
|
|
|
|
counterBasedMode = apiRequest ? CounterBasedMode::explicitlyEnabled : CounterBasedMode::implicitlyEnabled;
|
2024-01-03 16:55:03 +08:00
|
|
|
counterBasedFlags = flags;
|
2023-11-06 22:48:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Event::disableImplicitCounterBasedMode() {
|
|
|
|
if (isCounterBasedExplicitlyEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-19 18:42:58 +08:00
|
|
|
if (counterBasedMode == CounterBasedMode::implicitlyEnabled || counterBasedMode == CounterBasedMode::initiallyDisabled) {
|
|
|
|
counterBasedMode = CounterBasedMode::implicitlyDisabled;
|
2024-01-03 16:55:03 +08:00
|
|
|
counterBasedFlags = 0;
|
2023-11-29 02:07:06 +08:00
|
|
|
unsetInOrderExecInfo();
|
2023-11-06 22:48:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 17:24:14 +08:00
|
|
|
uint64_t Event::getGpuAddress(Device *device) const {
|
2024-02-16 19:03:25 +08:00
|
|
|
return getPoolAllocation(device)->getGpuAddress() + this->eventPoolOffset;
|
2023-01-12 17:24:14 +08:00
|
|
|
}
|
|
|
|
|
2024-02-16 19:03:25 +08:00
|
|
|
NEO::GraphicsAllocation *Event::getPoolAllocation(Device *device) const {
|
|
|
|
return this->eventPoolAllocation ? this->eventPoolAllocation->getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex()) : nullptr;
|
2023-01-12 17:24:14 +08: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 15:06:00 +08: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 17:24:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-19 20:57:43 +08:00
|
|
|
void *Event::getCompletionFieldHostAddress() const {
|
|
|
|
return ptrOffset(getHostAddress(), getCompletionFieldOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Event::increaseKernelCount() {
|
|
|
|
kernelCount++;
|
|
|
|
UNRECOVERABLE_IF(kernelCount > maxKernelCount);
|
|
|
|
}
|
|
|
|
|
2023-01-12 17:24:14 +08:00
|
|
|
void Event::resetPackets(bool resetAllPackets) {
|
|
|
|
if (resetAllPackets) {
|
|
|
|
resetKernelCountAndPacketUsedCount();
|
|
|
|
}
|
|
|
|
cpuStartTimestamp = 0;
|
|
|
|
gpuStartTimestamp = 0;
|
|
|
|
gpuEndTimestamp = 0;
|
2023-04-27 22:11:10 +08:00
|
|
|
this->csrs.clear();
|
|
|
|
this->csrs.push_back(this->device->getNEODevice()->getDefaultEngine().commandStreamReceiver);
|
2023-01-12 17:24:14 +08:00
|
|
|
}
|
|
|
|
|
2023-04-27 00:43:07 +08:00
|
|
|
void Event::setIsCompleted() {
|
|
|
|
if (this->isCompleted.load() == STATE_CLEARED) {
|
|
|
|
this->isCompleted = STATE_SIGNALED;
|
|
|
|
}
|
2023-08-30 04:31:16 +08:00
|
|
|
unsetCmdQueue();
|
2023-04-27 00:43:07 +08:00
|
|
|
}
|
|
|
|
|
2023-12-11 20:10:56 +08:00
|
|
|
void Event::updateInOrderExecState(std::shared_ptr<NEO::InOrderExecInfo> &newInOrderExecInfo, uint64_t signalValue, uint32_t allocationOffset) {
|
2023-11-08 18:09:35 +08:00
|
|
|
resetCompletionStatus();
|
|
|
|
|
2023-09-27 22:02:30 +08:00
|
|
|
if (this->inOrderExecInfo.get() != newInOrderExecInfo.get()) {
|
|
|
|
inOrderExecInfo = newInOrderExecInfo;
|
2023-09-25 18:10:46 +08:00
|
|
|
}
|
|
|
|
|
2023-06-08 02:44:13 +08:00
|
|
|
inOrderExecSignalValue = signalValue;
|
2023-07-04 18:43:51 +08:00
|
|
|
inOrderAllocationOffset = allocationOffset;
|
2023-05-05 17:14:00 +08:00
|
|
|
}
|
|
|
|
|
2023-10-03 17:34:45 +08:00
|
|
|
uint64_t Event::getInOrderExecSignalValueWithSubmissionCounter() const {
|
2024-01-11 20:51:31 +08:00
|
|
|
uint64_t appendCounter = inOrderExecInfo.get() ? NEO::InOrderPatchCommandHelpers::getAppendCounterValue(*inOrderExecInfo) : 0;
|
|
|
|
return (inOrderExecSignalValue + appendCounter);
|
2023-09-29 21:47:43 +08:00
|
|
|
}
|
|
|
|
|
2023-06-23 00:38:44 +08:00
|
|
|
void Event::setLatestUsedCmdQueue(CommandQueue *newCmdQ) {
|
|
|
|
this->latestUsedCmdQueue = newCmdQ;
|
|
|
|
}
|
|
|
|
|
2023-08-30 04:31:16 +08:00
|
|
|
void Event::unsetCmdQueue() {
|
2023-09-25 15:58:39 +08:00
|
|
|
for (auto &csr : csrs) {
|
|
|
|
csr->unregisterClient(latestUsedCmdQueue);
|
2023-06-23 00:38:44 +08:00
|
|
|
}
|
2023-09-25 15:58:39 +08:00
|
|
|
|
2023-06-23 00:38:44 +08:00
|
|
|
latestUsedCmdQueue = nullptr;
|
|
|
|
}
|
|
|
|
|
2023-07-06 16:35:07 +08:00
|
|
|
void Event::setReferenceTs(uint64_t currentCpuTimeStamp) {
|
|
|
|
const auto recalculate =
|
|
|
|
(currentCpuTimeStamp - referenceTs.cpuTimeinNS) > timestampRefreshIntervalInNanoSec;
|
|
|
|
if (referenceTs.cpuTimeinNS == 0 || recalculate) {
|
2024-04-30 18:59:04 +08:00
|
|
|
device->getNEODevice()->getOSTime()->getGpuCpuTime(&referenceTs, true);
|
2023-07-06 16:35:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-29 02:07:06 +08:00
|
|
|
void Event::unsetInOrderExecInfo() {
|
2024-07-19 23:15:04 +08:00
|
|
|
resetInOrderTimestampNode(nullptr);
|
2023-11-29 02:07:06 +08:00
|
|
|
inOrderExecInfo.reset();
|
|
|
|
inOrderAllocationOffset = 0;
|
|
|
|
inOrderExecSignalValue = 0;
|
|
|
|
}
|
|
|
|
|
2024-07-19 23:15:04 +08:00
|
|
|
void Event::resetInOrderTimestampNode(NEO::TagNodeBase *newNode) {
|
|
|
|
if (inOrderTimestampNode) {
|
|
|
|
inOrderExecInfo->pushTempTimestampNode(inOrderTimestampNode, inOrderExecSignalValue);
|
|
|
|
}
|
|
|
|
inOrderTimestampNode = newNode;
|
|
|
|
}
|
|
|
|
|
2020-03-06 18:09:57 +08:00
|
|
|
} // namespace L0
|