mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 21:18:24 +08:00
[n/n] Remove event registry.
Change-Id: Ie7da0f2dc944583771aaa80648217602ccff99ce
This commit is contained in:
committed by
sys_ocldev
parent
b0a41b81bb
commit
2a00a15141
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@@ -2,4 +2,4 @@
|
||||
neoDependenciesRev='716918-671'
|
||||
strategy='EQUAL'
|
||||
allowedF=49
|
||||
allowedCD=380
|
||||
allowedCD=377
|
||||
|
||||
@@ -237,8 +237,6 @@ set (RUNTIME_SRCS_EVENT
|
||||
event/event.h
|
||||
event/event_builder.cpp
|
||||
event/event_builder.h
|
||||
event/event_registry.cpp
|
||||
event/event_registry.h
|
||||
event/user_event.cpp
|
||||
event/user_event.h
|
||||
event/hw_timestamps.h
|
||||
|
||||
@@ -400,13 +400,6 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface **surfacesForResidency,
|
||||
queueOwnership.unlock();
|
||||
deviceOwnership.unlock();
|
||||
|
||||
if (blockQueue) {
|
||||
TakeOwnershipWrapper<CommandQueueHw<GfxFamily>> queueOwnership(*this);
|
||||
if (this->virtualEvent == eventBuilder.getEvent()) {
|
||||
eventBuilder.registerEvent();
|
||||
}
|
||||
}
|
||||
|
||||
if (blocking) {
|
||||
if (blockQueue) {
|
||||
while (isQueueBlocked())
|
||||
|
||||
@@ -172,7 +172,6 @@ bool Context::createImpl(const cl_context_properties *properties,
|
||||
if (devices.size() > 0) {
|
||||
this->memoryManager = this->getDevice(0)->getMemoryManager();
|
||||
this->svmAllocsManager = new SVMAllocsManager(this->memoryManager);
|
||||
this->eventsRegistry.setDevice(this->getDevice(0));
|
||||
if (memoryManager->isAsyncDeleterEnabled()) {
|
||||
memoryManager->getDeferredDeleter()->addClient();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#pragma once
|
||||
#include "runtime/device/device_vector.h"
|
||||
#include "runtime/event/event.h"
|
||||
#include "runtime/event/event_registry.h"
|
||||
#include "runtime/context/driver_diagnostics.h"
|
||||
#include <vector>
|
||||
|
||||
@@ -88,10 +87,6 @@ class Context : public BaseObject<_cl_context> {
|
||||
return svmAllocsManager;
|
||||
}
|
||||
|
||||
EventsRegistry &getEventsRegistry() {
|
||||
return eventsRegistry;
|
||||
}
|
||||
|
||||
DeviceQueue *getDefaultDeviceQueue();
|
||||
void setDefaultDeviceQueue(DeviceQueue *queue);
|
||||
|
||||
@@ -140,7 +135,6 @@ class Context : public BaseObject<_cl_context> {
|
||||
DeviceVector devices;
|
||||
MemoryManager *memoryManager;
|
||||
SVMAllocsManager *svmAllocsManager = nullptr;
|
||||
EventsRegistry eventsRegistry;
|
||||
CommandQueue *specialQueue;
|
||||
DeviceQueue *defaultDeviceQueue;
|
||||
std::vector<std::unique_ptr<SharingFunctions>> sharingFunctions;
|
||||
|
||||
@@ -53,7 +53,6 @@ Event::Event(
|
||||
ctx(ctx),
|
||||
cmdQueue(cmdQueue),
|
||||
cmdType(cmdType),
|
||||
requiresUnregistration(false),
|
||||
dataCalculated(false),
|
||||
timeStampNode(nullptr),
|
||||
perfCounterNode(nullptr),
|
||||
@@ -129,11 +128,6 @@ Event::~Event() {
|
||||
}
|
||||
|
||||
if (ctx != nullptr) {
|
||||
if (requiresUnregistration) {
|
||||
// in case Event was not properly unregistered prior to destruction
|
||||
// we need to remove it from registry to guard it from being corrupted
|
||||
ctx->getEventsRegistry().dropEvent(*this);
|
||||
}
|
||||
if (timeStampNode != nullptr) {
|
||||
TagAllocator<HwTimeStamps> *allocator = ctx->getDevice(0)->getMemoryManager()->getEventTsAllocator();
|
||||
allocator->returnTag(timeStampNode);
|
||||
@@ -634,18 +628,6 @@ void Event::tryFlushEvent() {
|
||||
}
|
||||
}
|
||||
|
||||
void Event::unregisterEvent(Event *ev) {
|
||||
if (ev == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (ev->ctx != nullptr) {
|
||||
ev->requiresUnregistration = false;
|
||||
ev->ctx->getEventsRegistry().unregisterEvent(std::unique_ptr<Event>(ev));
|
||||
} else {
|
||||
delete ev;
|
||||
}
|
||||
}
|
||||
|
||||
void Event::setQueueTimeStamp() {
|
||||
if (this->profilingEnabled && (this->cmdQueue != nullptr)) {
|
||||
this->cmdQueue->getDevice().getOSTime()->getCpuTime(&queueTimeStamp.CPUTimeinNS);
|
||||
@@ -725,11 +707,4 @@ void Event::copyPerfCounters(InstrPmRegsCfg *config) {
|
||||
memcpy_s(perfConfigurationData, sizeof(InstrPmRegsCfg), config, sizeof(InstrPmRegsCfg));
|
||||
}
|
||||
|
||||
void Event::addToRegistry() {
|
||||
UNRECOVERABLE_IF(requiresUnregistration);
|
||||
if (this->ctx != nullptr) {
|
||||
requiresUnregistration = true;
|
||||
this->ctx->getEventsRegistry().registerEvent(*this);
|
||||
}
|
||||
}
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -291,11 +291,6 @@ class Event : public BaseObject<_cl_event>, public IDNode<Event> {
|
||||
virtual void updateExecutionStatus();
|
||||
void tryFlushEvent();
|
||||
|
||||
using DeleterFuncType = void (*)(Event *);
|
||||
DeleterFuncType getCustomDeleter() const {
|
||||
return &unregisterEvent;
|
||||
}
|
||||
|
||||
uint32_t peekTaskCount() const {
|
||||
return this->taskCount;
|
||||
}
|
||||
@@ -318,15 +313,12 @@ class Event : public BaseObject<_cl_event>, public IDNode<Event> {
|
||||
this->cmdType = cmdType;
|
||||
}
|
||||
|
||||
void addToRegistry();
|
||||
std::vector<Event *> &getParentEvents() { return this->parentEvents; }
|
||||
|
||||
protected:
|
||||
Event(Context *ctx, CommandQueue *cmdQueue, cl_command_type cmdType,
|
||||
uint32_t taskLevel, uint32_t taskCount);
|
||||
|
||||
static void unregisterEvent(Event *ev);
|
||||
|
||||
ECallbackTarget translateToCallbackTarget(cl_int execStatus) {
|
||||
switch (execStatus) {
|
||||
default: {
|
||||
@@ -372,7 +364,6 @@ class Event : public BaseObject<_cl_event>, public IDNode<Event> {
|
||||
Context *ctx;
|
||||
CommandQueue *cmdQueue;
|
||||
cl_command_type cmdType;
|
||||
bool requiresUnregistration;
|
||||
|
||||
// callbacks to be executed when this event changes its execution state
|
||||
IFList<Callback, true, true> callbacks[(uint32_t)ECallbackTarget::MAX];
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "runtime/api/cl_types.h"
|
||||
#include "runtime/context/context.h"
|
||||
#include "runtime/event/event_builder.h"
|
||||
#include "runtime/event/event_registry.h"
|
||||
#include "runtime/event/user_event.h"
|
||||
#include "runtime/helpers/debug_helpers.h"
|
||||
|
||||
@@ -31,7 +30,6 @@ namespace OCLRT {
|
||||
EventBuilder::~EventBuilder() {
|
||||
UNRECOVERABLE_IF((this->event == nullptr) && ((parentEvents.size() != 0U)));
|
||||
finalize();
|
||||
registerEvent();
|
||||
}
|
||||
|
||||
void EventBuilder::addParentEvent(Event &newParentEvent) {
|
||||
@@ -88,12 +86,4 @@ void EventBuilder::clear() {
|
||||
|
||||
parentEvents.clear();
|
||||
}
|
||||
|
||||
void EventBuilder::registerEvent() {
|
||||
if (this->event && !doNotRegister) {
|
||||
this->event->addToRegistry();
|
||||
doNotRegister = true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -63,15 +63,12 @@ class EventBuilder {
|
||||
|
||||
Event *finalizeAndRelease() {
|
||||
finalize();
|
||||
registerEvent();
|
||||
Event *retEvent = this->event;
|
||||
this->event = nullptr;
|
||||
finalized = false;
|
||||
return retEvent;
|
||||
}
|
||||
|
||||
void registerEvent();
|
||||
|
||||
protected:
|
||||
void clear();
|
||||
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/event/event_registry.h"
|
||||
|
||||
namespace OCLRT {
|
||||
void EventsRegistry::broadcastUpdateAll() {
|
||||
this->processLocked<EventsRegistry, &EventsRegistry::updateSingleImpl>(nullptr, nullptr);
|
||||
}
|
||||
|
||||
void EventsRegistry::setDevice(Device *device) {
|
||||
DEBUG_BREAK_IF(this->device != nullptr);
|
||||
device->incRefInternal();
|
||||
this->device = device;
|
||||
}
|
||||
|
||||
EventsRegistry::~EventsRegistry() {
|
||||
if (device) {
|
||||
device->decRefInternal();
|
||||
}
|
||||
}
|
||||
|
||||
Event *EventsRegistry::updateSingleImpl(Event *, void *) {
|
||||
executeDeferredDeletionList();
|
||||
Event *curr = head;
|
||||
while (curr != nullptr) {
|
||||
curr->updateExecutionStatus();
|
||||
curr = curr->next;
|
||||
}
|
||||
executeDeferredDeletionList();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void EventsRegistry::unregisterEvent(std::unique_ptr<Event> event) {
|
||||
if (this->lockOwner == std::this_thread::get_id()) {
|
||||
// current thread is processing the list - add event to deferred deletion list
|
||||
deferredDeletion.pushRefFrontOne(*event.release());
|
||||
} else {
|
||||
this->removeOne(*event.release());
|
||||
}
|
||||
}
|
||||
} // namespace OCLRT
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "runtime/utilities/idlist.h"
|
||||
#include "runtime/utilities/iflist.h"
|
||||
#include "runtime/event/event.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
class EventsRegistry : private IDList<Event, true, false> {
|
||||
public:
|
||||
void broadcastUpdateAll();
|
||||
|
||||
void registerEvent(Event &event) {
|
||||
pushTailOne(event);
|
||||
}
|
||||
|
||||
void unregisterEvent(std::unique_ptr<Event> event);
|
||||
|
||||
void dropEvent(Event &event) {
|
||||
this->removeOne(event).release();
|
||||
}
|
||||
|
||||
Event *peekHead() {
|
||||
return IDList<Event, true, false>::peekHead();
|
||||
}
|
||||
|
||||
void setDevice(Device *device);
|
||||
~EventsRegistry();
|
||||
|
||||
protected:
|
||||
void executeDeferredDeletionList() {
|
||||
auto nodesToDelete = deferredDeletion.detachNodes();
|
||||
auto curr = nodesToDelete;
|
||||
while (curr != nullptr) {
|
||||
this->removeOne(*curr->ref);
|
||||
auto next = curr->next;
|
||||
delete curr;
|
||||
curr = next;
|
||||
}
|
||||
}
|
||||
|
||||
IFRefList<Event, true, true> deferredDeletion;
|
||||
|
||||
friend class IDList<Event, true, false>;
|
||||
Event *updateSingleImpl(Event *, void *);
|
||||
|
||||
Device *device = nullptr;
|
||||
};
|
||||
} // namespace OCLRT
|
||||
@@ -261,46 +261,6 @@ HWTEST_F(CommandQueueCommandStreamTest, givenCommandQueueThatWaitsOnAbortedUserE
|
||||
EXPECT_EQ(100u, cmdQ.taskLevel);
|
||||
}
|
||||
|
||||
TEST_F(CommandQueueCommandStreamTest, givenCmdQueueBlockedByEventWhenEventIsAsynchronouslyCompletedThenBroadcastUpdateAllIsNotCalledOnIsQueueBlockedCall) {
|
||||
MockContext context;
|
||||
CommandQueue cmdQ(&context, pDevice, 0);
|
||||
|
||||
class MockEventWithSetCompleteOnUpdate : public Event {
|
||||
public:
|
||||
MockEventWithSetCompleteOnUpdate(CommandQueue *cmdQueue, cl_command_type cmdType,
|
||||
uint32_t taskLevel, uint32_t taskCount) : Event(cmdQueue, cmdType, taskLevel, taskCount) {
|
||||
}
|
||||
void updateExecutionStatus() override {
|
||||
setStatus(CL_COMPLETE);
|
||||
}
|
||||
};
|
||||
|
||||
MockEventWithSetCompleteOnUpdate *event = new MockEventWithSetCompleteOnUpdate(&cmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
|
||||
event->setStatus(CL_SUBMITTED);
|
||||
|
||||
Event virtualEvent(&cmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 20);
|
||||
|
||||
event->addChild(virtualEvent);
|
||||
|
||||
// Put Queue in blocked state by assigning virtualEvent
|
||||
virtualEvent.incRefInternal();
|
||||
cmdQ.virtualEvent = &virtualEvent;
|
||||
cmdQ.incRefInternal();
|
||||
|
||||
context.getEventsRegistry().registerEvent(*event);
|
||||
|
||||
EXPECT_TRUE(cmdQ.isQueueBlocked());
|
||||
// This second check is purposely here, queue shouldn't be unblocked asynchrounously in isQueueBlocked
|
||||
// because it can lead to deadlock when isQueueBlocked() is called under device mutex and would try to
|
||||
// acquire registry mutex, while second thread owns mutex for registry processing.
|
||||
EXPECT_TRUE(cmdQ.isQueueBlocked());
|
||||
|
||||
context.getEventsRegistry().broadcastUpdateAll();
|
||||
context.getEventsRegistry().dropEvent(*event);
|
||||
|
||||
event->release();
|
||||
}
|
||||
|
||||
TEST_F(CommandQueueCommandStreamTest, GetCommandStreamReturnsValidObject) {
|
||||
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
|
||||
CommandQueue commandQueue(&context, pDevice, props);
|
||||
|
||||
@@ -217,39 +217,6 @@ HWTEST_F(EnqueueHandlerTest, enqueueBlockedUnsetsCurrentCmdQVirtualEventForPrevi
|
||||
mockCmdQ->release();
|
||||
}
|
||||
|
||||
HWTEST_F(EnqueueHandlerTest, blockedEnqueueRegistersEvent) {
|
||||
UserEvent userEvent;
|
||||
cl_event clUserEvent = &userEvent;
|
||||
|
||||
MockKernelWithInternals kernelInternals(*pDevice, &context);
|
||||
Kernel *kernel = kernelInternals.mockKernel;
|
||||
MockMultiDispatchInfo multiDispatchInfo(kernel);
|
||||
cl_event outputEvent = nullptr;
|
||||
|
||||
auto mockCmdQ = new MockCommandQueueHw<FamilyType>(&context, pDevice, 0);
|
||||
|
||||
bool blocking = false;
|
||||
mockCmdQ->template enqueueHandler<CL_COMMAND_NDRANGE_KERNEL>(nullptr,
|
||||
0,
|
||||
blocking,
|
||||
multiDispatchInfo,
|
||||
1,
|
||||
&clUserEvent,
|
||||
&outputEvent);
|
||||
ASSERT_NE(nullptr, outputEvent);
|
||||
Event *event = castToObjectOrAbort<Event>(outputEvent);
|
||||
ASSERT_NE(nullptr, event);
|
||||
|
||||
ASSERT_NE(nullptr, mockCmdQ->virtualEvent);
|
||||
EXPECT_EQ(event, mockCmdQ->virtualEvent);
|
||||
|
||||
Event *head = context.getEventsRegistry().peekHead();
|
||||
EXPECT_EQ(head, mockCmdQ->virtualEvent);
|
||||
|
||||
event->release();
|
||||
mockCmdQ->release();
|
||||
}
|
||||
|
||||
HWTEST_F(EnqueueHandlerTest, enqueueWithOutputEventRegistersEvent) {
|
||||
MockKernelWithInternals kernelInternals(*pDevice, &context);
|
||||
Kernel *kernel = kernelInternals.mockKernel;
|
||||
@@ -270,9 +237,6 @@ HWTEST_F(EnqueueHandlerTest, enqueueWithOutputEventRegistersEvent) {
|
||||
Event *event = castToObjectOrAbort<Event>(outputEvent);
|
||||
ASSERT_NE(nullptr, event);
|
||||
|
||||
Event *head = context.getEventsRegistry().peekHead();
|
||||
EXPECT_EQ(head, event);
|
||||
|
||||
event->release();
|
||||
mockCmdQ->release();
|
||||
}
|
||||
|
||||
@@ -425,8 +425,6 @@ TEST_F(EnqueueMapImageTest, givenBlockedCommandQueueWhenBlockingMapWith2DImageIs
|
||||
};
|
||||
MockEventWithSetCompleteOnUpdate blockingEvent(pCmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 1);
|
||||
|
||||
pCmdQ->getContext().getEventsRegistry().registerEvent(blockingEvent);
|
||||
|
||||
cl_event blockingClEvent = &blockingEvent;
|
||||
|
||||
int32_t initialRefCountCmdQ = pCmdQ->getRefInternalCount();
|
||||
@@ -469,8 +467,6 @@ TEST_F(EnqueueMapImageTest, givenBlockedCommandQueueWhenBlockingMapWith1DImageIs
|
||||
};
|
||||
MockEventWithSetCompleteOnUpdate blockingEvent(pCmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 1);
|
||||
|
||||
pCmdQ->getContext().getEventsRegistry().registerEvent(blockingEvent);
|
||||
|
||||
cl_event blockingClEvent = &blockingEvent;
|
||||
|
||||
int32_t initialRefCountCmdQ = pCmdQ->getRefInternalCount();
|
||||
|
||||
@@ -285,23 +285,6 @@ TEST_F(ContextTest, GivenInteropSyncParamWhenCreateContextThenSetContextParam) {
|
||||
delete context;
|
||||
}
|
||||
|
||||
TEST_F(ContextTest, givenDeviceOnContextCreationThenUpdateInternalRefCountForEventsRegistry) {
|
||||
EventsRegistry registry;
|
||||
auto pPlatform = OCLRT::platform();
|
||||
cl_platform_id pid = pPlatform;
|
||||
cl_context_properties validProperties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties)pid, 0};
|
||||
auto device = castToObject<Device>(devices[0]);
|
||||
ASSERT_NE(device, nullptr);
|
||||
|
||||
auto initDeviceRefCount = device->getRefInternalCount();
|
||||
|
||||
auto context = Context::create<Context>(validProperties, DeviceVector(&devices[0], 1), nullptr, nullptr, retVal);
|
||||
|
||||
EXPECT_EQ(initDeviceRefCount + 1, device->getRefInternalCount());
|
||||
|
||||
delete context;
|
||||
}
|
||||
|
||||
class ContextWithAsyncDeleterTest : public ::testing::WithParamInterface<bool>,
|
||||
public ::testing::Test {
|
||||
public:
|
||||
|
||||
@@ -24,7 +24,6 @@ set(IGDRCL_SRCS_tests_event
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/event_builder_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/event_callbacks_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/event_fixture.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/event_registry_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/event_tests.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/event_tests_mt.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/user_events_tests.cpp"
|
||||
|
||||
@@ -108,7 +108,6 @@ TEST(EventBuilder, whenFinalizeIsCalledTwiceOnEventBuilderThenSecondRequestIsDro
|
||||
auto numChildren = (ev->peekChildEvents() != nullptr) ? 1U + ev->peekChildEvents()->countSuccessors() : 0;
|
||||
eventBuilder.addParentEvent(*falseParentEvent);
|
||||
eventBuilder.finalize();
|
||||
eventBuilder.registerEvent();
|
||||
// make sure that new parent was not added in second finalize
|
||||
EXPECT_EQ(numParents, ev->peekNumEventsBlockingThis());
|
||||
EXPECT_EQ(numChildren, (ev->peekChildEvents() != nullptr) ? 1U + ev->peekChildEvents()->countSuccessors() : 0);
|
||||
@@ -171,21 +170,6 @@ TEST(EventBuilder, whenFinalizeIsCalledWithEmptyEventsListsThenParentAndChildLis
|
||||
event->release();
|
||||
}
|
||||
|
||||
TEST(EventBuilder, whenFinalizeIsCalledAndCtxIsNotNullThenEventGetsRegistered) {
|
||||
MockContext mockContext;
|
||||
MockCommandQueue mockCommandQueue(&mockContext, nullptr, nullptr);
|
||||
|
||||
EventBuilder eventBuilder;
|
||||
eventBuilder.create<MockEvent<Event>>(&mockCommandQueue, CL_COMMAND_MARKER, 0, 0);
|
||||
|
||||
EXPECT_EQ(nullptr, mockContext.getEventsRegistry().peekHead());
|
||||
Event *event = eventBuilder.finalizeAndRelease();
|
||||
|
||||
EXPECT_EQ(event, mockContext.getEventsRegistry().peekHead());
|
||||
event->release();
|
||||
EXPECT_EQ(nullptr, mockContext.getEventsRegistry().peekHead());
|
||||
}
|
||||
|
||||
TEST(EventBuilder, whenFinalizeIsCalledAndBuildersEventsListAreNotEmptyThenEventsListsAreAddedToEvent) {
|
||||
MockEvent<UserEvent> *parentEvent = new MockEvent<UserEvent>();
|
||||
|
||||
@@ -258,59 +242,6 @@ TEST(EventBuilder, whenAddingMultipleEventsAsNewParentsThenOnlyValidOnesAreInser
|
||||
event->release();
|
||||
}
|
||||
|
||||
TEST(EventBuilder, registerEvent) {
|
||||
MockContext mockContext;
|
||||
MockCommandQueue mockCommandQueue(&mockContext, nullptr, nullptr);
|
||||
|
||||
EventBuilder eventBuilder;
|
||||
eventBuilder.create<MockEvent<Event>>(&mockCommandQueue, CL_COMMAND_MARKER, 0, 0);
|
||||
|
||||
EXPECT_EQ(nullptr, mockContext.getEventsRegistry().peekHead());
|
||||
eventBuilder.registerEvent();
|
||||
|
||||
EXPECT_EQ(eventBuilder.getEvent(), mockContext.getEventsRegistry().peekHead());
|
||||
eventBuilder.getEvent()->release();
|
||||
EXPECT_EQ(nullptr, mockContext.getEventsRegistry().peekHead());
|
||||
}
|
||||
|
||||
TEST(EventBuilder, registerEventForTheSecondtimeDoesNotRegister) {
|
||||
MockContext mockContext;
|
||||
MockCommandQueue mockCommandQueue(&mockContext, nullptr, nullptr);
|
||||
|
||||
EventBuilder eventBuilder;
|
||||
eventBuilder.create<MockEvent<Event>>(&mockCommandQueue, CL_COMMAND_MARKER, 0, 0);
|
||||
|
||||
EXPECT_EQ(nullptr, mockContext.getEventsRegistry().peekHead());
|
||||
eventBuilder.registerEvent();
|
||||
EXPECT_EQ(eventBuilder.getEvent(), mockContext.getEventsRegistry().peekHead());
|
||||
|
||||
eventBuilder.registerEvent();
|
||||
|
||||
Event *event = mockContext.getEventsRegistry().peekHead();
|
||||
EXPECT_EQ(nullptr, event->next);
|
||||
|
||||
eventBuilder.getEvent()->release();
|
||||
EXPECT_EQ(nullptr, mockContext.getEventsRegistry().peekHead());
|
||||
}
|
||||
|
||||
TEST(EventBuilder, destructorRegistersEvent) {
|
||||
MockContext mockContext;
|
||||
MockCommandQueue mockCommandQueue(&mockContext, nullptr, nullptr);
|
||||
|
||||
EventBuilder *eventBuilder = new EventBuilder;
|
||||
eventBuilder->create<MockEvent<Event>>(&mockCommandQueue, CL_COMMAND_MARKER, 0, 0);
|
||||
|
||||
EXPECT_EQ(nullptr, mockContext.getEventsRegistry().peekHead());
|
||||
|
||||
Event *event = eventBuilder->getEvent();
|
||||
delete eventBuilder;
|
||||
|
||||
EXPECT_NE(nullptr, mockContext.getEventsRegistry().peekHead());
|
||||
|
||||
event->release();
|
||||
EXPECT_EQ(nullptr, mockContext.getEventsRegistry().peekHead());
|
||||
}
|
||||
|
||||
TEST(EventBuilder, parentListDoesNotHaveDuplicates) {
|
||||
MockContext mockContext;
|
||||
MockCommandQueue mockCommandQueue(&mockContext, nullptr, nullptr);
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/event/event.h"
|
||||
#include "runtime/event/user_event.h"
|
||||
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
||||
#include "runtime/helpers/options.h"
|
||||
#include "unit_tests/fixtures/device_fixture.h"
|
||||
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "unit_tests/mocks/mock_command_queue.h"
|
||||
#include "unit_tests/mocks/mock_event.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
void CL_CALLBACK WriteInputBufferComplete(cl_event e, cl_int status, void *data) {
|
||||
++(*(int *)data);
|
||||
}
|
||||
|
||||
TEST(Event, GivenContextOnCreationAndDeletionUsesEventRegistry) {
|
||||
MockContext ctx;
|
||||
UserEvent *ue = MockEventBuilder::createAndFinalize<UserEvent>(&ctx);
|
||||
|
||||
ASSERT_EQ(ue, ctx.getEventsRegistry().peekHead());
|
||||
ue->release();
|
||||
ASSERT_EQ(nullptr, ctx.getEventsRegistry().peekHead());
|
||||
}
|
||||
|
||||
TEST(Event, WhenAddToRegistryIsCalledThenEvenAddsItselfToEventsRegistry) {
|
||||
MockContext ctx;
|
||||
UserEvent *ue = new UserEvent(&ctx);
|
||||
ASSERT_EQ(nullptr, ctx.getEventsRegistry().peekHead());
|
||||
ue->addToRegistry();
|
||||
ASSERT_EQ(ue, ctx.getEventsRegistry().peekHead());
|
||||
ue->release();
|
||||
ASSERT_EQ(nullptr, ctx.getEventsRegistry().peekHead());
|
||||
}
|
||||
|
||||
TEST(InternalsEventTests, dontLockDeviceOnRegistryBroadcastUpdateAll) {
|
||||
class MyMockDevice : public Device {
|
||||
public:
|
||||
MyMockDevice() : Device(*platformDevices[0], false) { memoryManager = new OsAgnosticMemoryManager; }
|
||||
bool takeOwnership(bool waitUntilGet) const override {
|
||||
acquireCounter++;
|
||||
return Device::takeOwnership(waitUntilGet);
|
||||
}
|
||||
void releaseOwnership() const override {
|
||||
releaseCounter++;
|
||||
Device::releaseOwnership();
|
||||
}
|
||||
mutable uint32_t acquireCounter = 0;
|
||||
mutable uint32_t releaseCounter = 0;
|
||||
} myDevice;
|
||||
|
||||
EventsRegistry registry;
|
||||
registry.setDevice(&myDevice);
|
||||
registry.broadcastUpdateAll();
|
||||
EXPECT_EQ(0u, myDevice.acquireCounter);
|
||||
EXPECT_EQ(0u, myDevice.releaseCounter);
|
||||
}
|
||||
|
||||
TEST(EventsRegistry, broadcast) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.EnableAsyncEventsHandler.set(false);
|
||||
auto device = Device::create<MockDevice>(nullptr);
|
||||
*device->getTagAddress() = 0u;
|
||||
MockContext ctx;
|
||||
auto cmdQ = new MockCommandQueue(&ctx, device, 0);
|
||||
|
||||
class SmallMockEvent : public Event {
|
||||
public:
|
||||
SmallMockEvent(CommandQueue *cmdQueue) : Event(cmdQueue, CL_COMMAND_NDRANGE_KERNEL, 1, 1) {}
|
||||
void switchToComplete() {
|
||||
transitionExecutionStatus(CL_COMPLETE);
|
||||
}
|
||||
};
|
||||
|
||||
int counter = 0;
|
||||
EventBuilder eventBuilder1;
|
||||
eventBuilder1.create<SmallMockEvent>(cmdQ);
|
||||
eventBuilder1.getEvent()->addCallback(WriteInputBufferComplete, CL_COMPLETE, &counter);
|
||||
auto event1 = static_cast<SmallMockEvent *>(eventBuilder1.finalizeAndRelease());
|
||||
|
||||
EventBuilder eventBuilder2;
|
||||
eventBuilder2.create<SmallMockEvent>(cmdQ);
|
||||
eventBuilder2.getEvent()->addCallback(WriteInputBufferComplete, CL_COMPLETE, &counter);
|
||||
auto event2 = static_cast<SmallMockEvent *>(eventBuilder2.finalizeAndRelease());
|
||||
|
||||
auto ® = ctx.getEventsRegistry();
|
||||
|
||||
event1->switchToComplete();
|
||||
event2->switchToComplete();
|
||||
ASSERT_EQ(0, counter);
|
||||
reg.broadcastUpdateAll();
|
||||
ASSERT_EQ(2, counter);
|
||||
|
||||
// delete events prior to delete command queue, otherwise events will defer-delete already deleted cmdQ
|
||||
event1->release();
|
||||
event2->release();
|
||||
|
||||
delete cmdQ;
|
||||
delete device;
|
||||
}
|
||||
@@ -36,43 +36,6 @@ class SmallMockEvent : public Event {
|
||||
}
|
||||
};
|
||||
|
||||
void CL_CALLBACK SetEventCompleteCallback(cl_event e, cl_int status, void *data) {
|
||||
*(bool *)data = true;
|
||||
}
|
||||
|
||||
TEST(EventCallback, callbackForNonSharedContext) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.EnableAsyncEventsHandler.set(false);
|
||||
MockContext ctx;
|
||||
auto ® = ctx.getEventsRegistry();
|
||||
auto evt = MockEventBuilder::createAndFinalize<SmallMockEvent>(&ctx);
|
||||
bool complete = false;
|
||||
|
||||
//non-shared context (single device)
|
||||
ctx.isSharedContext = false;
|
||||
evt->switchToSubmitted();
|
||||
|
||||
std::thread t([&]() {
|
||||
//wait for addCallback to be called in main thread
|
||||
while (evt->peekHasCallbacks() == false)
|
||||
;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
evt->switchToComplete();
|
||||
});
|
||||
|
||||
EXPECT_FALSE(complete);
|
||||
|
||||
evt->addCallback(SetEventCompleteCallback, CL_COMPLETE, &complete);
|
||||
|
||||
t.join();
|
||||
|
||||
//single device - callback shall be executed provided that event status is broadcast
|
||||
reg.broadcastUpdateAll();
|
||||
|
||||
EXPECT_TRUE(complete);
|
||||
evt->release();
|
||||
}
|
||||
|
||||
TEST(EventTestMt, waitForEventsDoesNotReturnUntilSetStatusCompletes) {
|
||||
|
||||
for (uint32_t i = 0; i < 100; i++) {
|
||||
|
||||
@@ -43,7 +43,6 @@ MockContext::MockContext(Device *device, bool noSpecialQueue) {
|
||||
assert(retVal == CL_SUCCESS);
|
||||
setSpecialQueue(commandQueue);
|
||||
}
|
||||
eventsRegistry.setDevice(device);
|
||||
}
|
||||
|
||||
MockContext::MockContext(
|
||||
|
||||
Reference in New Issue
Block a user