Skip to content

Commit e662166

Browse files
[SYCL][L0] make_device shouldn't need platform as an input (#4561)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 094ca47 commit e662166

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

sycl/include/CL/sycl/detail/pi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ piextDeviceGetNativeHandle(pi_device device, pi_native_handle *nativeHandle);
962962
/// NOTE: The created PI object takes ownership of the native handle.
963963
///
964964
/// \param nativeHandle is the native handle to create PI device from.
965-
/// \param platform is the platform of the device.
965+
/// \param platform is the platform of the device (optional).
966966
/// \param device is the PI device created from the native handle.
967967
__SYCL_EXPORT pi_result piextDeviceCreateWithNativeHandle(
968968
pi_native_handle nativeHandle, pi_platform platform, pi_device *device);

sycl/include/sycl/ext/oneapi/backend/level_zero.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,24 @@ template <> struct BackendInput<backend::level_zero, context> {
7878
using type = struct {
7979
interop<backend::level_zero, context>::type NativeHandle;
8080
std::vector<device> DeviceList;
81-
ext::oneapi::level_zero::ownership Ownership;
81+
ext::oneapi::level_zero::ownership Ownership{
82+
ext::oneapi::level_zero::ownership::transfer};
8283
};
8384
};
8485

8586
template <> struct BackendInput<backend::level_zero, queue> {
8687
using type = struct {
8788
interop<backend::level_zero, queue>::type NativeHandle;
88-
ext::oneapi::level_zero::ownership Ownership;
89+
ext::oneapi::level_zero::ownership Ownership{
90+
ext::oneapi::level_zero::ownership::transfer};
8991
};
9092
};
9193

9294
template <> struct BackendInput<backend::level_zero, event> {
9395
using type = struct {
9496
interop<backend::level_zero, event>::type NativeHandle;
95-
ext::oneapi::level_zero::ownership Ownership;
97+
ext::oneapi::level_zero::ownership Ownership{
98+
ext::oneapi::level_zero::ownership::transfer};
9699
};
97100
};
98101

sycl/plugins/level_zero/pi_level_zero.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -2528,18 +2528,33 @@ pi_result piextDeviceCreateWithNativeHandle(pi_native_handle NativeHandle,
25282528
pi_device *Device) {
25292529
PI_ASSERT(Device, PI_INVALID_DEVICE);
25302530
PI_ASSERT(NativeHandle, PI_INVALID_VALUE);
2531-
PI_ASSERT(Platform, PI_INVALID_PLATFORM);
25322531

25332532
auto ZeDevice = pi_cast<ze_device_handle_t>(NativeHandle);
25342533

25352534
// The SYCL spec requires that the set of devices must remain fixed for the
25362535
// duration of the application's execution. We assume that we found all of the
2537-
// Level Zero devices when we initialized the device cache, so the
2536+
// Level Zero devices when we initialized the platforms/devices cache, so the
25382537
// "NativeHandle" must already be in the cache. If it is not, this must not be
25392538
// a valid Level Zero device.
2540-
pi_device Dev = Platform->getDeviceFromNativeHandle(ZeDevice);
2539+
//
2540+
// TODO: maybe we should populate cache of platforms if it wasn't already.
2541+
// For now assert that is was populated.
2542+
PI_ASSERT(PiPlatformCachePopulated, PI_INVALID_VALUE);
2543+
const std::lock_guard<sycl::detail::SpinLock> Lock{*PiPlatformsCacheMutex};
2544+
2545+
pi_device Dev = nullptr;
2546+
for (auto &ThePlatform : *PiPlatformsCache) {
2547+
Dev = ThePlatform->getDeviceFromNativeHandle(ZeDevice);
2548+
if (Dev) {
2549+
// Check that the input Platform, if was given, matches the found one.
2550+
PI_ASSERT(!Platform || Platform == ThePlatform, PI_INVALID_PLATFORM);
2551+
break;
2552+
}
2553+
}
2554+
25412555
if (Dev == nullptr)
25422556
return PI_INVALID_VALUE;
2557+
25432558
*Device = Dev;
25442559
return PI_SUCCESS;
25452560
}

0 commit comments

Comments
 (0)