Skip to content

Commit 4d46cd3

Browse files
committed
[UR][L0v2] Check for external memory mapping extension before use
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 46f2ff5 commit 4d46cd3

4 files changed

Lines changed: 11 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ 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+
ZeExternalMemoryMappingExtensionSupported = true;
303+
}
300304
zeDriverExtensionMap[extension.name] = extension.version;
301305
}
302306

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: 4 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};

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

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

4545
TEST_P(urUSMHostMemRegisterTest, Success) {
46-
ASSERT_SUCCESS(urUSMHostAllocRegisterExp(context, alloc, allocSize, nullptr));
46+
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
47+
urUSMHostAllocRegisterExp(context, alloc, allocSize, nullptr));
4748

4849
void *alloc2 = nullptr;
4950
ASSERT_SUCCESS(urUSMHostAlloc(context, nullptr, nullptr, allocSize, &alloc2));

0 commit comments

Comments
 (0)