@@ -729,15 +729,47 @@ ur_result_t urBindlessImagesMapExternalArrayExp(
729
729
ur_result_t urBindlessImagesMapExternalLinearMemoryExp (
730
730
ur_context_handle_t hContext, ur_device_handle_t hDevice, uint64_t offset,
731
731
uint64_t size, ur_exp_external_mem_handle_t hExternalMem, void **phRetMem) {
732
- std::ignore = hContext;
733
- std::ignore = hDevice;
734
- std::ignore = size;
735
- std::ignore = offset;
736
- std::ignore = hExternalMem;
737
- std::ignore = phRetMem;
738
- logger::error (" [UR][L0] {} function not implemented!" ,
739
- " {} function not implemented!" , __FUNCTION__);
740
- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
732
+ UR_ASSERT (hContext && hDevice && hExternalMem,
733
+ UR_RESULT_ERROR_INVALID_NULL_HANDLE);
734
+ UR_ASSERT (offset && size, UR_RESULT_ERROR_INVALID_BUFFER_SIZE);
735
+
736
+ struct ur_ze_external_memory_data *externalMemoryData =
737
+ reinterpret_cast <ur_ze_external_memory_data *>(hExternalMem);
738
+ UR_ASSERT (externalMemoryData && externalMemoryData->importExtensionDesc ,
739
+ UR_RESULT_ERROR_INVALID_NULL_POINTER);
740
+
741
+ struct ur_ze_external_memory_data *mappedMemory =
742
+ new struct ur_ze_external_memory_data ;
743
+
744
+ mappedMemory->importExtensionDesc = externalMemoryData->importExtensionDesc ;
745
+ mappedMemory->type = externalMemoryData->type ;
746
+ mappedMemory->size = size;
747
+
748
+ ze_device_mem_alloc_desc_t allocDesc = {};
749
+ allocDesc.stype = ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC;
750
+ allocDesc.flags = 0 ;
751
+ allocDesc.ordinal = 0 ;
752
+
753
+ ze_result_t zeResult =
754
+ zeMemAllocDevice (hContext->ZeContext , &allocDesc, size, 1 ,
755
+ hDevice->ZeDevice , &(mappedMemory->importExtensionDesc ));
756
+ if (zeResult != ZE_RESULT_SUCCESS) {
757
+ return UR_RESULT_ERROR_OUT_OF_RESOURCES;
758
+ }
759
+
760
+ zeResult = zeContextMakeMemoryResident (hContext->ZeContext , hDevice->ZeDevice ,
761
+ mappedMemory, size);
762
+ if (zeResult != ZE_RESULT_SUCCESS) {
763
+ zeMemFree (hContext->ZeContext , mappedMemory);
764
+ return UR_RESULT_ERROR_UNKNOWN;
765
+ }
766
+ *phRetMem = reinterpret_cast <void *>(
767
+ reinterpret_cast <uintptr_t >(mappedMemory) + offset);
768
+
769
+ externalMemoryData->urMemoryHandle =
770
+ reinterpret_cast <ur_mem_handle_t >(*phRetMem);
771
+
772
+ return UR_RESULT_SUCCESS;
741
773
}
742
774
743
775
ur_result_t urBindlessImagesReleaseExternalMemoryExp (
0 commit comments