Skip to content

Commit e455095

Browse files
committed
added comment and fixed ref count issue
Signed-off-by: Byoungro So <[email protected]>
1 parent 2e0dbc1 commit e455095

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ pi_result piPlatformsGet(pi_uint32 NumEntries, pi_platform *Platforms,
461461
return PI_INVALID_VALUE;
462462
}
463463

464+
// Cache pi_platforms for reuse in the future
465+
// It solves two problems;
466+
// 1. sycl::device equality issue; we always return the same pi_device.
467+
// 2. performance; we can save time by immediately return from cache.
464468
static std::vector<pi_platform> PiPlatformsCache;
465469
static std::mutex PiPlatformsCacheMutex;
466470

@@ -689,7 +693,6 @@ pi_result piDevicesGet(pi_platform Platform, pi_device_type DeviceType,
689693

690694
pi_result piDeviceRetain(pi_device Device) {
691695
assert(Device);
692-
693696
// The root-device ref-count remains unchanged (always 1).
694697
if (Device->IsSubDevice) {
695698
++(Device->RefCount);
@@ -699,9 +702,11 @@ pi_result piDeviceRetain(pi_device Device) {
699702

700703
pi_result piDeviceRelease(pi_device Device) {
701704
assert(Device);
705+
assert(Device->RefCount > 0 && "Device is already released.");
702706
// TODO: OpenCL says root-device ref-count remains unchanged (1),
703707
// but when would we free the device's data?
704-
--(Device->RefCount);
708+
if (Device->IsSubDevice)
709+
--(Device->RefCount);
705710
// TODO: All cached pi_devices live until the program ends.
706711
// If L0 RT does not do its own cleanup for Ze_Device_Handle upon tear-down,
707712
// we need to figure out a way to call here

0 commit comments

Comments
 (0)