Skip to content

Commit 63aaf07

Browse files
authored
Merge pull request #924 from kbenzie/benie/multi-device-compile
[UR][L0] Add the multi-device-compile experimental feature
2 parents 0d320f8 + c90b27b commit 63aaf07

File tree

14 files changed

+1505
-3
lines changed

14 files changed

+1505
-3
lines changed

include/ur.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ class ur_function_v(IntEnum):
202202
KERNEL_SUGGEST_MAX_COOPERATIVE_GROUP_COUNT_EXP = 194## Enumerator for ::urKernelSuggestMaxCooperativeGroupCountExp
203203
COMMAND_BUFFER_APPEND_USM_PREFETCH_EXP = 195 ## Enumerator for ::urCommandBufferAppendUSMPrefetchExp
204204
COMMAND_BUFFER_APPEND_USM_ADVISE_EXP = 196 ## Enumerator for ::urCommandBufferAppendUSMAdviseExp
205-
LOADER_CONFIG_SET_CODE_LOCATION_CALLBACK = 197 ## Enumerator for ::urLoaderConfigSetCodeLocationCallback
205+
PROGRAM_BUILD_EXP = 197 ## Enumerator for ::urProgramBuildExp
206+
PROGRAM_COMPILE_EXP = 198 ## Enumerator for ::urProgramCompileExp
207+
PROGRAM_LINK_EXP = 199 ## Enumerator for ::urProgramLinkExp
208+
LOADER_CONFIG_SET_CODE_LOCATION_CALLBACK = 200 ## Enumerator for ::urLoaderConfigSetCodeLocationCallback
206209

207210
class ur_function_t(c_int):
208211
def __str__(self):
@@ -2315,6 +2318,11 @@ class ur_exp_command_buffer_handle_t(c_void_p):
23152318
## which is returned when querying device extensions.
23162319
UR_COOPERATIVE_KERNELS_EXTENSION_STRING_EXP = "ur_exp_cooperative_kernels"
23172320

2321+
###############################################################################
2322+
## @brief The extension string which defines support for test
2323+
## which is returned when querying device extensions.
2324+
UR_MULTI_DEVICE_COMPILE_EXTENSION_STRING_EXP = "ur_exp_multi_device_compile"
2325+
23182326
###############################################################################
23192327
## @brief Supported peer info
23202328
class ur_exp_peer_info_v(IntEnum):
@@ -2631,6 +2639,37 @@ class ur_program_dditable_t(Structure):
26312639
("pfnCreateWithNativeHandle", c_void_p) ## _urProgramCreateWithNativeHandle_t
26322640
]
26332641

