Skip to content

Commit 973199d

Browse files
authored
Merge pull request #2408 from oneapi-src/v0.10.14rc
Candidate for the v0.10.14 release tag
2 parents 5d95b45 + a03458c commit 973199d

File tree

3 files changed

+57
-44
lines changed

3 files changed

+57
-44
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
cmake_minimum_required(VERSION 3.20.0 FATAL_ERROR)
7-
project(unified-runtime VERSION 0.10.13)
7+
project(unified-runtime VERSION 0.10.14)
88

99
# Check if unified runtime is built as a standalone project.
1010
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR UR_STANDALONE_BUILD)

source/adapters/level_zero/context.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,18 +561,26 @@ ur_event_handle_t ur_context_handle_t_::getEventFromContextCache(
561561
bool HostVisible, bool WithProfiling, ur_device_handle_t Device,
562562
bool CounterBasedEventEnabled) {
563563
std::scoped_lock<ur_mutex> Lock(EventCacheMutex);
564-
auto Cache = getEventCache(HostVisible, WithProfiling, Device);
565-
if (Cache->empty())
564+
auto Cache = getEventCache(HostVisible, WithProfiling, Device,
565+
CounterBasedEventEnabled);
566+
if (Cache->empty()) {
567+
logger::info("Cache empty (Host Visible: {}, Profiling: {}, Counter: {}, "
568+
"Device: {})",
569+
HostVisible, WithProfiling, CounterBasedEventEnabled, Device);
566570
return nullptr;
571+
}
567572

568573
auto It = Cache->begin();
569574
ur_event_handle_t Event = *It;
570-
if (Event->CounterBasedEventsEnabled != CounterBasedEventEnabled) {
571-
return nullptr;
572-
}
573575
Cache->erase(It);
574576
// We have to reset event before using it.
575577
Event->reset();
578+
579+
logger::info("Using {} event (Host Visible: {}, Profiling: {}, Counter: {}, "
580+
"Device: {}) from cache {}",
581+
Event, Event->HostVisibleEvent, Event->isProfilingEnabled(),
582+
Event->CounterBasedEventsEnabled, Device, Cache);
583+
576584
return Event;
577585
}
578586

@@ -584,8 +592,13 @@ void ur_context_handle_t_::addEventToContextCache(ur_event_handle_t Event) {
584592
Device = Legacy(Event->UrQueue)->Device;
585593
}
586594

587-
auto Cache = getEventCache(Event->isHostVisible(),
588-
Event->isProfilingEnabled(), Device);
595+
auto Cache =
596+
getEventCache(Event->isHostVisible(), Event->isProfilingEnabled(), Device,
597+
Event->CounterBasedEventsEnabled);
598+
logger::info("Inserting {} event (Host Visible: {}, Profiling: {}, Counter: "
599+
"{}, Device: {}) into cache {}",
600+
Event, Event->HostVisibleEvent, Event->isProfilingEnabled(),
601+
Event->CounterBasedEventsEnabled, Device, Cache);
589602
Cache->emplace_back(Event);
590603
}
591604

source/adapters/level_zero/context.hpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ struct ur_context_handle_t_ : _ur_object {
168168
// holding the current pool usage counts.
169169
ur_mutex ZeEventPoolCacheMutex;
170170

171-
// Mutex to control operations on event caches.
172-
ur_mutex EventCacheMutex;
173-
174-
// Caches for events.
175-
using EventCache = std::vector<std::list<ur_event_handle_t>>;
176-
EventCache EventCaches{4};
177-
std::vector<std::unordered_map<ur_device_handle_t, size_t>>
178-
EventCachesDeviceMap{4};
179-
180171
// Initialize the PI context.
181172
ur_result_t initialize();
182173

@@ -306,36 +297,45 @@ struct ur_context_handle_t_ : _ur_object {
306297
bool isValidDevice(ur_device_handle_t Device) const;
307298

308299
private:
300+
enum EventFlags {
301+
EVENT_FLAG_HOST_VISIBLE = UR_BIT(0),
302+
EVENT_FLAG_WITH_PROFILING = UR_BIT(1),
303+
EVENT_FLAG_COUNTER = UR_BIT(2),
304+
EVENT_FLAG_DEVICE = UR_BIT(3), // if set, subsequent bits are device id
305+
MAX_EVENT_FLAG_BITS =
306+
4, // this is used as an offset for embedding device id
307+
};
308+
309+
// Mutex to control operations on event caches.
310+
ur_mutex EventCacheMutex;
311+
312+
// Caches for events.
313+
using EventCache = std::list<ur_event_handle_t>;
314+
std::vector<EventCache> EventCaches;
315+
309316
// Get the cache of events for a provided scope and profiling mode.
310-
auto getEventCache(bool HostVisible, bool WithProfiling,
311-
ur_device_handle_t Device) {
317+
EventCache *getEventCache(bool HostVisible, bool WithProfiling,
318+
ur_device_handle_t Device, bool Counter) {
319+
320+
size_t index = 0;
312321
if (HostVisible) {
313-
if (Device) {
314-
auto EventCachesMap =
315-
WithProfiling ? &EventCachesDeviceMap[0] : &EventCachesDeviceMap[1];
316-
if (EventCachesMap->find(Device) == EventCachesMap->end()) {
317-
EventCaches.emplace_back();
318-
EventCachesMap->insert(
319-
std::make_pair(Device, EventCaches.size() - 1));
320-
}
321-
return &EventCaches[(*EventCachesMap)[Device]];
322-
} else {
323-
return WithProfiling ? &EventCaches[0] : &EventCaches[1];
324-
}
325-
} else {
326-
if (Device) {
327-
auto EventCachesMap =
328-
WithProfiling ? &EventCachesDeviceMap[2] : &EventCachesDeviceMap[3];
329-
if (EventCachesMap->find(Device) == EventCachesMap->end()) {
330-
EventCaches.emplace_back();
331-
EventCachesMap->insert(
332-
std::make_pair(Device, EventCaches.size() - 1));
333-
}
334-
return &EventCaches[(*EventCachesMap)[Device]];
335-
} else {
336-
return WithProfiling ? &EventCaches[2] : &EventCaches[3];
337-
}
322+
index |= EVENT_FLAG_HOST_VISIBLE;
323+
}
324+
if (WithProfiling) {
325+
index |= EVENT_FLAG_WITH_PROFILING;
338326
}
327+
if (Counter) {
328+
index |= EVENT_FLAG_COUNTER;
329+
}
330+
if (Device) {
331+
index |= EVENT_FLAG_DEVICE | (*Device->Id << MAX_EVENT_FLAG_BITS);
332+
}
333+
334+
if (index >= EventCaches.size()) {
335+
EventCaches.resize(index + 1);
336+
}
337+
338+
return &EventCaches[index];
339339
}
340340
};
341341

0 commit comments

Comments
 (0)