Skip to content

[UR][L0v2] Check for external memory mapping extension before use#21645

Merged
againull merged 2 commits intointel:syclfrom
ldorau:URL0v2_Check_for_external_memory_mapping_extension_before_use
Apr 3, 2026
Merged

[UR][L0v2] Check for external memory mapping extension before use#21645
againull merged 2 commits intointel:syclfrom
ldorau:URL0v2_Check_for_external_memory_mapping_extension_before_use

Conversation

@ldorau
Copy link
Copy Markdown
Contributor

@ldorau ldorau commented Mar 27, 2026

urUSMHostAllocRegisterExp in the L0v2 adapter was unconditionally using
the ZE_extension_external_memmap_sysmem extension to register host
memory, causing zeMemAllocHost to return ZE_RESULT_ERROR_INVALID_ARGUMENT
on drivers that do not support this extension. This resulted in
UR_RESULT_ERROR_INVALID_VALUE being returned instead of the expected
UR_RESULT_ERROR_UNSUPPORTED_FEATURE.

Add a platform-level check for ZE_EXTERNAL_MEMORY_MAPPING_EXT_NAME
during driver extension enumeration, and return
UR_RESULT_ERROR_UNSUPPORTED_FEATURE early from urUSMHostAllocRegisterExp
when the extension is not available.

Update the conformance test to use UUR_ASSERT_SUCCESS_OR_UNSUPPORTED so
it gracefully skips when the driver does not support the extension,
rather than failing.

@ldorau ldorau requested review from a team as code owners March 27, 2026 13:42
@ldorau ldorau requested a review from kswiecicki March 27, 2026 13:43
@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented Mar 27, 2026

Please review @kswiecicki

@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented Mar 30, 2026

Please review @intel/unified-runtime-reviewers and/or @intel/unified-runtime-reviewers-level-zero

@ldorau ldorau requested a review from KFilipek March 30, 2026 11:26
@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented Mar 30, 2026

Please review @KFilipek

@ldorau ldorau force-pushed the URL0v2_Check_for_external_memory_mapping_extension_before_use branch from 4d46cd3 to 8795325 Compare March 31, 2026 12:09
@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented Mar 31, 2026

Rebased because of a merge conflict

@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented Mar 31, 2026

Please review @intel/unified-runtime-reviewers and/or @intel/unified-runtime-reviewers-level-zero

1 similar comment
@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented Apr 1, 2026

Please review @intel/unified-runtime-reviewers and/or @intel/unified-runtime-reviewers-level-zero

@ldorau ldorau requested a review from Copilot April 1, 2026 08:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Level Zero v2 USM host memory registration behavior when the external memory mapping extension is not supported by the driver, aligning the returned error code with the expected UR_RESULT_ERROR_UNSUPPORTED_FEATURE and updating the CTS to skip gracefully in that case.

Changes:

  • Add a platform-level flag indicating support for ZE_EXTERNAL_MEMORY_MAPPING_EXT_NAME during Level Zero driver extension enumeration.
  • Gate urUSMHostAllocRegisterExp in the Level Zero v2 adapter on that flag and return UR_RESULT_ERROR_UNSUPPORTED_FEATURE when unavailable.
  • Update the conformance test to accept success or unsupported feature (skip when unsupported).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
unified-runtime/source/adapters/level_zero/platform.hpp Adds a cached boolean for external memory mapping extension support.
unified-runtime/source/adapters/level_zero/platform.cpp Detects the external memory mapping extension during driver extension enumeration.
unified-runtime/source/adapters/level_zero/v2/usm.cpp Returns unsupported feature early for host memory registration when the extension is absent.
unified-runtime/test/conformance/exp_usm_host_mem_register/urUSMHostMemRegister.cpp Updates CTS to skip (not fail) when host registration is unsupported.

@ldorau ldorau force-pushed the URL0v2_Check_for_external_memory_mapping_extension_before_use branch from 8795325 to 360dd7e Compare April 1, 2026 09:41
@ldorau ldorau requested a review from Copilot April 1, 2026 09:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented Apr 1, 2026

Please review @intel/unified-runtime-reviewers and/or @intel/unified-runtime-reviewers-level-zero

ldorau added 2 commits April 1, 2026 10:26
urUSMHostAllocRegisterExp in the L0v2 adapter was unconditionally using
the ZE_extension_external_memmap_sysmem extension to register host
memory, causing zeMemAllocHost to return ZE_RESULT_ERROR_INVALID_ARGUMENT
on drivers that do not support this extension. This resulted in
UR_RESULT_ERROR_INVALID_VALUE being returned instead of the expected
UR_RESULT_ERROR_UNSUPPORTED_FEATURE.

Add a platform-level check for ZE_EXTERNAL_MEMORY_MAPPING_EXT_NAME
during driver extension enumeration, and return
UR_RESULT_ERROR_UNSUPPORTED_FEATURE early from urUSMHostAllocRegisterExp
when the extension is not available.

Update the conformance test to use UUR_ASSERT_SUCCESS_OR_UNSUPPORTED so
it gracefully skips when the driver does not support the extension,
rather than failing.

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
urUSMHostAllocUnregisterExp calls zeMemFree on a pointer that was
previously registered via urUSMHostAllocRegisterExp (which uses
zeMemAllocHost with the ZE_extension_external_memmap_sysmem extension).
If the extension is not supported and urUSMHostAllocRegisterExp returned
UR_RESULT_ERROR_UNSUPPORTED_FEATURE early, calling
urUSMHostAllocUnregisterExp on the same unregistered pointer would
invoke zeMemFree on a pointer that was never registered with the driver,
leading to undefined behaviour.

Add the same ZeExternalMemoryMappingExtensionSupported guard that
urUSMHostAllocRegisterExp already has, so both register and unregister
consistently return UR_RESULT_ERROR_UNSUPPORTED_FEATURE when the
extension is unavailable.

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

@intel/llvm-gatekeepers please consider merging

@againull againull merged commit b0e2777 into intel:sycl Apr 3, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants