Skip to content

Commit 5a05d76

Browse files
Correct event reset
Signed-off-by: Daria Hinz <daria.hinz@intel.com>
1 parent dd0601a commit 5a05d76

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

level_zero/core/source/event/event.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ ze_result_t EventImp::calculateProfilingData() {
172172

173173
void EventImp::assignTimestampData(void *address) {
174174
auto baseAddr = reinterpret_cast<uint64_t>(address);
175+
uint32_t packetsToCopy = packetsInUse ? packetsInUse : NEO::TimestampPacketSizeControl::preferredPacketCount;
175176

176177
auto copyData = [&](uint32_t &timestampField, auto tsAddr) {
177178
memcpy_s(static_cast<void *>(&timestampField), sizeof(uint32_t), reinterpret_cast<void *>(tsAddr), sizeof(uint32_t));
178179
};
179180

180-
for (uint32_t i = 0; i < packetsInUse; i++) {
181-
181+
for (uint32_t i = 0; i < packetsToCopy; i++) {
182182
auto &packet = timestampsData->packets[i];
183183
copyData(packet.globalStart, baseAddr + offsetof(TimestampPacketStorage::Packet, globalStart));
184184
copyData(packet.contextStart, baseAddr + offsetof(TimestampPacketStorage::Packet, contextStart));
@@ -223,10 +223,14 @@ ze_result_t EventImp::hostEventSetValueTimestamps(uint32_t eventVal) {
223223
}
224224
};
225225

226-
eventTsSetFunc(baseAddr + offsetof(TimestampPacketStorage::Packet, contextStart));
227-
eventTsSetFunc(baseAddr + offsetof(TimestampPacketStorage::Packet, globalStart));
228-
eventTsSetFunc(baseAddr + offsetof(TimestampPacketStorage::Packet, contextEnd));
229-
eventTsSetFunc(baseAddr + offsetof(TimestampPacketStorage::Packet, globalEnd));
226+
for (uint32_t i = 0; i < NEO::TimestampPacketSizeControl::preferredPacketCount; i++) {
227+
eventTsSetFunc(baseAddr + offsetof(TimestampPacketStorage::Packet, contextStart));
228+
eventTsSetFunc(baseAddr + offsetof(TimestampPacketStorage::Packet, globalStart));
229+
eventTsSetFunc(baseAddr + offsetof(TimestampPacketStorage::Packet, contextEnd));
230+
eventTsSetFunc(baseAddr + offsetof(TimestampPacketStorage::Packet, globalEnd));
231+
baseAddr += sizeof(struct TimestampPacketStorage::Packet);
232+
}
233+
assignTimestampData(hostAddress);
230234

231235
return ZE_RESULT_SUCCESS;
232236
}
@@ -288,6 +292,7 @@ ze_result_t EventImp::hostSynchronize(uint64_t timeout) {
288292
}
289293

290294
ze_result_t EventImp::reset() {
295+
resetPackets();
291296
return hostEventSetValue(Event::STATE_INITIAL);
292297
}
293298

level_zero/core/source/event/event.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct Event : _ze_event_handle_t {
5454

5555
void *hostAddress = nullptr;
5656
uint64_t gpuAddress;
57-
uint32_t packetsInUse = 0;
57+
uint32_t packetsInUse;
5858

5959
ze_event_scope_flags_t signalScope = 0u;
6060
ze_event_scope_flags_t waitScope = 0u;
@@ -157,8 +157,8 @@ struct EventPoolImp : public EventPool {
157157
size_t numEvents;
158158

159159
protected:
160-
const uint32_t eventSize = static_cast<uint32_t>(NEO::TimestampPacketSizeControl::preferredPacketCount * alignUp(sizeof(struct TimestampPacketStorage::Packet),
161-
MemoryConstants::cacheLineSize));
160+
const uint32_t eventSize = static_cast<uint32_t>(alignUp(NEO::TimestampPacketSizeControl::preferredPacketCount * sizeof(struct TimestampPacketStorage::Packet),
161+
MemoryConstants::cacheLineSize));
162162
const uint32_t eventAlignment = MemoryConstants::cacheLineSize;
163163
};
164164

level_zero/core/test/unit_tests/sources/event/test_event.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ TEST_F(EventPoolCreate, givenTimestampEventsThenEventSizeSufficientForAllKernelT
4242

4343
std::unique_ptr<L0::EventPool> eventPool(EventPool::create(driverHandle.get(), 0, nullptr, &eventPoolDesc));
4444
ASSERT_NE(nullptr, eventPool);
45-
46-
uint32_t kernelTimestampsSize = static_cast<uint32_t>(NEO::TimestampPacketSizeControl::preferredPacketCount *
47-
alignUp(sizeof(struct TimestampPacketStorage::Packet), MemoryConstants::cacheLineSize));
45+
uint32_t packetsSize = NEO::TimestampPacketSizeControl::preferredPacketCount * sizeof(struct TimestampPacketStorage::Packet);
46+
uint32_t kernelTimestampsSize = static_cast<uint32_t>(alignUp(packetsSize, MemoryConstants::cacheLineSize));
4847
EXPECT_EQ(kernelTimestampsSize, eventPool->getEventSize());
4948
}
5049

@@ -196,6 +195,20 @@ TEST_F(TimestampEventCreate, givenEventCreatedWithTimestampThenIsTimestampEventF
196195
EXPECT_TRUE(event->isTimestampEvent);
197196
}
198197

198+
TEST_F(TimestampEventCreate, givenEventTimestampsCreatedWhenResetIsInvokeThenCorrectDataAreSet) {
199+
EXPECT_NE(nullptr, event->timestampsData);
200+
201+
for (auto i = 0u; i < NEO::TimestampPacketSizeControl::preferredPacketCount; i++) {
202+
auto &packet = event->timestampsData->packets[i];
203+
EXPECT_EQ(Event::State::STATE_INITIAL, packet.contextStart);
204+
EXPECT_EQ(Event::State::STATE_INITIAL, packet.globalStart);
205+
EXPECT_EQ(Event::State::STATE_INITIAL, packet.contextEnd);
206+
EXPECT_EQ(Event::State::STATE_INITIAL, packet.globalEnd);
207+
}
208+
209+
EXPECT_EQ(0u, event->getPacketsInUse());
210+
}
211+
199212
TEST_F(TimestampEventCreate, givenSingleTimestampEventThenAllocationSizeCreatedForAllTimestamps) {
200213
auto allocation = &eventPool->getAllocation();
201214
ASSERT_NE(nullptr, allocation);

0 commit comments

Comments
 (0)