Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *CallStr,
return mapError(Result);
#define ZE_CALL_NOCHECK(Call) ZeCall().doCall(Call, #Call, false)

_pi_device::~_pi_device() {
// Destroy all the command lists associated with this device.
std::lock_guard<std::mutex> Lock(ZeCommandListCacheMutex);
for (ze_command_list_handle_t &ZeCommandList : ZeCommandListCache) {
if (ZeCommandList)
zeCommandListDestroy(ZeCommandList);
}
ZeCommandListCache.clear();
}

pi_result _pi_device::initialize() {
uint32_t numQueueGroups = 0;
ZE_CALL(zeDeviceGetCommandQueueGroupProperties(ZeDevice, &numQueueGroups,
Expand Down Expand Up @@ -1012,6 +1022,8 @@ pi_result piextPlatformCreateWithNativeHandle(pi_native_handle NativeHandle,
return PI_INVALID_VALUE;
}

_pi_platform::~_pi_platform() { PiDevicesCache.clear(); }

// Get the cahched PI device created for the L0 device handle.
// Return NULL if no such PI device found.
pi_device _pi_platform::getDeviceFromNativeHandle(ze_device_handle_t ZeDevice) {
Expand Down Expand Up @@ -1128,17 +1140,9 @@ pi_result piDeviceRelease(pi_device Device) {
if (Device->RefCount <= 0)
die("piDeviceRelease: the device has been already released");

// TODO: OpenCL says root-device ref-count remains unchanged (1),
// but when would we free the device's data?
// Root devices are destroyed during the piTearDown process.
if (Device->IsSubDevice) {
if (--(Device->RefCount) == 0) {
// Destroy all the command lists associated with this device.
Device->ZeCommandListCacheMutex.lock();
for (ze_command_list_handle_t &ZeCommandList :
Device->ZeCommandListCache) {
zeCommandListDestroy(ZeCommandList);
}
Device->ZeCommandListCacheMutex.unlock();
delete Device;
}
}
Expand Down
2 changes: 2 additions & 0 deletions sycl/plugins/level_zero/pi_level_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct _pi_object {

struct _pi_platform {
_pi_platform(ze_driver_handle_t Driver) : ZeDriver{Driver} {}
~_pi_platform();

// Level Zero lacks the notion of a platform, but there is a driver, which is
// a pretty good fit to keep here.
Expand Down Expand Up @@ -142,6 +143,7 @@ struct _pi_device : _pi_object {
// NOTE: one must additionally call initialize() to complete
// PI device creation.
}
~_pi_device();

// Keep the ordinal of a "compute" commands group, where we send all
// commands currently.
Expand Down