Skip to content

Commit 4500fa9

Browse files
committed
Make urKernelCreateWithNativeHandle's program param optional.
Not all backends requires this parameter so sycl doesn't always provide it. This prevents those cases from getting caught in the validation layer.
1 parent 1b8ee0d commit 4500fa9

File tree

9 files changed

+23
-23
lines changed

9 files changed

+23
-23
lines changed

include/ur_api.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5276,6 +5276,8 @@ typedef struct ur_kernel_native_properties_t {
52765276
/// - The application may call this function from simultaneous threads for
52775277
/// the same context.
52785278
/// - The implementation of this function should be thread-safe.
5279+
/// - The implementation may require a valid program handle to return the
5280+
/// native kernel handle
52795281
///
52805282
/// @returns
52815283
/// - ::UR_RESULT_SUCCESS
@@ -5284,7 +5286,7 @@ typedef struct ur_kernel_native_properties_t {
52845286
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
52855287
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
52865288
/// + `NULL == hContext`
5287-
/// + `NULL == hProgram`
5289+
/// + If `hProgram == NULL` and the implementation requires a valid program.
52885290
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
52895291
/// + `NULL == phKernel`
52905292
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
@@ -5293,7 +5295,7 @@ UR_APIEXPORT ur_result_t UR_APICALL
52935295
urKernelCreateWithNativeHandle(
52945296
ur_native_handle_t hNativeKernel, ///< [in][nocheck] the native handle of the kernel.
52955297
ur_context_handle_t hContext, ///< [in] handle of the context object
5296-
ur_program_handle_t hProgram, ///< [in] handle of the program associated with the kernel
5298+
ur_program_handle_t hProgram, ///< [in][optional] handle of the program associated with the kernel
52975299
const ur_kernel_native_properties_t *pProperties, ///< [in][optional] pointer to native kernel properties struct
52985300
ur_kernel_handle_t *phKernel ///< [out] pointer to the handle of the kernel object created.
52995301
);

scripts/core/kernel.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ details:
513513
- "Creates runtime kernel handle from native driver kernel handle."
514514
- "The application may call this function from simultaneous threads for the same context."
515515
- "The implementation of this function should be thread-safe."
516+
- "The implementation may require a valid program handle to return the native kernel handle"
516517
params:
517518
- type: $x_native_handle_t
518519
name: hNativeKernel
@@ -523,7 +524,7 @@ params:
523524
desc: "[in] handle of the context object"
524525
- type: $x_program_handle_t
525526
name: hProgram
526-
desc: "[in] handle of the program associated with the kernel"
527+
desc: "[in][optional] handle of the program associated with the kernel"
527528
- type: "const $x_kernel_native_properties_t*"
528529
name: pProperties
529530
desc: "[in][optional] pointer to native kernel properties struct"
@@ -534,6 +535,8 @@ params:
534535
returns:
535536
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
536537
- "If the adapter has no underlying equivalent handle."
538+
- $X_RESULT_ERROR_INVALID_NULL_HANDLE:
539+
- "If `hProgram == NULL` and the implementation requires a valid program."
537540
--- #--------------------------------------------------------------------------
538541
type: function
539542
desc: "Get the suggested local work size for a kernel."

source/adapters/mock/ur_mockddi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4489,7 +4489,7 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
44894489
hNativeKernel, ///< [in][nocheck] the native handle of the kernel.
44904490
ur_context_handle_t hContext, ///< [in] handle of the context object
44914491
ur_program_handle_t
4492-
hProgram, ///< [in] handle of the program associated with the kernel
4492+
hProgram, ///< [in][optional] handle of the program associated with the kernel
44934493
const ur_kernel_native_properties_t *
44944494
pProperties, ///< [in][optional] pointer to native kernel properties struct
44954495
ur_kernel_handle_t

source/loader/layers/tracing/ur_trcddi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3428,7 +3428,7 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
34283428
hNativeKernel, ///< [in][nocheck] the native handle of the kernel.
34293429
ur_context_handle_t hContext, ///< [in] handle of the context object
34303430
ur_program_handle_t
3431-
hProgram, ///< [in] handle of the program associated with the kernel
3431+
hProgram, ///< [in][optional] handle of the program associated with the kernel
34323432
const ur_kernel_native_properties_t *
34333433
pProperties, ///< [in][optional] pointer to native kernel properties struct
34343434
ur_kernel_handle_t

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,7 +3855,7 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
38553855
hNativeKernel, ///< [in][nocheck] the native handle of the kernel.
38563856
ur_context_handle_t hContext, ///< [in] handle of the context object
38573857
ur_program_handle_t
3858-
hProgram, ///< [in] handle of the program associated with the kernel
3858+
hProgram, ///< [in][optional] handle of the program associated with the kernel
38593859
const ur_kernel_native_properties_t *
38603860
pProperties, ///< [in][optional] pointer to native kernel properties struct
38613861
ur_kernel_handle_t
@@ -3873,10 +3873,6 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
38733873
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
38743874
}
38753875

3876-
if (NULL == hProgram) {
3877-
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
3878-
}
3879-
38803876
if (NULL == phKernel) {
38813877
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
38823878
}

source/loader/ur_ldrddi.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,7 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
35923592
hNativeKernel, ///< [in][nocheck] the native handle of the kernel.
35933593
ur_context_handle_t hContext, ///< [in] handle of the context object
35943594
ur_program_handle_t
3595-
hProgram, ///< [in] handle of the program associated with the kernel
3595+
hProgram, ///< [in][optional] handle of the program associated with the kernel
35963596
const ur_kernel_native_properties_t *
35973597
pProperties, ///< [in][optional] pointer to native kernel properties struct
35983598
ur_kernel_handle_t
@@ -3614,7 +3614,9 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
36143614
hContext = reinterpret_cast<ur_context_object_t *>(hContext)->handle;
36153615

36163616
// convert loader handle to platform handle
3617-
hProgram = reinterpret_cast<ur_program_object_t *>(hProgram)->handle;
3617+
hProgram = (hProgram)
3618+
? reinterpret_cast<ur_program_object_t *>(hProgram)->handle
3619+
: nullptr;
36183620

36193621
// forward to device-platform
36203622
result = pfnCreateWithNativeHandle(hNativeKernel, hContext, hProgram,

source/loader/ur_libapi.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,6 +4139,8 @@ ur_result_t UR_APICALL urKernelGetNativeHandle(
41394139
/// - The application may call this function from simultaneous threads for
41404140
/// the same context.
41414141
/// - The implementation of this function should be thread-safe.
4142+
/// - The implementation may require a valid program handle to return the
4143+
/// native kernel handle
41424144
///
41434145
/// @returns
41444146
/// - ::UR_RESULT_SUCCESS
@@ -4147,7 +4149,7 @@ ur_result_t UR_APICALL urKernelGetNativeHandle(
41474149
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
41484150
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
41494151
/// + `NULL == hContext`
4150-
/// + `NULL == hProgram`
4152+
/// + If `hProgram == NULL` and the implementation requires a valid program.
41514153
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
41524154
/// + `NULL == phKernel`
41534155
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
@@ -4157,7 +4159,7 @@ ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
41574159
hNativeKernel, ///< [in][nocheck] the native handle of the kernel.
41584160
ur_context_handle_t hContext, ///< [in] handle of the context object
41594161
ur_program_handle_t
4160-
hProgram, ///< [in] handle of the program associated with the kernel
4162+
hProgram, ///< [in][optional] handle of the program associated with the kernel
41614163
const ur_kernel_native_properties_t *
41624164
pProperties, ///< [in][optional] pointer to native kernel properties struct
41634165
ur_kernel_handle_t

source/ur_api.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3516,6 +3516,8 @@ ur_result_t UR_APICALL urKernelGetNativeHandle(
35163516
/// - The application may call this function from simultaneous threads for
35173517
/// the same context.
35183518
/// - The implementation of this function should be thread-safe.
3519+
/// - The implementation may require a valid program handle to return the
3520+
/// native kernel handle
35193521
///
35203522
/// @returns
35213523
/// - ::UR_RESULT_SUCCESS
@@ -3524,7 +3526,7 @@ ur_result_t UR_APICALL urKernelGetNativeHandle(
35243526
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
35253527
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
35263528
/// + `NULL == hContext`
3527-
/// + `NULL == hProgram`
3529+
/// + If `hProgram == NULL` and the implementation requires a valid program.
35283530
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
35293531
/// + `NULL == phKernel`
35303532
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
@@ -3534,7 +3536,7 @@ ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
35343536
hNativeKernel, ///< [in][nocheck] the native handle of the kernel.
35353537
ur_context_handle_t hContext, ///< [in] handle of the context object
35363538
ur_program_handle_t
3537-
hProgram, ///< [in] handle of the program associated with the kernel
3539+
hProgram, ///< [in][optional] handle of the program associated with the kernel
35383540
const ur_kernel_native_properties_t *
35393541
pProperties, ///< [in][optional] pointer to native kernel properties struct
35403542
ur_kernel_handle_t

test/conformance/kernel/urKernelCreateWithNativeHandle.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ TEST_P(urKernelCreateWithNativeHandleTest, InvalidNullHandleContext) {
5050
&properties, &native_kernel));
5151
}
5252

53-
TEST_P(urKernelCreateWithNativeHandleTest, InvalidNullHandleProgram) {
54-
ASSERT_EQ_RESULT(
55-
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
56-
urKernelCreateWithNativeHandle(native_kernel_handle, context, nullptr,
57-
&properties, &native_kernel));
58-
}
59-
6053
TEST_P(urKernelCreateWithNativeHandleTest, InvalidNullPointerNativeKernel) {
6154
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
6255
urKernelCreateWithNativeHandle(native_kernel_handle,

0 commit comments

Comments
 (0)