Skip to content

Commit c54b782

Browse files
authored
Merge pull request #327 from veselypeta/petr/252/binary-structs
[UR] `urDeviceSelectBinary` spec changes
2 parents 5e7fcbf + 8077602 commit c54b782

File tree

12 files changed

+277
-58
lines changed

12 files changed

+277
-58
lines changed

include/ur.py

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class ur_structure_type_v(IntEnum):
209209
USM_DESC = 7 ## ::ur_usm_desc_t
210210
USM_POOL_DESC = 8 ## ::ur_usm_pool_desc_t
211211
USM_POOL_LIMITS_DESC = 9 ## ::ur_usm_pool_limits_desc_t
212+
DEVICE_BINARY = 10 ## ::ur_device_binary_t
212213

213214
class ur_structure_type_t(c_int):
214215
def __str__(self):
@@ -293,6 +294,61 @@ def __str__(self):
293294
return str(ur_api_version_v(self.value))
294295

295296

297+
###############################################################################
298+
## @brief Target identification strings for
299+
## ::ur_device_binary_t.pDeviceTargetSpec
300+
## A device type represented by a particular target triple requires
301+
## specific
302+
## binary images. We need to map the image type onto the device target triple
303+
UR_DEVICE_BINARY_TARGET_UNKNOWN = "<unknown>"
304+
305+
###############################################################################
306+
## @brief SPIR-V 32-bit image <-> "spir", 32-bit OpenCL device
307+
UR_DEVICE_BINARY_TARGET_SPIRV32 = "spir"
308+
309+
###############################################################################
310+
## @brief SPIR-V 64-bit image <-> "spir64", 64-bit OpenCL device
311+
UR_DEVICE_BINARY_TARGET_SPIRV64 = "spir64"
312+
313+
###############################################################################
314+
## @brief Device-specific binary images produced from SPIR-V 64-bit <-> various
315+
## "spir64_*" triples for specific 64-bit OpenCL CPU devices
316+
UR_DEVICE_BINARY_TARGET_SPIRV64_X86_64 = "spir64_x86_64"
317+
318+
###############################################################################
319+
## @brief Generic GPU device (64-bit OpenCL)
320+
UR_DEVICE_BINARY_TARGET_SPIRV64_GEN = "spir64_gen"
321+
322+
###############################################################################
323+
## @brief 64-bit OpenCL FPGA device
324+
UR_DEVICE_BINARY_TARGET_SPIRV64_FPGA = "spir64_fpga"
325+
326+
###############################################################################
327+
## @brief PTX 64-bit image <-> "nvptx64", 64-bit NVIDIA PTX device
328+
UR_DEVICE_BINARY_TARGET_NVPTX64 = "nvptx64"
329+
330+
###############################################################################
331+
## @brief AMD GCN
332+
UR_DEVICE_BINARY_TARGET_AMDGCN = "amdgcn"
333+
334+
###############################################################################
335+
## @brief Device Binary Type
336+
class ur_device_binary_t(Structure):
337+
_fields_ = [
338+
("stype", ur_structure_type_t), ## [in] type of this structure, must be ::UR_STRUCTURE_TYPE_DEVICE_BINARY
339+
("pNext", c_void_p), ## [in][optional] pointer to extension-specific structure
340+
("pDeviceTargetSpec", c_char_p) ## [in] null-terminated string representation of the device's target architecture.
341+
## For example:
342+
## + ::UR_DEVICE_BINARY_TARGET_UNKNOWN
343+
## + ::UR_DEVICE_BINARY_TARGET_SPIRV32
344+
## + ::UR_DEVICE_BINARY_TARGET_SPIRV64
345+
## + ::UR_DEVICE_BINARY_TARGET_SPIRV64_X86_64
346+
## + ::UR_DEVICE_BINARY_TARGET_SPIRV64_GEN
347+
## + ::UR_DEVICE_BINARY_TARGET_SPIRV64_FPGA
348+
## + ::UR_DEVICE_BINARY_TARGET_NVPTX64
349+
## + ::UR_DEVICE_BINARY_TARGET_AMDGCN
350+
]
351+
296352
###############################################################################
297353
## @brief Supported device types
298354
class ur_device_type_v(IntEnum):
@@ -2386,9 +2442,9 @@ class ur_usm_dditable_t(Structure):
23862442
###############################################################################
23872443
## @brief Function-pointer for urDeviceSelectBinary
23882444
if __use_win_types:
2389-
_urDeviceSelectBinary_t = WINFUNCTYPE( ur_result_t, ur_device_handle_t, POINTER(POINTER(c_ubyte)), c_ulong, POINTER(c_ulong) )
2445+
_urDeviceSelectBinary_t = WINFUNCTYPE( ur_result_t, ur_device_handle_t, POINTER(ur_device_binary_t), c_ulong, POINTER(c_ulong) )
23902446
else:
2391-
_urDeviceSelectBinary_t = CFUNCTYPE( ur_result_t, ur_device_handle_t, POINTER(POINTER(c_ubyte)), c_ulong, POINTER(c_ulong) )
2447+
_urDeviceSelectBinary_t = CFUNCTYPE( ur_result_t, ur_device_handle_t, POINTER(ur_device_binary_t), c_ulong, POINTER(c_ulong) )
23922448

