Skip to content

Commit 8edca04

Browse files
authored
Merge pull request #434 from jandres742/url0_loader_urKernelCreateWithNativeHandle
Expand urKernelCreateWithNativeHandle
2 parents ec06bc6 + c939dac commit 8edca04

File tree

12 files changed

+154
-13
lines changed

12 files changed

+154
-13
lines changed

include/ur.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class ur_structure_type_v(IntEnum):
216216
QUEUE_PROPERTIES = 14 ## ::ur_queue_properties_t
217217
QUEUE_INDEX_PROPERTIES = 15 ## ::ur_queue_properties_t
218218
CONTEXT_NATIVE_PROPERTIES = 16 ## ::ur_context_native_properties_t
219+
KERNEL_NATIVE_PROPERTIES = 17 ## ::ur_kernel_native_properties_t
219220

220221
class ur_structure_type_t(c_int):
221222
def __str__(self):
@@ -1326,6 +1327,18 @@ def __str__(self):
13261327
return str(ur_kernel_exec_info_v(self.value))
13271328

13281329

1330+
###############################################################################
1331+
## @brief Properties for for ::urKernelCreateWithNativeHandle.
1332+
class ur_kernel_native_properties_t(Structure):
1333+
_fields_ = [
1334+
("stype", ur_structure_type_t), ## [in] type of this structure, must be
1335+
## ::UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES
1336+
("pNext", c_void_p), ## [in,out][optional] pointer to extension-specific structure
1337+
("isNativeHandleOwned", c_bool) ## [in] Indicates UR owns the native handle or if it came from an interoperability
1338+
## operation in the application that asked to not transfer the ownership to
1339+
## the unified-runtime.
1340+
]
1341+
13291342
###############################################################################
13301343
## @brief Query queue info
13311344
class ur_queue_info_v(IntEnum):
@@ -1987,9 +2000,9 @@ class ur_program_dditable_t(Structure):
19872000
###############################################################################
19882001
## @brief Function-pointer for urKernelCreateWithNativeHandle
19892002
if __use_win_types:
1990-
_urKernelCreateWithNativeHandle_t = WINFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, POINTER(ur_kernel_handle_t) )
2003+
_urKernelCreateWithNativeHandle_t = WINFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, ur_program_handle_t, POINTER(ur_kernel_native_properties_t), POINTER(ur_kernel_handle_t) )
19912004
else:
1992-
_urKernelCreateWithNativeHandle_t = CFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, POINTER(ur_kernel_handle_t) )
2005+
_urKernelCreateWithNativeHandle_t = CFUNCTYPE( ur_result_t, ur_native_handle_t, ur_context_handle_t, ur_program_handle_t, POINTER(ur_kernel_native_properties_t), POINTER(ur_kernel_handle_t) )
19932006

19942007
###############################################################################
19952008
## @brief Function-pointer for urKernelSetArgValue

