Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2820,6 +2820,8 @@ urMemBufferPartition(
/// - The application may call this function from simultaneous threads for
/// the same context.
/// - The implementation of this function should be thread-safe.
/// - The implementation may require a valid device handle to return the
/// native mem handle
///
/// @returns
/// - ::UR_RESULT_SUCCESS
Expand All @@ -2828,15 +2830,16 @@ urMemBufferPartition(
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hMem`
/// + `NULL == hDevice`
/// + If `hDevice == NULL` and the implementation requires a valid device.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phNativeMem`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
/// + If the adapter has no underlying equivalent handle.
UR_APIEXPORT ur_result_t UR_APICALL
urMemGetNativeHandle(
ur_mem_handle_t hMem, ///< [in] handle of the mem.
ur_device_handle_t hDevice, ///< [in] handle of the device that the native handle will be resident on.
ur_device_handle_t hDevice, ///< [in][optional] handle of the device that the native handle will be
///< resident on.
ur_native_handle_t *phNativeMem ///< [out] a pointer to the native handle of the mem.
);

Expand Down
5 changes: 4 additions & 1 deletion scripts/core/memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ details:
- "Use interoperability platform extensions to convert native handle to native type."
- "The application may call this function from simultaneous threads for the same context."
- "The implementation of this function should be thread-safe."
- "The implementation may require a valid device handle to return the native mem handle"
params:
- type: $x_mem_handle_t
name: hMem
Expand All @@ -444,14 +445,16 @@ params:
- type: $x_device_handle_t
name: hDevice
desc: |
[in] handle of the device that the native handle will be resident on.
[in][optional] handle of the device that the native handle will be resident on.
- type: $x_native_handle_t*
name: phNativeMem
desc: |
[out] a pointer to the native handle of the mem.
returns:
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
- "If the adapter has no underlying equivalent handle."
- $X_RESULT_ERROR_INVALID_NULL_HANDLE:
- "If `hDevice == NULL` and the implementation requires a valid device."
--- #--------------------------------------------------------------------------
type: struct
desc: "Native memory object creation properties"
Expand Down
1 change: 1 addition & 0 deletions source/adapters/cuda/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
UR_APIEXPORT ur_result_t UR_APICALL
urMemGetNativeHandle(ur_mem_handle_t hMem, ur_device_handle_t Device,
ur_native_handle_t *phNativeMem) {
UR_ASSERT(Device != nullptr, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
try {
*phNativeMem = reinterpret_cast<ur_native_handle_t>(
std::get<BufferMem>(hMem->Mem).getPtr(Device));
Expand Down
1 change: 1 addition & 0 deletions source/adapters/hip/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory,
UR_APIEXPORT ur_result_t UR_APICALL
urMemGetNativeHandle(ur_mem_handle_t hMem, ur_device_handle_t Device,
ur_native_handle_t *phNativeMem) {
UR_ASSERT(Device != nullptr, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
#if defined(__HIP_PLATFORM_NVIDIA__)
if (sizeof(BufferMem::native_type) > sizeof(ur_native_handle_t)) {
// Check that all the upper bits that cannot be represented by
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/null/ur_nullddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferPartition(
__urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
ur_mem_handle_t hMem, ///< [in] handle of the mem.
ur_device_handle_t
hDevice, ///< [in] handle of the device that the native handle will be resident on.
hDevice, ///< [in][optional] handle of the device that the native handle will be
///< resident on.
ur_native_handle_t
*phNativeMem ///< [out] a pointer to the native handle of the mem.
) try {
Expand Down
3 changes: 2 additions & 1 deletion source/loader/layers/tracing/ur_trcddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,8 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferPartition(
__urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
ur_mem_handle_t hMem, ///< [in] handle of the mem.
ur_device_handle_t
hDevice, ///< [in] handle of the device that the native handle will be resident on.
hDevice, ///< [in][optional] handle of the device that the native handle will be
///< resident on.
ur_native_handle_t
*phNativeMem ///< [out] a pointer to the native handle of the mem.
) {
Expand Down
7 changes: 2 additions & 5 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,8 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferPartition(
__urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
ur_mem_handle_t hMem, ///< [in] handle of the mem.
ur_device_handle_t
hDevice, ///< [in] handle of the device that the native handle will be resident on.
hDevice, ///< [in][optional] handle of the device that the native handle will be
///< resident on.
ur_native_handle_t
*phNativeMem ///< [out] a pointer to the native handle of the mem.
) {
Expand All @@ -1305,10 +1306,6 @@ __urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
}

if (NULL == hDevice) {
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
}

if (NULL == phNativeMem) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}
Expand Down
7 changes: 5 additions & 2 deletions source/loader/ur_ldrddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,8 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferPartition(
__urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
ur_mem_handle_t hMem, ///< [in] handle of the mem.
ur_device_handle_t
hDevice, ///< [in] handle of the device that the native handle will be resident on.
hDevice, ///< [in][optional] handle of the device that the native handle will be
///< resident on.
ur_native_handle_t
*phNativeMem ///< [out] a pointer to the native handle of the mem.
) {
Expand All @@ -1276,7 +1277,9 @@ __urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
hMem = reinterpret_cast<ur_mem_object_t *>(hMem)->handle;

// convert loader handle to platform handle
hDevice = reinterpret_cast<ur_device_object_t *>(hDevice)->handle;
hDevice = (hDevice)
? reinterpret_cast<ur_device_object_t *>(hDevice)->handle
: nullptr;

// forward to device-platform
result = pfnGetNativeHandle(hMem, hDevice, phNativeMem);
Expand Down
7 changes: 5 additions & 2 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,8 @@ ur_result_t UR_APICALL urMemBufferPartition(
/// - The application may call this function from simultaneous threads for
/// the same context.
/// - The implementation of this function should be thread-safe.
/// - The implementation may require a valid device handle to return the
/// native mem handle
///
/// @returns
/// - ::UR_RESULT_SUCCESS
Expand All @@ -1725,15 +1727,16 @@ ur_result_t UR_APICALL urMemBufferPartition(
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hMem`
/// + `NULL == hDevice`
/// + If `hDevice == NULL` and the implementation requires a valid device.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phNativeMem`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
/// + If the adapter has no underlying equivalent handle.
ur_result_t UR_APICALL urMemGetNativeHandle(
ur_mem_handle_t hMem, ///< [in] handle of the mem.
ur_device_handle_t
hDevice, ///< [in] handle of the device that the native handle will be resident on.
hDevice, ///< [in][optional] handle of the device that the native handle will be
///< resident on.
ur_native_handle_t
*phNativeMem ///< [out] a pointer to the native handle of the mem.
) try {
Expand Down
7 changes: 5 additions & 2 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,8 @@ ur_result_t UR_APICALL urMemBufferPartition(
/// - The application may call this function from simultaneous threads for
/// the same context.
/// - The implementation of this function should be thread-safe.
/// - The implementation may require a valid device handle to return the
/// native mem handle
///
/// @returns
/// - ::UR_RESULT_SUCCESS
Expand All @@ -1487,15 +1489,16 @@ ur_result_t UR_APICALL urMemBufferPartition(
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hMem`
/// + `NULL == hDevice`
/// + If `hDevice == NULL` and the implementation requires a valid device.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phNativeMem`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
/// + If the adapter has no underlying equivalent handle.
ur_result_t UR_APICALL urMemGetNativeHandle(
ur_mem_handle_t hMem, ///< [in] handle of the mem.
ur_device_handle_t
hDevice, ///< [in] handle of the device that the native handle will be resident on.
hDevice, ///< [in][optional] handle of the device that the native handle will be
///< resident on.
ur_native_handle_t
*phNativeMem ///< [out] a pointer to the native handle of the mem.
) {
Expand Down
6 changes: 0 additions & 6 deletions test/conformance/memory/urMemGetNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ TEST_P(urMemGetNativeHandleTest, InvalidNullHandleMem) {
urMemGetNativeHandle(nullptr, device, &phNativeMem));
}

TEST_P(urMemGetNativeHandleTest, InvalidNullHandleDevice) {
ur_native_handle_t phNativeMem;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urMemGetNativeHandle(buffer, nullptr, &phNativeMem));
}

TEST_P(urMemGetNativeHandleTest, InvalidNullPointerNativeMem) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
urMemGetNativeHandle(buffer, device, nullptr));
Expand Down