2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-01-04 23:00:09 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-10-06 03:51:57 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/event/event_builder.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
|
|
|
#include "shared/source/helpers/timestamp_packet.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/api/cl_types.h"
|
|
|
|
#include "opencl/source/event/user_event.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
EventBuilder::~EventBuilder() {
|
|
|
|
UNRECOVERABLE_IF((this->event == nullptr) && ((parentEvents.size() != 0U)));
|
|
|
|
finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventBuilder::addParentEvent(Event &newParentEvent) {
|
|
|
|
bool duplicate = false;
|
|
|
|
for (Event *parent : parentEvents) {
|
|
|
|
if (parent == &newParentEvent) {
|
|
|
|
duplicate = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!duplicate) {
|
|
|
|
newParentEvent.incRefInternal();
|
|
|
|
parentEvents.push_back(&newParentEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventBuilder::addParentEvents(ArrayRef<const cl_event> newParentEvents) {
|
|
|
|
for (cl_event clEv : newParentEvents) {
|
|
|
|
auto neoEv = castToObject<Event>(clEv);
|
|
|
|
DEBUG_BREAK_IF(neoEv == nullptr);
|
|
|
|
addParentEvent(neoEv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventBuilder::finalize() {
|
|
|
|
if ((this->event == nullptr) || finalized) {
|
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (parentEvents.size() != 0) {
|
|
|
|
UserEvent sentinel;
|
|
|
|
sentinel.addChild(*this->event);
|
|
|
|
for (Event *parent : parentEvents) {
|
|
|
|
|
2023-01-04 23:00:09 +08:00
|
|
|
// do not add as child if:
|
|
|
|
// parent has no parents and is not blocked
|
2020-06-16 19:19:11 +08:00
|
|
|
if (!(parent->peekIsBlocked() == false && parent->taskLevel != CompletionStamp::notReady) ||
|
2019-02-04 20:08:47 +08:00
|
|
|
(!parent->isEventWithoutCommand() && !parent->peekIsCmdSubmitted())) {
|
2017-12-21 07:45:38 +08:00
|
|
|
parent->addChild(*this->event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sentinel.setStatus(CL_COMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
|
|
|
finalized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventBuilder::clear() {
|
|
|
|
for (Event *parent : parentEvents) {
|
|
|
|
parent->decRefInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
parentEvents.clear();
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|