2642+
###############################################################################
2643+
## @brief Function-pointer for urProgramBuildExp
2644+
if __use_win_types:
2645+
_urProgramBuildExp_t = WINFUNCTYPE( ur_result_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2646+
else:
2647+
_urProgramBuildExp_t = CFUNCTYPE( ur_result_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2648+
2649+
###############################################################################
2650+
## @brief Function-pointer for urProgramCompileExp
2651+
if __use_win_types:
2652+
_urProgramCompileExp_t = WINFUNCTYPE( ur_result_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2653+
else:
2654+
_urProgramCompileExp_t = CFUNCTYPE( ur_result_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2655+
2656+
###############################################################################
2657+
## @brief Function-pointer for urProgramLinkExp
2658+
if __use_win_types:
2659+
_urProgramLinkExp_t = WINFUNCTYPE( ur_result_t, ur_context_handle_t, c_ulong, POINTER(ur_device_handle_t), c_ulong, POINTER(ur_program_handle_t), c_char_p, POINTER(ur_program_handle_t) )
2660+
else:
2661+
_urProgramLinkExp_t = CFUNCTYPE( ur_result_t, ur_context_handle_t, c_ulong, POINTER(ur_device_handle_t), c_ulong, POINTER(ur_program_handle_t), c_char_p, POINTER(ur_program_handle_t) )
2662+
2663+
2664+
###############################################################################
2665+
## @brief Table of ProgramExp functions pointers
2666+
class ur_program_exp_dditable_t(Structure):
2667+
_fields_ = [
2668+
("pfnBuildExp", c_void_p), ## _urProgramBuildExp_t
2669+
("pfnCompileExp", c_void_p), ## _urProgramCompileExp_t
2670+
("pfnLinkExp", c_void_p) ## _urProgramLinkExp_t
2671+
]
2672+
26342673
###############################################################################
26352674
## @brief Function-pointer for urKernelCreate
26362675
if __use_win_types:
@@ -3862,6 +3901,7 @@ class ur_dditable_t(Structure):
38623901
("Context", ur_context_dditable_t),
38633902
("Event", ur_event_dditable_t),
38643903
("Program", ur_program_dditable_t),
3904+
("ProgramExp", ur_program_exp_dditable_t),
38653905
("Kernel", ur_kernel_dditable_t),
38663906
("KernelExp", ur_kernel_exp_dditable_t),
38673907
("Sampler", ur_sampler_dditable_t),
@@ -3966,6 +4006,18 @@ def __init__(self, version : ur_api_version_t):
39664006
self.urProgramGetNativeHandle = _urProgramGetNativeHandle_t(self.__dditable.Program.pfnGetNativeHandle)
39674007
self.urProgramCreateWithNativeHandle = _urProgramCreateWithNativeHandle_t(self.__dditable.Program.pfnCreateWithNativeHandle)
39684008

4009+
# call driver to get function pointers
4010+
ProgramExp = ur_program_exp_dditable_t()
4011+
r = ur_result_v(self.__dll.urGetProgramExpProcAddrTable(version, byref(ProgramExp)))
4012+
if r != ur_result_v.SUCCESS:
4013+
raise Exception(r)
4014+
self.__dditable.ProgramExp = ProgramExp
4015+
4016+
# attach function interface to function address
4017+
self.urProgramBuildExp = _urProgramBuildExp_t(self.__dditable.ProgramExp.pfnBuildExp)
4018+
self.urProgramCompileExp = _urProgramCompileExp_t(self.__dditable.ProgramExp.pfnCompileExp)
4019+
self.urProgramLinkExp = _urProgramLinkExp_t(self.__dditable.ProgramExp.pfnLinkExp)
4020+
39694021
# call driver to get function pointers
39704022
Kernel = ur_kernel_dditable_t()
39714023
r = ur_result_v(self.__dll.urGetKernelProcAddrTable(version, byref(Kernel)))

include/ur_api.h

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ typedef enum ur_function_t {
211211
UR_FUNCTION_KERNEL_SUGGEST_MAX_COOPERATIVE_GROUP_COUNT_EXP = 194, ///< Enumerator for ::urKernelSuggestMaxCooperativeGroupCountExp
212212
UR_FUNCTION_COMMAND_BUFFER_APPEND_USM_PREFETCH_EXP = 195, ///< Enumerator for ::urCommandBufferAppendUSMPrefetchExp
213213
UR_FUNCTION_COMMAND_BUFFER_APPEND_USM_ADVISE_EXP = 196, ///< Enumerator for ::urCommandBufferAppendUSMAdviseExp
214-
UR_FUNCTION_LOADER_CONFIG_SET_CODE_LOCATION_CALLBACK = 197, ///< Enumerator for ::urLoaderConfigSetCodeLocationCallback
214+
UR_FUNCTION_PROGRAM_BUILD_EXP = 197, ///< Enumerator for ::urProgramBuildExp
215+
UR_FUNCTION_PROGRAM_COMPILE_EXP = 198, ///< Enumerator for ::urProgramCompileExp
216+
UR_FUNCTION_PROGRAM_LINK_EXP = 199, ///< Enumerator for ::urProgramLinkExp
217+
UR_FUNCTION_LOADER_CONFIG_SET_CODE_LOCATION_CALLBACK = 200, ///< Enumerator for ::urLoaderConfigSetCodeLocationCallback
215218
/// @cond
216219
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
217220
/// @endcond
@@ -8408,6 +8411,131 @@ urKernelSuggestMaxCooperativeGroupCountExp(
84088411
uint32_t *pGroupCountRet ///< [out] pointer to maximum number of groups
84098412
);
84108413

8414+
#if !defined(__GNUC__)
8415+
#pragma endregion
8416+
#endif
8417+
// Intel 'oneAPI' Unified Runtime Experimental APIs for multi-device compile
8418+
#if !defined(__GNUC__)
8419+
#pragma region multi device compile(experimental)
8420+
#endif
8421+
///////////////////////////////////////////////////////////////////////////////
8422+
#ifndef UR_MULTI_DEVICE_COMPILE_EXTENSION_STRING_EXP
8423+
/// @brief The extension string which defines support for test
8424+
/// which is returned when querying device extensions.
8425+
#define UR_MULTI_DEVICE_COMPILE_EXTENSION_STRING_EXP "ur_exp_multi_device_compile"
8426+
#endif // UR_MULTI_DEVICE_COMPILE_EXTENSION_STRING_EXP
8427+
8428+
///////////////////////////////////////////////////////////////////////////////
8429+
/// @brief Produces an executable program from one program, negates need for the
8430+
/// linking step.
8431+
///
8432+
/// @details
8433+
/// - The application may call this function from simultaneous threads.
8434+
/// - Following a successful call to this entry point, the program passed
8435+
/// will contain a binary of the ::UR_PROGRAM_BINARY_TYPE_EXECUTABLE type
8436+
/// for each device in `phDevices`.
8437+
///
8438+
/// @remarks
8439+
/// _Analogues_
8440+
/// - **clBuildProgram**
8441+
///
8442+
/// @returns
8443+
/// - ::UR_RESULT_SUCCESS
8444+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
8445+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
8446+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
8447+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
8448+
/// + `NULL == hProgram`
8449+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
8450+
/// + `NULL == phDevices`
8451+
/// - ::UR_RESULT_ERROR_INVALID_PROGRAM
8452+
/// + If `hProgram` isn't a valid program object.
8453+
/// - ::UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE
8454+
/// + If an error occurred when building `hProgram`.
8455+
UR_APIEXPORT ur_result_t UR_APICALL
8456+
urProgramBuildExp(
8457+
ur_program_handle_t hProgram, ///< [in] Handle of the program to build.
8458+
uint32_t numDevices, ///< [in] number of devices
8459+
ur_device_handle_t *phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
8460+
const char *pOptions ///< [in][optional] pointer to build options null-terminated string.
8461+
);
8462+
8463+
///////////////////////////////////////////////////////////////////////////////
8464+
/// @brief Produces an executable program from one or more programs.
8465+
///
8466+
/// @details
8467+
/// - The application may call this function from simultaneous threads.
8468+
/// - Following a successful call to this entry point `hProgram` will
8469+
/// contain a binary of the ::UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT type
8470+
/// for each device in `phDevices`.
8471+
///
8472+
/// @remarks
8473+
/// _Analogues_
8474+
/// - **clCompileProgram**
8475+
///
8476+
/// @returns
8477+
/// - ::UR_RESULT_SUCCESS
8478+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
8479+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
8480+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
8481+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
8482+
/// + `NULL == hProgram`
8483+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
8484+
/// + `NULL == phDevices`
8485+
/// - ::UR_RESULT_ERROR_INVALID_PROGRAM
8486+
/// + If `hProgram` isn't a valid program object.
8487+
/// - ::UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE
8488+
/// + If an error occurred while compiling `hProgram`.
8489+
UR_APIEXPORT ur_result_t UR_APICALL
8490+
urProgramCompileExp(
8491+
ur_program_handle_t hProgram, ///< [in][out] handle of the program to compile.
8492+
uint32_t numDevices, ///< [in] number of devices
8493+
ur_device_handle_t *phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
8494+
const char *pOptions ///< [in][optional] pointer to build options null-terminated string.
8495+
);
8496+
8497+
///////////////////////////////////////////////////////////////////////////////
8498+
/// @brief Produces an executable program from one or more programs.
8499+
///
8500+
/// @details
8501+
/// - The application may call this function from simultaneous threads.
8502+
/// - Following a successful call to this entry point the program returned
8503+
/// in `phProgram` will contain a binary of the
8504+
/// ::UR_PROGRAM_BINARY_TYPE_EXECUTABLE type for each device in
8505+
/// `phDevices`.
8506+
///
8507+
/// @remarks
8508+
/// _Analogues_
8509+
/// - **clLinkProgram**
8510+
///
8511+
/// @returns
8512+
/// - ::UR_RESULT_SUCCESS
8513+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
8514+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
8515+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
8516+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
8517+
/// + `NULL == hContext`
8518+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
8519+
/// + `NULL == phDevices`
8520+
/// + `NULL == phPrograms`
8521+
/// + `NULL == phProgram`
8522+
/// - ::UR_RESULT_ERROR_INVALID_PROGRAM
8523+
/// + If one of the programs in `phPrograms` isn't a valid program object.
8524+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
8525+
/// + `count == 0`
8526+
/// - ::UR_RESULT_ERROR_PROGRAM_LINK_FAILURE
8527+
/// + If an error occurred while linking `phPrograms`.
8528+
UR_APIEXPORT ur_result_t UR_APICALL
8529+
urProgramLinkExp(
8530+
ur_context_handle_t hContext, ///< [in] handle of the context instance.
8531+
uint32_t numDevices, ///< [in] number of devices
8532+
ur_device_handle_t *phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
8533+
uint32_t count, ///< [in] number of program handles in `phPrograms`.
8534+
const ur_program_handle_t *phPrograms, ///< [in][range(0, count)] pointer to array of program handles.
8535+
const char *pOptions, ///< [in][optional] pointer to linker options null-terminated string.
8536+
ur_program_handle_t *phProgram ///< [out] pointer to handle of program object created.
8537+
);
8538+
84118539
#if !defined(__GNUC__)
84128540
#pragma endregion
84138541
#endif
@@ -8919,6 +9047,17 @@ typedef struct ur_program_build_params_t {
89199047
const char **ppOptions;
89209048
} ur_program_build_params_t;
89219049

9050+
///////////////////////////////////////////////////////////////////////////////
9051+
/// @brief Function parameters for urProgramBuildExp
9052+
/// @details Each entry is a pointer to the parameter passed to the function;
9053+
/// allowing the callback the ability to modify the parameter's value
9054+
typedef struct ur_program_build_exp_params_t {
9055+
ur_program_handle_t *phProgram;
9056+
uint32_t *pnumDevices;
9057+
ur_device_handle_t **pphDevices;
9058+
const char **ppOptions;
9059+
} ur_program_build_exp_params_t;
9060+
89229061
///////////////////////////////////////////////////////////////////////////////
89239062
/// @brief Function parameters for urProgramCompile
89249063
/// @details Each entry is a pointer to the parameter passed to the function;
@@ -8929,6 +9068,17 @@ typedef struct ur_program_compile_params_t {
89299068
const char **ppOptions;
89309069
} ur_program_compile_params_t;
89319070

9071+
///////////////////////////////////////////////////////////////////////////////
9072+
/// @brief Function parameters for urProgramCompileExp
9073+
/// @details Each entry is a pointer to the parameter passed to the function;
9074+
/// allowing the callback the ability to modify the parameter's value
9075+
typedef struct ur_program_compile_exp_params_t {
9076+
ur_program_handle_t *phProgram;
9077+
uint32_t *pnumDevices;
9078+
ur_device_handle_t **pphDevices;
9079+
const char **ppOptions;
9080+
} ur_program_compile_exp_params_t;
9081+
89329082
///////////////////////////////////////////////////////////////////////////////
89339083
/// @brief Function parameters for urProgramLink
89349084
/// @details Each entry is a pointer to the parameter passed to the function;
@@ -8941,6 +9091,20 @@ typedef struct ur_program_link_params_t {
89419091
ur_program_handle_t **pphProgram;
89429092
} ur_program_link_params_t;
89439093

9094+
///////////////////////////////////////////////////////////////////////////////
9095+
/// @brief Function parameters for urProgramLinkExp
9096+
/// @details Each entry is a pointer to the parameter passed to the function;
9097+
/// allowing the callback the ability to modify the parameter's value
9098+
typedef struct ur_program_link_exp_params_t {
9099+
ur_context_handle_t *phContext;
9100+
uint32_t *pnumDevices;
9101+
ur_device_handle_t **pphDevices;
9102+
uint32_t *pcount;
9103+
const ur_program_handle_t **pphPrograms;
9104+
const char **ppOptions;
9105+
ur_program_handle_t **pphProgram;
9106+
} ur_program_link_exp_params_t;
9107+
89449108
///////////////////////////////////////////////////////////////////////////////
89459109
/// @brief Function parameters for urProgramRetain
89469110
/// @details Each entry is a pointer to the parameter passed to the function;

include/ur_ddi.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,62 @@ typedef ur_result_t(UR_APICALL *ur_pfnGetProgramProcAddrTable_t)(
408408
ur_api_version_t,
409409
ur_program_dditable_t *);
410410

411+
///////////////////////////////////////////////////////////////////////////////
412+
/// @brief Function-pointer for urProgramBuildExp
413+
typedef ur_result_t(UR_APICALL *ur_pfnProgramBuildExp_t)(
414+
ur_program_handle_t,
415+
uint32_t,
416+
ur_device_handle_t *,
417+
const char *);
418+
419+
///////////////////////////////////////////////////////////////////////////////
420+
/// @brief Function-pointer for urProgramCompileExp
421+
typedef ur_result_t(UR_APICALL *ur_pfnProgramCompileExp_t)(
422+
ur_program_handle_t,
423+
uint32_t,
424+
ur_device_handle_t *,
425+
const char *);
426+
427+
///////////////////////////////////////////////////////////////////////////////
428+
/// @brief Function-pointer for urProgramLinkExp
429+
typedef ur_result_t(UR_APICALL *ur_pfnProgramLinkExp_t)(
430+
ur_context_handle_t,
431+
uint32_t,
432+
ur_device_handle_t *,
433+
uint32_t,
434+
const ur_program_handle_t *,
435+
const char *,
436+
ur_program_handle_t *);
437+
438+
///////////////////////////////////////////////////////////////////////////////
439+
/// @brief Table of ProgramExp functions pointers
440+
typedef struct ur_program_exp_dditable_t {
441+
ur_pfnProgramBuildExp_t pfnBuildExp;
442+
ur_pfnProgramCompileExp_t pfnCompileExp;
443+
ur_pfnProgramLinkExp_t pfnLinkExp;
444+
} ur_program_exp_dditable_t;
445+
446+
///////////////////////////////////////////////////////////////////////////////
447+
/// @brief Exported function for filling application's ProgramExp table
448+
/// with current process' addresses
449+
///
450+
/// @returns
451+
/// - ::UR_RESULT_SUCCESS
452+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
453+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
454+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_VERSION
455+
UR_DLLEXPORT ur_result_t UR_APICALL
456+
urGetProgramExpProcAddrTable(
457+
ur_api_version_t version, ///< [in] API version requested
458+
ur_program_exp_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers
459+
);
460+
461+
///////////////////////////////////////////////////////////////////////////////
462+
/// @brief Function-pointer for urGetProgramExpProcAddrTable
463+
typedef ur_result_t(UR_APICALL *ur_pfnGetProgramExpProcAddrTable_t)(
464+
ur_api_version_t,
465+
ur_program_exp_dditable_t *);
466+
411467
///////////////////////////////////////////////////////////////////////////////
412468
/// @brief Function-pointer for urKernelCreate
413469
typedef ur_result_t(UR_APICALL *ur_pfnKernelCreate_t)(
@@ -2250,6 +2306,7 @@ typedef struct ur_dditable_t {
22502306
ur_context_dditable_t Context;
22512307
ur_event_dditable_t Event;
22522308
ur_program_dditable_t Program;
2309+
ur_program_exp_dditable_t ProgramExp;
22532310
ur_kernel_dditable_t Kernel;
22542311
ur_kernel_exp_dditable_t KernelExp;
22552312
ur_sampler_dditable_t Sampler;

0 commit comments

Comments
 (0)