Skip to content

Commit c8a55e8

Browse files
authored
[sycl-rel] Cherry-pick UR patches (#18884)
Cherry-pick commits that reached the internal branch between intel/llvm cutoff and release branch pulldown. Patches included: --- [Coverity][UR] Remove noexcept keywords from pool_manager methods (#17678) This should fix coverity issues in `ur_pool_manager.hpp`, `ur_util.hpp` and `ur_adapter_registry.hpp` files reported in: https://coverity.devtools.intel.com/prod6/#/project-view/26752/10020 Patch-by: Krzysztof Święcicki <[email protected]> --- [UR][L0] Enable support for using L0 spec External Semaphores (#17671) - Implements the spec version of the L0 Extension External Semaphores - Implements handling the translation of handles if the driver only supports the EXP functions. Patch-by: Neil R. Spruit <[email protected]> --- [UR][L0] Memory interop support given external buffer (#17458) Enable L0 to directly import the memory allocated for NPU/iGPU and let SYCL kernel running on iGPU be able to directly access the data it will reduce the overhead of data movement between NPU/iGPU and iGPU. Patch-by: Zhang, Winston <[email protected]> Co-authored-by: Peter Žužek <[email protected]> --- [UR] Fix Loader Negative Prefilters (#17528) This commit fixes #17086. Patch-by: Isaac Ault <[email protected]> --- [UR] Remove unnecessary null pointer check in OpenCL command buffer code, and update declaration of filter lamba to avoid copies (#17615) Patch-by: Martin Grant <[email protected]>
1 parent df9841a commit c8a55e8

File tree

10 files changed

+406
-142
lines changed

10 files changed

+406
-142
lines changed

unified-runtime/scripts/core/manifests.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
#
2+
# Copyright (C) 2025 Intel Corporation
3+
#
4+
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
5+
# See LICENSE.TXT
6+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
#
8+
# See YaML.md for syntax definition
9+
#
10+
# NOTE: device_types must be explictly listed. Refrain from using
11+
# $X_DEVICE_TYPE_ALL. See https://github.com/intel/llvm/issues/17527.
112
--- #--------------------------------------------------------------------------
213
type: header
314
desc: "Intel $OneApi Unified Runtime adapter manifests"
@@ -7,7 +18,11 @@ type: manifest
718
name: opencl
819
backend: $X_ADAPTER_BACKEND_OPENCL
920
device_types:
10-
- $X_DEVICE_TYPE_ALL
21+
- $X_DEVICE_TYPE_CPU
22+
- $X_DEVICE_TYPE_GPU
23+
- $X_DEVICE_TYPE_FPGA
24+
- $X_DEVICE_TYPE_MCA
25+
- $X_DEVICE_TYPE_VPU
1126
--- #--------------------------------------------------------------------------
1227
type: manifest
1328
name: cuda
@@ -25,13 +40,21 @@ type: manifest
2540
name: level_zero
2641
backend: $X_ADAPTER_BACKEND_LEVEL_ZERO
2742
device_types:
28-
- $X_DEVICE_TYPE_ALL
43+
- $X_DEVICE_TYPE_CPU
44+
- $X_DEVICE_TYPE_GPU
45+
- $X_DEVICE_TYPE_FPGA
46+
- $X_DEVICE_TYPE_MCA
47+
- $X_DEVICE_TYPE_VPU
2948
--- #--------------------------------------------------------------------------
3049
type: manifest
3150
name: level_zero_v2
3251
backend: $X_ADAPTER_BACKEND_LEVEL_ZERO
3352
device_types:
34-
- $X_DEVICE_TYPE_ALL
53+
- $X_DEVICE_TYPE_CPU
54+
- $X_DEVICE_TYPE_GPU
55+
- $X_DEVICE_TYPE_FPGA
56+
- $X_DEVICE_TYPE_MCA
57+
- $X_DEVICE_TYPE_VPU
3558
--- #--------------------------------------------------------------------------
3659
type: manifest
3760
name: native_cpu

unified-runtime/source/adapters/level_zero/device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,8 @@ ur_result_t urDeviceGetInfo(
11191119
return ReturnValue(false);
11201120
}
11211121
case UR_DEVICE_INFO_EXTERNAL_MEMORY_IMPORT_SUPPORT_EXP: {
1122-
// L0 does not support importing external memory.
1123-
return ReturnValue(false);
1122+
// L0 supports importing external memory.
1123+
return ReturnValue(true);
11241124
}
11251125
case UR_DEVICE_INFO_EXTERNAL_SEMAPHORE_IMPORT_SUPPORT_EXP: {
11261126
return ReturnValue(Device->Platform->ZeExternalSemaphoreExt.Supported);

unified-runtime/source/adapters/level_zero/image.cpp

Lines changed: 237 additions & 87 deletions
Large diffs are not rendered by default.

unified-runtime/source/adapters/level_zero/platform.cpp

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ ur_result_t ur_platform_handle_t_::initialize() {
227227

228228
bool MutableCommandListSpecExtensionSupported = false;
229229
bool ZeIntelExternalSemaphoreExtensionSupported = false;
230+
bool ZeExternalSemaphoreExtensionSupported = false;
230231
bool ZeImmediateCommandListAppendExtensionFound = false;
231232
for (auto &extension : ZeExtensions) {
232233
// Check if global offset extension is available
@@ -267,13 +268,20 @@ ur_result_t ur_platform_handle_t_::initialize() {
267268
MutableCommandListSpecExtensionSupported = true;
268269
}
269270
}
270-
// Check if extension is available for External Sempahores
271+
// Check if extension is available for Exp External Sempahores
271272
if (strncmp(extension.name, ZE_INTEL_EXTERNAL_SEMAPHORE_EXP_NAME,
272273
strlen(ZE_INTEL_EXTERNAL_SEMAPHORE_EXP_NAME) + 1) == 0) {
273274
if (extension.version == ZE_EXTERNAL_SEMAPHORE_EXP_VERSION_1_0) {
274275
ZeIntelExternalSemaphoreExtensionSupported = true;
275276
}
276277
}
278+
// Check if extension is available for Spec External Sempahores
279+
if (strncmp(extension.name, ZE_EXTERNAL_SEMAPHORES_EXTENSION_NAME,
280+
strlen(ZE_EXTERNAL_SEMAPHORES_EXTENSION_NAME) + 1) == 0) {
281+
if (extension.version == ZE_EXTERNAL_SEMAPHORE_EXT_VERSION_1_0) {
282+
ZeExternalSemaphoreExtensionSupported = true;
283+
}
284+
}
277285
if (strncmp(extension.name, ZE_EU_COUNT_EXT_NAME,
278286
strlen(ZE_EU_COUNT_EXT_NAME) + 1) == 0) {
279287
if (extension.version == ZE_EU_COUNT_EXT_VERSION_1_0) {
@@ -323,36 +331,83 @@ ur_result_t ur_platform_handle_t_::initialize() {
323331
// If yes, then set up L0 API pointers if the platform supports it.
324332
ZeUSMImport.setZeUSMImport(this);
325333

326-
if (ZeIntelExternalSemaphoreExtensionSupported) {
334+
if (ZeExternalSemaphoreExtensionSupported) {
335+
#ifdef UR_STATIC_LEVEL_ZERO
336+
ZeExternalSemaphoreExt.zexImportExternalSemaphoreExp =
337+
zeDeviceImportExternalSemaphoreExt;
338+
ZeExternalSemaphoreExt.zexCommandListAppendWaitExternalSemaphoresExp =
339+
zeCommandListAppendWaitExternalSemaphoreExt;
340+
ZeExternalSemaphoreExt.zexCommandListAppendSignalExternalSemaphoresExp =
341+
zeCommandListAppendSignalExternalSemaphoreExt;
342+
ZeExternalSemaphoreExt.zexDeviceReleaseExternalSemaphoreExp =
343+
zeDeviceReleaseExternalSemaphoreExt;
344+
#else
345+
ZeExternalSemaphoreExt.zexImportExternalSemaphoreExp =
346+
(ze_pfnDeviceImportExternalSemaphoreExt_t)
347+
ur_loader::LibLoader::getFunctionPtr(
348+
GlobalAdapter->processHandle,
349+
"zeDeviceImportExternalSemaphoreExt");
350+
351+
ZeExternalSemaphoreExt.zexCommandListAppendWaitExternalSemaphoresExp =
352+
(ze_pfnCommandListAppendWaitExternalSemaphoreExt_t)
353+
ur_loader::LibLoader::getFunctionPtr(
354+
GlobalAdapter->processHandle,
355+
"zeCommandListAppendWaitExternalSemaphoreExt");
356+
357+
ZeExternalSemaphoreExt.zexCommandListAppendSignalExternalSemaphoresExp =
358+
(ze_pfnCommandListAppendSignalExternalSemaphoreExt_t)
359+
ur_loader::LibLoader::getFunctionPtr(
360+
GlobalAdapter->processHandle,
361+
"zeCommandListAppendSignalExternalSemaphoreExt");
362+
363+
ZeExternalSemaphoreExt.zexDeviceReleaseExternalSemaphoreExp =
364+
(ze_pfnDeviceReleaseExternalSemaphoreExt_t)
365+
ur_loader::LibLoader::getFunctionPtr(
366+
GlobalAdapter->processHandle,
367+
"zeDeviceReleaseExternalSemaphoreExt");
368+
#endif
369+
ZeExternalSemaphoreExt.Supported |=
370+
ZeExternalSemaphoreExt.zexImportExternalSemaphoreExp != nullptr;
371+
ZeExternalSemaphoreExt.Supported |=
372+
ZeExternalSemaphoreExt.zexCommandListAppendWaitExternalSemaphoresExp !=
373+
nullptr;
374+
ZeExternalSemaphoreExt.Supported |=
375+
ZeExternalSemaphoreExt
376+
.zexCommandListAppendSignalExternalSemaphoresExp != nullptr;
377+
ZeExternalSemaphoreExt.Supported |=
378+
ZeExternalSemaphoreExt.zexDeviceReleaseExternalSemaphoreExp != nullptr;
379+
ZeExternalSemaphoreExt.LoaderExtension = true;
380+
} else if (ZeIntelExternalSemaphoreExtensionSupported) {
327381
ZeExternalSemaphoreExt.Supported |=
328382
(ZE_CALL_NOCHECK(
329383
zeDriverGetExtensionFunctionAddress,
330384
(ZeDriver, "zeIntelDeviceImportExternalSemaphoreExp",
331385
reinterpret_cast<void **>(
332-
&ZeExternalSemaphoreExt.zexImportExternalSemaphoreExp))) ==
386+
&ZeExternalSemaphoreExt.zexExpImportExternalSemaphoreExp))) ==
333387
0);
334388
ZeExternalSemaphoreExt.Supported |=
335389
(ZE_CALL_NOCHECK(
336390
zeDriverGetExtensionFunctionAddress,
337391
(ZeDriver, "zeIntelCommandListAppendWaitExternalSemaphoresExp",
338392
reinterpret_cast<void **>(
339393
&ZeExternalSemaphoreExt
340-
.zexCommandListAppendWaitExternalSemaphoresExp))) == 0);
394+
.zexExpCommandListAppendWaitExternalSemaphoresExp))) ==
395+
0);
341396
ZeExternalSemaphoreExt.Supported |=
342397
(ZE_CALL_NOCHECK(
343398
zeDriverGetExtensionFunctionAddress,
344399
(ZeDriver, "zeIntelCommandListAppendSignalExternalSemaphoresExp",
345400
reinterpret_cast<void **>(
346401
&ZeExternalSemaphoreExt
347-
.zexCommandListAppendSignalExternalSemaphoresExp))) ==
402+
.zexExpCommandListAppendSignalExternalSemaphoresExp))) ==
348403
0);
349404
ZeExternalSemaphoreExt.Supported |=
350-
(ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress,
351-
(ZeDriver, "zeIntelDeviceReleaseExternalSemaphoreExp",
352-
reinterpret_cast<void **>(
353-
&ZeExternalSemaphoreExt
354-
.zexDeviceReleaseExternalSemaphoreExp))) ==
355-
0);
405+
(ZE_CALL_NOCHECK(
406+
zeDriverGetExtensionFunctionAddress,
407+
(ZeDriver, "zeIntelDeviceReleaseExternalSemaphoreExp",
408+
reinterpret_cast<void **>(
409+
&ZeExternalSemaphoreExt
410+
.zexExpDeviceReleaseExternalSemaphoreExp))) == 0);
356411
}
357412

