Skip to content

Commit 416c471

Browse files
committed
[SYCL][L0] Honor property::queue::enable_profiling
Signed-off-by: Sergey V Maslov <sergey.v.maslov@intel.com>
1 parent e6d0547 commit 416c471

File tree

2 files changed

+68
-49
lines changed

2 files changed

+68
-49
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ extern "C" {
3232
// Forward declarartions.
3333
static pi_result EventRelease(pi_event Event, pi_queue LockedQueue);
3434
static pi_result QueueRelease(pi_queue Queue, pi_queue LockedQueue);
35-
static pi_result EventCreate(pi_context Context, bool HostVisible,
36-
pi_event *RetEvent);
35+
static pi_result EventCreate(pi_context Context, pi_queue Queue,
36+
bool HostVisible, pi_event *RetEvent);
3737
}
3838

3939
namespace {
@@ -428,20 +428,13 @@ pi_result _pi_mem::removeMapping(void *MappedTo, Mapping &MapInfo) {
428428

429429
pi_result
430430
_pi_context::getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &Pool,
431-
size_t &Index, bool HostVisible) {
431+
size_t &Index, bool HostVisible,
432+
bool ProfilingEnabled) {
432433
// Lock while updating event pool machinery.
433434
std::lock_guard<std::mutex> Lock(ZeEventPoolCacheMutex);
434435

435-
// Setup for host-visible pool as needed.
436-
ze_event_pool_flag_t ZePoolFlag = {};
437-
std::list<ze_event_pool_handle_t> *ZePoolCache;
438-
439-
if (HostVisible) {
440-
ZePoolFlag = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
441-
ZePoolCache = &ZeHostVisibleEventPoolCache;
442-
} else {
443-
ZePoolCache = &ZeDeviceScopeEventPoolCache;
444-
}
436+
std::list<ze_event_pool_handle_t> *ZePoolCache =
437+
getZeEventPoolCache(HostVisible, ProfilingEnabled);
445438

446439
// Remove full pool from the cache.
447440
if (!ZePoolCache->empty()) {
@@ -460,7 +453,13 @@ _pi_context::getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &Pool,
460453
if (*ZePool == nullptr) {
461454
ZeStruct<ze_event_pool_desc_t> ZeEventPoolDesc;
462455
ZeEventPoolDesc.count = MaxNumEventsPerPool;
463-
ZeEventPoolDesc.flags = ZePoolFlag | ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
456+
ZeEventPoolDesc.flags = 0;
457+
if (HostVisible) {
458+
ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
459+
}
460+
if (ProfilingEnabled) {
461+
ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
462+
}
464463

465464
std::vector<ze_device_handle_t> ZeDevices;
466465
std::for_each(Devices.begin(), Devices.end(),
@@ -486,12 +485,8 @@ pi_result _pi_context::decrementUnreleasedEventsInPool(pi_event Event) {
486485
return PI_SUCCESS;
487486
}
488487

489-
std::list<ze_event_pool_handle_t> *ZePoolCache;
490-
if (Event->IsHostVisible()) {
491-
ZePoolCache = &ZeHostVisibleEventPoolCache;
492-
} else {
493-
ZePoolCache = &ZeDeviceScopeEventPoolCache;
494-
}
488+
std::list<ze_event_pool_handle_t> *ZePoolCache =
489+
getZeEventPoolCache(Event->isHostVisible(), Event->isProfilingEnabled());
495490

496491
// Put the empty pool to the cache of the pools.
497492
std::lock_guard<std::mutex> Lock(ZeEventPoolCacheMutex);
@@ -615,9 +610,9 @@ inline static pi_result
615610
createEventAndAssociateQueue(pi_queue Queue, pi_event *Event,
616611
pi_command_type CommandType,
617612
pi_command_list_ptr_t CommandList) {
618-
pi_result Res = piEventCreate(Queue->Context, Event);
619-
if (Res != PI_SUCCESS)
620-
return Res;
613+
614+
PI_CALL(
615+
EventCreate(Queue->Context, Queue, EventsScope == AllHostVisible, Event));
621616

622617
(*Event)->Queue = Queue;
623618
(*Event)->CommandType = CommandType;
@@ -806,13 +801,11 @@ pi_result _pi_context::finalize() {
806801
// For example, event pool caches would be still alive.
807802
{
808803
std::lock_guard<std::mutex> Lock(ZeEventPoolCacheMutex);
809-
for (auto &ZePool : ZeDeviceScopeEventPoolCache)
810-
ZE_CALL(zeEventPoolDestroy, (ZePool));
811-
for (auto &ZePool : ZeHostVisibleEventPoolCache)
812-
ZE_CALL(zeEventPoolDestroy, (ZePool));
813-
814-
ZeDeviceScopeEventPoolCache.clear();
815-
ZeHostVisibleEventPoolCache.clear();
804+
for (auto &ZePoolCache : ZeEventPoolCache) {
805+
for (auto &ZePool : ZePoolCache)
806+
ZE_CALL(zeEventPoolDestroy, (ZePool));
807+
ZePoolCache.clear();
808+
}
816809
}
817810

818811
// Destroy the command list used for initializations
@@ -841,8 +834,7 @@ pi_result _pi_context::finalize() {
841834

842835
bool _pi_queue::isInOrderQueue() const {
843836
// If out-of-order queue property is not set, then this is a in-order queue.
844-
return ((this->PiQueueProperties & PI_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) ==
845-
0);
837+
return ((this->Properties & PI_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) == 0);
846838
}
847839

848840
pi_result _pi_queue::resetCommandList(pi_command_list_ptr_t CommandList,
@@ -1032,11 +1024,10 @@ static const zeCommandListBatchConfig ZeCommandListBatchCopyConfig = [] {
10321024
_pi_queue::_pi_queue(ze_command_queue_handle_t Queue,
10331025
std::vector<ze_command_queue_handle_t> &CopyQueues,
10341026
pi_context Context, pi_device Device,
1035-
bool OwnZeCommandQueue,
1036-
pi_queue_properties PiQueueProperties)
1027+
bool OwnZeCommandQueue, pi_queue_properties Properties)
10371028
: ZeComputeCommandQueue{Queue}, ZeCopyCommandQueues{CopyQueues},
10381029
Context{Context}, Device{Device}, OwnZeCommandQueue{OwnZeCommandQueue},
1039-
PiQueueProperties(PiQueueProperties) {
1030+
Properties(Properties) {
10401031
ComputeCommandBatch.OpenCommandList = CommandListMap.end();
10411032
CopyCommandBatch.OpenCommandList = CommandListMap.end();
10421033
ComputeCommandBatch.QueueBatchSize =
@@ -1350,7 +1341,7 @@ pi_result _pi_queue::executeCommandList(pi_command_list_ptr_t CommandList,
13501341
// Create a "proxy" host-visible event.
13511342
//
13521343
pi_event HostVisibleEvent;
1353-
PI_CALL(EventCreate(Context, true, &HostVisibleEvent));
1344+
PI_CALL(EventCreate(Context, this, true, &HostVisibleEvent));
13541345

13551346
// Update each command's event in the command-list to "see" this
13561347
// proxy event as a host-visible counterpart.
@@ -4955,7 +4946,7 @@ _pi_event::getOrCreateHostVisibleEvent(ze_event_handle_t &ZeHostVisibleEvent) {
49554946
die("getOrCreateHostVisibleEvent: missing host-visible event");
49564947

49574948
// Create a "proxy" host-visible event on demand.
4958-
PI_CALL(EventCreate(Context, true, &HostVisibleEvent));
4949+
PI_CALL(EventCreate(Context, Queue, true, &HostVisibleEvent));
49594950
HostVisibleEvent->CleanedUp = true;
49604951

49614952
// Submit the command(s) signalling the proxy event to the queue.
@@ -4988,12 +4979,21 @@ _pi_event::getOrCreateHostVisibleEvent(ze_event_handle_t &ZeHostVisibleEvent) {
49884979
return PI_SUCCESS;
49894980
}
49904981

4991-
static pi_result EventCreate(pi_context Context, bool HostVisible,
4992-
pi_event *RetEvent) {
4982+
// Helper function for creating a PI event.
4983+
// The "Queue" argument specifies the PI queue where a command is submitted.
4984+
// The "HostVisible" argument specifies if event needs to be allocated from
4985+
// a host-visible pool.
4986+
//
4987+
static pi_result EventCreate(pi_context Context, pi_queue Queue,
4988+
bool HostVisible, pi_event *RetEvent) {
4989+
4990+
bool ProfilingEnabled =
4991+
!Queue || (Queue->Properties & PI_QUEUE_PROFILING_ENABLE) != 0;
4992+
49934993
size_t Index = 0;
49944994
ze_event_pool_handle_t ZeEventPool = {};
4995-
if (auto Res = Context->getFreeSlotInExistingOrNewPool(ZeEventPool, Index,
4996-
HostVisible))
4995+
if (auto Res = Context->getFreeSlotInExistingOrNewPool(
4996+
ZeEventPool, Index, HostVisible, ProfilingEnabled))
49974997
return Res;
49984998

49994999
ze_event_handle_t ZeEvent;
@@ -5034,8 +5034,9 @@ static pi_result EventCreate(pi_context Context, bool HostVisible,
50345034
return PI_SUCCESS;
50355035
}
50365036

5037+
// Exteral PI API entry
50375038
pi_result piEventCreate(pi_context Context, pi_event *RetEvent) {
5038-
return EventCreate(Context, EventsScope == AllHostVisible, RetEvent);
5039+
return EventCreate(Context, nullptr, EventsScope == AllHostVisible, RetEvent);
50395040
}
50405041

50415042
pi_result piEventGetInfo(pi_event Event, pi_event_info ParamName,
@@ -5101,6 +5102,11 @@ pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName,
51015102

51025103
PI_ASSERT(Event, PI_INVALID_EVENT);
51035104

5105+
if (Event->Queue &&
5106+
(Event->Queue->Properties & PI_QUEUE_PROFILING_ENABLE) == 0) {
5107+
return PI_PROFILING_INFO_NOT_AVAILABLE;
5108+
}
5109+
51045110
uint64_t ZeTimerResolution =
51055111
Event->Queue
51065112
? Event->Queue->Device->ZeDeviceProperties->timerResolution

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,11 @@ struct _pi_context : _pi_object {
562562

563563
// Get index of the free slot in the available pool. If there is no available
564564
// pool then create new one. The HostVisible parameter tells if we need a
565-
// slot for a host-visible event.
565+
// slot for a host-visible event. The ProfilingEnabled tells is we need a
566+
// slot for an event with profiling capabilities.
566567
pi_result getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &, size_t &,
567-
bool HostVisible);
568+
bool HostVisible,
569+
bool ProfilingEnabled);
568570

569571
// Decrement number of events living in the pool upon event destroy
570572
// and return the pool to the cache if there are no unreleased events.
@@ -601,9 +603,14 @@ struct _pi_context : _pi_object {
601603
// head. In case there is no next pool, a new pool is created and made the
602604
// head.
603605
//
604-
std::list<ze_event_pool_handle_t> ZeDeviceScopeEventPoolCache;
605606
// Cache of event pools to which host-visible events are added to.
606-
std::list<ze_event_pool_handle_t> ZeHostVisibleEventPoolCache;
607+
std::vector<std::list<ze_event_pool_handle_t>> ZeEventPoolCache{4};
608+
auto getZeEventPoolCache(bool HostVisible, bool WithProfiling) {
609+
if (HostVisible)
610+
return WithProfiling ? &ZeEventPoolCache[0] : &ZeEventPoolCache[1];
611+
else
612+
return WithProfiling ? &ZeEventPoolCache[2] : &ZeEventPoolCache[3];
613+
}
607614

608615
// This map will be used to determine if a pool is full or not
609616
// by storing number of empty slots available in the pool.
@@ -625,7 +632,7 @@ struct _pi_queue : _pi_object {
625632
_pi_queue(ze_command_queue_handle_t Queue,
626633
std::vector<ze_command_queue_handle_t> &CopyQueues,
627634
pi_context Context, pi_device Device, bool OwnZeCommandQueue,
628-
pi_queue_properties PiQueueProperties = 0);
635+
pi_queue_properties Properties = 0);
629636

630637
// Level Zero compute command queue handle.
631638
ze_command_queue_handle_t ZeComputeCommandQueue;
@@ -731,7 +738,7 @@ struct _pi_queue : _pi_object {
731738
bool isBatchingAllowed(bool IsCopy) const;
732739

733740
// Keeps the properties of this queue.
734-
pi_queue_properties PiQueueProperties;
741+
pi_queue_properties Properties;
735742

736743
// Returns true if the queue is a in-order queue.
737744
bool isInOrderQueue() const;
@@ -986,11 +993,17 @@ struct _pi_event : _pi_object {
986993
// than by just this one event, depending on the mode (see EventsScope).
987994
//
988995
pi_event HostVisibleEvent = {nullptr};
989-
bool IsHostVisible() const { return this == HostVisibleEvent; }
996+
bool isHostVisible() const { return this == HostVisibleEvent; }
990997

991998
// Get the host-visible event or create one and enqueue its signal.
992999
pi_result getOrCreateHostVisibleEvent(ze_event_handle_t &HostVisibleEvent);
9931000

1001+
// Tells if this event is with profiling capabilities.
1002+
bool isProfilingEnabled() const {
1003+
return !Queue || // tentatively assume user events are profiling enabled
1004+
(Queue->Properties & PI_QUEUE_PROFILING_ENABLE) != 0;
1005+
}
1006+
9941007
// Level Zero command list where the command signaling this event was appended
9951008
// to. This is currently used to remember/destroy the command list after all
9961009
// commands in it are completed, i.e. this event signaled.

0 commit comments

Comments
 (0)