Skip to content

Commit 1eccddb

Browse files
authored
[UR][L0 v2] check if copy offload is supported before requesting it (#17120)
1 parent 9164df1 commit 1eccddb

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,15 @@ ur_result_t ur_platform_handle_t_::initialize() {
276276
ZeDriverEuCountExtensionFound = true;
277277
}
278278
}
279+
if (strncmp(extension.name,
280+
ZEX_INTEL_QUEUE_COPY_OPERATIONS_OFFLOAD_HINT_EXP_NAME,
281+
strlen(ZEX_INTEL_QUEUE_COPY_OPERATIONS_OFFLOAD_HINT_EXP_NAME) +
282+
1) == 0) {
283+
if (extension.version ==
284+
ZEX_INTEL_QUEUE_COPY_OPERATIONS_OFFLOAD_HINT_EXP_VERSION_1_0) {
285+
ZeCopyOffloadExtensionSupported = true;
286+
}
287+
}
279288
zeDriverExtensionMap[extension.name] = extension.version;
280289
}
281290

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct ur_platform_handle_t_ : public _ur_platform {
6262
bool ZeDriverEventPoolCountingEventsExtensionFound{false};
6363
bool zeDriverImmediateCommandListAppendFound{false};
6464
bool ZeDriverEuCountExtensionFound{false};
65+
bool ZeCopyOffloadExtensionSupported{false};
6566

6667
// Cache UR devices for reuse
6768
std::vector<std::unique_ptr<ur_device_handle_t_>> URDevicesCache;

unified-runtime/source/adapters/level_zero/v2/command_list_cache.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,25 @@ inline size_t command_list_descriptor_hash_t::operator()(
4646
}
4747
}
4848

49-
command_list_cache_t::command_list_cache_t(ze_context_handle_t ZeContext)
50-
: ZeContext{ZeContext} {}
49+
command_list_cache_t::command_list_cache_t(ze_context_handle_t ZeContext,
50+
bool ZeCopyOffloadExtensionSupported)
51+
: ZeContext{ZeContext},
52+
ZeCopyOffloadExtensionSupported{ZeCopyOffloadExtensionSupported} {}
5153

5254
raii::ze_command_list_handle_t
5355
command_list_cache_t::createCommandList(const command_list_descriptor_t &desc) {
5456
ZeStruct<zex_intel_queue_copy_operations_offload_hint_exp_desc_t> offloadDesc;
55-
offloadDesc.copyOffloadEnabled =
57+
auto requestedCopyOffload =
5658
std::visit([](auto &&arg) { return arg.CopyOffloadEnabled; }, desc);
5759

60+
if (!ZeCopyOffloadExtensionSupported && requestedCopyOffload) {
61+
logger::info(
62+
"Copy offload is requested but is not supported by the driver.");
63+
offloadDesc.copyOffloadEnabled = false;
64+
} else {
65+
offloadDesc.copyOffloadEnabled = requestedCopyOffload;
66+
}
67+
5868
if (auto ImmCmdDesc =
5969
std::get_if<immediate_command_list_descriptor_t>(&desc)) {
6070
ze_command_list_handle_t ZeCommandList;

unified-runtime/source/adapters/level_zero/v2/command_list_cache.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ struct command_list_descriptor_hash_t {
5454
};
5555

5656
struct command_list_cache_t {
57-
command_list_cache_t(ze_context_handle_t ZeContext);
57+
command_list_cache_t(ze_context_handle_t ZeContext,
58+
bool ZeCopyOffloadExtensionSupported);
5859

5960
raii::command_list_unique_handle
6061
getImmediateCommandList(ze_device_handle_t ZeDevice, bool IsInOrder,
@@ -72,6 +73,7 @@ struct command_list_cache_t {
7273

7374
private:
7475
ze_context_handle_t ZeContext;
76+
bool ZeCopyOffloadExtensionSupported;
7577
std::unordered_map<command_list_descriptor_t,
7678
std::stack<raii::ze_command_list_handle_t>,
7779
command_list_descriptor_hash_t>

unified-runtime/source/adapters/level_zero/v2/context.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ ur_context_handle_t_::ur_context_handle_t_(ze_context_handle_t hContext,
4949
const ur_device_handle_t *phDevices,
5050
bool ownZeContext)
5151
: hContext(hContext, ownZeContext),
52-
hDevices(phDevices, phDevices + numDevices), commandListCache(hContext),
52+
hDevices(phDevices, phDevices + numDevices),
53+
commandListCache(hContext,
54+
phDevices[0]->Platform->ZeCopyOffloadExtensionSupported),
5355
eventPoolCache(this, phDevices[0]->Platform->getNumDevices(),
5456
[context = this, platform = phDevices[0]->Platform](
5557
DeviceId deviceId, v2::event_flags_t flags)

unified-runtime/test/adapters/level_zero/v2/command_list_cache_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct CommandListCacheTest : public uur::urContextTest {};
2424
UUR_INSTANTIATE_DEVICE_TEST_SUITE(CommandListCacheTest);
2525

2626
TEST_P(CommandListCacheTest, CanStoreAndRetriveImmediateAndRegularCmdLists) {
27-
v2::command_list_cache_t cache(context->getZeHandle());
27+
v2::command_list_cache_t cache(context->getZeHandle(), false);
2828

2929
bool IsInOrder = false;
3030
uint32_t Ordinal = 0;
@@ -76,7 +76,7 @@ TEST_P(CommandListCacheTest, CanStoreAndRetriveImmediateAndRegularCmdLists) {
7676
}
7777

7878
TEST_P(CommandListCacheTest, ImmediateCommandListsHaveProperAttributes) {
79-
v2::command_list_cache_t cache(context->getZeHandle());
79+
v2::command_list_cache_t cache(context->getZeHandle(), false);
8080

8181
uint32_t numQueueGroups = 0;
8282
ASSERT_EQ(zeDeviceGetCommandQueueGroupProperties(device->ZeDevice,

0 commit comments

Comments
 (0)