23932449
###############################################################################
23942450
## @brief Function-pointer for urDeviceGetNativeHandle

include/ur_api.h

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ typedef enum ur_structure_type_t {
233233
UR_STRUCTURE_TYPE_USM_DESC = 7, ///< ::ur_usm_desc_t
234234
UR_STRUCTURE_TYPE_USM_POOL_DESC = 8, ///< ::ur_usm_pool_desc_t
235235
UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC = 9, ///< ::ur_usm_pool_limits_desc_t
236+
UR_STRUCTURE_TYPE_DEVICE_BINARY = 10, ///< ::ur_device_binary_t
236237
/// @cond
237238
UR_STRUCTURE_TYPE_FORCE_UINT32 = 0x7fffffff
238239
/// @endcond
@@ -548,6 +549,77 @@ urGetLastResult(
548549
#if !defined(__GNUC__)
549550
#pragma region device
550551
#endif
552+
///////////////////////////////////////////////////////////////////////////////
553+
#ifndef UR_DEVICE_BINARY_TARGET_UNKNOWN
554+
/// @brief Target identification strings for
555+
/// ::ur_device_binary_t.pDeviceTargetSpec
556+
/// A device type represented by a particular target triple requires
557+
/// specific
558+
/// binary images. We need to map the image type onto the device target triple
559+
#define UR_DEVICE_BINARY_TARGET_UNKNOWN "<unknown>"
560+
#endif // UR_DEVICE_BINARY_TARGET_UNKNOWN
561+
562+
///////////////////////////////////////////////////////////////////////////////
563+
#ifndef UR_DEVICE_BINARY_TARGET_SPIRV32
564+
/// @brief SPIR-V 32-bit image <-> "spir", 32-bit OpenCL device
565+
#define UR_DEVICE_BINARY_TARGET_SPIRV32 "spir"
566+
#endif // UR_DEVICE_BINARY_TARGET_SPIRV32
567+
568+
///////////////////////////////////////////////////////////////////////////////
569+
#ifndef UR_DEVICE_BINARY_TARGET_SPIRV64
570+
/// @brief SPIR-V 64-bit image <-> "spir64", 64-bit OpenCL device
571+
#define UR_DEVICE_BINARY_TARGET_SPIRV64 "spir64"
572+
#endif // UR_DEVICE_BINARY_TARGET_SPIRV64
573+
574+
///////////////////////////////////////////////////////////////////////////////
575+
#ifndef UR_DEVICE_BINARY_TARGET_SPIRV64_X86_64
576+
/// @brief Device-specific binary images produced from SPIR-V 64-bit <-> various
577+
/// "spir64_*" triples for specific 64-bit OpenCL CPU devices
578+
#define UR_DEVICE_BINARY_TARGET_SPIRV64_X86_64 "spir64_x86_64"
579+
#endif // UR_DEVICE_BINARY_TARGET_SPIRV64_X86_64
580+
581+
///////////////////////////////////////////////////////////////////////////////
582+
#ifndef UR_DEVICE_BINARY_TARGET_SPIRV64_GEN
583+
/// @brief Generic GPU device (64-bit OpenCL)
584+
#define UR_DEVICE_BINARY_TARGET_SPIRV64_GEN "spir64_gen"
585+
#endif // UR_DEVICE_BINARY_TARGET_SPIRV64_GEN
586+
587+
///////////////////////////////////////////////////////////////////////////////
588+
#ifndef UR_DEVICE_BINARY_TARGET_SPIRV64_FPGA
589+
/// @brief 64-bit OpenCL FPGA device
590+
#define UR_DEVICE_BINARY_TARGET_SPIRV64_FPGA "spir64_fpga"
591+
#endif // UR_DEVICE_BINARY_TARGET_SPIRV64_FPGA
592+
593+
///////////////////////////////////////////////////////////////////////////////
594+
#ifndef UR_DEVICE_BINARY_TARGET_NVPTX64
595+
/// @brief PTX 64-bit image <-> "nvptx64", 64-bit NVIDIA PTX device
596+
#define UR_DEVICE_BINARY_TARGET_NVPTX64 "nvptx64"
597+
#endif // UR_DEVICE_BINARY_TARGET_NVPTX64
598+
599+
///////////////////////////////////////////////////////////////////////////////
600+
#ifndef UR_DEVICE_BINARY_TARGET_AMDGCN
601+
/// @brief AMD GCN
602+
#define UR_DEVICE_BINARY_TARGET_AMDGCN "amdgcn"
603+
#endif // UR_DEVICE_BINARY_TARGET_AMDGCN
604+
605+
///////////////////////////////////////////////////////////////////////////////
606+
/// @brief Device Binary Type
607+
typedef struct ur_device_binary_t {
608+
ur_structure_type_t stype; ///< [in] type of this structure, must be ::UR_STRUCTURE_TYPE_DEVICE_BINARY
609+
const void *pNext; ///< [in][optional] pointer to extension-specific structure
610+
const char *pDeviceTargetSpec; ///< [in] null-terminated string representation of the device's target architecture.
611+
///< For example:
612+
///< + ::UR_DEVICE_BINARY_TARGET_UNKNOWN
613+
///< + ::UR_DEVICE_BINARY_TARGET_SPIRV32
614+
///< + ::UR_DEVICE_BINARY_TARGET_SPIRV64
615+
///< + ::UR_DEVICE_BINARY_TARGET_SPIRV64_X86_64
616+
///< + ::UR_DEVICE_BINARY_TARGET_SPIRV64_GEN
617+
///< + ::UR_DEVICE_BINARY_TARGET_SPIRV64_FPGA
618+
///< + ::UR_DEVICE_BINARY_TARGET_NVPTX64
619+
///< + ::UR_DEVICE_BINARY_TARGET_AMDGCN
620+
621+
} ur_device_binary_t;
622+
551623
///////////////////////////////////////////////////////////////////////////////
552624
/// @brief Supported device types
553625
typedef enum ur_device_type_t {
@@ -896,18 +968,19 @@ urDevicePartition(
896968
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
897969
/// + `NULL == hDevice`
898970
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
899-
/// + `NULL == ppBinaries`
971+
/// + `NULL == pBinaries`
900972
/// + `NULL == pSelectedBinary`
901-
/// - ::UR_RESULT_ERROR_INVALID_VALUE
973+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
974+
/// + `NumBinaries == 0`
902975
UR_APIEXPORT ur_result_t UR_APICALL
903976
urDeviceSelectBinary(
904-
ur_device_handle_t hDevice, ///< [in] handle of the device to select binary for.
905-
const uint8_t **ppBinaries, ///< [in] the array of binaries to select from.
906-
uint32_t NumBinaries, ///< [in] the number of binaries passed in ppBinaries.
907-
///< Must greater than or equal to zero otherwise
908-
///< ::UR_RESULT_ERROR_INVALID_VALUE is returned.
909-
uint32_t *pSelectedBinary ///< [out] the index of the selected binary in the input array of binaries.
910-
///< If a suitable binary was not found the function returns ${X}_INVALID_BINARY.
977+
ur_device_handle_t hDevice, ///< [in] handle of the device to select binary for.
978+
const ur_device_binary_t *pBinaries, ///< [in] the array of binaries to select from.
979+
uint32_t NumBinaries, ///< [in] the number of binaries passed in ppBinaries.
980+
///< Must greater than or equal to zero otherwise
981+
///< ::UR_RESULT_ERROR_INVALID_VALUE is returned.
982+
uint32_t *pSelectedBinary ///< [out] the index of the selected binary in the input array of binaries.
983+
///< If a suitable binary was not found the function returns ::UR_RESULT_ERROR_INVALID_BINARY.
911984
);
912985

913986
///////////////////////////////////////////////////////////////////////////////
@@ -7922,7 +7995,7 @@ typedef void(UR_APICALL *ur_pfnDevicePartitionCb_t)(
79227995
/// allowing the callback the ability to modify the parameter's value
79237996
typedef struct ur_device_select_binary_params_t {
79247997
ur_device_handle_t *phDevice;
7925-
const uint8_t ***pppBinaries;
7998+
const ur_device_binary_t **ppBinaries;
79267999
uint32_t *pNumBinaries;
79278000
uint32_t **ppSelectedBinary;
79288001
} ur_device_select_binary_params_t;

include/ur_ddi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ typedef ur_result_t(UR_APICALL *ur_pfnDevicePartition_t)(
13311331
/// @brief Function-pointer for urDeviceSelectBinary
13321332
typedef ur_result_t(UR_APICALL *ur_pfnDeviceSelectBinary_t)(
13331333
ur_device_handle_t,
1334-
const uint8_t **,
1334+
const ur_device_binary_t *,
13351335
uint32_t,
13361336
uint32_t *);
13371337

scripts/core/common.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ etors:
282282
desc: $x_usm_pool_desc_t
283283
- name: USM_POOL_LIMITS_DESC
284284
desc: $x_usm_pool_limits_desc_t
285+
- name: DEVICE_BINARY
286+
desc: "$x_device_binary_t"
285287
--- #--------------------------------------------------------------------------
286288
type: struct
287289
desc: "Base for all properties types"

scripts/core/device.yml

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,73 @@ type: header
1111
desc: "Intel $OneApi Unified Runtime APIs for Device"
1212
ordinal: "2"
1313
--- #--------------------------------------------------------------------------
14+
type: macro
15+
desc: |
16+
Target identification strings for $x_device_binary_t.pDeviceTargetSpec
17+
A device type represented by a particular target triple requires specific
18+
binary images. We need to map the image type onto the device target triple
19+
name: "$X_DEVICE_BINARY_TARGET_UNKNOWN"
20+
value: "\"<unknown>\""
21+
--- #--------------------------------------------------------------------------
22+
type: macro
23+
desc: |
24+
SPIR-V 32-bit image <-> "spir", 32-bit OpenCL device
25+
name: "$X_DEVICE_BINARY_TARGET_SPIRV32"
26+
value: "\"spir\""
27+
--- #--------------------------------------------------------------------------
28+
type: macro
29+
desc: |
30+
SPIR-V 64-bit image <-> "spir64", 64-bit OpenCL device
31+
name: "$X_DEVICE_BINARY_TARGET_SPIRV64"
32+
value: "\"spir64\""
33+
--- #--------------------------------------------------------------------------
34+
type: macro
35+
desc: |
36+
Device-specific binary images produced from SPIR-V 64-bit <-> various
37+
"spir64_*" triples for specific 64-bit OpenCL CPU devices
38+
name: "$X_DEVICE_BINARY_TARGET_SPIRV64_X86_64"
39+
value: "\"spir64_x86_64\""
40+
--- #--------------------------------------------------------------------------
41+
type: macro
42+
desc: "Generic GPU device (64-bit OpenCL)"
43+
name: "$X_DEVICE_BINARY_TARGET_SPIRV64_GEN"
44+
value: "\"spir64_gen\""
45+
--- #--------------------------------------------------------------------------
46+
type: macro
47+
desc: "64-bit OpenCL FPGA device"
48+
name: "$X_DEVICE_BINARY_TARGET_SPIRV64_FPGA"
49+
value: "\"spir64_fpga\""
50+
--- #--------------------------------------------------------------------------
51+
type: macro
52+
desc: |
53+
PTX 64-bit image <-> "nvptx64", 64-bit NVIDIA PTX device
54+
name: "$X_DEVICE_BINARY_TARGET_NVPTX64"
55+
value: "\"nvptx64\""
56+
--- #--------------------------------------------------------------------------
57+
type: macro
58+
desc: "AMD GCN"
59+
name: "$X_DEVICE_BINARY_TARGET_AMDGCN"
60+
value: "\"amdgcn\""
61+
--- #--------------------------------------------------------------------------
62+
type: struct
63+
desc: "Device Binary Type"
64+
name: $x_device_binary_t
65+
base: $x_base_desc_t
66+
members:
67+
- type: const char*
68+
name: pDeviceTargetSpec
69+
desc: |
70+
[in] null-terminated string representation of the device's target architecture.
71+
For example:
72+
+ $X_DEVICE_BINARY_TARGET_UNKNOWN
73+
+ $X_DEVICE_BINARY_TARGET_SPIRV32
74+
+ $X_DEVICE_BINARY_TARGET_SPIRV64
75+
+ $X_DEVICE_BINARY_TARGET_SPIRV64_X86_64
76+
+ $X_DEVICE_BINARY_TARGET_SPIRV64_GEN
77+
+ $X_DEVICE_BINARY_TARGET_SPIRV64_FPGA
78+
+ $X_DEVICE_BINARY_TARGET_NVPTX64
79+
+ $X_DEVICE_BINARY_TARGET_AMDGCN
80+
--- #--------------------------------------------------------------------------
1481
type: enum
1582
desc: "Supported device types"
1683
class: $xDevice
@@ -440,8 +507,8 @@ params:
440507
name: hDevice
441508
desc: |
442509
[in] handle of the device to select binary for.
443-
- type: "const uint8_t**"
444-
name: ppBinaries
510+
- type: "const $x_device_binary_t*"
511+
name: pBinaries
445512
desc: |
446513
[in] the array of binaries to select from.
447514
- type: "uint32_t"
@@ -453,9 +520,10 @@ params:
453520
name: pSelectedBinary
454521
desc: |
455522
[out] the index of the selected binary in the input array of binaries.
456-
If a suitable binary was not found the function returns ${X}_INVALID_BINARY.
523+
If a suitable binary was not found the function returns $X_RESULT_ERROR_INVALID_BINARY.
457524
returns:
458-
- $X_RESULT_ERROR_INVALID_VALUE
525+
- $X_RESULT_ERROR_INVALID_SIZE:
526+
- "`NumBinaries == 0`"
459527
--- #--------------------------------------------------------------------------
460528
type: enum
461529
desc: "FP capabilities"

source/drivers/null/ur_nullddi.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,22 @@ __urdlllocal ur_result_t UR_APICALL urDevicePartition(
329329
__urdlllocal ur_result_t UR_APICALL urDeviceSelectBinary(
330330
ur_device_handle_t
331331
hDevice, ///< [in] handle of the device to select binary for.
332-
const uint8_t **ppBinaries, ///< [in] the array of binaries to select from.
332+
const ur_device_binary_t
333+
*pBinaries, ///< [in] the array of binaries to select from.
333334
uint32_t NumBinaries, ///< [in] the number of binaries passed in ppBinaries.
334335
///< Must greater than or equal to zero otherwise
335336
///< ::UR_RESULT_ERROR_INVALID_VALUE is returned.
336337
uint32_t *
337338
pSelectedBinary ///< [out] the index of the selected binary in the input array of binaries.
338-
///< If a suitable binary was not found the function returns ${X}_INVALID_BINARY.
339+
///< If a suitable binary was not found the function returns ::UR_RESULT_ERROR_INVALID_BINARY.
339340
) {
340341
ur_result_t result = UR_RESULT_SUCCESS;
341342

342343
// if the driver has created a custom function, then call it instead of using the generic path
343344
auto pfnSelectBinary = d_context.urDdiTable.Device.pfnSelectBinary;
344345
if (nullptr != pfnSelectBinary) {
345346
result =
346-
pfnSelectBinary(hDevice, ppBinaries, NumBinaries, pSelectedBinary);
347+
pfnSelectBinary(hDevice, pBinaries, NumBinaries, pSelectedBinary);
347348
} else {
348349
// generic implementation
349350
}

source/loader/layers/tracing/ur_trcddi.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,27 +392,28 @@ __urdlllocal ur_result_t UR_APICALL urDevicePartition(
392392
__urdlllocal ur_result_t UR_APICALL urDeviceSelectBinary(
393393
ur_device_handle_t
394394
hDevice, ///< [in] handle of the device to select binary for.
395-
const uint8_t **ppBinaries, ///< [in] the array of binaries to select from.
395+
const ur_device_binary_t
396+
*pBinaries, ///< [in] the array of binaries to select from.
396397
uint32_t NumBinaries, ///< [in] the number of binaries passed in ppBinaries.
397398
///< Must greater than or equal to zero otherwise
398399
///< ::UR_RESULT_ERROR_INVALID_VALUE is returned.
399400
uint32_t *
400401
pSelectedBinary ///< [out] the index of the selected binary in the input array of binaries.
401-
///< If a suitable binary was not found the function returns ${X}_INVALID_BINARY.
402+
///< If a suitable binary was not found the function returns ::UR_RESULT_ERROR_INVALID_BINARY.
402403
) {
403404
auto pfnSelectBinary = context.urDdiTable.Device.pfnSelectBinary;
404405

405406
if (nullptr == pfnSelectBinary) {
406407
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
407408
}
408409

409-
ur_device_select_binary_params_t params = {&hDevice, &ppBinaries,
410+
ur_device_select_binary_params_t params = {&hDevice, &pBinaries,
410411
&NumBinaries, &pSelectedBinary};
411412
uint64_t instance = context.notify_begin(UR_FUNCTION_DEVICE_SELECT_BINARY,
412413
"urDeviceSelectBinary", &params);
413414

414415
ur_result_t result =
415-
pfnSelectBinary(hDevice, ppBinaries, NumBinaries, pSelectedBinary);
416+
pfnSelectBinary(hDevice, pBinaries, NumBinaries, pSelectedBinary);
416417

417418
context.notify_end(UR_FUNCTION_DEVICE_SELECT_BINARY, "urDeviceSelectBinary",
418419
&params, &result, instance);

0 commit comments

Comments
 (0)