From 2c312bc70a3e8657a374380c57cdfaa2c0e8a1d1 Mon Sep 17 00:00:00 2001 From: Aravind Gopalakrishnan Date: Thu, 5 Nov 2020 17:42:06 -0800 Subject: [PATCH] Use device allocation for events if host visibility not set Signed-off-by: Aravind Gopalakrishnan --- level_zero/core/source/cmdlist/cmdlist_hw.inl | 60 +++++++------ level_zero/core/source/event/event.cpp | 85 +++++++++++++++---- level_zero/core/source/event/event.h | 19 +++-- .../gen12lp/test_events_gen12lp.cpp | 2 +- .../core/test/unit_tests/mocks/mock_event.h | 2 +- .../sources/cmdlist/test_cmdlist_1.cpp | 4 +- .../sources/cmdlist/test_cmdlist_2.cpp | 4 +- .../test_cmdlist_append_event_reset.cpp | 3 +- .../test_cmdlist_append_launch_kernel.cpp | 4 +- .../test_cmdlist_append_signal_event.cpp | 2 +- .../sources/cmdlist/test_cmdlist_blit.cpp | 4 +- .../unit_tests/sources/event/test_event.cpp | 70 ++++++++++++++- .../metrics/test_metric_query_pool_1.cpp | 4 +- 13 files changed, 195 insertions(+), 68 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index d8e02a3fdc..cfda36a46b 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -198,34 +198,6 @@ ze_result_t CommandListCoreFamily::appendLaunchMultipleKernelsInd return ZE_RESULT_SUCCESS; } -template -ze_result_t CommandListCoreFamily::appendEventReset(ze_event_handle_t hEvent) { - using POST_SYNC_OPERATION = typename GfxFamily::PIPE_CONTROL::POST_SYNC_OPERATION; - auto event = Event::fromHandle(hEvent); - - uint64_t baseAddr = event->getGpuAddress(); - size_t eventOffset = 0; - if (event->isTimestampEvent) { - eventOffset = offsetof(KernelTimestampEvent, contextEnd); - } - commandContainer.addToResidencyContainer(&event->getAllocation()); - if (isCopyOnly()) { - NEO::EncodeMiFlushDW::programMiFlushDw(*commandContainer.getCommandStream(), event->getGpuAddress(), Event::STATE_CLEARED, false, true); - } else { - NEO::PipeControlArgs args; - args.dcFlushEnable = (!event->signalScope) ? false : true; - NEO::MemorySynchronizationCommands::addPipeControlAndProgramPostSyncOperation( - *commandContainer.getCommandStream(), - POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, - ptrOffset(baseAddr, eventOffset), - Event::STATE_CLEARED, - commandContainer.getDevice()->getHardwareInfo(), - args); - } - - return ZE_RESULT_SUCCESS; -} - template ze_result_t CommandListCoreFamily::appendBarrier(ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, @@ -1339,6 +1311,7 @@ ze_result_t CommandListCoreFamily::appendSignalEvent(ze_event_han auto event = Event::fromHandle(hEvent); commandContainer.addToResidencyContainer(&event->getAllocation()); + uint64_t baseAddr = event->getGpuAddress(); size_t eventSignalOffset = 0; if (event->isTimestampEvent) { @@ -1359,6 +1332,36 @@ ze_result_t CommandListCoreFamily::appendSignalEvent(ze_event_han return ZE_RESULT_SUCCESS; } +template +ze_result_t CommandListCoreFamily::appendEventReset(ze_event_handle_t hEvent) { + using POST_SYNC_OPERATION = typename GfxFamily::PIPE_CONTROL::POST_SYNC_OPERATION; + auto event = Event::fromHandle(hEvent); + + uint64_t baseAddr = event->getGpuAddress(); + size_t eventOffset = 0; + if (event->isTimestampEvent) { + eventOffset = offsetof(KernelTimestampEvent, contextEnd); + } + + commandContainer.addToResidencyContainer(&event->getAllocation()); + + if (isCopyOnly()) { + NEO::EncodeMiFlushDW::programMiFlushDw(*commandContainer.getCommandStream(), event->getGpuAddress(), Event::STATE_CLEARED, false, true); + } else { + NEO::PipeControlArgs args; + args.dcFlushEnable = (!event->signalScope) ? false : true; + NEO::MemorySynchronizationCommands::addPipeControlAndProgramPostSyncOperation( + *commandContainer.getCommandStream(), + POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, + ptrOffset(baseAddr, eventOffset), + Event::STATE_CLEARED, + commandContainer.getDevice()->getHardwareInfo(), + args); + } + + return ZE_RESULT_SUCCESS; +} + template ze_result_t CommandListCoreFamily::appendWaitOnEvents(uint32_t numEvents, ze_event_handle_t *phEvent) { @@ -1414,6 +1417,7 @@ void CommandListCoreFamily::appendEventForProfiling(ze_event_hand } commandContainer.addToResidencyContainer(&event->getAllocation()); + auto baseAddr = event->getGpuAddress(); if (beforeWalker) { diff --git a/level_zero/core/source/event/event.cpp b/level_zero/core/source/event/event.cpp index 1680165a78..f10218b961 100644 --- a/level_zero/core/source/event/event.cpp +++ b/level_zero/core/source/event/event.cpp @@ -19,6 +19,8 @@ #include "shared/source/memory_manager/memory_operations_handler.h" #include "shared/source/utilities/cpuintrinsics.h" +#include "level_zero/core/source/cmdlist/cmdlist.h" +#include "level_zero/core/source/cmdqueue/cmdqueue.h" #include "level_zero/core/source/device/device.h" #include "level_zero/core/source/device/device_imp.h" #include "level_zero/tools/source/metrics/metric.h" @@ -56,25 +58,57 @@ ze_result_t EventPoolImp::initialize(DriverHandle *driver, uint32_t numDevices, maxRootDeviceIndex = rootDeviceIndices[0]; } + if (this->devices.size() > 1) { + this->allocOnDevice = false; + } + + if (allocOnDevice) { + ze_command_queue_desc_t cmdQueueDesc = {}; + cmdQueueDesc.ordinal = 0; + cmdQueueDesc.index = 0; + cmdQueueDesc.flags = 0; + cmdQueueDesc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC; + cmdQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS; + ze_result_t returnValue = ZE_RESULT_SUCCESS; + eventPoolCommandList = + CommandList::createImmediate( + static_cast(this->devices[0])->neoDevice->getHardwareInfo().platform.eProductFamily, + this->devices[0], + &cmdQueueDesc, + true, + NEO::EngineGroupType::RenderCompute, + returnValue); + + if (!this->eventPoolCommandList) { + this->allocOnDevice = false; + } + } + eventPoolAllocations = new NEO::MultiGraphicsAllocation(maxRootDeviceIndex); uint32_t rootDeviceIndex = rootDeviceIndices.at(0); - NEO::SVMAllocsManager::UnifiedMemoryProperties memoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY, - devices[0]->getNEODevice()->getDeviceBitfield()); + auto subDeviceBitField = devices[0]->getNEODevice()->getDeviceBitfield(); + auto internalMemoryType = InternalMemoryType::HOST_UNIFIED_MEMORY; + auto allocationType = isEventPoolUsedForTimestamp ? NEO::GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER : NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; + if (this->allocOnDevice) { + internalMemoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY; + allocationType = NEO::GraphicsAllocation::AllocationType::BUFFER; + } - NEO::AllocationProperties unifiedMemoryProperties{rootDeviceIndex, - true, - alignUp(numEvents * eventSize, MemoryConstants::pageSize64k), - isEventPoolUsedForTimestamp ? NEO::GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER - : NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, - memoryProperties.subdeviceBitfield.count() > 1, - memoryProperties.subdeviceBitfield.count() > 1, - memoryProperties.subdeviceBitfield}; - unifiedMemoryProperties.alignment = eventAlignment; + NEO::SVMAllocsManager::UnifiedMemoryProperties memoryProperties(internalMemoryType, subDeviceBitField); + NEO::AllocationProperties eventPoolAllocationProperties{rootDeviceIndex, + true, + alignUp(numEvents * eventSize, MemoryConstants::pageSize64k), + allocationType, + memoryProperties.subdeviceBitfield.count() > 1, + memoryProperties.subdeviceBitfield.count() > 1, + memoryProperties.subdeviceBitfield}; + + eventPoolAllocationProperties.alignment = MemoryConstants::cacheLineSize; void *eventPoolPtr = driver->getMemoryManager()->createMultiGraphicsAllocation(rootDeviceIndices, - unifiedMemoryProperties, + eventPoolAllocationProperties, *eventPoolAllocations); if (!eventPoolPtr) { return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; @@ -90,6 +124,11 @@ EventPoolImp::~EventPoolImp() { } delete eventPoolAllocations; eventPoolAllocations = nullptr; + + if (eventPoolCommandList) { + eventPoolCommandList->destroy(); + eventPoolCommandList = nullptr; + } } ze_result_t EventPoolImp::getIpcHandle(ze_ipc_event_pool_handle_t *pIpcHandle) { @@ -122,6 +161,9 @@ Event *Event::create(EventPool *eventPool, const ze_event_desc_t *desc, Device * if (eventPool->isEventPoolUsedForTimestamp) { event->isTimestampEvent = true; } + if (eventPool->allocOnDevice) { + event->allocOnDevice = true; + } auto alloc = eventPool->getAllocation().getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex()); @@ -135,6 +177,10 @@ Event *Event::create(EventPool *eventPool, const ze_event_desc_t *desc, Device * event->reset(); + if (event->allocOnDevice) { + eventPool->eventPoolCommandList->appendEventReset(event->toHandle()); + } + return event; } @@ -144,6 +190,10 @@ NEO::GraphicsAllocation &Event::getAllocation() { return *eventImp->eventPool->getAllocation().getGraphicsAllocation(eventImp->device->getNEODevice()->getRootDeviceIndex()); } +uint64_t Event::getGpuAddress() { + return gpuAddress; +} + ze_result_t Event::destroy() { delete this; return ZE_RESULT_SUCCESS; @@ -165,7 +215,7 @@ ze_result_t EventImp::queryStatus() { return queryVal == Event::STATE_CLEARED ? ZE_RESULT_NOT_READY : ZE_RESULT_SUCCESS; } -ze_result_t EventImp::hostEventSetValueTimestamps(uint32_t eventVal) { +void EventImp::hostEventSetValueTimestamps(uint32_t eventVal) { auto baseAddr = reinterpret_cast(hostAddress); auto signalScopeFlag = this->signalScope; @@ -182,13 +232,11 @@ ze_result_t EventImp::hostEventSetValueTimestamps(uint32_t eventVal) { eventTsSetFunc(baseAddr + offsetof(KernelTimestampEvent, globalStart)); eventTsSetFunc(baseAddr + offsetof(KernelTimestampEvent, contextEnd)); eventTsSetFunc(baseAddr + offsetof(KernelTimestampEvent, globalEnd)); - - return ZE_RESULT_SUCCESS; } ze_result_t EventImp::hostEventSetValue(uint32_t eventVal) { if (isTimestampEvent) { - return hostEventSetValueTimestamps(eventVal); + hostEventSetValueTimestamps(eventVal); } auto hostAddr = static_cast(hostAddress); @@ -243,6 +291,11 @@ ze_result_t EventImp::hostSynchronize(uint64_t timeout) { } ze_result_t EventImp::reset() { + + if (allocOnDevice) { + return ZE_RESULT_SUCCESS; + } + return hostEventSetValue(Event::STATE_INITIAL); } diff --git a/level_zero/core/source/event/event.h b/level_zero/core/source/event/event.h index 433ace2f3b..79cea9da28 100644 --- a/level_zero/core/source/event/event.h +++ b/level_zero/core/source/event/event.h @@ -44,15 +44,16 @@ struct Event : _ze_event_handle_t { virtual NEO::GraphicsAllocation &getAllocation(); - uint64_t getGpuAddress() { return gpuAddress; } + virtual uint64_t getGpuAddress(); void *hostAddress = nullptr; - uint64_t gpuAddress; + uint64_t gpuAddress = 0u; ze_event_scope_flags_t signalScope = 0u; ze_event_scope_flags_t waitScope = 0u; bool isTimestampEvent = false; + bool allocOnDevice = false; // Metric streamer instance associated with the event. MetricStreamer *metricStreamer = nullptr; @@ -84,7 +85,7 @@ struct EventImp : public Event { protected: ze_result_t hostEventSetValue(uint32_t eventValue); - ze_result_t hostEventSetValueTimestamps(uint32_t eventVal); + void hostEventSetValueTimestamps(uint32_t eventVal); void makeAllocationResident(); }; @@ -112,9 +113,12 @@ struct EventPool : _ze_event_pool_handle_t { virtual NEO::MultiGraphicsAllocation &getAllocation() { return *eventPoolAllocations; } - virtual uint32_t getEventSize() = 0; + virtual size_t getEventSize() = 0; bool isEventPoolUsedForTimestamp = false; + bool allocOnDevice = false; + + CommandList *eventPoolCommandList = nullptr; protected: NEO::MultiGraphicsAllocation *eventPoolAllocations = nullptr; @@ -125,6 +129,10 @@ struct EventPoolImp : public EventPool { if (flags & ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP) { isEventPoolUsedForTimestamp = true; } + + if (!(flags & ZE_EVENT_POOL_FLAG_HOST_VISIBLE)) { + allocOnDevice = true; + } } ze_result_t initialize(DriverHandle *driver, @@ -142,7 +150,7 @@ struct EventPoolImp : public EventPool { ze_result_t createEvent(const ze_event_desc_t *desc, ze_event_handle_t *phEvent) override; - uint32_t getEventSize() override { return eventSize; } + size_t getEventSize() override { return eventSize; } size_t getNumEvents() { return numEvents; } Device *getDevice() override { return devices[0]; } @@ -153,7 +161,6 @@ struct EventPoolImp : public EventPool { protected: const uint32_t eventSize = static_cast(alignUp(sizeof(struct KernelTimestampEvent), MemoryConstants::cacheLineSize)); - const uint32_t eventAlignment = MemoryConstants::cacheLineSize; }; } // namespace L0 diff --git a/level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp b/level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp index 5ed0becc53..96ee9e17e2 100644 --- a/level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp +++ b/level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp @@ -20,7 +20,7 @@ struct TimestampEvent : public Test { DeviceFixture::SetUp(); ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; diff --git a/level_zero/core/test/unit_tests/mocks/mock_event.h b/level_zero/core/test/unit_tests/mocks/mock_event.h index 327bf7deb1..7ebbe4fc7f 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_event.h +++ b/level_zero/core/test/unit_tests/mocks/mock_event.h @@ -72,7 +72,7 @@ struct Mock : public EventPool { MOCK_METHOD2(reserveEventFromPool, ze_result_t(int index, ::L0::Event *event)); MOCK_METHOD1(releaseEventToPool, ze_result_t(::L0::Event *event)); MOCK_METHOD0(getDevice, Device *()); - MOCK_METHOD0(getEventSize, uint32_t()); + MOCK_METHOD0(getEventSize, size_t()); std::vector pool; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp index 721a61ec19..2914c11765 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp @@ -916,7 +916,7 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListWhenProfilingBeforeCommandForCo commandList->initialize(device, NEO::EngineGroupType::Copy); ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; @@ -949,7 +949,7 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListWhenProfilingAfterCommandForCop commandList->initialize(device, NEO::EngineGroupType::Copy); ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp index 54c63af54a..f190a30d5c 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp @@ -467,7 +467,7 @@ HWTEST2_F(CommandListCreate, givenCommandListWhenTimestampPassedToMemoryCopyThen ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; @@ -1027,7 +1027,7 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListWhenTimestampPassedToMemoryCopy void *srcPtr = reinterpret_cast(0x1234); void *dstPtr = reinterpret_cast(0x2345); ze_event_pool_desc_t eventPoolDesc = {}; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; eventPoolDesc.count = 1; ze_event_desc_t eventDesc = {}; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_event_reset.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_event_reset.cpp index b6dffd9f30..a4c16dda39 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_event_reset.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_event_reset.cpp @@ -129,7 +129,7 @@ HWTEST2_F(CommandListAppendEventReset, givenTimestampEventUsedInResetThenPipeCon ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; @@ -170,6 +170,7 @@ HWTEST2_F(CommandListAppendEventReset, givenEventWithHostScopeUsedInResetThenPip ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; 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 407bbbc91c..d5c634188c 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 @@ -292,7 +292,7 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenTimestampEventsWhenAppendingKernel auto usedSpaceBefore = commandList->commandContainer.getCommandStream()->getUsed(); ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; @@ -376,7 +376,7 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenKernelLaunchWithTSEventAndScopeFla auto usedSpaceBefore = commandList->commandContainer.getCommandStream()->getUsed(); ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; const ze_event_desc_t eventDesc = { ZE_STRUCTURE_TYPE_EVENT_DESC, 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 7edc3891a7..3033d6fe88 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 @@ -193,7 +193,7 @@ HWTEST2_F(CommandListAppendSignalEvent, givenTimestampEventUsedInSignalThenPipeC ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_blit.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_blit.cpp index 72312faaf5..40dfa109b8 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_blit.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_blit.cpp @@ -307,7 +307,7 @@ HWTEST2_F(AppendMemoryCopy, givenCopyCommandListWhenTimestampPassedToMemoryCopyR commandList->initialize(device, NEO::EngineGroupType::Copy); ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; @@ -366,7 +366,7 @@ HWTEST2_F(AppendMemoryCopy, givenCopyCommandListWhenTimestampPassedToImageCopyBl commandList->initialize(device, NEO::EngineGroupType::Copy); ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; 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 ab1406ff79..aba7a5474c 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 @@ -30,7 +30,7 @@ TEST_F(EventPoolCreate, allocationContainsAtLeast16Bytes) { auto allocation = &eventPool->getAllocation(); ASSERT_NE(nullptr, allocation); - uint32_t minAllocationSize = eventPool->getEventSize(); + size_t minAllocationSize = eventPool->getEventSize(); EXPECT_GE(allocation->getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex())->getUnderlyingBufferSize(), minAllocationSize); } @@ -38,7 +38,7 @@ TEST_F(EventPoolCreate, allocationContainsAtLeast16Bytes) { TEST_F(EventPoolCreate, givenTimestampEventsThenEventSizeSufficientForAllKernelTimestamps) { ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; std::unique_ptr eventPool(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); @@ -143,6 +143,37 @@ TEST_F(EventPoolCreate, returnsSuccessFromCreateEventPoolWithDevice) { eventPool->destroy(); } +TEST_F(EventPoolCreate, whenHostVisibleFlagNotSetThenEventAllocationIsOnDevice) { + ze_event_pool_desc_t eventPoolDesc = { + ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, + nullptr, + 0u, + 4}; + + auto deviceHandle = device->toHandle(); + auto eventPool = EventPool::create(driverHandle.get(), 1, &deviceHandle, &eventPoolDesc); + + ASSERT_NE(nullptr, eventPool); + + EXPECT_EQ(NEO::GraphicsAllocation::AllocationType::BUFFER, eventPool->getAllocation().getAllocationType()); + eventPool->destroy(); +} + +TEST_F(EventPoolCreate, whenHostVisibleFlagNotSetThenEventPoolCommandListIsCreated) { + ze_event_pool_desc_t eventPoolDesc = { + ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, + nullptr, + 0u, + 4}; + + auto deviceHandle = device->toHandle(); + auto eventPool = EventPool::create(driverHandle.get(), 1, &deviceHandle, &eventPoolDesc); + + ASSERT_NE(nullptr, eventPool->eventPoolCommandList); + + eventPool->destroy(); +} + struct EventCreateAllocationResidencyTest : public ::testing::Test { void SetUp() override { neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); @@ -171,7 +202,7 @@ class TimestampEventCreate : public Test { DeviceFixture::SetUp(); ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE; ze_event_desc_t eventDesc = {}; eventDesc.index = 0; @@ -200,7 +231,7 @@ TEST_F(TimestampEventCreate, givenSingleTimestampEventThenAllocationSizeCreatedF auto allocation = &eventPool->getAllocation(); ASSERT_NE(nullptr, allocation); - uint32_t minTimestampEventAllocation = eventPool->getEventSize(); + size_t minTimestampEventAllocation = eventPool->getEventSize(); EXPECT_GE(allocation->getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex())->getUnderlyingBufferSize(), minTimestampEventAllocation); } @@ -286,6 +317,37 @@ TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithMultipleDevicesThenE delete[] devices; } +TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithMultipleDevicesAndHostVisibleFlagNotSetThenEventPoolCreateSucceedsButEventAllocNotPlacedOnDevice) { + ze_event_pool_desc_t eventPoolDesc = {}; + eventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; + eventPoolDesc.count = 32; + + uint32_t deviceCount = 0; + ze_result_t result = zeDeviceGet(driverHandle.get(), &deviceCount, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_EQ(deviceCount, numRootDevices); + + ze_device_handle_t *devices = new ze_device_handle_t[deviceCount]; + result = zeDeviceGet(driverHandle.get(), &deviceCount, devices); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + std::unique_ptr eventPool(EventPool::create(driverHandle.get(), + deviceCount, + devices, + &eventPoolDesc)); + EXPECT_NE(nullptr, eventPool); + + auto allocation = &eventPool->getAllocation(); + EXPECT_NE(nullptr, allocation); + + EXPECT_EQ(allocation->getGraphicsAllocations().size(), numRootDevices); + + EXPECT_EQ(false, eventPool->allocOnDevice); + + delete[] devices; +} + TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithNoDevicesThenEventPoolCreatedWithOneDevice) { ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC; diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp index 80f9ef50f1..df6b1072d7 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp @@ -537,7 +537,7 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZeEventPoolCreateIsCalledTh ze_event_pool_handle_t eventPoolHandle = {}; ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = 0; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; eventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC; // Create event pool. @@ -554,7 +554,7 @@ TEST_F(MetricQueryPoolTest, givenIncorrectArgumentsWhenZeEventCreateIsCalledThen ze_event_pool_handle_t eventPoolHandle = {}; ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; - eventPoolDesc.flags = 0; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; eventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC; // Create event pool.