2020-03-06 18:09:57 +08:00
|
|
|
/*
|
2023-01-02 17:56:45 +08:00
|
|
|
* Copyright (C) 2020-2023 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 *);
|
2020-03-06 18:09:57 +08:00
|
|
|
|
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);
|
|
|
|
|
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);
|
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();
|
|
|
|
}
|
2023-03-25 05:26:48 +08:00
|
|
|
|
|
|
|
isImplicitScalingCapable |= eventDevice->isImplicitScalingCapable();
|
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
|
|
|
|
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
|
|
|
|
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) {
|
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) {
|
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
|
|
|
|
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;
|
2022-11-10 10:57:51 +08:00
|
|
|
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_IPC) {
|
|
|
|
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);
|
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
|
|
|
}
|
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
|
|
|
|
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);
|
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
|
|
|
|
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-01-17 01:12:02 +08:00
|
|
|
bool EventPool::isEventPoolTimestampFlagSet() const {
|
2023-01-16 23:30:27 +08:00
|
|
|
if (NEO::DebugManager.flags.OverrideTimestampEvents.get() != -1) {
|
|
|
|
auto timestampOverride = !!NEO::DebugManager.flags.OverrideTimestampEvents.get();
|
|
|
|
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
|
|
|
|
|
|
|
int retCode = this->eventPoolAllocations->getDefaultGraphicsAllocation()->peekInternalHandle(this->context->getDriverHandle()->getMemoryManager(), poolData.handle);
|
|
|
|
return retCode == 0 ? ZE_RESULT_SUCCESS : ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
NEO::osHandle osHandle = static_cast<NEO::osHandle>(poolData.handle);
|
|
|
|
|
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) {
|
|
|
|
PRINT_DEBUG_STRING(NEO::DebugManager.flags.PrintDebugMessages.get(),
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NEO::AllocationType allocationType = NEO::AllocationType::BUFFER_HOST_MEMORY;
|
|
|
|
if (eventPool->isDeviceEventPoolAllocation) {
|
|
|
|
allocationType = NEO::AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
false);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-01-12 17:24:14 +08:00
|
|
|
uint64_t Event::getGpuAddress(Device *device) const {
|
|
|
|
return getAllocation(device).getGpuAddress() + this->eventPoolOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
NEO::GraphicsAllocation &Event::getAllocation(Device *device) const {
|
|
|
|
return *this->eventPool->getAllocation().getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-05 17:14:00 +08:00
|
|
|
void Event::enableInOrderExecMode(NEO::GraphicsAllocation &inOrderDependenciesAllocation, uint32_t signalValue) {
|
|
|
|
inOrderExecEvent = true;
|
|
|
|
inOrderExecSignalValue = signalValue;
|
|
|
|
inOrderExecDataAllocation = &inOrderDependenciesAllocation;
|
|
|
|
}
|
|
|
|
|
2020-03-06 18:09:57 +08:00
|
|
|
} // namespace L0
|