Skip to content

Commit b0e2777

Browse files
authored
[UR][L0v2] Check for external memory mapping extension before use (#21645)
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>
1 parent 008f241 commit b0e2777

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ ur_result_t ur_platform_handle_t_::initialize() {
297297
ZeLUIDSupported = true;
298298
}
299299
}
300+
if (strncmp(extension.name, ZE_EXTERNAL_MEMORY_MAPPING_EXT_NAME,
301+
strlen(ZE_EXTERNAL_MEMORY_MAPPING_EXT_NAME) + 1) == 0) {
302+
if (extension.version == ZE_EXTERNAL_MEMMAP_SYSMEM_EXT_VERSION_CURRENT) {
303+
ZeExternalMemoryMappingExtensionSupported = true;
304+
}
305+
}
300306
zeDriverExtensionMap[extension.name] = extension.version;
301307
}
302308

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct ur_platform_handle_t_ : ur::handle_base<ur::level_zero::ddi_getter>,
7474
bool ZeCopyOffloadQueueFlagSupported{false};
7575
bool ZeCopyOffloadListFlagSupported{false};
7676
bool ZeBindlessImagesExtensionSupported{false};
77+
bool ZeExternalMemoryMappingExtensionSupported{false};
7778
bool ZeLUIDSupported{false};
7879

7980
// Cache UR devices for reuse

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,10 @@ ur_result_t UR_APICALL urUSMContextMemcpyExp(ur_context_handle_t hContext,
847847
ur_result_t urUSMHostAllocRegisterExp(
848848
ur_context_handle_t hContext, void *pHostMem, size_t size,
849849
const ur_exp_usm_host_alloc_register_properties_t * /*pProperties*/) {
850+
if (!hContext->getPlatform()->ZeExternalMemoryMappingExtensionSupported) {
851+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
852+
}
853+
850854
ze_external_memmap_sysmem_ext_desc_t sysMemDesc = {
851855
ZE_STRUCTURE_TYPE_EXTERNAL_MEMMAP_SYSMEM_EXT_DESC, nullptr, pHostMem,
852856
size};
@@ -864,6 +868,10 @@ ur_result_t urUSMHostAllocRegisterExp(
864868

865869
ur_result_t urUSMHostAllocUnregisterExp(ur_context_handle_t hContext,
866870
void *pHostMem) {
871+
if (!hContext->getPlatform()->ZeExternalMemoryMappingExtensionSupported) {
872+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
873+
}
874+
867875
ZE2UR_CALL(zeMemFree, (hContext->getZeHandle(), pHostMem));
868876

869877
return UR_RESULT_SUCCESS;

unified-runtime/test/conformance/exp_usm_host_mem_register/urUSMHostMemRegister.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ struct urUSMHostMemRegisterTest : uur::urQueueTest {
4343
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urUSMHostMemRegisterTest);
4444

4545
TEST_P(urUSMHostMemRegisterTest, Success) {
46-
// https://github.com/intel/llvm/issues/21633
47-
UUR_KNOWN_FAILURE_ON(uur::LevelZeroV2{});
48-
49-
ASSERT_SUCCESS(urUSMHostAllocRegisterExp(context, alloc, allocSize, nullptr));
46+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
47+
urUSMHostAllocRegisterExp(context, alloc, allocSize, nullptr));
5048

5149
void *alloc2 = nullptr;
5250
ASSERT_SUCCESS(urUSMHostAlloc(context, nullptr, nullptr, allocSize, &alloc2));

0 commit comments

Comments
 (0)