include/ur_api.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ typedef enum ur_structure_type_t {
240240
UR_STRUCTURE_TYPE_QUEUE_PROPERTIES = 14, ///< ::ur_queue_properties_t
241241
UR_STRUCTURE_TYPE_QUEUE_INDEX_PROPERTIES = 15, ///< ::ur_queue_properties_t
242242
UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES = 16, ///< ::ur_context_native_properties_t
243+
UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES = 17, ///< ::ur_kernel_native_properties_t
243244
/// @cond
244245
UR_STRUCTURE_TYPE_FORCE_UINT32 = 0x7fffffff
245246
/// @endcond
@@ -3609,6 +3610,18 @@ urKernelGetNativeHandle(
36093610
ur_native_handle_t *phNativeKernel ///< [out] a pointer to the native handle of the kernel.
36103611
);
36113612

3613+
///////////////////////////////////////////////////////////////////////////////
3614+
/// @brief Properties for for ::urKernelCreateWithNativeHandle.
3615+
typedef struct ur_kernel_native_properties_t {
3616+
ur_structure_type_t stype; ///< [in] type of this structure, must be
3617+
///< ::UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES
3618+
void *pNext; ///< [in,out][optional] pointer to extension-specific structure
3619+
bool isNativeHandleOwned; ///< [in] Indicates UR owns the native handle or if it came from an interoperability
3620+
///< operation in the application that asked to not transfer the ownership to
3621+
///< the unified-runtime.
3622+
3623+
} ur_kernel_native_properties_t;
3624+
36123625
///////////////////////////////////////////////////////////////////////////////
36133626
/// @brief Create runtime kernel object from native kernel handle.
36143627
///
@@ -3625,13 +3638,17 @@ urKernelGetNativeHandle(
36253638
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
36263639
/// + `NULL == hNativeKernel`
36273640
/// + `NULL == hContext`
3641+
/// + `NULL == hProgram`
36283642
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
3643+
/// + `NULL == pProperties`
36293644
/// + `NULL == phKernel`
36303645
UR_APIEXPORT ur_result_t UR_APICALL
36313646
urKernelCreateWithNativeHandle(
3632-
ur_native_handle_t hNativeKernel, ///< [in] the native handle of the kernel.
3633-
ur_context_handle_t hContext, ///< [in] handle of the context object
3634-
ur_kernel_handle_t *phKernel ///< [out] pointer to the handle of the kernel object created.
3647+
ur_native_handle_t hNativeKernel, ///< [in] the native handle of the kernel.
3648+
ur_context_handle_t hContext, ///< [in] handle of the context object
3649+
ur_program_handle_t hProgram, ///< [in] handle of the program associated with the kernel
3650+
const ur_kernel_native_properties_t *pProperties, ///< [in] pointer to properties struct
3651+
ur_kernel_handle_t *phKernel ///< [out] pointer to the handle of the kernel object created.
36353652
);
36363653

36373654
#if !defined(__GNUC__)
@@ -5920,6 +5937,8 @@ typedef struct ur_kernel_get_native_handle_params_t {
59205937
typedef struct ur_kernel_create_with_native_handle_params_t {
59215938
ur_native_handle_t *phNativeKernel;
59225939
ur_context_handle_t *phContext;
5940+
ur_program_handle_t *phProgram;
5941+
const ur_kernel_native_properties_t **ppProperties;
59235942
ur_kernel_handle_t **pphKernel;
59245943
} ur_kernel_create_with_native_handle_params_t;
59255944

include/ur_ddi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ typedef ur_result_t(UR_APICALL *ur_pfnKernelGetNativeHandle_t)(
458458
typedef ur_result_t(UR_APICALL *ur_pfnKernelCreateWithNativeHandle_t)(
459459
ur_native_handle_t,
460460
ur_context_handle_t,
461+
ur_program_handle_t,
462+
const ur_kernel_native_properties_t *,
461463
ur_kernel_handle_t *);
462464

463465
///////////////////////////////////////////////////////////////////////////////

scripts/core/common.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ etors:
296296
desc: $x_queue_properties_t
297297
- name: CONTEXT_NATIVE_PROPERTIES
298298
desc: $x_context_native_properties_t
299+
- name: KERNEL_NATIVE_PROPERTIES
300+
desc: $x_kernel_native_properties_t
299301
--- #--------------------------------------------------------------------------
300302
type: struct
301303
desc: "Base for all properties types"

scripts/core/kernel.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,19 @@ params:
408408
desc: |
409409
[out] a pointer to the native handle of the kernel.
410410
--- #--------------------------------------------------------------------------
411+
type: struct
412+
desc: "Properties for for $xKernelCreateWithNativeHandle."
413+
class: $xKernel
414+
name: $x_kernel_native_properties_t
415+
base: $x_base_properties_t
416+
members:
417+
- type: bool
418+
name: isNativeHandleOwned
419+
desc: |
420+
[in] Indicates UR owns the native handle or if it came from an interoperability
421+
operation in the application that asked to not transfer the ownership to
422+
the unified-runtime.
423+
--- #--------------------------------------------------------------------------
411424
type: function
412425
desc: "Create runtime kernel object from native kernel handle."
413426
class: $xKernel
@@ -426,6 +439,12 @@ params:
426439
- type: $x_context_handle_t
427440
name: hContext
428441
desc: "[in] handle of the context object"
442+
- type: $x_program_handle_t
443+
name: hProgram
444+
desc: "[in] handle of the program associated with the kernel"
445+
- type: "const $x_kernel_native_properties_t*"
446+
name: pProperties
447+
desc: "[in] pointer to properties struct"
429448
- type: "$x_kernel_handle_t*"
430449
name: phKernel
431450
desc: |

source/common/ur_params.hpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ inline std::ostream &operator<<(std::ostream &os,
239239
enum ur_kernel_cache_config_t value);
240240
inline std::ostream &operator<<(std::ostream &os,
241241
enum ur_kernel_exec_info_t value);
242+
inline std::ostream &
243+
operator<<(std::ostream &os, const struct ur_kernel_native_properties_t params);
242244
inline std::ostream &operator<<(std::ostream &os, enum ur_queue_info_t value);
243245
inline std::ostream &operator<<(std::ostream &os, enum ur_queue_flag_t value);
244246
inline std::ostream &operator<<(std::ostream &os,
@@ -612,6 +614,10 @@ inline std::ostream &operator<<(std::ostream &os,
612614
case UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES:
613615
os << "UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES";
614616
break;
617+
618+
case UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES:
619+
os << "UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES";
620+
break;
615621
default:
616622
os << "unknown enumerator";
617623
break;
@@ -721,6 +727,12 @@ inline void serializeStruct(std::ostream &os, const void *ptr) {
721727
(const ur_context_native_properties_t *)ptr;
722728
ur_params::serializePtr(os, pstruct);
723729
} break;
730+
731+
case UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES: {
732+
const ur_kernel_native_properties_t *pstruct =
733+
(const ur_kernel_native_properties_t *)ptr;
734+
ur_params::serializePtr(os, pstruct);
735+
} break;
724736
default:
725737
os << "unknown enumerator";
726738
break;
@@ -6183,6 +6195,28 @@ serializeTaggedTyped_ur_kernel_exec_info_t(std::ostream &os, const void *ptr,
61836195
}
61846196
}
61856197
} // namespace ur_params
6198+
inline std::ostream &
6199+
operator<<(std::ostream &os,
6200+
const struct ur_kernel_native_properties_t params) {
6201+
os << "(struct ur_kernel_native_properties_t){";
6202+
6203+
os << ".stype = ";
6204+
6205+
os << (params.stype);
6206+
6207+
os << ", ";
6208+
os << ".pNext = ";
6209+
6210+
ur_params::serializeStruct(os, (params.pNext));
6211+
6212+
os << ", ";
6213+
os << ".isNativeHandleOwned = ";
6214+
6215+
os << (params.isNativeHandleOwned);
6216+
6217+
os << "}";
6218+
return os;
6219+
}
61866220
inline std::ostream &operator<<(std::ostream &os, enum ur_queue_info_t value) {
61876221
switch (value) {
61886222

@@ -9302,6 +9336,16 @@ operator<<(std::ostream &os,
93029336

93039337
ur_params::serializePtr(os, *(params->phContext));
93049338

9339+
os << ", ";
9340+
os << ".hProgram = ";
9341+
9342+
ur_params::serializePtr(os, *(params->phProgram));
9343+
9344+
os << ", ";
9345+
os << ".pProperties = ";
9346+
9347+
ur_params::serializePtr(os, *(params->ppProperties));
9348+
93059349
os << ", ";
93069350
os << ".phKernel = ";
93079351

source/drivers/null/ur_nullddi.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,10 @@ __urdlllocal ur_result_t UR_APICALL urKernelGetNativeHandle(
17771777
__urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
17781778
ur_native_handle_t hNativeKernel, ///< [in] the native handle of the kernel.
17791779
ur_context_handle_t hContext, ///< [in] handle of the context object
1780+
ur_program_handle_t
1781+
hProgram, ///< [in] handle of the program associated with the kernel
1782+
const ur_kernel_native_properties_t
1783+
*pProperties, ///< [in] pointer to properties struct
17801784
ur_kernel_handle_t
17811785
*phKernel ///< [out] pointer to the handle of the kernel object created.
17821786
) {
@@ -1786,7 +1790,8 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
17861790
auto pfnCreateWithNativeHandle =
17871791
d_context.urDdiTable.Kernel.pfnCreateWithNativeHandle;
17881792
if (nullptr != pfnCreateWithNativeHandle) {
1789-
result = pfnCreateWithNativeHandle(hNativeKernel, hContext, phKernel);
1793+
result = pfnCreateWithNativeHandle(hNativeKernel, hContext, hProgram,
1794+
pProperties, phKernel);
17901795
} else {
17911796
// generic implementation
17921797
*phKernel = reinterpret_cast<ur_kernel_handle_t>(d_context.get());

source/loader/layers/tracing/ur_trcddi.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,10 @@ __urdlllocal ur_result_t UR_APICALL urKernelGetNativeHandle(
22012201
__urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
22022202
ur_native_handle_t hNativeKernel, ///< [in] the native handle of the kernel.
22032203
ur_context_handle_t hContext, ///< [in] handle of the context object
2204+
ur_program_handle_t
2205+
hProgram, ///< [in] handle of the program associated with the kernel
2206+
const ur_kernel_native_properties_t
2207+
*pProperties, ///< [in] pointer to properties struct
22042208
ur_kernel_handle_t
22052209
*phKernel ///< [out] pointer to the handle of the kernel object created.
22062210
) {
@@ -2212,13 +2216,13 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
22122216
}
22132217

22142218
ur_kernel_create_with_native_handle_params_t params = {
2215-
&hNativeKernel, &hContext, &phKernel};
2219+
&hNativeKernel, &hContext, &hProgram, &pProperties, &phKernel};
22162220
uint64_t instance =
22172221
context.notify_begin(UR_FUNCTION_KERNEL_CREATE_WITH_NATIVE_HANDLE,
22182222
"urKernelCreateWithNativeHandle", &params);
22192223

2220-
ur_result_t result =
2221-
pfnCreateWithNativeHandle(hNativeKernel, hContext, phKernel);
2224+
ur_result_t result = pfnCreateWithNativeHandle(
2225+
hNativeKernel, hContext, hProgram, pProperties, phKernel);
22222226

22232227
context.notify_end(UR_FUNCTION_KERNEL_CREATE_WITH_NATIVE_HANDLE,
22242228
"urKernelCreateWithNativeHandle", &params, &result,

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,6 +2599,10 @@ __urdlllocal ur_result_t UR_APICALL urKernelGetNativeHandle(
25992599
__urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
26002600
ur_native_handle_t hNativeKernel, ///< [in] the native handle of the kernel.
26012601
ur_context_handle_t hContext, ///< [in] handle of the context object
2602+
ur_program_handle_t
2603+
hProgram, ///< [in] handle of the program associated with the kernel
2604+
const ur_kernel_native_properties_t
2605+
*pProperties, ///< [in] pointer to properties struct
26022606
ur_kernel_handle_t
26032607
*phKernel ///< [out] pointer to the handle of the kernel object created.
26042608
) {
@@ -2618,13 +2622,21 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
26182622
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
26192623
}
26202624

2625+
if (NULL == hProgram) {
2626+
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
2627+
}
2628+
2629+
if (NULL == pProperties) {
2630+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
2631+
}
2632+
26212633
if (NULL == phKernel) {
26222634
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
26232635
}
26242636
}
26252637

2626-
ur_result_t result =
2627-
pfnCreateWithNativeHandle(hNativeKernel, hContext, phKernel);
2638+
ur_result_t result = pfnCreateWithNativeHandle(
2639+
hNativeKernel, hContext, hProgram, pProperties, phKernel);
26282640

26292641
if (context.enableLeakChecking && result == UR_RESULT_SUCCESS) {
26302642
refCountContext.createRefCount(*phKernel);

source/loader/ur_ldrddi.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,10 @@ __urdlllocal ur_result_t UR_APICALL urKernelGetNativeHandle(
25432543
__urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
25442544
ur_native_handle_t hNativeKernel, ///< [in] the native handle of the kernel.
25452545
ur_context_handle_t hContext, ///< [in] handle of the context object
2546+
ur_program_handle_t
2547+
hProgram, ///< [in] handle of the program associated with the kernel
2548+
const ur_kernel_native_properties_t
2549+
*pProperties, ///< [in] pointer to properties struct
25462550
ur_kernel_handle_t
25472551
*phKernel ///< [out] pointer to the handle of the kernel object created.
25482552
) {
@@ -2564,8 +2568,12 @@ __urdlllocal ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
25642568
// convert loader handle to platform handle
25652569
hContext = reinterpret_cast<ur_context_object_t *>(hContext)->handle;
25662570

2571+
// convert loader handle to platform handle
2572+
hProgram = reinterpret_cast<ur_program_object_t *>(hProgram)->handle;
2573+
25672574
// forward to device-platform
2568-
result = pfnCreateWithNativeHandle(hNativeKernel, hContext, phKernel);
2575+
result = pfnCreateWithNativeHandle(hNativeKernel, hContext, hProgram,
2576+
pProperties, phKernel);
25692577

25702578
if (UR_RESULT_SUCCESS != result) {
25712579
return result;

0 commit comments

Comments
 (0)