diff --git a/include/ur_api.h b/include/ur_api.h index 8dd757afd2..86f9ceec36 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -227,6 +227,7 @@ typedef enum ur_function_t { UR_FUNCTION_ENQUEUE_NATIVE_COMMAND_EXP = 228, ///< Enumerator for ::urEnqueueNativeCommandExp UR_FUNCTION_LOADER_CONFIG_SET_MOCKING_ENABLED = 229, ///< Enumerator for ::urLoaderConfigSetMockingEnabled UR_FUNCTION_BINDLESS_IMAGES_RELEASE_EXTERNAL_MEMORY_EXP = 230, ///< Enumerator for ::urBindlessImagesReleaseExternalMemoryExp + UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP = 231, ///< Enumerator for ::urBindlessImagesMapExternalLinearMemoryExp /// @cond UR_FUNCTION_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -7962,6 +7963,36 @@ urBindlessImagesMapExternalArrayExp( ur_exp_image_mem_native_handle_t *phImageMem ///< [out] image memory handle to the externally allocated memory ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Map an external memory handle to a device memory region described by +/// void* +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hContext` +/// + `NULL == hDevice` +/// + `NULL == hExternalMem` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppRetMem` +/// - ::UR_RESULT_ERROR_INVALID_CONTEXT +/// - ::UR_RESULT_ERROR_INVALID_VALUE +/// - ::UR_RESULT_ERROR_INVALID_IMAGE_SIZE +/// - ::UR_RESULT_ERROR_INVALID_OPERATION +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +UR_APIEXPORT ur_result_t UR_APICALL +urBindlessImagesMapExternalLinearMemoryExp( + ur_context_handle_t hContext, ///< [in] handle of the context object + ur_device_handle_t hDevice, ///< [in] handle of the device object + uint64_t offset, ///< [in] offset into memory region to map + uint64_t size, ///< [in] size of memory region to map + ur_exp_external_mem_handle_t hExternalMem, ///< [in] external memory handle to the external memory + void **ppRetMem ///< [out] pointer of the externally allocated memory +); + /////////////////////////////////////////////////////////////////////////////// /// @brief Release external memory /// @@ -11231,6 +11262,19 @@ typedef struct ur_bindless_images_map_external_array_exp_params_t { ur_exp_image_mem_native_handle_t **pphImageMem; } ur_bindless_images_map_external_array_exp_params_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urBindlessImagesMapExternalLinearMemoryExp +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_bindless_images_map_external_linear_memory_exp_params_t { + ur_context_handle_t *phContext; + ur_device_handle_t *phDevice; + uint64_t *poffset; + uint64_t *psize; + ur_exp_external_mem_handle_t *phExternalMem; + void ***pppRetMem; +} ur_bindless_images_map_external_linear_memory_exp_params_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Function parameters for urBindlessImagesReleaseExternalMemoryExp /// @details Each entry is a pointer to the parameter passed to the function; diff --git a/include/ur_ddi.h b/include/ur_ddi.h index ac47d7559f..66d072c331 100644 --- a/include/ur_ddi.h +++ b/include/ur_ddi.h @@ -1639,6 +1639,16 @@ typedef ur_result_t(UR_APICALL *ur_pfnBindlessImagesMapExternalArrayExp_t)( ur_exp_external_mem_handle_t, ur_exp_image_mem_native_handle_t *); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urBindlessImagesMapExternalLinearMemoryExp +typedef ur_result_t(UR_APICALL *ur_pfnBindlessImagesMapExternalLinearMemoryExp_t)( + ur_context_handle_t, + ur_device_handle_t, + uint64_t, + uint64_t, + ur_exp_external_mem_handle_t, + void **); + /////////////////////////////////////////////////////////////////////////////// /// @brief Function-pointer for urBindlessImagesReleaseExternalMemoryExp typedef ur_result_t(UR_APICALL *ur_pfnBindlessImagesReleaseExternalMemoryExp_t)( @@ -1699,6 +1709,7 @@ typedef struct ur_bindless_images_exp_dditable_t { ur_pfnBindlessImagesMipmapFreeExp_t pfnMipmapFreeExp; ur_pfnBindlessImagesImportExternalMemoryExp_t pfnImportExternalMemoryExp; ur_pfnBindlessImagesMapExternalArrayExp_t pfnMapExternalArrayExp; + ur_pfnBindlessImagesMapExternalLinearMemoryExp_t pfnMapExternalLinearMemoryExp; ur_pfnBindlessImagesReleaseExternalMemoryExp_t pfnReleaseExternalMemoryExp; ur_pfnBindlessImagesImportExternalSemaphoreExp_t pfnImportExternalSemaphoreExp; ur_pfnBindlessImagesReleaseExternalSemaphoreExp_t pfnReleaseExternalSemaphoreExp; diff --git a/include/ur_print.h b/include/ur_print.h index a3a915827b..c70e661fb1 100644 --- a/include/ur_print.h +++ b/include/ur_print.h @@ -2146,6 +2146,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urPrintBindlessImagesImportExternalMemoryExp /// - `buff_size < out_size` UR_APIEXPORT ur_result_t UR_APICALL urPrintBindlessImagesMapExternalArrayExpParams(const struct ur_bindless_images_map_external_array_exp_params_t *params, char *buffer, const size_t buff_size, size_t *out_size); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_bindless_images_map_external_linear_memory_exp_params_t struct +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// - `buff_size < out_size` +UR_APIEXPORT ur_result_t UR_APICALL urPrintBindlessImagesMapExternalLinearMemoryExpParams(const struct ur_bindless_images_map_external_linear_memory_exp_params_t *params, char *buffer, const size_t buff_size, size_t *out_size); + /////////////////////////////////////////////////////////////////////////////// /// @brief Print ur_bindless_images_release_external_memory_exp_params_t struct /// @returns diff --git a/include/ur_print.hpp b/include/ur_print.hpp index d8ac521bdc..487f73533e 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -942,6 +942,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) { case UR_FUNCTION_BINDLESS_IMAGES_RELEASE_EXTERNAL_MEMORY_EXP: os << "UR_FUNCTION_BINDLESS_IMAGES_RELEASE_EXTERNAL_MEMORY_EXP"; break; + case UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP: + os << "UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP"; + break; default: os << "unknown enumerator"; break; @@ -15190,6 +15193,48 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct return os; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ur_bindless_images_map_external_linear_memory_exp_params_t type +/// @returns +/// std::ostream & +inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct ur_bindless_images_map_external_linear_memory_exp_params_t *params) { + + os << ".hContext = "; + + ur::details::printPtr(os, + *(params->phContext)); + + os << ", "; + os << ".hDevice = "; + + ur::details::printPtr(os, + *(params->phDevice)); + + os << ", "; + os << ".offset = "; + + os << *(params->poffset); + + os << ", "; + os << ".size = "; + + os << *(params->psize); + + os << ", "; + os << ".hExternalMem = "; + + ur::details::printPtr(os, + *(params->phExternalMem)); + + os << ", "; + os << ".ppRetMem = "; + + ur::details::printPtr(os, + *(params->pppRetMem)); + + return os; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Print operator for the ur_bindless_images_release_external_memory_exp_params_t type /// @returns @@ -17804,6 +17849,9 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os, ur_function_ case UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_ARRAY_EXP: { os << (const struct ur_bindless_images_map_external_array_exp_params_t *)params; } break; + case UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP: { + os << (const struct ur_bindless_images_map_external_linear_memory_exp_params_t *)params; + } break; case UR_FUNCTION_BINDLESS_IMAGES_RELEASE_EXTERNAL_MEMORY_EXP: { os << (const struct ur_bindless_images_release_external_memory_exp_params_t *)params; } break; diff --git a/scripts/core/EXP-BINDLESS-IMAGES.rst b/scripts/core/EXP-BINDLESS-IMAGES.rst index 398d3ba06c..c2b3d1114e 100644 --- a/scripts/core/EXP-BINDLESS-IMAGES.rst +++ b/scripts/core/EXP-BINDLESS-IMAGES.rst @@ -181,6 +181,7 @@ Functions * Interop * ${x}BindlessImagesImportExternalMemoryExp * ${x}BindlessImagesMapExternalArrayExp + * ${x}BindlessImagesMapExternalLinearMemoryExp * ${x}BindlessImagesReleaseExternalMemoryExp * ${x}BindlessImagesImportExternalSemaphoreExp * ${x}BindlessImagesReleaseExternalSemaphoreExp @@ -250,6 +251,8 @@ Changelog | 17.0 || Rename interop related structs and funcs with "external" | | || keyword over "interop". | +----------+-------------------------------------------------------------+ +| 18.0 | Added BindlessImagesMapExternalLinearMemoryExp function. | ++----------+-------------------------------------------------------------+ Contributors -------------------------------------------------------------------------------- diff --git a/scripts/core/exp-bindless-images.yml b/scripts/core/exp-bindless-images.yml index 52cd754644..d78583ac39 100644 --- a/scripts/core/exp-bindless-images.yml +++ b/scripts/core/exp-bindless-images.yml @@ -737,6 +737,37 @@ returns: - $X_RESULT_ERROR_OUT_OF_RESOURCES --- #-------------------------------------------------------------------------- type: function +desc: "Map an external memory handle to a device memory region described by void*" +class: $xBindlessImages +name: MapExternalLinearMemoryExp +ordinal: "0" +params: + - type: $x_context_handle_t + name: hContext + desc: "[in] handle of the context object" + - type: $x_device_handle_t + name: hDevice + desc: "[in] handle of the device object" + - type: uint64_t + name: offset + desc: "[in] offset into memory region to map" + - type: uint64_t + name: size + desc: "[in] size of memory region to map" + - type: $x_exp_external_mem_handle_t + name: hExternalMem + desc: "[in] external memory handle to the external memory" + - type: void** + name: ppRetMem + desc: "[out] pointer of the externally allocated memory" +returns: + - $X_RESULT_ERROR_INVALID_CONTEXT + - $X_RESULT_ERROR_INVALID_VALUE + - $X_RESULT_ERROR_INVALID_IMAGE_SIZE + - $X_RESULT_ERROR_INVALID_OPERATION + - $X_RESULT_ERROR_OUT_OF_RESOURCES +--- #-------------------------------------------------------------------------- +type: function desc: "Release external memory" class: $xBindlessImages name: ReleaseExternalMemoryExp diff --git a/scripts/core/registry.yml b/scripts/core/registry.yml index d80c56b500..ab59404bb4 100644 --- a/scripts/core/registry.yml +++ b/scripts/core/registry.yml @@ -595,6 +595,9 @@ etors: - name: BINDLESS_IMAGES_RELEASE_EXTERNAL_MEMORY_EXP desc: Enumerator for $xBindlessImagesReleaseExternalMemoryExp value: '230' +- name: BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP + desc: Enumerator for $xBindlessImagesMapExternalLinearMemoryExp + value: '231' --- type: enum desc: Defines structure types diff --git a/source/adapters/cuda/image.cpp b/source/adapters/cuda/image.cpp index 58ee98184d..2b3d3ad667 100644 --- a/source/adapters/cuda/image.cpp +++ b/source/adapters/cuda/image.cpp @@ -1169,6 +1169,36 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return UR_RESULT_SUCCESS; } +UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + ur_context_handle_t hContext, ur_device_handle_t hDevice, uint64_t offset, + uint64_t size, ur_exp_external_mem_handle_t hExternalMem, void **ppRetMem) { + UR_ASSERT(std::find(hContext->getDevices().begin(), + hContext->getDevices().end(), + hDevice) != hContext->getDevices().end(), + UR_RESULT_ERROR_INVALID_CONTEXT); + + try { + ScopedContext Active(hDevice); + + CUDA_EXTERNAL_MEMORY_BUFFER_DESC BufferDesc = {}; + BufferDesc.size = size; + BufferDesc.offset = offset; + BufferDesc.flags = 0; + + CUdeviceptr retMem; + UR_CHECK_ERROR(cuExternalMemoryGetMappedBuffer( + &retMem, (CUexternalMemory)hExternalMem, &BufferDesc)); + + *ppRetMem = (void *)retMem; + + } catch (ur_result_t Err) { + return Err; + } catch (...) { + return UR_RESULT_ERROR_UNKNOWN; + } + return UR_RESULT_SUCCESS; +} + UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesReleaseExternalMemoryExp( ur_context_handle_t hContext, ur_device_handle_t hDevice, ur_exp_external_mem_handle_t hExternalMem) { diff --git a/source/adapters/cuda/ur_interface_loader.cpp b/source/adapters/cuda/ur_interface_loader.cpp index 2e01a4b7a3..bb3fb9aee5 100644 --- a/source/adapters/cuda/ur_interface_loader.cpp +++ b/source/adapters/cuda/ur_interface_loader.cpp @@ -340,6 +340,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetBindlessImagesExpProcAddrTable( pDdiTable->pfnImportExternalMemoryExp = urBindlessImagesImportExternalMemoryExp; pDdiTable->pfnMapExternalArrayExp = urBindlessImagesMapExternalArrayExp; + pDdiTable->pfnMapExternalLinearMemoryExp = + urBindlessImagesMapExternalLinearMemoryExp; pDdiTable->pfnReleaseExternalMemoryExp = urBindlessImagesReleaseExternalMemoryExp; pDdiTable->pfnImportExternalSemaphoreExp = diff --git a/source/adapters/hip/image.cpp b/source/adapters/hip/image.cpp index 75f93ca4f3..7449c3ba3f 100644 --- a/source/adapters/hip/image.cpp +++ b/source/adapters/hip/image.cpp @@ -132,6 +132,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } +UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + [[maybe_unused]] ur_context_handle_t hContext, + [[maybe_unused]] ur_device_handle_t hDevice, + [[maybe_unused]] uint64_t offset, [[maybe_unused]] uint64_t size, + [[maybe_unused]] ur_exp_external_mem_handle_t hExternalMem, + [[maybe_unused]] void **phRetMem) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesReleaseExternalMemoryExp( [[maybe_unused]] ur_context_handle_t hContext, [[maybe_unused]] ur_device_handle_t hDevice, diff --git a/source/adapters/level_zero/image.cpp b/source/adapters/level_zero/image.cpp index 1537a1d201..61ff5a98f0 100644 --- a/source/adapters/level_zero/image.cpp +++ b/source/adapters/level_zero/image.cpp @@ -1083,6 +1083,20 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return UR_RESULT_SUCCESS; } +UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + ur_context_handle_t hContext, ur_device_handle_t hDevice, uint64_t offset, + uint64_t size, ur_exp_external_mem_handle_t hExternalMem, void **phRetMem) { + std::ignore = hContext; + std::ignore = hDevice; + std::ignore = size; + std::ignore = offset; + std::ignore = hExternalMem; + std::ignore = phRetMem; + logger::error("[UR][L0] {} function not implemented!", + "{} function not implemented!", __FUNCTION__); + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesReleaseExternalMemoryExp( ur_context_handle_t hContext, ur_device_handle_t hDevice, ur_exp_external_mem_handle_t hExternalMem) { diff --git a/source/adapters/level_zero/ur_interface_loader.cpp b/source/adapters/level_zero/ur_interface_loader.cpp index 939a625122..8941f756ea 100644 --- a/source/adapters/level_zero/ur_interface_loader.cpp +++ b/source/adapters/level_zero/ur_interface_loader.cpp @@ -387,6 +387,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetBindlessImagesExpProcAddrTable( pDdiTable->pfnImportExternalMemoryExp = urBindlessImagesImportExternalMemoryExp; pDdiTable->pfnMapExternalArrayExp = urBindlessImagesMapExternalArrayExp; + pDdiTable->pfnMapExternalLinearMemoryExp = + urBindlessImagesMapExternalLinearMemoryExp; pDdiTable->pfnReleaseExternalMemoryExp = urBindlessImagesReleaseExternalMemoryExp; pDdiTable->pfnImportExternalSemaphoreExp = diff --git a/source/adapters/mock/ur_mockddi.cpp b/source/adapters/mock/ur_mockddi.cpp index 1f42e5dbbe..6f19df7581 100644 --- a/source/adapters/mock/ur_mockddi.cpp +++ b/source/adapters/mock/ur_mockddi.cpp @@ -7805,6 +7805,58 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return exceptionToResult(std::current_exception()); } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urBindlessImagesMapExternalLinearMemoryExp +__urdlllocal ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + ur_context_handle_t hContext, ///< [in] handle of the context object + ur_device_handle_t hDevice, ///< [in] handle of the device object + uint64_t offset, ///< [in] offset into memory region to map + uint64_t size, ///< [in] size of memory region to map + ur_exp_external_mem_handle_t + hExternalMem, ///< [in] external memory handle to the external memory + void **ppRetMem ///< [out] pointer of the externally allocated memory + ) try { + ur_result_t result = UR_RESULT_SUCCESS; + + ur_bindless_images_map_external_linear_memory_exp_params_t params = { + &hContext, &hDevice, &offset, &size, &hExternalMem, &ppRetMem}; + + auto beforeCallback = reinterpret_cast( + mock::getCallbacks().get_before_callback( + "urBindlessImagesMapExternalLinearMemoryExp")); + if (beforeCallback) { + result = beforeCallback(¶ms); + if (result != UR_RESULT_SUCCESS) { + return result; + } + } + + auto replaceCallback = reinterpret_cast( + mock::getCallbacks().get_replace_callback( + "urBindlessImagesMapExternalLinearMemoryExp")); + if (replaceCallback) { + result = replaceCallback(¶ms); + } else { + + result = UR_RESULT_SUCCESS; + } + + if (result != UR_RESULT_SUCCESS) { + return result; + } + + auto afterCallback = reinterpret_cast( + mock::getCallbacks().get_after_callback( + "urBindlessImagesMapExternalLinearMemoryExp")); + if (afterCallback) { + return afterCallback(¶ms); + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urBindlessImagesReleaseExternalMemoryExp __urdlllocal ur_result_t UR_APICALL urBindlessImagesReleaseExternalMemoryExp( @@ -10272,6 +10324,9 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetBindlessImagesExpProcAddrTable( pDdiTable->pfnMapExternalArrayExp = driver::urBindlessImagesMapExternalArrayExp; + pDdiTable->pfnMapExternalLinearMemoryExp = + driver::urBindlessImagesMapExternalLinearMemoryExp; + pDdiTable->pfnReleaseExternalMemoryExp = driver::urBindlessImagesReleaseExternalMemoryExp; diff --git a/source/adapters/native_cpu/image.cpp b/source/adapters/native_cpu/image.cpp index a1b862ad9f..d89990ed10 100644 --- a/source/adapters/native_cpu/image.cpp +++ b/source/adapters/native_cpu/image.cpp @@ -132,6 +132,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } +UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + [[maybe_unused]] ur_context_handle_t hContext, + [[maybe_unused]] ur_device_handle_t hDevice, + [[maybe_unused]] uint64_t offset, [[maybe_unused]] uint64_t size, + [[maybe_unused]] ur_exp_external_mem_handle_t hExternalMem, + [[maybe_unused]] void **phRetMem) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesReleaseExternalMemoryExp( [[maybe_unused]] ur_context_handle_t hContext, [[maybe_unused]] ur_device_handle_t hDevice, diff --git a/source/adapters/native_cpu/ur_interface_loader.cpp b/source/adapters/native_cpu/ur_interface_loader.cpp index 7b5f1b923d..ff6c9d8c0f 100644 --- a/source/adapters/native_cpu/ur_interface_loader.cpp +++ b/source/adapters/native_cpu/ur_interface_loader.cpp @@ -329,6 +329,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetBindlessImagesExpProcAddrTable( pDdiTable->pfnImportExternalMemoryExp = urBindlessImagesImportExternalMemoryExp; pDdiTable->pfnMapExternalArrayExp = urBindlessImagesMapExternalArrayExp; + pDdiTable->pfnMapExternalLinearMemoryExp = + urBindlessImagesMapExternalLinearMemoryExp; pDdiTable->pfnReleaseExternalMemoryExp = urBindlessImagesReleaseExternalMemoryExp; pDdiTable->pfnImportExternalSemaphoreExp = diff --git a/source/adapters/opencl/image.cpp b/source/adapters/opencl/image.cpp index c33bb57b0f..0c628594bb 100644 --- a/source/adapters/opencl/image.cpp +++ b/source/adapters/opencl/image.cpp @@ -132,6 +132,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } +UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + [[maybe_unused]] ur_context_handle_t hContext, + [[maybe_unused]] ur_device_handle_t hDevice, + [[maybe_unused]] uint64_t offset, [[maybe_unused]] uint64_t size, + [[maybe_unused]] ur_exp_external_mem_handle_t hExternalMem, + [[maybe_unused]] void **phRetMem) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesReleaseExternalMemoryExp( [[maybe_unused]] ur_context_handle_t hContext, [[maybe_unused]] ur_device_handle_t hDevice, diff --git a/source/adapters/opencl/ur_interface_loader.cpp b/source/adapters/opencl/ur_interface_loader.cpp index 171c561c28..100bb888cf 100644 --- a/source/adapters/opencl/ur_interface_loader.cpp +++ b/source/adapters/opencl/ur_interface_loader.cpp @@ -347,6 +347,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetBindlessImagesExpProcAddrTable( pDdiTable->pfnImportExternalMemoryExp = urBindlessImagesImportExternalMemoryExp; pDdiTable->pfnMapExternalArrayExp = urBindlessImagesMapExternalArrayExp; + pDdiTable->pfnMapExternalLinearMemoryExp = + urBindlessImagesMapExternalLinearMemoryExp; pDdiTable->pfnReleaseExternalMemoryExp = urBindlessImagesReleaseExternalMemoryExp; pDdiTable->pfnImportExternalSemaphoreExp = diff --git a/source/loader/layers/tracing/ur_trcddi.cpp b/source/loader/layers/tracing/ur_trcddi.cpp index 315be97531..83ef28a3e8 100644 --- a/source/loader/layers/tracing/ur_trcddi.cpp +++ b/source/loader/layers/tracing/ur_trcddi.cpp @@ -6048,6 +6048,51 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urBindlessImagesMapExternalLinearMemoryExp +__urdlllocal ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + ur_context_handle_t hContext, ///< [in] handle of the context object + ur_device_handle_t hDevice, ///< [in] handle of the device object + uint64_t offset, ///< [in] offset into memory region to map + uint64_t size, ///< [in] size of memory region to map + ur_exp_external_mem_handle_t + hExternalMem, ///< [in] external memory handle to the external memory + void **ppRetMem ///< [out] pointer of the externally allocated memory +) { + auto pfnMapExternalLinearMemoryExp = + getContext() + ->urDdiTable.BindlessImagesExp.pfnMapExternalLinearMemoryExp; + + if (nullptr == pfnMapExternalLinearMemoryExp) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ur_bindless_images_map_external_linear_memory_exp_params_t params = { + &hContext, &hDevice, &offset, &size, &hExternalMem, &ppRetMem}; + uint64_t instance = getContext()->notify_begin( + UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP, + "urBindlessImagesMapExternalLinearMemoryExp", ¶ms); + + getContext()->logger.info( + "---> urBindlessImagesMapExternalLinearMemoryExp"); + + ur_result_t result = pfnMapExternalLinearMemoryExp( + hContext, hDevice, offset, size, hExternalMem, ppRetMem); + + getContext()->notify_end( + UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP, + "urBindlessImagesMapExternalLinearMemoryExp", ¶ms, &result, + instance); + + std::ostringstream args_str; + ur::extras::printFunctionParams( + args_str, UR_FUNCTION_BINDLESS_IMAGES_MAP_EXTERNAL_LINEAR_MEMORY_EXP, + ¶ms); + getContext()->logger.info("({}) -> {};\n", args_str.str(), result); + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urBindlessImagesReleaseExternalMemoryExp __urdlllocal ur_result_t UR_APICALL urBindlessImagesReleaseExternalMemoryExp( @@ -8126,6 +8171,11 @@ __urdlllocal ur_result_t UR_APICALL urGetBindlessImagesExpProcAddrTable( pDdiTable->pfnMapExternalArrayExp = ur_tracing_layer::urBindlessImagesMapExternalArrayExp; + dditable.pfnMapExternalLinearMemoryExp = + pDdiTable->pfnMapExternalLinearMemoryExp; + pDdiTable->pfnMapExternalLinearMemoryExp = + ur_tracing_layer::urBindlessImagesMapExternalLinearMemoryExp; + dditable.pfnReleaseExternalMemoryExp = pDdiTable->pfnReleaseExternalMemoryExp; pDdiTable->pfnReleaseExternalMemoryExp = diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index 8539951293..2b5b99c7d8 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -7549,6 +7549,59 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urBindlessImagesMapExternalLinearMemoryExp +__urdlllocal ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + ur_context_handle_t hContext, ///< [in] handle of the context object + ur_device_handle_t hDevice, ///< [in] handle of the device object + uint64_t offset, ///< [in] offset into memory region to map + uint64_t size, ///< [in] size of memory region to map + ur_exp_external_mem_handle_t + hExternalMem, ///< [in] external memory handle to the external memory + void **ppRetMem ///< [out] pointer of the externally allocated memory +) { + auto pfnMapExternalLinearMemoryExp = + getContext() + ->urDdiTable.BindlessImagesExp.pfnMapExternalLinearMemoryExp; + + if (nullptr == pfnMapExternalLinearMemoryExp) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + if (getContext()->enableParameterValidation) { + if (NULL == hContext) { + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (NULL == hDevice) { + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (NULL == hExternalMem) { + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + } + + if (NULL == ppRetMem) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(hContext)) { + getContext()->refCountContext->logInvalidReference(hContext); + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(hDevice)) { + getContext()->refCountContext->logInvalidReference(hDevice); + } + + ur_result_t result = pfnMapExternalLinearMemoryExp( + hContext, hDevice, offset, size, hExternalMem, ppRetMem); + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urBindlessImagesReleaseExternalMemoryExp __urdlllocal ur_result_t UR_APICALL urBindlessImagesReleaseExternalMemoryExp( @@ -9751,6 +9804,11 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetBindlessImagesExpProcAddrTable( pDdiTable->pfnMapExternalArrayExp = ur_validation_layer::urBindlessImagesMapExternalArrayExp; + dditable.pfnMapExternalLinearMemoryExp = + pDdiTable->pfnMapExternalLinearMemoryExp; + pDdiTable->pfnMapExternalLinearMemoryExp = + ur_validation_layer::urBindlessImagesMapExternalLinearMemoryExp; + dditable.pfnReleaseExternalMemoryExp = pDdiTable->pfnReleaseExternalMemoryExp; pDdiTable->pfnReleaseExternalMemoryExp = diff --git a/source/loader/loader.def.in b/source/loader/loader.def.in index b94442c9a7..5e628b4faf 100644 --- a/source/loader/loader.def.in +++ b/source/loader/loader.def.in @@ -12,6 +12,7 @@ EXPORTS urBindlessImagesImportExternalMemoryExp urBindlessImagesImportExternalSemaphoreExp urBindlessImagesMapExternalArrayExp + urBindlessImagesMapExternalLinearMemoryExp urBindlessImagesMipmapFreeExp urBindlessImagesMipmapGetLevelExp urBindlessImagesReleaseExternalMemoryExp @@ -181,6 +182,7 @@ EXPORTS urPrintBindlessImagesImportExternalMemoryExpParams urPrintBindlessImagesImportExternalSemaphoreExpParams urPrintBindlessImagesMapExternalArrayExpParams + urPrintBindlessImagesMapExternalLinearMemoryExpParams urPrintBindlessImagesMipmapFreeExpParams urPrintBindlessImagesMipmapGetLevelExpParams urPrintBindlessImagesReleaseExternalMemoryExpParams diff --git a/source/loader/loader.map.in b/source/loader/loader.map.in index ab5a7c19ab..18e4018aee 100644 --- a/source/loader/loader.map.in +++ b/source/loader/loader.map.in @@ -12,6 +12,7 @@ urBindlessImagesImportExternalMemoryExp; urBindlessImagesImportExternalSemaphoreExp; urBindlessImagesMapExternalArrayExp; + urBindlessImagesMapExternalLinearMemoryExp; urBindlessImagesMipmapFreeExp; urBindlessImagesMipmapGetLevelExp; urBindlessImagesReleaseExternalMemoryExp; @@ -181,6 +182,7 @@ urPrintBindlessImagesImportExternalMemoryExpParams; urPrintBindlessImagesImportExternalSemaphoreExpParams; urPrintBindlessImagesMapExternalArrayExpParams; + urPrintBindlessImagesMapExternalLinearMemoryExpParams; urPrintBindlessImagesMipmapFreeExpParams; urPrintBindlessImagesMipmapGetLevelExpParams; urPrintBindlessImagesReleaseExternalMemoryExpParams; diff --git a/source/loader/ur_ldrddi.cpp b/source/loader/ur_ldrddi.cpp index 1a867fb57d..2f2cf2bc70 100644 --- a/source/loader/ur_ldrddi.cpp +++ b/source/loader/ur_ldrddi.cpp @@ -6641,6 +6641,46 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urBindlessImagesMapExternalLinearMemoryExp +__urdlllocal ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + ur_context_handle_t hContext, ///< [in] handle of the context object + ur_device_handle_t hDevice, ///< [in] handle of the device object + uint64_t offset, ///< [in] offset into memory region to map + uint64_t size, ///< [in] size of memory region to map + ur_exp_external_mem_handle_t + hExternalMem, ///< [in] external memory handle to the external memory + void **ppRetMem ///< [out] pointer of the externally allocated memory +) { + ur_result_t result = UR_RESULT_SUCCESS; + + [[maybe_unused]] auto context = getContext(); + + // extract platform's function pointer table + auto dditable = reinterpret_cast(hContext)->dditable; + auto pfnMapExternalLinearMemoryExp = + dditable->ur.BindlessImagesExp.pfnMapExternalLinearMemoryExp; + if (nullptr == pfnMapExternalLinearMemoryExp) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + // convert loader handle to platform handle + hContext = reinterpret_cast(hContext)->handle; + + // convert loader handle to platform handle + hDevice = reinterpret_cast(hDevice)->handle; + + // convert loader handle to platform handle + hExternalMem = + reinterpret_cast(hExternalMem)->handle; + + // forward to device-platform + result = pfnMapExternalLinearMemoryExp(hContext, hDevice, offset, size, + hExternalMem, ppRetMem); + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urBindlessImagesReleaseExternalMemoryExp __urdlllocal ur_result_t UR_APICALL urBindlessImagesReleaseExternalMemoryExp( @@ -8691,6 +8731,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetBindlessImagesExpProcAddrTable( ur_loader::urBindlessImagesImportExternalMemoryExp; pDdiTable->pfnMapExternalArrayExp = ur_loader::urBindlessImagesMapExternalArrayExp; + pDdiTable->pfnMapExternalLinearMemoryExp = + ur_loader::urBindlessImagesMapExternalLinearMemoryExp; pDdiTable->pfnReleaseExternalMemoryExp = ur_loader::urBindlessImagesReleaseExternalMemoryExp; pDdiTable->pfnImportExternalSemaphoreExp = diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index aadcb5cda1..ba2eb67073 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -7111,6 +7111,48 @@ ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return exceptionToResult(std::current_exception()); } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Map an external memory handle to a device memory region described by +/// void* +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hContext` +/// + `NULL == hDevice` +/// + `NULL == hExternalMem` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppRetMem` +/// - ::UR_RESULT_ERROR_INVALID_CONTEXT +/// - ::UR_RESULT_ERROR_INVALID_VALUE +/// - ::UR_RESULT_ERROR_INVALID_IMAGE_SIZE +/// - ::UR_RESULT_ERROR_INVALID_OPERATION +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + ur_context_handle_t hContext, ///< [in] handle of the context object + ur_device_handle_t hDevice, ///< [in] handle of the device object + uint64_t offset, ///< [in] offset into memory region to map + uint64_t size, ///< [in] size of memory region to map + ur_exp_external_mem_handle_t + hExternalMem, ///< [in] external memory handle to the external memory + void **ppRetMem ///< [out] pointer of the externally allocated memory + ) try { + auto pfnMapExternalLinearMemoryExp = + ur_lib::getContext() + ->urDdiTable.BindlessImagesExp.pfnMapExternalLinearMemoryExp; + if (nullptr == pfnMapExternalLinearMemoryExp) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + return pfnMapExternalLinearMemoryExp(hContext, hDevice, offset, size, + hExternalMem, ppRetMem); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Release external memory /// diff --git a/source/loader/ur_print.cpp b/source/loader/ur_print.cpp index db31600e2c..f9d510e95d 100644 --- a/source/loader/ur_print.cpp +++ b/source/loader/ur_print.cpp @@ -1219,6 +1219,15 @@ ur_result_t urPrintBindlessImagesMapExternalArrayExpParams( return str_copy(&ss, buffer, buff_size, out_size); } +ur_result_t urPrintBindlessImagesMapExternalLinearMemoryExpParams( + const struct ur_bindless_images_map_external_linear_memory_exp_params_t + *params, + char *buffer, const size_t buff_size, size_t *out_size) { + std::stringstream ss; + ss << params; + return str_copy(&ss, buffer, buff_size, out_size); +} + ur_result_t urPrintBindlessImagesReleaseExternalMemoryExpParams( const struct ur_bindless_images_release_external_memory_exp_params_t *params, diff --git a/source/ur_api.cpp b/source/ur_api.cpp index 0b3ee0b936..7735101c18 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -6051,6 +6051,39 @@ ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Map an external memory handle to a device memory region described by +/// void* +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hContext` +/// + `NULL == hDevice` +/// + `NULL == hExternalMem` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppRetMem` +/// - ::UR_RESULT_ERROR_INVALID_CONTEXT +/// - ::UR_RESULT_ERROR_INVALID_VALUE +/// - ::UR_RESULT_ERROR_INVALID_IMAGE_SIZE +/// - ::UR_RESULT_ERROR_INVALID_OPERATION +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +ur_result_t UR_APICALL urBindlessImagesMapExternalLinearMemoryExp( + ur_context_handle_t hContext, ///< [in] handle of the context object + ur_device_handle_t hDevice, ///< [in] handle of the device object + uint64_t offset, ///< [in] offset into memory region to map + uint64_t size, ///< [in] size of memory region to map + ur_exp_external_mem_handle_t + hExternalMem, ///< [in] external memory handle to the external memory + void **ppRetMem ///< [out] pointer of the externally allocated memory +) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Release external memory ///