2020-03-06 18:09:57 +08:00
|
|
|
/*
|
2020-12-19 01:01:08 +08:00
|
|
|
* Copyright (C) 2019-2021 Intel Corporation
|
2020-03-06 18:09:57 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-09-15 15:33:12 +08:00
|
|
|
#include "shared/source/helpers/timestamp_packet.h"
|
|
|
|
|
2020-03-19 13:21:57 +08:00
|
|
|
#include "level_zero/core/source/cmdlist/cmdlist.h"
|
|
|
|
#include "level_zero/core/source/device/device.h"
|
|
|
|
#include "level_zero/core/source/driver/driver_handle.h"
|
2020-07-29 17:45:54 +08:00
|
|
|
#include <level_zero/ze_api.h>
|
2020-03-06 18:09:57 +08:00
|
|
|
|
|
|
|
struct _ze_event_handle_t {};
|
|
|
|
|
|
|
|
struct _ze_event_pool_handle_t {};
|
|
|
|
|
|
|
|
namespace L0 {
|
|
|
|
typedef uint64_t FlushStamp;
|
|
|
|
struct EventPool;
|
2020-07-09 20:21:33 +08:00
|
|
|
struct MetricStreamer;
|
2020-09-15 15:33:12 +08:00
|
|
|
using TimestampPacketStorage = NEO::TimestampPackets<uint32_t>;
|
2020-03-06 18:09:57 +08:00
|
|
|
|
|
|
|
struct Event : _ze_event_handle_t {
|
|
|
|
virtual ~Event() = default;
|
|
|
|
virtual ze_result_t destroy();
|
|
|
|
virtual ze_result_t hostSignal() = 0;
|
2020-07-29 17:45:54 +08:00
|
|
|
virtual ze_result_t hostSynchronize(uint64_t timeout) = 0;
|
2020-03-06 18:09:57 +08:00
|
|
|
virtual ze_result_t queryStatus() = 0;
|
|
|
|
virtual ze_result_t reset() = 0;
|
2020-07-29 20:25:20 +08:00
|
|
|
virtual ze_result_t queryKernelTimestamp(ze_kernel_timestamp_result_t *dstptr) = 0;
|
2020-04-09 03:44:14 +08:00
|
|
|
enum State : uint32_t {
|
2020-03-06 18:09:57 +08:00
|
|
|
STATE_SIGNALED = 0u,
|
2020-04-09 03:44:14 +08:00
|
|
|
STATE_CLEARED = static_cast<uint32_t>(-1),
|
2020-03-06 18:09:57 +08:00
|
|
|
STATE_INITIAL = STATE_CLEARED
|
|
|
|
};
|
|
|
|
|
|
|
|
static Event *create(EventPool *eventPool, const ze_event_desc_t *desc, Device *device);
|
|
|
|
|
|
|
|
static Event *fromHandle(ze_event_handle_t handle) { return static_cast<Event *>(handle); }
|
|
|
|
|
|
|
|
inline ze_event_handle_t toHandle() { return this; }
|
|
|
|
|
2020-04-07 22:50:09 +08:00
|
|
|
virtual NEO::GraphicsAllocation &getAllocation();
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2020-12-19 01:01:08 +08:00
|
|
|
void increasePacketsInUse() { packetsInUse++; }
|
|
|
|
void resetPackets() { packetsInUse = 0; }
|
2020-11-21 03:11:34 +08:00
|
|
|
uint64_t getGpuAddress() { return gpuAddress; }
|
2020-12-19 01:01:08 +08:00
|
|
|
uint32_t getPacketsInUse() { return packetsInUse; }
|
|
|
|
uint64_t getTimestampPacketAddress();
|
2020-03-06 18:09:57 +08:00
|
|
|
|
|
|
|
void *hostAddress = nullptr;
|
2020-11-21 03:11:34 +08:00
|
|
|
uint64_t gpuAddress;
|
2020-12-19 01:01:08 +08:00
|
|
|
uint32_t packetsInUse = 0;
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2020-08-25 11:21:34 +08:00
|
|
|
ze_event_scope_flags_t signalScope = 0u;
|
|
|
|
ze_event_scope_flags_t waitScope = 0u;
|
2020-03-06 18:09:57 +08:00
|
|
|
bool isTimestampEvent = false;
|
|
|
|
|
2020-09-15 15:33:12 +08:00
|
|
|
std::unique_ptr<TimestampPacketStorage> timestampsData = nullptr;
|
|
|
|
uint64_t globalStartTS;
|
|
|
|
uint64_t globalEndTS;
|
|
|
|
uint64_t contextStartTS;
|
|
|
|
uint64_t contextEndTS;
|
|
|
|
|
2020-07-09 20:21:33 +08:00
|
|
|
// Metric streamer instance associated with the event.
|
|
|
|
MetricStreamer *metricStreamer = nullptr;
|
2020-04-21 23:10:00 +08:00
|
|
|
NEO::CommandStreamReceiver *csr = nullptr;
|
|
|
|
|
2020-03-06 18:09:57 +08:00
|
|
|
protected:
|
|
|
|
NEO::GraphicsAllocation *allocation = nullptr;
|
|
|
|
};
|
|
|
|
|
2020-09-03 15:06:11 +08:00
|
|
|
struct EventImp : public Event {
|
|
|
|
EventImp(EventPool *eventPool, int index, Device *device)
|
|
|
|
: device(device), eventPool(eventPool) {}
|
|
|
|
|
|
|
|
~EventImp() override {}
|
|
|
|
|
|
|
|
ze_result_t hostSignal() override;
|
|
|
|
|
|
|
|
ze_result_t hostSynchronize(uint64_t timeout) override;
|
|
|
|
|
|
|
|
ze_result_t queryStatus() override;
|
|
|
|
|
|
|
|
ze_result_t reset() override;
|
|
|
|
|
|
|
|
ze_result_t queryKernelTimestamp(ze_kernel_timestamp_result_t *dstptr) override;
|
|
|
|
|
|
|
|
Device *device;
|
|
|
|
EventPool *eventPool;
|
|
|
|
|
|
|
|
protected:
|
2020-09-15 15:33:12 +08:00
|
|
|
ze_result_t calculateProfilingData();
|
2020-09-03 15:06:11 +08:00
|
|
|
ze_result_t hostEventSetValue(uint32_t eventValue);
|
2020-11-21 03:11:34 +08:00
|
|
|
ze_result_t hostEventSetValueTimestamps(uint32_t eventVal);
|
2020-09-15 15:33:12 +08:00
|
|
|
void assignTimestampData(void *address);
|
2020-09-03 15:06:11 +08:00
|
|
|
void makeAllocationResident();
|
|
|
|
};
|
|
|
|
|
2020-03-06 18:09:57 +08:00
|
|
|
struct EventPool : _ze_event_pool_handle_t {
|
2020-03-17 06:47:18 +08:00
|
|
|
static EventPool *create(DriverHandle *driver, uint32_t numDevices, ze_device_handle_t *phDevices, const ze_event_pool_desc_t *desc);
|
2020-03-06 18:09:57 +08:00
|
|
|
virtual ~EventPool() = default;
|
|
|
|
virtual ze_result_t destroy() = 0;
|
|
|
|
virtual ze_result_t getIpcHandle(ze_ipc_event_pool_handle_t *pIpcHandle) = 0;
|
|
|
|
virtual ze_result_t closeIpcHandle() = 0;
|
|
|
|
virtual ze_result_t createEvent(const ze_event_desc_t *desc, ze_event_handle_t *phEvent) = 0;
|
|
|
|
virtual Device *getDevice() = 0;
|
|
|
|
|
|
|
|
static EventPool *fromHandle(ze_event_pool_handle_t handle) {
|
|
|
|
return static_cast<EventPool *>(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ze_event_pool_handle_t toHandle() { return this; }
|
|
|
|
|
2020-10-14 08:23:09 +08:00
|
|
|
virtual NEO::MultiGraphicsAllocation &getAllocation() { return *eventPoolAllocations; }
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2020-11-21 03:11:34 +08:00
|
|
|
virtual uint32_t getEventSize() = 0;
|
2020-03-06 18:09:57 +08:00
|
|
|
|
|
|
|
bool isEventPoolUsedForTimestamp = false;
|
|
|
|
|
|
|
|
protected:
|
2020-10-14 08:23:09 +08:00
|
|
|
NEO::MultiGraphicsAllocation *eventPoolAllocations = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EventPoolImp : public EventPool {
|
|
|
|
EventPoolImp(DriverHandle *driver, uint32_t numDevices, ze_device_handle_t *phDevices, uint32_t numEvents, ze_event_pool_flags_t flags) : numEvents(numEvents) {
|
|
|
|
if (flags & ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP) {
|
|
|
|
isEventPoolUsedForTimestamp = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ze_result_t initialize(DriverHandle *driver,
|
|
|
|
uint32_t numDevices,
|
|
|
|
ze_device_handle_t *phDevices,
|
|
|
|
uint32_t numEvents);
|
|
|
|
|
|
|
|
~EventPoolImp();
|
|
|
|
|
|
|
|
ze_result_t destroy() override;
|
|
|
|
|
|
|
|
ze_result_t getIpcHandle(ze_ipc_event_pool_handle_t *pIpcHandle) override;
|
|
|
|
|
|
|
|
ze_result_t closeIpcHandle() override;
|
|
|
|
|
|
|
|
ze_result_t createEvent(const ze_event_desc_t *desc, ze_event_handle_t *phEvent) override;
|
|
|
|
|
2020-11-21 03:11:34 +08:00
|
|
|
uint32_t getEventSize() override { return eventSize; }
|
2020-10-14 08:23:09 +08:00
|
|
|
size_t getNumEvents() { return numEvents; }
|
|
|
|
|
|
|
|
Device *getDevice() override { return devices[0]; }
|
|
|
|
|
|
|
|
std::vector<Device *> devices;
|
|
|
|
size_t numEvents;
|
|
|
|
|
|
|
|
protected:
|
2020-09-15 15:33:12 +08:00
|
|
|
const uint32_t eventSize = static_cast<uint32_t>(NEO::TimestampPacketSizeControl::preferredPacketCount * alignUp(sizeof(struct TimestampPacketStorage::Packet),
|
|
|
|
MemoryConstants::cacheLineSize));
|
2020-11-21 03:11:34 +08:00
|
|
|
const uint32_t eventAlignment = MemoryConstants::cacheLineSize;
|
2020-03-06 18:09:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace L0
|