2020-03-06 11:09:57 +01:00
|
|
|
/*
|
2023-01-02 09:56:45 +00:00
|
|
|
* Copyright (C) 2020-2023 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-01-19 12:57:43 +00:00
|
|
|
#include "shared/source/helpers/hw_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"
|
|
|
|
|
#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"
|
2021-05-18 16:28:14 +00:00
|
|
|
#include "level_zero/core/source/hw_helpers/l0_hw_helper.h"
|
2020-03-06 11:09:57 +01:00
|
|
|
#include "level_zero/tools/source/metrics/metric.h"
|
|
|
|
|
|
2021-05-11 18:43:28 +00:00
|
|
|
#include <set>
|
2020-03-06 11:09:57 +01:00
|
|
|
|
2021-05-18 16:28:14 +00:00
|
|
|
//
|
|
|
|
|
#include "level_zero/core/source/event/event_impl.inl"
|
|
|
|
|
|
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 *);
|
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);
|
|
|
|
|
|
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);
|
2022-04-07 13:09:40 +00:00
|
|
|
rootDeviceIndices.push_back(eventDevice->getNEODevice()->getRootDeviceIndex());
|
2021-05-07 15:41:43 +00:00
|
|
|
if (maxRootDeviceIndex < eventDevice->getNEODevice()->getRootDeviceIndex()) {
|
|
|
|
|
maxRootDeviceIndex = eventDevice->getNEODevice()->getRootDeviceIndex();
|
|
|
|
|
}
|
2021-04-12 22:00:23 +00:00
|
|
|
}
|
2022-04-07 13:09:40 +00:00
|
|
|
rootDeviceIndices.remove_duplicates();
|
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
|
|
|
|
2022-04-23 03:53:39 +02:00
|
|
|
NEO::AllocationType allocationType = isEventPoolTimestampFlagSet() ? NEO::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER
|
|
|
|
|
: NEO::AllocationType::BUFFER_HOST_MEMORY;
|
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) {
|
2022-02-04 13:59:01 +00:00
|
|
|
allocationType = NEO::AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER;
|
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
|
|
|
|
2022-12-15 08:15:18 -08:00
|
|
|
this->isHostVisibleEventPoolAllocation = !(isEventPoolDeviceAllocationFlagSet());
|
|
|
|
|
|
|
|
|
|
if (this->isDeviceEventPoolAllocation) {
|
2022-10-27 11:40:44 +00:00
|
|
|
NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), this->eventPoolSize, allocationType, devices[0]->getNEODevice()->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;
|
2022-11-10 02:57:51 +00:00
|
|
|
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_IPC) {
|
|
|
|
|
uint64_t handle = 0;
|
|
|
|
|
this->isShareableEventMemory = (graphicsAllocation->peekInternalHandle(memoryManager, handle) == 0);
|
|
|
|
|
}
|
2021-10-13 15:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
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);
|
|
|
|
|
|
2022-08-03 14:06:59 -07:00
|
|
|
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_IPC) {
|
|
|
|
|
this->isShareableEventMemory = eventPoolAllocations->getDefaultGraphicsAllocation()->isShareableHostMemory;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
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
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 11:09:57 +01:00
|
|
|
ze_result_t Event::destroy() {
|
|
|
|
|
delete this;
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2021-04-12 22:00:23 +00:00
|
|
|
if (!eventPool) {
|
2021-11-09 14:44:11 +00:00
|
|
|
result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
|
2021-04-12 22:00:23 +00:00
|
|
|
DEBUG_BREAK_IF(true);
|
2020-10-13 17:23:09 -07:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
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-01-16 17:12:02 +00:00
|
|
|
bool EventPool::isEventPoolTimestampFlagSet() const {
|
2023-01-16 15:30:27 +00: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-12 09:24:14 +00: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 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;
|
|
|
|
|
this->csr = this->device->getNEODevice()->getDefaultEngine().commandStreamReceiver;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 11:09:57 +01:00
|
|
|
} // namespace L0
|