Skip to content

[UR][L0 v2] check if copy offload is supported before requesting it #17120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions unified-runtime/source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ ur_result_t ur_platform_handle_t_::initialize() {
ZeDriverEuCountExtensionFound = true;
}
}
if (strncmp(extension.name,
ZEX_INTEL_QUEUE_COPY_OPERATIONS_OFFLOAD_HINT_EXP_NAME,
strlen(ZEX_INTEL_QUEUE_COPY_OPERATIONS_OFFLOAD_HINT_EXP_NAME) +
1) == 0) {
if (extension.version ==
ZEX_INTEL_QUEUE_COPY_OPERATIONS_OFFLOAD_HINT_EXP_VERSION_1_0) {
ZeCopyOffloadExtensionSupported = true;
}
}
zeDriverExtensionMap[extension.name] = extension.version;
}

Expand Down
1 change: 1 addition & 0 deletions unified-runtime/source/adapters/level_zero/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct ur_platform_handle_t_ : public _ur_platform {
bool ZeDriverEventPoolCountingEventsExtensionFound{false};
bool zeDriverImmediateCommandListAppendFound{false};
bool ZeDriverEuCountExtensionFound{false};
bool ZeCopyOffloadExtensionSupported{false};

// Cache UR devices for reuse
std::vector<std::unique_ptr<ur_device_handle_t_>> URDevicesCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,25 @@ inline size_t command_list_descriptor_hash_t::operator()(
}
}

command_list_cache_t::command_list_cache_t(ze_context_handle_t ZeContext)
: ZeContext{ZeContext} {}
command_list_cache_t::command_list_cache_t(ze_context_handle_t ZeContext,
bool ZeCopyOffloadExtensionSupported)
: ZeContext{ZeContext},
ZeCopyOffloadExtensionSupported{ZeCopyOffloadExtensionSupported} {}

raii::ze_command_list_handle_t
command_list_cache_t::createCommandList(const command_list_descriptor_t &desc) {
ZeStruct<zex_intel_queue_copy_operations_offload_hint_exp_desc_t> offloadDesc;
offloadDesc.copyOffloadEnabled =
auto requestedCopyOffload =
std::visit([](auto &&arg) { return arg.CopyOffloadEnabled; }, desc);

if (!ZeCopyOffloadExtensionSupported && requestedCopyOffload) {
logger::info(
"Copy offload is requested but is not supported by the driver.");
offloadDesc.copyOffloadEnabled = false;
} else {
offloadDesc.copyOffloadEnabled = requestedCopyOffload;
}

if (auto ImmCmdDesc =
std::get_if<immediate_command_list_descriptor_t>(&desc)) {
ze_command_list_handle_t ZeCommandList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ struct command_list_descriptor_hash_t {
};

struct command_list_cache_t {
command_list_cache_t(ze_context_handle_t ZeContext);
command_list_cache_t(ze_context_handle_t ZeContext,
bool ZeCopyOffloadExtensionSupported);

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

private:
ze_context_handle_t ZeContext;
bool ZeCopyOffloadExtensionSupported;
std::unordered_map<command_list_descriptor_t,
std::stack<raii::ze_command_list_handle_t>,
command_list_descriptor_hash_t>
Expand Down
4 changes: 3 additions & 1 deletion unified-runtime/source/adapters/level_zero/v2/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ ur_context_handle_t_::ur_context_handle_t_(ze_context_handle_t hContext,
const ur_device_handle_t *phDevices,
bool ownZeContext)
: hContext(hContext, ownZeContext),
hDevices(phDevices, phDevices + numDevices), commandListCache(hContext),
hDevices(phDevices, phDevices + numDevices),
commandListCache(hContext,
phDevices[0]->Platform->ZeCopyOffloadExtensionSupported),
eventPoolCache(this, phDevices[0]->Platform->getNumDevices(),
[context = this, platform = phDevices[0]->Platform](
DeviceId deviceId, v2::event_flags_t flags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct CommandListCacheTest : public uur::urContextTest {};
UUR_INSTANTIATE_DEVICE_TEST_SUITE(CommandListCacheTest);

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

bool IsInOrder = false;
uint32_t Ordinal = 0;
Expand Down Expand Up @@ -76,7 +76,7 @@ TEST_P(CommandListCacheTest, CanStoreAndRetriveImmediateAndRegularCmdLists) {
}

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

uint32_t numQueueGroups = 0;
ASSERT_EQ(zeDeviceGetCommandQueueGroupProperties(device->ZeDevice,
Expand Down
Loading