From 2dbffe8b640caddd3001a293ffa9958efea116e8 Mon Sep 17 00:00:00 2001 From: Jim Snow Date: Mon, 16 Mar 2020 15:47:18 -0700 Subject: [PATCH] Allow zeEventPoolCreate with no device We use the first device associated with the driver when no device is explicitly provided. Event pools are no longer created via a device method. Change-Id: Ib16dc79be3ceb1f822c7c1dace7264a0052a6593 Signed-off-by: Jim Snow --- level_zero/core/source/device/device.h | 2 - level_zero/core/source/device/device_imp.cpp | 6 --- level_zero/core/source/device/device_imp.h | 2 - .../core/source/driver/driver_handle_imp.cpp | 11 +++++- level_zero/core/source/event/event.cpp | 28 ++++++++++---- level_zero/core/source/event/event.h | 3 +- .../unit_tests/fixtures/cmdlist_fixture.h | 2 +- .../test_cmdlist_append_launch_kernel.cpp | 10 ++--- .../test_cmdlist_append_signal_event.cpp | 5 ++- .../unit_tests/sources/event/test_event.cpp | 37 ++++++++++++++++--- 10 files changed, 70 insertions(+), 36 deletions(-) diff --git a/level_zero/core/source/device/device.h b/level_zero/core/source/device/device.h index 65154c6ec5..45170eeedb 100644 --- a/level_zero/core/source/device/device.h +++ b/level_zero/core/source/device/device.h @@ -44,8 +44,6 @@ struct Device : _ze_device_handle_t { virtual ze_result_t createCommandQueue(const ze_command_queue_desc_t *desc, ze_command_queue_handle_t *commandQueue) = 0; - virtual ze_result_t createEventPool(const ze_event_pool_desc_t *desc, - ze_event_pool_handle_t *phEventPool) = 0; virtual ze_result_t createImage(const ze_image_desc_t *desc, ze_image_handle_t *phImage) = 0; virtual ze_result_t createModule(const ze_module_desc_t *desc, ze_module_handle_t *module, diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index e65b6bad02..8cbcd924df 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -124,12 +124,6 @@ ze_result_t DeviceImp::createCommandQueue(const ze_command_queue_desc_t *desc, return ZE_RESULT_SUCCESS; } -ze_result_t DeviceImp::createEventPool(const ze_event_pool_desc_t *desc, - ze_event_pool_handle_t *eventPool) { - *eventPool = EventPool::create(this, desc); - return ZE_RESULT_SUCCESS; -} - ze_result_t DeviceImp::createImage(const ze_image_desc_t *desc, ze_image_handle_t *phImage) { auto productFamily = neoDevice->getHardwareInfo().platform.eProductFamily; *phImage = Image::create(productFamily, this, desc); diff --git a/level_zero/core/source/device/device_imp.h b/level_zero/core/source/device/device_imp.h index dd1d840c19..74e1461375 100644 --- a/level_zero/core/source/device/device_imp.h +++ b/level_zero/core/source/device/device_imp.h @@ -25,8 +25,6 @@ struct DeviceImp : public Device { ze_command_list_handle_t *phCommandList) override; ze_result_t createCommandQueue(const ze_command_queue_desc_t *desc, ze_command_queue_handle_t *commandQueue) override; - ze_result_t createEventPool(const ze_event_pool_desc_t *desc, - ze_event_pool_handle_t *eventPool) override; ze_result_t createImage(const ze_image_desc_t *desc, ze_image_handle_t *phImage) override; ze_result_t createModule(const ze_module_desc_t *desc, ze_module_handle_t *module, ze_module_build_log_handle_t *buildLog) override; diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 94c0aac2c2..8bc0af4869 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -223,8 +223,15 @@ ze_result_t DriverHandleImp::createEventPool(const ze_event_pool_desc_t *desc, uint32_t numDevices, ze_device_handle_t *phDevices, ze_event_pool_handle_t *phEventPool) { - auto device = Device::fromHandle(phDevices[0]); - return device->createEventPool(desc, phEventPool); + EventPool *eventPool = EventPool::create(this, numDevices, phDevices, desc); + + if (eventPool == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } + + *phEventPool = eventPool->toHandle(); + + return ZE_RESULT_SUCCESS; } ze_result_t DriverHandleImp::openEventPoolIpcHandle(ze_ipc_event_pool_handle_t hIpc, diff --git a/level_zero/core/source/event/event.cpp b/level_zero/core/source/event/event.cpp index 7ce183b25a..b6485d51e2 100644 --- a/level_zero/core/source/event/event.cpp +++ b/level_zero/core/source/event/event.cpp @@ -72,7 +72,8 @@ struct EventImp : public Event { }; struct EventPoolImp : public EventPool { - EventPoolImp(Device *device, uint32_t count, ze_event_pool_flag_t flags) : device(device), count(count) { + EventPoolImp(DriverHandle *driver, uint32_t numDevices, ze_device_handle_t *phDevices, uint32_t count, ze_event_pool_flag_t flags) : count(count) { + pool = std::vector(this->count); eventPoolUsedCount = 0; for (uint32_t i = 0; i < count; i++) { @@ -85,10 +86,22 @@ struct EventPoolImp : public EventPool { timestampMultiplier = numEventTimestampsToRead; } + ze_device_handle_t hDevice; + if (numDevices > 0) { + hDevice = phDevices[0]; + } else { + uint32_t count = 1; + ze_result_t result = driver->getDevice(&count, &hDevice); + + UNRECOVERABLE_IF(result != ZE_RESULT_SUCCESS); + } + device = Device::fromHandle(hDevice); + NEO::AllocationProperties properties( - device->getRootDeviceIndex(), count * eventSize * timestampMultiplier, NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); + device->getRootDeviceIndex(), count * eventSize * timestampMultiplier, + NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); properties.alignment = MemoryConstants::cacheLineSize; - eventPoolAllocation = device->getDriverHandle()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties); + eventPoolAllocation = driver->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties); UNRECOVERABLE_IF(eventPoolAllocation == nullptr); } @@ -319,11 +332,10 @@ ze_result_t EventImp::getTimestamp(ze_event_timestamp_type_t timestampType, void return ZE_RESULT_SUCCESS; } -EventPool *EventPool::create(Device *device, const ze_event_pool_desc_t *desc) { - auto eventPool = new EventPoolImp(device, desc->count, desc->flags); - UNRECOVERABLE_IF(eventPool == nullptr); - - return eventPool; +EventPool *EventPool::create(DriverHandle *driver, uint32_t numDevices, + ze_device_handle_t *phDevices, + const ze_event_pool_desc_t *desc) { + return new EventPoolImp(driver, numDevices, phDevices, desc->count, desc->flags); } ze_result_t EventPoolImp::reserveEventFromPool(int index, Event *event) { diff --git a/level_zero/core/source/event/event.h b/level_zero/core/source/event/event.h index 461f723ebd..ca6b10d9e5 100644 --- a/level_zero/core/source/event/event.h +++ b/level_zero/core/source/event/event.h @@ -73,8 +73,7 @@ struct Event : _ze_event_handle_t { }; struct EventPool : _ze_event_pool_handle_t { - static EventPool *create(Device *device, const ze_event_pool_desc_t *desc); - + static EventPool *create(DriverHandle *driver, uint32_t numDevices, ze_device_handle_t *phDevices, const ze_event_pool_desc_t *desc); virtual ~EventPool() = default; virtual ze_result_t destroy() = 0; virtual size_t getPoolSize() = 0; diff --git a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h index 7ee68cceb2..1123cf2005 100644 --- a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h @@ -32,7 +32,7 @@ class CommandListFixture : public DeviceFixture { ZE_EVENT_SCOPE_FLAG_NONE, ZE_EVENT_SCOPE_FLAG_NONE}; - eventPool = std::unique_ptr(EventPool::create(device, &eventPoolDesc)); + eventPool = std::unique_ptr(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); event = std::unique_ptr(Event::create(eventPool.get(), &eventDesc, device)); } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel.cpp index 2e88a3ac9f..4d0e2ae475 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel.cpp @@ -190,7 +190,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandListAppendLaunchKernel, givenEventsWhenAppend ZE_EVENT_SCOPE_FLAG_NONE, ZE_EVENT_SCOPE_FLAG_NONE}; - auto eventPool = std::unique_ptr(EventPool::create(device, &eventPoolDesc)); + auto eventPool = std::unique_ptr(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); auto event = std::unique_ptr(Event::create(eventPool.get(), &eventDesc, device)); ze_group_count_t groupCount{1, 1, 1}; @@ -254,7 +254,7 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenTimestampEventsWhenAppendingKernel ZE_EVENT_SCOPE_FLAG_NONE, ZE_EVENT_SCOPE_FLAG_NONE}; - auto eventPool = std::unique_ptr(EventPool::create(device, &eventPoolDesc)); + auto eventPool = std::unique_ptr(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); auto event = std::unique_ptr(Event::create(eventPool.get(), &eventDesc, device)); ze_group_count_t groupCount{1, 1, 1}; @@ -477,7 +477,7 @@ HWTEST_F(CommandListAppendLaunchKernel, givenSingleValidWaitEventsAddsSemaphoreT ze_event_desc_t eventDesc = {ZE_EVENT_DESC_VERSION_CURRENT, 0, ZE_EVENT_SCOPE_FLAG_NONE, ZE_EVENT_SCOPE_FLAG_NONE}; - std::unique_ptr eventPool(EventPool::create(device, &eventPoolDesc)); + std::unique_ptr eventPool(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); std::unique_ptr event(Event::create(eventPool.get(), &eventDesc, device)); ze_event_handle_t hEventHandle = event->toHandle(); @@ -523,7 +523,7 @@ HWTEST_F(CommandListAppendLaunchKernel, givenMultipleValidWaitEventsAddsSemaphor ze_event_desc_t eventDesc2 = {ZE_EVENT_DESC_VERSION_CURRENT, 1, ZE_EVENT_SCOPE_FLAG_NONE, ZE_EVENT_SCOPE_FLAG_NONE}; - std::unique_ptr eventPool(EventPool::create(device, &eventPoolDesc)); + std::unique_ptr eventPool(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); std::unique_ptr event1(Event::create(eventPool.get(), &eventDesc1, device)); std::unique_ptr event2(Event::create(eventPool.get(), &eventDesc2, device)); ze_event_handle_t hEventHandle1 = event1->toHandle(); @@ -550,4 +550,4 @@ HWTEST_F(CommandListAppendLaunchKernel, givenMultipleValidWaitEventsAddsSemaphor } } // namespace ult -} // namespace L0 \ No newline at end of file +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp index 49d4f1ef64..070049d5a6 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp @@ -110,7 +110,8 @@ HWTEST_F(CommandListAppendSignalEvent, givenEventWithScopeFlagDeviceWhenAppendin ZE_EVENT_SCOPE_FLAG_DEVICE, ZE_EVENT_SCOPE_FLAG_NONE}; - auto eventPoolHostVisible = std::unique_ptr(EventPool::create(device, &eventPoolDesc)); + auto eventPoolHostVisible = + std::unique_ptr(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); auto eventHostVisible = std::unique_ptr(Event::create(eventPoolHostVisible.get(), &eventDesc, device)); auto usedSpaceBefore = commandList->commandContainer.getCommandStream()->getUsed(); @@ -141,4 +142,4 @@ HWTEST_F(CommandListAppendSignalEvent, givenEventWithScopeFlagDeviceWhenAppendin } } // namespace ult -} // namespace L0 \ No newline at end of file +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/event/test_event.cpp b/level_zero/core/test/unit_tests/sources/event/test_event.cpp index 12d5703eba..43c3cf5d39 100644 --- a/level_zero/core/test/unit_tests/sources/event/test_event.cpp +++ b/level_zero/core/test/unit_tests/sources/event/test_event.cpp @@ -23,7 +23,7 @@ TEST_F(EventPoolCreate, allocationContainsAtLeast16Bytes) { ZE_EVENT_POOL_FLAG_HOST_VISIBLE, 1}; - std::unique_ptr eventPool(EventPool::create(device, &eventPoolDesc)); + std::unique_ptr eventPool(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); auto allocation = &eventPool->getAllocation(); @@ -39,7 +39,7 @@ TEST_F(EventPoolCreate, givenTimestampEventsThenVerifyNumTimestampsToRead) { ZE_EVENT_POOL_FLAG_TIMESTAMP, // all events in pool are visible to Host 1}; - std::unique_ptr eventPool(EventPool::create(device, &eventPoolDesc)); + std::unique_ptr eventPool(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); uint32_t numTimestamps = 4u; @@ -59,7 +59,7 @@ TEST_F(EventPoolCreate, givenAnEventIsCreatedFromThisEventPoolThenEventContainsD ze_event_handle_t event = nullptr; - std::unique_ptr eventPool(EventPool::create(device, &eventPoolDesc)); + std::unique_ptr eventPool(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); eventPool->createEvent(&eventDesc, &event); @@ -80,7 +80,7 @@ TEST_F(EventCreate, givenAnEventCreatedThenTheEventHasTheDeviceCommandStreamRece ZE_EVENT_SCOPE_FLAG_DEVICE, ZE_EVENT_SCOPE_FLAG_DEVICE}; - std::unique_ptr eventPool(EventPool::create(device, &eventPoolDesc)); + std::unique_ptr eventPool(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); std::unique_ptr event(Event::create(eventPool.get(), &eventDesc, device)); @@ -89,6 +89,31 @@ TEST_F(EventCreate, givenAnEventCreatedThenTheEventHasTheDeviceCommandStreamRece ASSERT_EQ(static_cast(device)->neoDevice->getDefaultEngine().commandStreamReceiver, event.get()->csr); } +TEST_F(EventPoolCreate, returnsSuccessFromCreateEventPoolWithNoDevice) { + ze_event_pool_desc_t eventPoolDesc = { + ZE_EVENT_POOL_DESC_VERSION_CURRENT, + ZE_EVENT_POOL_FLAG_HOST_VISIBLE, + 4}; + + auto eventPool = EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc); + + ASSERT_NE(nullptr, eventPool); + eventPool->destroy(); +} + +TEST_F(EventPoolCreate, returnsSuccessFromCreateEventPoolWithDevice) { + ze_event_pool_desc_t eventPoolDesc = { + ZE_EVENT_POOL_DESC_VERSION_CURRENT, + ZE_EVENT_POOL_FLAG_HOST_VISIBLE, + 4}; + + auto deviceHandle = device->toHandle(); + auto eventPool = EventPool::create(driverHandle.get(), 1, &deviceHandle, &eventPoolDesc); + + ASSERT_NE(nullptr, eventPool); + eventPool->destroy(); +} + class TimestampEventCreate : public Test { public: void SetUp() override { @@ -104,7 +129,7 @@ class TimestampEventCreate : public Test { ZE_EVENT_SCOPE_FLAG_NONE, ZE_EVENT_SCOPE_FLAG_NONE}; - eventPool = std::unique_ptr(L0::EventPool::create(device, &eventPoolDesc)); + eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); ASSERT_NE(nullptr, eventPool); @@ -146,4 +171,4 @@ TEST_F(TimestampEventCreate, givenSingleTimestampEventThenAllocationSizeCreatedF } } // namespace ult -} // namespace L0 \ No newline at end of file +} // namespace L0