Skip to content

Commit 2084114

Browse files
committed
Make device param in urMemGetNativeHandle optional
1 parent 771af62 commit 2084114

File tree

11 files changed

+32
-22
lines changed

11 files changed

+32
-22
lines changed

include/ur_api.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,6 +2825,8 @@ urMemBufferPartition(
28252825
/// - The application may call this function from simultaneous threads for
28262826
/// the same context.
28272827
/// - The implementation of this function should be thread-safe.
2828+
/// - The implementation may require a valid device handle to return the
2829+
/// native mem handle
28282830
///
28292831
/// @returns
28302832
/// - ::UR_RESULT_SUCCESS
@@ -2833,15 +2835,16 @@ urMemBufferPartition(
28332835
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
28342836
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
28352837
/// + `NULL == hMem`
2836-
/// + `NULL == hDevice`
2838+
/// + If `hDevice == NULL` and the implementation requires a valid device.
28372839
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
28382840
/// + `NULL == phNativeMem`
28392841
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
28402842
/// + If the adapter has no underlying equivalent handle.
28412843
UR_APIEXPORT ur_result_t UR_APICALL
28422844
urMemGetNativeHandle(
28432845
ur_mem_handle_t hMem, ///< [in] handle of the mem.
2844-
ur_device_handle_t hDevice, ///< [in] handle of the device that the native handle will be resident on.
2846+
ur_device_handle_t hDevice, ///< [in][optional] handle of the device that the native handle will be
2847+
///< resident on.
28452848
ur_native_handle_t *phNativeMem ///< [out] a pointer to the native handle of the mem.
28462849
);
28472850

scripts/core/memory.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ details:
436436
- "Use interoperability platform extensions to convert native handle to native type."
437437
- "The application may call this function from simultaneous threads for the same context."
438438
- "The implementation of this function should be thread-safe."
439+
- "The implementation may require a valid device handle to return the native mem handle"
439440
params:
440441
- type: $x_mem_handle_t
441442
name: hMem
@@ -444,14 +445,16 @@ params:
444445
- type: $x_device_handle_t
445446
name: hDevice
446447
desc: |
447-
[in] handle of the device that the native handle will be resident on.
448+
[in][optional] handle of the device that the native handle will be resident on.
448449
- type: $x_native_handle_t*
449450
name: phNativeMem
450451
desc: |
451452
[out] a pointer to the native handle of the mem.
452453
returns:
453454
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
454455
- "If the adapter has no underlying equivalent handle."
456+
- $X_RESULT_ERROR_INVALID_NULL_HANDLE:
457+
- "If `hDevice == NULL` and the implementation requires a valid device."
455458
--- #--------------------------------------------------------------------------
456459
type: struct
457460
desc: "Native memory object creation properties"

source/adapters/cuda/memory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
130130
UR_APIEXPORT ur_result_t UR_APICALL
131131
urMemGetNativeHandle(ur_mem_handle_t hMem, ur_device_handle_t Device,
132132
ur_native_handle_t *phNativeMem) {
133+
UR_ASSERT(Device != nullptr, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
133134
try {
134135
*phNativeMem = reinterpret_cast<ur_native_handle_t>(
135136
std::get<BufferMem>(hMem->Mem).getPtr(Device));

source/adapters/hip/memory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory,
301301
UR_APIEXPORT ur_result_t UR_APICALL
302302
urMemGetNativeHandle(ur_mem_handle_t hMem, ur_device_handle_t Device,
303303
ur_native_handle_t *phNativeMem) {
304+
UR_ASSERT(Device != nullptr, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
304305
#if defined(__HIP_PLATFORM_NVIDIA__)
305306
if (sizeof(BufferMem::native_type) > sizeof(ur_native_handle_t)) {
306307
// Check that all the upper bits that cannot be represented by

source/adapters/null/ur_nullddi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,8 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferPartition(
937937
__urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
938938
ur_mem_handle_t hMem, ///< [in] handle of the mem.
939939
ur_device_handle_t
940-
hDevice, ///< [in] handle of the device that the native handle will be resident on.
940+
hDevice, ///< [in][optional] handle of the device that the native handle will be
941+
///< resident on.
941942
ur_native_handle_t
942943
*phNativeMem ///< [out] a pointer to the native handle of the mem.
943944
) try {

source/loader/layers/tracing/ur_trcddi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,8 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferPartition(
12091209
__urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
12101210
ur_mem_handle_t hMem, ///< [in] handle of the mem.
12111211
ur_device_handle_t
1212-
hDevice, ///< [in] handle of the device that the native handle will be resident on.
1212+
hDevice, ///< [in][optional] handle of the device that the native handle will be
1213+
///< resident on.
12131214
ur_native_handle_t
12141215
*phNativeMem ///< [out] a pointer to the native handle of the mem.
12151216
) {

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,8 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferPartition(
12901290
__urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
12911291
ur_mem_handle_t hMem, ///< [in] handle of the mem.
12921292
ur_device_handle_t
1293-
hDevice, ///< [in] handle of the device that the native handle will be resident on.
1293+
hDevice, ///< [in][optional] handle of the device that the native handle will be
1294+
///< resident on.
12941295
ur_native_handle_t
12951296
*phNativeMem ///< [out] a pointer to the native handle of the mem.
12961297
) {
@@ -1305,10 +1306,6 @@ __urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
13051306
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
13061307
}
13071308

1308-
if (NULL == hDevice) {
1309-
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
1310-
}
1311-
13121309
if (NULL == phNativeMem) {
13131310
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
13141311
}

source/loader/ur_ldrddi.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,8 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferPartition(
12591259
__urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
12601260
ur_mem_handle_t hMem, ///< [in] handle of the mem.
12611261
ur_device_handle_t
1262-
hDevice, ///< [in] handle of the device that the native handle will be resident on.
1262+
hDevice, ///< [in][optional] handle of the device that the native handle will be
1263+
///< resident on.
12631264
ur_native_handle_t
12641265
*phNativeMem ///< [out] a pointer to the native handle of the mem.
12651266
) {
@@ -1276,7 +1277,9 @@ __urdlllocal ur_result_t UR_APICALL urMemGetNativeHandle(
12761277
hMem = reinterpret_cast<ur_mem_object_t *>(hMem)->handle;
12771278

12781279
// convert loader handle to platform handle
1279-
hDevice = reinterpret_cast<ur_device_object_t *>(hDevice)->handle;
1280+
hDevice = (hDevice)
1281+
? reinterpret_cast<ur_device_object_t *>(hDevice)->handle
1282+
: nullptr;
12801283

12811284
// forward to device-platform
12821285
result = pfnGetNativeHandle(hMem, hDevice, phNativeMem);

source/loader/ur_libapi.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,8 @@ ur_result_t UR_APICALL urMemBufferPartition(
17171717
/// - The application may call this function from simultaneous threads for
17181718
/// the same context.
17191719
/// - The implementation of this function should be thread-safe.
1720+
/// - The implementation may require a valid device handle to return the
1721+
/// native mem handle
17201722
///
17211723
/// @returns
17221724
/// - ::UR_RESULT_SUCCESS
@@ -1725,15 +1727,16 @@ ur_result_t UR_APICALL urMemBufferPartition(
17251727
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
17261728
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
17271729
/// + `NULL == hMem`
1728-
/// + `NULL == hDevice`
1730+
/// + If `hDevice == NULL` and the implementation requires a valid device.
17291731
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
17301732
/// + `NULL == phNativeMem`
17311733
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
17321734
/// + If the adapter has no underlying equivalent handle.
17331735
ur_result_t UR_APICALL urMemGetNativeHandle(
17341736
ur_mem_handle_t hMem, ///< [in] handle of the mem.
17351737
ur_device_handle_t
1736-
hDevice, ///< [in] handle of the device that the native handle will be resident on.
1738+
hDevice, ///< [in][optional] handle of the device that the native handle will be
1739+
///< resident on.
17371740
ur_native_handle_t
17381741
*phNativeMem ///< [out] a pointer to the native handle of the mem.
17391742
) try {

source/ur_api.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,8 @@ ur_result_t UR_APICALL urMemBufferPartition(
14791479
/// - The application may call this function from simultaneous threads for
14801480
/// the same context.
14811481
/// - The implementation of this function should be thread-safe.
1482+
/// - The implementation may require a valid device handle to return the
1483+
/// native mem handle
14821484
///
14831485
/// @returns
14841486
/// - ::UR_RESULT_SUCCESS
@@ -1487,15 +1489,16 @@ ur_result_t UR_APICALL urMemBufferPartition(
14871489
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
14881490
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
14891491
/// + `NULL == hMem`
1490-
/// + `NULL == hDevice`
1492+
/// + If `hDevice == NULL` and the implementation requires a valid device.
14911493
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
14921494
/// + `NULL == phNativeMem`
14931495
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
14941496
/// + If the adapter has no underlying equivalent handle.
14951497
ur_result_t UR_APICALL urMemGetNativeHandle(
14961498
ur_mem_handle_t hMem, ///< [in] handle of the mem.
14971499
ur_device_handle_t
1498-
hDevice, ///< [in] handle of the device that the native handle will be resident on.
1500+
hDevice, ///< [in][optional] handle of the device that the native handle will be
1501+
///< resident on.
14991502
ur_native_handle_t
15001503
*phNativeMem ///< [out] a pointer to the native handle of the mem.
15011504
) {

test/conformance/memory/urMemGetNativeHandle.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ TEST_P(urMemGetNativeHandleTest, InvalidNullHandleMem) {
2020
urMemGetNativeHandle(nullptr, device, &phNativeMem));
2121
}
2222

23-
TEST_P(urMemGetNativeHandleTest, InvalidNullHandleDevice) {
24-
ur_native_handle_t phNativeMem;
25-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
26-
urMemGetNativeHandle(buffer, nullptr, &phNativeMem));
27-
}
28-
2923
TEST_P(urMemGetNativeHandleTest, InvalidNullPointerNativeMem) {
3024
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
3125
urMemGetNativeHandle(buffer, device, nullptr));

0 commit comments

Comments
 (0)