@@ -1032,13 +1032,32 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetNativeHandle(
10321032}
10331033
10341034UR_APIEXPORT ur_result_t UR_APICALL urDeviceCreateWithNativeHandle (
1035- ur_native_handle_t hNativeDevice, ur_platform_handle_t hPlatform ,
1035+ ur_native_handle_t hNativeDevice, ur_platform_handle_t ,
10361036 const ur_device_native_properties_t *, ur_device_handle_t *phDevice) {
10371037 cl_device_id NativeHandle = reinterpret_cast <cl_device_id>(hNativeDevice);
1038- auto URDevice =
1039- std::make_unique<ur_device_handle_t_>(NativeHandle, hPlatform, nullptr );
1040- *phDevice = URDevice.release ();
1041- return UR_RESULT_SUCCESS;
1038+
1039+ uint32_t NumPlatforms = 0 ;
1040+ UR_RETURN_ON_FAILURE (urPlatformGet (nullptr , 0 , 0 , nullptr , &NumPlatforms));
1041+ std::vector<ur_platform_handle_t > Platforms (NumPlatforms);
1042+ UR_RETURN_ON_FAILURE (
1043+ urPlatformGet (nullptr , 0 , NumPlatforms, Platforms.data (), nullptr ));
1044+
1045+ for (uint32_t i = 0 ; i < NumPlatforms; i++) {
1046+ uint32_t NumDevices = 0 ;
1047+ UR_RETURN_ON_FAILURE (
1048+ urDeviceGet (Platforms[i], UR_DEVICE_TYPE_ALL, 0 , nullptr , &NumDevices));
1049+ std::vector<ur_device_handle_t > Devices (NumDevices);
1050+ UR_RETURN_ON_FAILURE (urDeviceGet (Platforms[i], UR_DEVICE_TYPE_ALL,
1051+ NumDevices, Devices.data (), nullptr ));
1052+
1053+ for (auto &Device : Devices) {
1054+ if (Device->get () == NativeHandle) {
1055+ *phDevice = Device;
1056+ return UR_RESULT_SUCCESS;
1057+ }
1058+ }
1059+ }
1060+ return UR_RESULT_ERROR_INVALID_DEVICE;
10421061}
10431062
10441063UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetGlobalTimestamps (
0 commit comments