Cleanup event class to use function getter/setters

Signed-off-by: Aravind Gopalakrishnan <aravind.gopalakrishnan@intel.com>
This commit is contained in:
Aravind Gopalakrishnan 2021-06-09 20:15:59 +00:00 committed by Compute-Runtime-Automation
parent e1bcad51f0
commit e27d8a53a1
6 changed files with 49 additions and 40 deletions

View File

@ -241,7 +241,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendEventReset(ze_event_hand
uint32_t packetsToReset = 1;
if (event->isTimestampEvent) {
if (event->isEventTimestampFlagSet()) {
baseAddr += event->getContextEndOffset();
packetsToReset = EventPacketsCount::eventPackets;
event->resetPackets();
@ -1408,7 +1408,7 @@ void CommandListCoreFamily<gfxCoreFamily>::appendSignalEventPostWalker(ze_event_
return;
}
auto event = Event::fromHandle(hEvent);
if (event->isTimestampEvent) {
if (event->isEventTimestampFlagSet()) {
appendEventForProfiling(hEvent, false);
} else {
CommandListCoreFamily<gfxCoreFamily>::appendSignalEvent(hEvent);
@ -1420,7 +1420,7 @@ void CommandListCoreFamily<gfxCoreFamily>::appendEventForProfilingCopyCommand(ze
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
auto event = Event::fromHandle(hEvent);
if (!event->isTimestampEvent) {
if (!event->isEventTimestampFlagSet()) {
return;
}
commandContainer.addToResidencyContainer(&event->getAllocation(this->device));
@ -1524,7 +1524,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendSignalEvent(ze_event_han
commandContainer.addToResidencyContainer(&event->getAllocation(this->device));
uint64_t baseAddr = event->getGpuAddress(this->device);
size_t eventSignalOffset = 0;
if (event->isTimestampEvent) {
if (event->isEventTimestampFlagSet()) {
eventSignalOffset = event->getContextEndOffset();
}
@ -1574,7 +1574,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendWaitOnEvents(uint32_t nu
gpuAddr = event->getGpuAddress(this->device);
uint32_t packetsToWait = event->getPacketsInUse();
if (event->isTimestampEvent) {
if (event->isEventTimestampFlagSet()) {
gpuAddr += event->getContextEndOffset();
}
for (uint32_t i = 0u; i < packetsToWait; i++) {
@ -1647,7 +1647,7 @@ void CommandListCoreFamily<gfxCoreFamily>::appendEventForProfiling(ze_event_hand
} else {
auto event = Event::fromHandle(hEvent);
if (!event->isTimestampEvent) {
if (!event->isEventTimestampFlagSet()) {
return;
}

View File

@ -45,11 +45,11 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendBarrier(
bool isTimestampEvent = false;
for (uint32_t i = 0; i < numWaitEvents; i++) {
auto event = Event::fromHandle(phWaitEvents[i]);
isTimestampEvent |= (event->isTimestampEvent) ? true : false;
isTimestampEvent |= (event->isEventTimestampFlagSet()) ? true : false;
}
if (hSignalEvent) {
auto signalEvent = Event::fromHandle(hSignalEvent);
isTimestampEvent |= signalEvent->isTimestampEvent;
isTimestampEvent |= signalEvent->isEventTimestampFlagSet();
}
if (isSyncModeQueue || isTimestampEvent) {
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendBarrier(hSignalEvent, numWaitEvents, phWaitEvents);
@ -126,7 +126,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendMemoryFill(void
template <GFXCORE_FAMILY gfxCoreFamily>
ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendSignalEvent(ze_event_handle_t hEvent) {
auto event = Event::fromHandle(hEvent);
if (isSyncModeQueue || event->isTimestampEvent) {
if (isSyncModeQueue || event->isEventTimestampFlagSet()) {
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendSignalEvent(hEvent);
if (ret == ZE_RESULT_SUCCESS) {
executeCommandListImmediate(true);
@ -146,7 +146,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendSignalEvent(ze_
template <GFXCORE_FAMILY gfxCoreFamily>
ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendEventReset(ze_event_handle_t hEvent) {
auto event = Event::fromHandle(hEvent);
if (isSyncModeQueue || event->isTimestampEvent) {
if (isSyncModeQueue || event->isEventTimestampFlagSet()) {
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendEventReset(hEvent);
if (ret == ZE_RESULT_SUCCESS) {
executeCommandListImmediate(true);
@ -177,7 +177,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendWaitOnEvents(ui
bool isTimestampEvent = false;
for (uint32_t i = 0; i < numEvents; i++) {
auto event = Event::fromHandle(phEvent[i]);
isTimestampEvent |= (event->isTimestampEvent) ? true : false;
isTimestampEvent |= (event->isEventTimestampFlagSet()) ? true : false;
}
if (isSyncModeQueue || isTimestampEvent) {
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendWaitOnEvents(numEvents, phEvent);

View File

@ -46,6 +46,7 @@ ze_result_t EventPoolImp::initialize(DriverHandle *driver, Context *context, uin
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driver);
bool useDevicesFromApi = true;
bool useDeviceAlloc = isEventPoolDeviceAllocationFlagSet();
if (numDevices == 0) {
numDevices = static_cast<uint32_t>(driverHandleImp->devices.size());
@ -72,19 +73,19 @@ ze_result_t EventPoolImp::initialize(DriverHandle *driver, Context *context, uin
}
}
if (this->devices.size() > 1) {
this->allocOnDevice = false;
}
auto &hwHelper = devices[0]->getHwHelper();
eventAlignment = static_cast<uint32_t>(hwHelper.getTimestampPacketAllocatorAlignment());
eventSize = static_cast<uint32_t>(alignUp(EventPacketsCount::eventPackets * hwHelper.getSingleTimestampPacketSize(), eventAlignment));
size_t alignedSize = alignUp<size_t>(numEvents * eventSize, MemoryConstants::pageSize64k);
NEO::GraphicsAllocation::AllocationType allocationType = isEventPoolUsedForTimestamp ? NEO::GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER
: NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
if (this->allocOnDevice && !isEventPoolUsedForTimestamp) {
NEO::GraphicsAllocation::AllocationType allocationType = isEventPoolTimestampFlagSet() ? NEO::GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER
: NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
if (this->devices.size() > 1) {
useDeviceAlloc = false;
}
if (useDeviceAlloc && !isEventPoolTimestampFlagSet()) {
allocationType = NEO::GraphicsAllocation::AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER;
}

View File

@ -70,8 +70,6 @@ struct Event : _ze_event_handle_t {
uint32_t kernelCount = 1u;
ze_event_scope_flags_t signalScope = 0u;
ze_event_scope_flags_t waitScope = 0u;
bool isTimestampEvent = false;
bool allocOnDevice = false;
bool updateTaskCountEnabled = false;
uint64_t globalStartTS;
@ -83,9 +81,16 @@ struct Event : _ze_event_handle_t {
MetricStreamer *metricStreamer = nullptr;
NEO::CommandStreamReceiver *csr = nullptr;
void setEventTimestampFlag(bool timestampFlag) {
isTimestampEvent = timestampFlag;
}
bool isEventTimestampFlagSet() { return isTimestampEvent; }
protected:
uint64_t gpuAddress;
NEO::GraphicsAllocation *allocation = nullptr;
bool isTimestampEvent = false;
};
template <typename TagSizeT>
@ -153,20 +158,27 @@ struct EventPool : _ze_event_pool_handle_t {
virtual uint32_t getEventSize() = 0;
bool isEventPoolUsedForTimestamp = false;
bool allocOnDevice = false;
bool isEventPoolTimestampFlagSet() {
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP) {
return true;
}
return false;
}
bool isEventPoolDeviceAllocationFlagSet() {
if (!(eventPoolFlags & ZE_EVENT_POOL_FLAG_HOST_VISIBLE)) {
return true;
}
return false;
}
std::unique_ptr<NEO::MultiGraphicsAllocation> eventPoolAllocations;
ze_event_pool_flags_t eventPoolFlags;
};
struct EventPoolImp : public EventPool {
EventPoolImp(const ze_event_pool_desc_t *desc) : numEvents(desc->count) {
if (desc->flags & ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP) {
isEventPoolUsedForTimestamp = true;
}
if (!(desc->flags & ZE_EVENT_POOL_FLAG_HOST_VISIBLE)) {
allocOnDevice = true;
}
eventPoolFlags = desc->flags;
}
ze_result_t initialize(DriverHandle *driver, Context *context, uint32_t numDevices, ze_device_handle_t *phDevices);

View File

@ -13,15 +13,11 @@ Event *Event::create(EventPool *eventPool, const ze_event_desc_t *desc, Device *
auto event = new EventImp<TagSizeT>(eventPool, desc->index, device);
UNRECOVERABLE_IF(event == nullptr);
if (eventPool->isEventPoolUsedForTimestamp) {
event->isTimestampEvent = true;
if (eventPool->isEventPoolTimestampFlagSet()) {
event->setEventTimestampFlag(true);
event->kernelTimestampsData = std::make_unique<NEO::TimestampPackets<TagSizeT>[]>(EventPacketsCount::maxKernelSplit);
}
if (eventPool->allocOnDevice) {
event->allocOnDevice = true;
}
auto alloc = eventPool->getAllocation().getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex());
uint64_t baseHostAddr = reinterpret_cast<uint64_t>(alloc->getUnderlyingBuffer());
@ -107,7 +103,7 @@ ze_result_t EventImp<TagSizeT>::queryStatus() {
*hostAddr = metricStreamer->getNotificationState();
}
this->csr->downloadAllocations();
if (isTimestampEvent) {
if (isEventTimestampFlagSet()) {
return queryStatusKernelTimestamp();
}
memcpy_s(static_cast<void *>(&queryVal), sizeof(uint32_t), static_cast<void *>(hostAddr), sizeof(uint32_t));
@ -156,7 +152,7 @@ ze_result_t EventImp<TagSizeT>::hostEventSetValueTimestamps(TagSizeT eventVal) {
template <typename TagSizeT>
ze_result_t EventImp<TagSizeT>::hostEventSetValue(uint32_t eventVal) {
if (isTimestampEvent) {
if (isEventTimestampFlagSet()) {
return hostEventSetValueTimestamps(static_cast<TagSizeT>(eventVal));
}
@ -220,7 +216,7 @@ ze_result_t EventImp<TagSizeT>::hostSynchronize(uint64_t timeout) {
template <typename TagSizeT>
ze_result_t EventImp<TagSizeT>::reset() {
if (isTimestampEvent) {
if (isEventTimestampFlagSet()) {
kernelCount = EventPacketsCount::maxKernelSplit;
for (uint32_t i = 0; i < kernelCount; i++) {
kernelTimestampsData[i].setPacketsUsed(NEO::TimestampPacketSizeControl::preferredPacketCount);
@ -274,7 +270,7 @@ void EventImp<TagSizeT>::resetPackets() {
template <typename TagSizeT>
uint32_t EventImp<TagSizeT>::getPacketsInUse() {
if (isTimestampEvent) {
if (isEventTimestampFlagSet()) {
uint32_t packetsInUse = 0;
for (uint32_t i = 0; i < kernelCount; i++) {
packetsInUse += kernelTimestampsData[i].getPacketsUsed();
@ -293,7 +289,7 @@ void EventImp<TagSizeT>::setPacketsInUse(uint32_t value) {
template <typename TagSizeT>
uint64_t EventImp<TagSizeT>::getPacketAddress(Device *device) {
uint64_t address = getGpuAddress(device);
if (isTimestampEvent && kernelCount > 1) {
if (isEventTimestampFlagSet() && kernelCount > 1) {
for (uint32_t i = 0; i < kernelCount - 1; i++) {
address += kernelTimestampsData[i].getPacketsUsed() *
NEO::TimestampPackets<TagSizeT>::getSinglePacketSize();

View File

@ -543,7 +543,7 @@ class TimestampEventCreate : public Test<DeviceFixture> {
};
TEST_F(TimestampEventCreate, givenEventCreatedWithTimestampThenIsTimestampEventFlagSet) {
EXPECT_TRUE(event->isTimestampEvent);
EXPECT_TRUE(event->isEventTimestampFlagSet());
}
TEST_F(TimestampEventCreate, givenEventTimestampsCreatedWhenResetIsInvokeThenCorrectDataAreSet) {