Skip to content

Commit 223de6d

Browse files
Revert "Use device allocation for events if host visibility not set"
This reverts commit 2c312bc. Reverting due to failures in CI
1 parent a67e829 commit 223de6d

File tree

13 files changed

+68
-195
lines changed

13 files changed

+68
-195
lines changed

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,34 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendLaunchMultipleKernelsInd
198198
return ZE_RESULT_SUCCESS;
199199
}
200200

201+
template <GFXCORE_FAMILY gfxCoreFamily>
202+
ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendEventReset(ze_event_handle_t hEvent) {
203+
using POST_SYNC_OPERATION = typename GfxFamily::PIPE_CONTROL::POST_SYNC_OPERATION;
204+
auto event = Event::fromHandle(hEvent);
205+
206+
uint64_t baseAddr = event->getGpuAddress();
207+
size_t eventOffset = 0;
208+
if (event->isTimestampEvent) {
209+
eventOffset = offsetof(KernelTimestampEvent, contextEnd);
210+
}
211+
commandContainer.addToResidencyContainer(&event->getAllocation());
212+
if (isCopyOnly()) {
213+
NEO::EncodeMiFlushDW<GfxFamily>::programMiFlushDw(*commandContainer.getCommandStream(), event->getGpuAddress(), Event::STATE_CLEARED, false, true);
214+
} else {
215+
NEO::PipeControlArgs args;
216+
args.dcFlushEnable = (!event->signalScope) ? false : true;
217+
NEO::MemorySynchronizationCommands<GfxFamily>::addPipeControlAndProgramPostSyncOperation(
218+
*commandContainer.getCommandStream(),
219+
POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA,
220+
ptrOffset(baseAddr, eventOffset),
221+
Event::STATE_CLEARED,
222+
commandContainer.getDevice()->getHardwareInfo(),
223+
args);
224+
}
225+
226+
return ZE_RESULT_SUCCESS;
227+
}
228+
201229
template <GFXCORE_FAMILY gfxCoreFamily>
202230
ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendBarrier(ze_event_handle_t hSignalEvent,
203231
uint32_t numWaitEvents,
@@ -1311,7 +1339,6 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendSignalEvent(ze_event_han
13111339
auto event = Event::fromHandle(hEvent);
13121340

13131341
commandContainer.addToResidencyContainer(&event->getAllocation());
1314-
13151342
uint64_t baseAddr = event->getGpuAddress();
13161343
size_t eventSignalOffset = 0;
13171344
if (event->isTimestampEvent) {
@@ -1332,36 +1359,6 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendSignalEvent(ze_event_han
13321359
return ZE_RESULT_SUCCESS;
13331360
}
13341361

1335-
template <GFXCORE_FAMILY gfxCoreFamily>
1336-
ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendEventReset(ze_event_handle_t hEvent) {
1337-
using POST_SYNC_OPERATION = typename GfxFamily::PIPE_CONTROL::POST_SYNC_OPERATION;
1338-
auto event = Event::fromHandle(hEvent);
1339-
1340-
uint64_t baseAddr = event->getGpuAddress();
1341-
size_t eventOffset = 0;
1342-
if (event->isTimestampEvent) {
1343-
eventOffset = offsetof(KernelTimestampEvent, contextEnd);
1344-
}
1345-
1346-
commandContainer.addToResidencyContainer(&event->getAllocation());
1347-
1348-
if (isCopyOnly()) {
1349-
NEO::EncodeMiFlushDW<GfxFamily>::programMiFlushDw(*commandContainer.getCommandStream(), event->getGpuAddress(), Event::STATE_CLEARED, false, true);
1350-
} else {
1351-
NEO::PipeControlArgs args;
1352-
args.dcFlushEnable = (!event->signalScope) ? false : true;
1353-
NEO::MemorySynchronizationCommands<GfxFamily>::addPipeControlAndProgramPostSyncOperation(
1354-
*commandContainer.getCommandStream(),
1355-
POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA,
1356-
ptrOffset(baseAddr, eventOffset),
1357-
Event::STATE_CLEARED,
1358-
commandContainer.getDevice()->getHardwareInfo(),
1359-
args);
1360-
}
1361-
1362-
return ZE_RESULT_SUCCESS;
1363-
}
1364-
13651362
template <GFXCORE_FAMILY gfxCoreFamily>
13661363
ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendWaitOnEvents(uint32_t numEvents,
13671364
ze_event_handle_t *phEvent) {
@@ -1417,7 +1414,6 @@ void CommandListCoreFamily<gfxCoreFamily>::appendEventForProfiling(ze_event_hand
14171414
}
14181415

14191416
commandContainer.addToResidencyContainer(&event->getAllocation());
1420-
14211417
auto baseAddr = event->getGpuAddress();
14221418

14231419
if (beforeWalker) {

level_zero/core/source/event/event.cpp

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include "shared/source/memory_manager/memory_operations_handler.h"
2020
#include "shared/source/utilities/cpuintrinsics.h"
2121

22-
#include "level_zero/core/source/cmdlist/cmdlist.h"
23-
#include "level_zero/core/source/cmdqueue/cmdqueue.h"
2422
#include "level_zero/core/source/device/device.h"
2523
#include "level_zero/core/source/device/device_imp.h"
2624
#include "level_zero/tools/source/metrics/metric.h"
@@ -58,57 +56,25 @@ ze_result_t EventPoolImp::initialize(DriverHandle *driver, uint32_t numDevices,
5856
maxRootDeviceIndex = rootDeviceIndices[0];
5957
}
6058

61-
if (this->devices.size() > 1) {
62-
this->allocOnDevice = false;
63-
}
64-
65-
if (allocOnDevice) {
66-
ze_command_queue_desc_t cmdQueueDesc = {};
67-
cmdQueueDesc.ordinal = 0;
68-
cmdQueueDesc.index = 0;
69-
cmdQueueDesc.flags = 0;
70-
cmdQueueDesc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
71-
cmdQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS;
72-
ze_result_t returnValue = ZE_RESULT_SUCCESS;
73-
eventPoolCommandList =
74-
CommandList::createImmediate(
75-
static_cast<DeviceImp *>(this->devices[0])->neoDevice->getHardwareInfo().platform.eProductFamily,
76-
this->devices[0],
77-
&cmdQueueDesc,
78-
true,
79-
NEO::EngineGroupType::RenderCompute,
80-
returnValue);
81-
82-
if (!this->eventPoolCommandList) {
83-
this->allocOnDevice = false;
84-
}
85-
}
86-
8759
eventPoolAllocations = new NEO::MultiGraphicsAllocation(maxRootDeviceIndex);
8860

8961
uint32_t rootDeviceIndex = rootDeviceIndices.at(0);
9062

91-
auto subDeviceBitField = devices[0]->getNEODevice()->getDeviceBitfield();
92-
auto internalMemoryType = InternalMemoryType::HOST_UNIFIED_MEMORY;
93-
auto allocationType = isEventPoolUsedForTimestamp ? NEO::GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER : NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
94-
if (this->allocOnDevice) {
95-
internalMemoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
96-
allocationType = NEO::GraphicsAllocation::AllocationType::BUFFER;
97-
}
98-
99-
NEO::SVMAllocsManager::UnifiedMemoryProperties memoryProperties(internalMemoryType, subDeviceBitField);
63+
NEO::SVMAllocsManager::UnifiedMemoryProperties memoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY,
64+
devices[0]->getNEODevice()->getDeviceBitfield());
10065

101-
NEO::AllocationProperties eventPoolAllocationProperties{rootDeviceIndex,
102-
true,
103-
alignUp<size_t>(numEvents * eventSize, MemoryConstants::pageSize64k),
104-
allocationType,
105-
memoryProperties.subdeviceBitfield.count() > 1,
106-
memoryProperties.subdeviceBitfield.count() > 1,
107-
memoryProperties.subdeviceBitfield};
66+
NEO::AllocationProperties unifiedMemoryProperties{rootDeviceIndex,
67+
true,
68+
alignUp<size_t>(numEvents * eventSize, MemoryConstants::pageSize64k),
69+
isEventPoolUsedForTimestamp ? NEO::GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER
70+
: NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY,
71+
memoryProperties.subdeviceBitfield.count() > 1,
72+
memoryProperties.subdeviceBitfield.count() > 1,
73+
memoryProperties.subdeviceBitfield};
74+
unifiedMemoryProperties.alignment = eventAlignment;
10875

109-
eventPoolAllocationProperties.alignment = MemoryConstants::cacheLineSize;
11076
void *eventPoolPtr = driver->getMemoryManager()->createMultiGraphicsAllocation(rootDeviceIndices,
111-
eventPoolAllocationProperties,
77+
unifiedMemoryProperties,
11278
*eventPoolAllocations);
11379
if (!eventPoolPtr) {
11480
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
@@ -124,11 +90,6 @@ EventPoolImp::~EventPoolImp() {
12490
}
12591
delete eventPoolAllocations;
12692
eventPoolAllocations = nullptr;
127-
128-
if (eventPoolCommandList) {
129-
eventPoolCommandList->destroy();
130-
eventPoolCommandList = nullptr;
131-
}
13293
}
13394

13495
ze_result_t EventPoolImp::getIpcHandle(ze_ipc_event_pool_handle_t *pIpcHandle) {
@@ -161,9 +122,6 @@ Event *Event::create(EventPool *eventPool, const ze_event_desc_t *desc, Device *
161122
if (eventPool->isEventPoolUsedForTimestamp) {
162123
event->isTimestampEvent = true;
163124
}
164-
if (eventPool->allocOnDevice) {
165-
event->allocOnDevice = true;
166-
}
167125

168126
auto alloc = eventPool->getAllocation().getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex());
169127

@@ -177,10 +135,6 @@ Event *Event::create(EventPool *eventPool, const ze_event_desc_t *desc, Device *
177135

178136
event->reset();
179137

180-
if (event->allocOnDevice) {
181-
eventPool->eventPoolCommandList->appendEventReset(event->toHandle());
182-
}
183-
184138
return event;
185139
}
186140

@@ -190,10 +144,6 @@ NEO::GraphicsAllocation &Event::getAllocation() {
190144
return *eventImp->eventPool->getAllocation().getGraphicsAllocation(eventImp->device->getNEODevice()->getRootDeviceIndex());
191145
}
192146

193-
uint64_t Event::getGpuAddress() {
194-
return gpuAddress;
195-
}
196-
197147
ze_result_t Event::destroy() {
198148
delete this;
199149
return ZE_RESULT_SUCCESS;
@@ -215,7 +165,7 @@ ze_result_t EventImp::queryStatus() {
215165
return queryVal == Event::STATE_CLEARED ? ZE_RESULT_NOT_READY : ZE_RESULT_SUCCESS;
216166
}
217167

218-
void EventImp::hostEventSetValueTimestamps(uint32_t eventVal) {
168+
ze_result_t EventImp::hostEventSetValueTimestamps(uint32_t eventVal) {
219169

220170
auto baseAddr = reinterpret_cast<uint64_t>(hostAddress);
221171
auto signalScopeFlag = this->signalScope;
@@ -232,11 +182,13 @@ void EventImp::hostEventSetValueTimestamps(uint32_t eventVal) {
232182
eventTsSetFunc(baseAddr + offsetof(KernelTimestampEvent, globalStart));
233183
eventTsSetFunc(baseAddr + offsetof(KernelTimestampEvent, contextEnd));
234184
eventTsSetFunc(baseAddr + offsetof(KernelTimestampEvent, globalEnd));
185+
186+
return ZE_RESULT_SUCCESS;
235187
}
236188

237189
ze_result_t EventImp::hostEventSetValue(uint32_t eventVal) {
238190
if (isTimestampEvent) {
239-
hostEventSetValueTimestamps(eventVal);
191+
return hostEventSetValueTimestamps(eventVal);
240192
}
241193

242194
auto hostAddr = static_cast<uint64_t *>(hostAddress);
@@ -291,11 +243,6 @@ ze_result_t EventImp::hostSynchronize(uint64_t timeout) {
291243
}
292244

293245
ze_result_t EventImp::reset() {
294-
295-
if (allocOnDevice) {
296-
return ZE_RESULT_SUCCESS;
297-
}
298-
299246
return hostEventSetValue(Event::STATE_INITIAL);
300247
}
301248

level_zero/core/source/event/event.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@ struct Event : _ze_event_handle_t {
4444

4545
virtual NEO::GraphicsAllocation &getAllocation();
4646

47-
virtual uint64_t getGpuAddress();
47+
uint64_t getGpuAddress() { return gpuAddress; }
4848

4949
void *hostAddress = nullptr;
50-
uint64_t gpuAddress = 0u;
50+
uint64_t gpuAddress;
5151

5252
ze_event_scope_flags_t signalScope = 0u;
5353
ze_event_scope_flags_t waitScope = 0u;
5454

5555
bool isTimestampEvent = false;
56-
bool allocOnDevice = false;
5756

5857
// Metric streamer instance associated with the event.
5958
MetricStreamer *metricStreamer = nullptr;
@@ -85,7 +84,7 @@ struct EventImp : public Event {
8584

8685
protected:
8786
ze_result_t hostEventSetValue(uint32_t eventValue);
88-
void hostEventSetValueTimestamps(uint32_t eventVal);
87+
ze_result_t hostEventSetValueTimestamps(uint32_t eventVal);
8988
void makeAllocationResident();
9089
};
9190

@@ -113,12 +112,9 @@ struct EventPool : _ze_event_pool_handle_t {
113112

114113
virtual NEO::MultiGraphicsAllocation &getAllocation() { return *eventPoolAllocations; }
115114

116-
virtual size_t getEventSize() = 0;
115+
virtual uint32_t getEventSize() = 0;
117116

118117
bool isEventPoolUsedForTimestamp = false;
119-
bool allocOnDevice = false;
120-
121-
CommandList *eventPoolCommandList = nullptr;
122118

123119
protected:
124120
NEO::MultiGraphicsAllocation *eventPoolAllocations = nullptr;
@@ -129,10 +125,6 @@ struct EventPoolImp : public EventPool {
129125
if (flags & ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP) {
130126
isEventPoolUsedForTimestamp = true;
131127
}
132-
133-
if (!(flags & ZE_EVENT_POOL_FLAG_HOST_VISIBLE)) {
134-
allocOnDevice = true;
135-
}
136128
}
137129

138130
ze_result_t initialize(DriverHandle *driver,
@@ -150,7 +142,7 @@ struct EventPoolImp : public EventPool {
150142

151143
ze_result_t createEvent(const ze_event_desc_t *desc, ze_event_handle_t *phEvent) override;
152144

153-
size_t getEventSize() override { return eventSize; }
145+
uint32_t getEventSize() override { return eventSize; }
154146
size_t getNumEvents() { return numEvents; }
155147

156148
Device *getDevice() override { return devices[0]; }
@@ -161,6 +153,7 @@ struct EventPoolImp : public EventPool {
161153
protected:
162154
const uint32_t eventSize = static_cast<uint32_t>(alignUp(sizeof(struct KernelTimestampEvent),
163155
MemoryConstants::cacheLineSize));
156+
const uint32_t eventAlignment = MemoryConstants::cacheLineSize;
164157
};
165158

166159
} // namespace L0

level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct TimestampEvent : public Test<DeviceFixture> {
2020
DeviceFixture::SetUp();
2121
ze_event_pool_desc_t eventPoolDesc = {};
2222
eventPoolDesc.count = 1;
23-
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
23+
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
2424

2525
ze_event_desc_t eventDesc = {};
2626
eventDesc.index = 0;

level_zero/core/test/unit_tests/mocks/mock_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct Mock<EventPool> : public EventPool {
7272
MOCK_METHOD2(reserveEventFromPool, ze_result_t(int index, ::L0::Event *event));
7373
MOCK_METHOD1(releaseEventToPool, ze_result_t(::L0::Event *event));
7474
MOCK_METHOD0(getDevice, Device *());
75-
MOCK_METHOD0(getEventSize, size_t());
75+
MOCK_METHOD0(getEventSize, uint32_t());
7676

7777
std::vector<int> pool;
7878

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListWhenProfilingBeforeCommandForCo
916916
commandList->initialize(device, NEO::EngineGroupType::Copy);
917917
ze_event_pool_desc_t eventPoolDesc = {};
918918
eventPoolDesc.count = 1;
919-
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
919+
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
920920

921921
ze_event_desc_t eventDesc = {};
922922
eventDesc.index = 0;
@@ -949,7 +949,7 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListWhenProfilingAfterCommandForCop
949949
commandList->initialize(device, NEO::EngineGroupType::Copy);
950950
ze_event_pool_desc_t eventPoolDesc = {};
951951
eventPoolDesc.count = 1;
952-
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
952+
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
953953

954954
ze_event_desc_t eventDesc = {};
955955
eventDesc.index = 0;

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ HWTEST2_F(CommandListCreate, givenCommandListWhenTimestampPassedToMemoryCopyThen
467467

468468
ze_event_pool_desc_t eventPoolDesc = {};
469469
eventPoolDesc.count = 1;
470-
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
470+
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
471471

472472
ze_event_desc_t eventDesc = {};
473473
eventDesc.index = 0;
@@ -1027,7 +1027,7 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListWhenTimestampPassedToMemoryCopy
10271027
void *srcPtr = reinterpret_cast<void *>(0x1234);
10281028
void *dstPtr = reinterpret_cast<void *>(0x2345);
10291029
ze_event_pool_desc_t eventPoolDesc = {};
1030-
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
1030+
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
10311031
eventPoolDesc.count = 1;
10321032

10331033
ze_event_desc_t eventDesc = {};

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_event_reset.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ HWTEST2_F(CommandListAppendEventReset, givenTimestampEventUsedInResetThenPipeCon
129129

130130
ze_event_pool_desc_t eventPoolDesc = {};
131131
eventPoolDesc.count = 1;
132-
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
132+
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
133133

134134
ze_event_desc_t eventDesc = {};
135135
eventDesc.index = 0;
@@ -170,7 +170,6 @@ HWTEST2_F(CommandListAppendEventReset, givenEventWithHostScopeUsedInResetThenPip
170170

171171
ze_event_pool_desc_t eventPoolDesc = {};
172172
eventPoolDesc.count = 1;
173-
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
174173

175174
ze_event_desc_t eventDesc = {};
176175
eventDesc.index = 0;

0 commit comments

Comments
 (0)