Skip to content

Commit f3d245d

Browse files
[SYCL][L0] Change to create all events host-visible by default (#6961)
Signed-off-by: Sergey V Maslov <sergey.v.maslov@intel.com>
1 parent 3fd0850 commit f3d245d

File tree

3 files changed

+29
-37
lines changed

3 files changed

+29
-37
lines changed

sycl/doc/EnvironmentVariables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ variables in production code.</span>
184184
| `SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE` | Any(\*) | This environment variable enables users to control use of copy engines for copy operations. If the value is an integer, it will allow the use of copy engines, if available in the device, in Level Zero plugin to transfer SYCL buffer or image data between the host and/or device(s) and to fill SYCL buffer or image data in device or shared memory. The value of this environment variable can also be a pair of the form "lower_index:upper_index" where the indices point to copy engines in a list of all available copy engines. The default is 1. |
185185
| `SYCL_PI_LEVEL_ZERO_USE_COMPUTE_ENGINE` | Integer | It can be set to an integer (>=0) in which case all compute commands will be submitted to the command-queue with the given index in the compute command group. If it is instead set to a negative value then all available compute engines may be used. The default value is "0" |
186186
| `SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE_FOR_D2D_COPY` (experimental) | Integer | Allows the use of copy engine, if available in the device, in Level Zero plugin for device to device copy operations. The default is 0. This option is experimental and will be removed once heuristics are added to make a decision about use of copy engine for device to device copy operations. |
187-
| `SYCL_PI_LEVEL_ZERO_DEVICE_SCOPE_EVENTS` | Any(\*) | Enable support of device-scope events whose state is not visible to the host. If enabled mode is SYCL_PI_LEVEL_ZERO_DEVICE_SCOPE_EVENTS=1 the Level Zero plugin would create all events having device-scope only and create proxy host-visible events for them when their status is needed (wait/query) on the host. If enabled mode is SYCL_PI_LEVEL_ZERO_DEVICE_SCOPE_EVENTS=2 the Level Zero plugin would create all events having device-scope and add proxy host-visible event at the end of each command-list submission. The default is 2, meaning only the last event in a batch is host-visible. |
187+
| `SYCL_PI_LEVEL_ZERO_DEVICE_SCOPE_EVENTS` | Any(\*) | Enable support of device-scope events whose state is not visible to the host. If enabled mode is SYCL_PI_LEVEL_ZERO_DEVICE_SCOPE_EVENTS=1 the Level Zero plugin would create all events having device-scope only and create proxy host-visible events for them when their status is needed (wait/query) on the host. If enabled mode is SYCL_PI_LEVEL_ZERO_DEVICE_SCOPE_EVENTS=2 the Level Zero plugin would create all events having device-scope and add proxy host-visible event at the end of each command-list submission. The default is 0, meaning all events have host visibility. |
188188
| `SYCL_PI_LEVEL_ZERO_USE_IMMEDIATE_COMMANDLISTS` | Integer | When set to a positive value enables use of Level Zero immediate commandlists, which means there is no batching and all commands are immediately submitted for execution. Default is 0. Note: When immediate commandlist usage is enabled it is necessary to also set SYCL_PI_LEVEL_ZERO_DEVICE_SCOPE_EVENTS to either 0 or 1. |
189189
| `SYCL_PI_LEVEL_ZERO_USE_MULTIPLE_COMMANDLIST_BARRIERS` | Integer | When set to a positive value enables use of multiple Level Zero commandlists when submitting barriers. Default is 1. |
190190
| `SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE_FOR_FILL` | Integer | When set to a positive value enables use of a copy engine for memory fill operations. Default is 0. |

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,29 @@ static const pi_uint32 MaxNumEventsPerPool = [] {
234234
return Result;
235235
}();
236236

237+
// Get value of device scope events env var setting or default setting
238+
static const int DeviceEventsSetting = [] {
239+
const char *DeviceEventsSettingStr =
240+
std::getenv("SYCL_PI_LEVEL_ZERO_DEVICE_SCOPE_EVENTS");
241+
if (DeviceEventsSettingStr) {
242+
// Override the default if user has explicitly chosen the events scope.
243+
switch (std::stoi(DeviceEventsSettingStr)) {
244+
case 0:
245+
return AllHostVisible;
246+
case 1:
247+
return OnDemandHostVisibleProxy;
248+
case 2:
249+
return LastCommandInBatchHostVisible;
250+
default:
251+
// fallthrough to default setting
252+
break;
253+
}
254+
}
255+
// This is our default setting, which is expected to be the fastest
256+
// with the modern GPU drivers.
257+
return AllHostVisible;
258+
}();
259+
237260
// Helper function to implement zeHostSynchronize.
238261
// The behavior is to avoid infinite wait during host sync under ZE_DEBUG.
239262
// This allows for a much more responsive debugging of hangs.
@@ -643,7 +666,7 @@ inline static pi_result createEventAndAssociateQueue(
643666
bool ForceHostVisible = false) {
644667

645668
if (!ForceHostVisible)
646-
ForceHostVisible = Queue->Device->eventsScope() == AllHostVisible;
669+
ForceHostVisible = DeviceEventsSetting == AllHostVisible;
647670
PI_CALL(EventCreate(Queue->Context, Queue, ForceHostVisible, Event));
648671

649672
(*Event)->Queue = Queue;
@@ -809,33 +832,6 @@ pi_result _pi_device::initialize(int SubSubDeviceOrdinal,
809832
return PI_SUCCESS;
810833
}
811834

812-
// Get value of device scope events env var setting or -1 if unset
813-
static const int DeviceEventsSetting = [] {
814-
const char *DeviceEventsSettingStr =
815-
std::getenv("SYCL_PI_LEVEL_ZERO_DEVICE_SCOPE_EVENTS");
816-
if (!DeviceEventsSettingStr)
817-
return -1;
818-
return std::stoi(DeviceEventsSettingStr);
819-
}();
820-
821-
// Controls the scope of events.
822-
// If immediate commandlists are being used then use compatible event scopes.
823-
enum EventsScope _pi_device::eventsScope() {
824-
// Set default based on type of commandlists being used.
825-
auto Default = useImmediateCommandLists() ? OnDemandHostVisibleProxy
826-
: LastCommandInBatchHostVisible;
827-
// Override the default if user has explicitly chosen the events scope.
828-
switch (DeviceEventsSetting) {
829-
case 0:
830-
return AllHostVisible;
831-
case 1:
832-
return OnDemandHostVisibleProxy;
833-
case 2:
834-
return LastCommandInBatchHostVisible;
835-
}
836-
return Default;
837-
}
838-
839835
// Get value of immediate commandlists env var setting or -1 if unset
840836
static const int ImmediateCommandlistsSetting = [] {
841837
const char *ImmediateCommandlistsSettingStr =
@@ -1627,7 +1623,7 @@ pi_result _pi_queue::executeCommandList(pi_command_list_ptr_t CommandList,
16271623
// in the command list is not empty, otherwise we are going to just create
16281624
// and remove proxy event right away and dereference deleted object
16291625
// afterwards.
1630-
if (Device->eventsScope() == LastCommandInBatchHostVisible &&
1626+
if (DeviceEventsSetting == LastCommandInBatchHostVisible &&
16311627
!CommandList->second.EventList.empty()) {
16321628
// If there are only internal events in the command list then we don't
16331629
// need to create host proxy event.
@@ -2007,7 +2003,7 @@ pi_result _pi_ze_event_list_t::createAndRetainPiZeEventList(
20072003
//
20082004
// Make sure that event1.wait() will wait for a host-visible
20092005
// event that is signalled before the command2 is enqueued.
2010-
if (CurQueue->Device->eventsScope() != AllHostVisible) {
2006+
if (DeviceEventsSetting != AllHostVisible) {
20112007
CurQueue->executeAllOpenCommandLists();
20122008
}
20132009
}
@@ -5527,7 +5523,7 @@ _pi_event::getOrCreateHostVisibleEvent(ze_event_handle_t &ZeHostVisibleEvent) {
55275523
this->Mutex);
55285524

55295525
if (!HostVisibleEvent) {
5530-
if (Queue->Device->eventsScope() != OnDemandHostVisibleProxy)
5526+
if (DeviceEventsSetting != OnDemandHostVisibleProxy)
55315527
die("getOrCreateHostVisibleEvent: missing host-visible event");
55325528

55335529
// Submit the command(s) signalling the proxy event to the queue.
@@ -5909,8 +5905,7 @@ pi_result piEventsWait(pi_uint32 NumEvents, const pi_event *EventList) {
59095905
return PI_ERROR_INVALID_EVENT;
59105906
}
59115907
for (uint32_t I = 0; I < NumEvents; I++) {
5912-
if (EventList[I]->Queue->Device->eventsScope() ==
5913-
OnDemandHostVisibleProxy) {
5908+
if (DeviceEventsSetting == OnDemandHostVisibleProxy) {
59145909
// Make sure to add all host-visible "proxy" event signals if needed.
59155910
// This ensures that all signalling commands are submitted below and
59165911
// thus proxy events can be waited without a deadlock.

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,6 @@ struct _pi_device : _pi_object {
564564
// For some devices (e.g. PVC) immediate commandlists are preferred.
565565
bool ImmCommandListsPreferred;
566566

567-
// Return the Events scope to be used in for this device.
568-
enum EventsScope eventsScope();
569-
570567
// Return whether to use immediate commandlists for this device.
571568
bool useImmediateCommandLists();
572569

0 commit comments

Comments
 (0)