358413
// Check if mutable command list extension is supported and initialize

unified-runtime/source/adapters/level_zero/platform.hpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,36 @@ struct ur_platform_handle_t_ : public _ur_platform {
126126
// Structure with function pointers for External Semaphore Extension.
127127
struct ZeExternalSemaphoreExtension {
128128
bool Supported = false;
129-
ze_result_t (*zexImportExternalSemaphoreExp)(
129+
// If LoaderExtension is true, the L0 loader is aware of the External
130+
// Semaphore Extension. If it is false, the extension has to be loaded
131+
// directly from the driver using zeDriverGetExtensionFunctionAddress. If it
132+
// is loaded directly from the driver, any handles passed to it must be
133+
// translated using zelLoaderTranslateHandle.
134+
bool LoaderExtension = false;
135+
// Spec Functions
136+
ze_pfnDeviceImportExternalSemaphoreExt_t zexImportExternalSemaphoreExp =
137+
nullptr;
138+
ze_pfnCommandListAppendWaitExternalSemaphoreExt_t
139+
zexCommandListAppendWaitExternalSemaphoresExp = nullptr;
140+
ze_pfnCommandListAppendSignalExternalSemaphoreExt_t
141+
zexCommandListAppendSignalExternalSemaphoresExp = nullptr;
142+
ze_pfnDeviceReleaseExternalSemaphoreExt_t
143+
zexDeviceReleaseExternalSemaphoreExp = nullptr;
144+
// Driver EXP Functions
145+
ze_result_t (*zexExpImportExternalSemaphoreExp)(
130146
ze_device_handle_t, const ze_intel_external_semaphore_exp_desc_t *,
131147
ze_intel_external_semaphore_exp_handle_t *);
132-
ze_result_t (*zexCommandListAppendWaitExternalSemaphoresExp)(
148+
ze_result_t (*zexExpCommandListAppendWaitExternalSemaphoresExp)(
133149
ze_command_list_handle_t, unsigned int,
134150
const ze_intel_external_semaphore_exp_handle_t *,
135151
const ze_intel_external_semaphore_wait_params_exp_t *,
136152
ze_event_handle_t, uint32_t, ze_event_handle_t *);
137-
ze_result_t (*zexCommandListAppendSignalExternalSemaphoresExp)(
153+
ze_result_t (*zexExpCommandListAppendSignalExternalSemaphoresExp)(
138154
ze_command_list_handle_t, size_t,
139155
const ze_intel_external_semaphore_exp_handle_t *,
140156
const ze_intel_external_semaphore_signal_params_exp_t *,
141157
ze_event_handle_t, uint32_t, ze_event_handle_t *);
142-
ze_result_t (*zexDeviceReleaseExternalSemaphoreExp)(
158+
ze_result_t (*zexExpDeviceReleaseExternalSemaphoreExp)(
143159
ze_intel_external_semaphore_exp_handle_t);
144160
} ZeExternalSemaphoreExt;
145161

unified-runtime/source/adapters/opencl/command_buffer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
3636
ur_queue_handle_t Queue = nullptr;
3737
ur_queue_properties_t QueueProperties = {UR_STRUCTURE_TYPE_QUEUE_PROPERTIES,
3838
nullptr, 0};
39-
const bool IsInOrder =
40-
pCommandBufferDesc ? pCommandBufferDesc->isInOrder : false;
39+
const bool IsInOrder = pCommandBufferDesc->isInOrder;
4140
if (!IsInOrder) {
4241
QueueProperties.flags = UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE;
4342
}

unified-runtime/source/common/ur_pool_manager.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ template <typename D, typename H> struct pool_manager {
174174
return {UR_RESULT_SUCCESS, std::move(manager)};
175175
}
176176

177-
ur_result_t addPool(const D &desc, unique_pool_handle_t &&hPool) noexcept {
177+
ur_result_t addPool(const D &desc, unique_pool_handle_t &&hPool) {
178178
if (!descToPoolMap.try_emplace(desc, std::move(hPool)).second) {
179179
logger::error("Pool for pool descriptor: {}, already exists", desc);
180180
return UR_RESULT_ERROR_INVALID_ARGUMENT;
@@ -183,7 +183,7 @@ template <typename D, typename H> struct pool_manager {
183183
return UR_RESULT_SUCCESS;
184184
}
185185

186-
std::optional<pool_handle_t> getPool(const D &desc) noexcept {
186+
std::optional<pool_handle_t> getPool(const D &desc) {
187187
auto it = descToPoolMap.find(desc);
188188
if (it == descToPoolMap.end()) {
189189
logger::error("Pool descriptor doesn't match any existing pool: {}",
@@ -193,7 +193,7 @@ template <typename D, typename H> struct pool_manager {
193193

194194
return it->second.get();
195195
}
196-
template <typename Func> void forEachPool(Func func) noexcept {
196+
template <typename Func> void forEachPool(Func func) {
197197
for (const auto &[desc, pool] : descToPoolMap) {
198198
if (!func(pool.get()))
199199
break;

unified-runtime/source/common/ur_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ inline std::optional<EnvVarMap> getenv_to_map(const char *env_var_name,
278278
if (map.find(key) != map.end()) {
279279
map[key].insert(map[key].end(), values_vec.begin(), values_vec.end());
280280
} else {
281-
map[key] = values_vec;
281+
map[key] = std::move(values_vec);
282282
}
283283
}
284284
return map;

unified-runtime/source/loader/ur_adapter_registry.hpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ namespace fs = filesystem;
2424

2525
namespace ur_loader {
2626

27+
struct ur_device_tuple {
28+
ur_adapter_backend_t backend;
29+
ur_device_type_t device;
30+
};
31+
2732
// Helper struct representing a ONEAPI_DEVICE_SELECTOR filter term.
2833
struct FilterTerm {
2934
std::string backend;
@@ -37,7 +42,7 @@ struct FilterTerm {
3742
{"native_cpu", UR_ADAPTER_BACKEND_NATIVE_CPU},
3843
};
3944

40-
bool matchesBackend(const ur_adapter_manifest &manifest) const {
45+
bool matchesBackend(const ur_adapter_backend_t &match_backend) const {
4146
if (backend.front() == '*') {
4247
return true;
4348
}
@@ -49,7 +54,7 @@ struct FilterTerm {
4954
backend);
5055
return false;
5156
}
52-
if (backendIter->second == manifest.backend) {
57+
if (backendIter->second == match_backend) {
5358
return true;
5459
}
5560
return false;
@@ -60,12 +65,7 @@ struct FilterTerm {
6065
{"gpu", UR_DEVICE_TYPE_GPU},
6166
{"fpga", UR_DEVICE_TYPE_FPGA}};
6267

63-
bool matchesDevices(const ur_adapter_manifest &manifest) const {
64-
// If the adapter can report all device types then it matches.
65-
if (std::find(manifest.device_types.begin(), manifest.device_types.end(),
66-
UR_DEVICE_TYPE_ALL) != manifest.device_types.end()) {
67-
return true;
68-
}
68+
bool matchesDevices(const ur_device_type_t &match_device) const {
6969
for (auto deviceString : devices) {
7070
// We don't have a way to determine anything about device indices or
7171
// sub-devices at this stage so just match any numeric value we get.
@@ -79,20 +79,19 @@ struct FilterTerm {
7979
deviceString);
8080
continue;
8181
}
82-
if (std::find(manifest.device_types.begin(), manifest.device_types.end(),
83-
deviceIter->second) != manifest.device_types.end()) {
82+
if (deviceIter->second == match_device) {
8483
return true;
8584
}
8685
}
8786
return false;
8887
}
8988

90-
bool matches(const ur_adapter_manifest &manifest) const {
91-
if (!matchesBackend(manifest)) {
89+
bool matches(const ur_device_tuple &device_tuple) const {
90+
if (!matchesBackend(device_tuple.backend)) {
9291
return false;
9392
}
9493

95-
return matchesDevices(manifest);
94+
return matchesDevices(device_tuple.device);
9695
}
9796
};
9897

@@ -278,24 +277,34 @@ class AdapterRegistry {
278277
[](unsigned char c) { return std::tolower(c); });
279278

280279
if (PositiveFilter) {
281-
positiveFilters.push_back({backend, termPair.second});
280+
positiveFilters.push_back({std::move(backend), termPair.second});
282281
} else {
283-
// To preserve the behaviour of the original pre-filter implementation,
284-
// we interpret all negative filters as backend only. This isn't
285-
// correct, see https://github.com/intel/llvm/issues/17086
286-
negativeFilters.push_back({backend, {"*"}});
282+
negativeFilters.push_back({std::move(backend), termPair.second});
287283
}
288284
}
289285

286+
// If ONEAPI_DEVICE_SELECTOR only specified negative filters then we
287+
// implicitly add a positive filter accepting all backends and devices.
288+
if (positiveFilters.empty()) {
289+
positiveFilters.push_back({"*", {"*"}});
290+
}
291+
290292
for (const auto &manifest : ur_adapter_manifests) {
291-
auto matchesFilter = [manifest](const FilterTerm &f) -> bool {
292-
return f.matches(manifest);
293-
};
294-
if (std::any_of(positiveFilters.begin(), positiveFilters.end(),
295-
matchesFilter) &&
296-
std::none_of(negativeFilters.begin(), negativeFilters.end(),
297-
matchesFilter)) {
298-
adapterNames.insert(manifest.library);
293+
// Check each device in the manifest.
294+
for (const auto &device : manifest.device_types) {
295+
ur_device_tuple single_device = {manifest.backend, device};
296+
297+
const auto matchesFilter =
298+
[single_device](const FilterTerm &f) -> bool {
299+
return f.matches(single_device);
300+
};
301+
302+
if (std::any_of(positiveFilters.begin(), positiveFilters.end(),
303+
matchesFilter) &&
304+
std::none_of(negativeFilters.begin(), negativeFilters.end(),
305+
matchesFilter)) {
306+
adapterNames.insert(manifest.library);
307+
}
299308
}
300309
}
301310

0 commit comments

Comments
 (0)