Skip to content

Commit 591638f

Browse files
igchorkbenzie
authored andcommitted
[UR][L0] Add support for passing device list to urProgramBuild
piProgramBuild receives a list of devices, while urProgramBuild does not. This produces a series of issues when a UR program needs to be created for a specific device. So define a new API, called urProgramBuildExp to pass this list. Authored-by: [email protected]
1 parent 3a85197 commit 591638f

File tree

13 files changed

+584
-0
lines changed

13 files changed

+584
-0
lines changed

include/ur.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ 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+
PROGRAM_BUILD_EXP = 197 ## Enumerator for ::urProgramBuildExp
205206

206207
class ur_function_t(c_int):
207208
def __str__(self):
@@ -2612,6 +2613,21 @@ class ur_program_dditable_t(Structure):
26122613
("pfnCreateWithNativeHandle", c_void_p) ## _urProgramCreateWithNativeHandle_t
26132614
]
26142615

2616+
###############################################################################
2617+
## @brief Function-pointer for urProgramBuildExp
2618+
if __use_win_types:
2619+
_urProgramBuildExp_t = WINFUNCTYPE( ur_result_t, ur_context_handle_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2620+
else:
2621+
_urProgramBuildExp_t = CFUNCTYPE( ur_result_t, ur_context_handle_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2622+
2623+
2624+
###############################################################################
2625+
## @brief Table of ProgramExp functions pointers
2626+
class ur_program_exp_dditable_t(Structure):
2627+
_fields_ = [
2628+
("pfnBuildExp", c_void_p) ## _urProgramBuildExp_t
2629+
]
2630+
26152631
###############################################################################
26162632
## @brief Function-pointer for urKernelCreate
26172633
if __use_win_types:
@@ -3843,6 +3859,7 @@ class ur_dditable_t(Structure):
38433859
("Context", ur_context_dditable_t),
38443860
("Event", ur_event_dditable_t),
38453861
("Program", ur_program_dditable_t),
3862+
("ProgramExp", ur_program_exp_dditable_t),
38463863
("Kernel", ur_kernel_dditable_t),
38473864
("KernelExp", ur_kernel_exp_dditable_t),
38483865
("Sampler", ur_sampler_dditable_t),
@@ -3947,6 +3964,16 @@ def __init__(self, version : ur_api_version_t):
39473964
self.urProgramGetNativeHandle = _urProgramGetNativeHandle_t(self.__dditable.Program.pfnGetNativeHandle)
39483965
self.urProgramCreateWithNativeHandle = _urProgramCreateWithNativeHandle_t(self.__dditable.Program.pfnCreateWithNativeHandle)
39493966

3967+
# call driver to get function pointers
3968+
ProgramExp = ur_program_exp_dditable_t()
3969+
r = ur_result_v(self.__dll.urGetProgramExpProcAddrTable(version, byref(ProgramExp)))
3970+
if r != ur_result_v.SUCCESS:
3971+
raise Exception(r)
3972+
self.__dditable.ProgramExp = ProgramExp
3973+
3974+
# attach function interface to function address
3975+
self.urProgramBuildExp = _urProgramBuildExp_t(self.__dditable.ProgramExp.pfnBuildExp)
3976+
39503977
# call driver to get function pointers
39513978
Kernel = ur_kernel_dditable_t()
39523979
r = ur_result_v(self.__dll.urGetKernelProcAddrTable(version, byref(Kernel)))

include/ur_api.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ 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_PROGRAM_BUILD_EXP = 197, ///< Enumerator for ::urProgramBuildExp
214215
/// @cond
215216
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
216217
/// @endcond
@@ -4031,6 +4032,43 @@ urProgramBuild(
40314032
const char *pOptions ///< [in][optional] pointer to build options null-terminated string.
40324033
);
40334034

4035+
///////////////////////////////////////////////////////////////////////////////
4036+
/// @brief Produces an executable program from one program, negates need for the
4037+
/// linking step.
4038+
///
4039+
/// @details
4040+
/// - The application may call this function from simultaneous threads.
4041+
/// - Following a successful call to this entry point, the program passed
4042+
/// will contain a binary of the ::UR_PROGRAM_BINARY_TYPE_EXECUTABLE type
4043+
/// for each device in `hContext`.
4044+
///
4045+
/// @remarks
4046+
/// _Analogues_
4047+
/// - **clBuildProgram**
4048+
///
4049+
/// @returns
4050+
/// - ::UR_RESULT_SUCCESS
4051+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
4052+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
4053+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
4054+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
4055+
/// + `NULL == hContext`
4056+
/// + `NULL == hProgram`
4057+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
4058+
/// + `NULL == phDevices`
4059+
/// - ::UR_RESULT_ERROR_INVALID_PROGRAM
4060+
/// + If `hProgram` isn't a valid program object.
4061+
/// - ::UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE
4062+
/// + If an error occurred when building `hProgram`.
4063+
UR_APIEXPORT ur_result_t UR_APICALL
4064+
urProgramBuildExp(
4065+
ur_context_handle_t hContext, ///< [in] handle of the context instance.
4066+
ur_program_handle_t hProgram, ///< [in] Handle of the program to build.
4067+
uint32_t numDevices, ///< [in] number of devices
4068+
ur_device_handle_t *phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
4069+
const char *pOptions ///< [in][optional] pointer to build options null-terminated string.
4070+
);
4071+
40344072
///////////////////////////////////////////////////////////////////////////////
40354073
/// @brief Produces an executable program from one or more programs.
40364074
///
@@ -8865,6 +8903,18 @@ typedef struct ur_program_build_params_t {
88658903
const char **ppOptions;
88668904
} ur_program_build_params_t;
88678905

8906+
///////////////////////////////////////////////////////////////////////////////
8907+
/// @brief Function parameters for urProgramBuildExp
8908+
/// @details Each entry is a pointer to the parameter passed to the function;
8909+
/// allowing the callback the ability to modify the parameter's value
8910+
typedef struct ur_program_build_exp_params_t {
8911+
ur_context_handle_t *phContext;
8912+
ur_program_handle_t *phProgram;
8913+
uint32_t *pnumDevices;
8914+
ur_device_handle_t **pphDevices;
8915+
const char **ppOptions;
8916+
} ur_program_build_exp_params_t;
8917+
88688918
///////////////////////////////////////////////////////////////////////////////
88698919
/// @brief Function parameters for urProgramCompile
88708920
/// @details Each entry is a pointer to the parameter passed to the function;

include/ur_ddi.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,42 @@ 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_context_handle_t,
415+
ur_program_handle_t,
416+
uint32_t,
417+
ur_device_handle_t *,
418+
const char *);
419+
420+
///////////////////////////////////////////////////////////////////////////////
421+
/// @brief Table of ProgramExp functions pointers
422+
typedef struct ur_program_exp_dditable_t {
423+
ur_pfnProgramBuildExp_t pfnBuildExp;
424+
} ur_program_exp_dditable_t;
425+
426+
///////////////////////////////////////////////////////////////////////////////
427+
/// @brief Exported function for filling application's ProgramExp table
428+
/// with current process' addresses
429+
///
430+
/// @returns
431+
/// - ::UR_RESULT_SUCCESS
432+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
433+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
434+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_VERSION
435+
UR_DLLEXPORT ur_result_t UR_APICALL
436+
urGetProgramExpProcAddrTable(
437+
ur_api_version_t version, ///< [in] API version requested
438+
ur_program_exp_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers
439+
);
440+
441+
///////////////////////////////////////////////////////////////////////////////
442+
/// @brief Function-pointer for urGetProgramExpProcAddrTable
443+
typedef ur_result_t(UR_APICALL *ur_pfnGetProgramExpProcAddrTable_t)(
444+
ur_api_version_t,
445+
ur_program_exp_dditable_t *);
446+
411447
///////////////////////////////////////////////////////////////////////////////
412448
/// @brief Function-pointer for urKernelCreate
413449
typedef ur_result_t(UR_APICALL *ur_pfnKernelCreate_t)(
@@ -2250,6 +2286,7 @@ typedef struct ur_dditable_t {
22502286
ur_context_dditable_t Context;
22512287
ur_event_dditable_t Event;
22522288
ur_program_dditable_t Program;
2289+
ur_program_exp_dditable_t ProgramExp;
22532290
ur_kernel_dditable_t Kernel;
22542291
ur_kernel_exp_dditable_t KernelExp;
22552292
ur_sampler_dditable_t Sampler;

scripts/core/program.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,39 @@ returns:
182182
- "If an error occurred when building `hProgram`."
183183
--- #--------------------------------------------------------------------------
184184
type: function
185+
desc: "Produces an executable program from one program, negates need for the linking step."
186+
class: $xProgram
187+
name: BuildExp
188+
ordinal: "2"
189+
decl: static
190+
analogue:
191+
- "**clBuildProgram**"
192+
details:
193+
- "The application may call this function from simultaneous threads."
194+
- "Following a successful call to this entry point, the program passed will contain a binary of the $X_PROGRAM_BINARY_TYPE_EXECUTABLE type for each device in `hContext`."
195+
params:
196+
- type: $x_context_handle_t
197+
name: hContext
198+
desc: "[in] handle of the context instance."
199+
- type: $x_program_handle_t
200+
name: hProgram
201+
desc: "[in] Handle of the program to build."
202+
- type: uint32_t
203+
name: numDevices
204+
desc: "[in] number of devices"
205+
- type: $x_device_handle_t*
206+
name: phDevices
207+
desc: "[in][range(0, numDevices)] pointer to array of device handles"
208+
- type: const char*
209+
name: pOptions
210+
desc: "[in][optional] pointer to build options null-terminated string."
211+
returns:
212+
- $X_RESULT_ERROR_INVALID_PROGRAM:
213+
- "If `hProgram` isn't a valid program object."
214+
- $X_RESULT_ERROR_PROGRAM_BUILD_FAILURE:
215+
- "If an error occurred when building `hProgram`."
216+
--- #--------------------------------------------------------------------------
217+
type: function
185218
desc: "Produces an executable program from one or more programs."
186219
class: $xProgram
187220
name: Compile

scripts/core/registry.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ etors:
547547
- name: COMMAND_BUFFER_APPEND_USM_ADVISE_EXP
548548
desc: Enumerator for $xCommandBufferAppendUSMAdviseExp
549549
value: '196'
550+
- name: PROGRAM_BUILD_EXP
551+
desc: Enumerator for $xProgramBuildExp
552+
value: '197'
550553
---
551554
type: enum
552555
desc: Defines structure types

source/adapters/null/ur_nullddi.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,33 @@ __urdlllocal ur_result_t UR_APICALL urProgramBuild(
17491749
return exceptionToResult(std::current_exception());
17501750
}
17511751

1752+
///////////////////////////////////////////////////////////////////////////////
1753+
/// @brief Intercept function for urProgramBuildExp
1754+
__urdlllocal ur_result_t UR_APICALL urProgramBuildExp(
1755+
ur_context_handle_t hContext, ///< [in] handle of the context instance.
1756+
ur_program_handle_t hProgram, ///< [in] Handle of the program to build.
1757+
uint32_t numDevices, ///< [in] number of devices
1758+
ur_device_handle_t *
1759+
phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
1760+
const char *
1761+
pOptions ///< [in][optional] pointer to build options null-terminated string.
1762+
) try {
1763+
ur_result_t result = UR_RESULT_SUCCESS;
1764+
1765+
// if the driver has created a custom function, then call it instead of using the generic path
1766+
auto pfnBuildExp = d_context.urDdiTable.ProgramExp.pfnBuildExp;
1767+
if (nullptr != pfnBuildExp) {
1768+
result =
1769+
pfnBuildExp(hContext, hProgram, numDevices, phDevices, pOptions);
1770+
} else {
1771+
// generic implementation
1772+
}
1773+
1774+
return result;
1775+
} catch (...) {
1776+
return exceptionToResult(std::current_exception());
1777+
}
1778+
17521779
///////////////////////////////////////////////////////////////////////////////
17531780
/// @brief Intercept function for urProgramCompile
17541781
__urdlllocal ur_result_t UR_APICALL urProgramCompile(
@@ -5853,6 +5880,36 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramProcAddrTable(
58535880
return exceptionToResult(std::current_exception());
58545881
}
58555882

5883+
///////////////////////////////////////////////////////////////////////////////
5884+
/// @brief Exported function for filling application's ProgramExp table
5885+
/// with current process' addresses
5886+
///
5887+
/// @returns
5888+
/// - ::UR_RESULT_SUCCESS
5889+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
5890+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_VERSION
5891+
UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramExpProcAddrTable(
5892+
ur_api_version_t version, ///< [in] API version requested
5893+
ur_program_exp_dditable_t
5894+
*pDdiTable ///< [in,out] pointer to table of DDI function pointers
5895+
) try {
5896+
if (nullptr == pDdiTable) {
5897+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
5898+
}
5899+
5900+
if (driver::d_context.version < version) {
5901+
return UR_RESULT_ERROR_UNSUPPORTED_VERSION;
5902+
}
5903+
5904+
ur_result_t result = UR_RESULT_SUCCESS;
5905+
5906+
pDdiTable->pfnBuildExp = driver::urProgramBuildExp;
5907+
5908+
return result;
5909+
} catch (...) {
5910+
return exceptionToResult(std::current_exception());
5911+
}
5912+
58565913
///////////////////////////////////////////////////////////////////////////////
58575914
/// @brief Exported function for filling application's Queue table
58585915
/// with current process' addresses

source/common/ur_params.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,10 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
12021202
case UR_FUNCTION_COMMAND_BUFFER_APPEND_USM_ADVISE_EXP:
12031203
os << "UR_FUNCTION_COMMAND_BUFFER_APPEND_USM_ADVISE_EXP";
12041204
break;
1205+
1206+
case UR_FUNCTION_PROGRAM_BUILD_EXP:
1207+
os << "UR_FUNCTION_PROGRAM_BUILD_EXP";
1208+
break;
12051209
default:
12061210
os << "unknown enumerator";
12071211
break;
@@ -14429,6 +14433,44 @@ operator<<(std::ostream &os,
1442914433
return os;
1443014434
}
1443114435

14436+
inline std::ostream &operator<<(
14437+
std::ostream &os,
14438+
[[maybe_unused]] const struct ur_program_build_exp_params_t *params) {
14439+
14440+
os << ".hContext = ";
14441+
14442+
ur_params::serializePtr(os, *(params->phContext));
14443+
14444+
os << ", ";
14445+
os << ".hProgram = ";
14446+
14447+
ur_params::serializePtr(os, *(params->phProgram));
14448+
14449+
os << ", ";
14450+
os << ".numDevices = ";
14451+
14452+
os << *(params->pnumDevices);
14453+
14454+
os << ", ";
14455+
os << ".phDevices = {";
14456+
for (size_t i = 0;
14457+
*(params->pphDevices) != NULL && i < *params->pnumDevices; ++i) {
14458+
if (i != 0) {
14459+
os << ", ";
14460+
}
14461+
14462+
ur_params::serializePtr(os, (*(params->pphDevices))[i]);
14463+
}
14464+
os << "}";
14465+
14466+
os << ", ";
14467+
os << ".pOptions = ";
14468+
14469+
ur_params::serializePtr(os, *(params->ppOptions));
14470+
14471+
return os;
14472+
}
14473+
1443214474
inline std::ostream &
1443314475
operator<<(std::ostream &os,
1443414476
[[maybe_unused]] const struct ur_program_compile_params_t *params) {
@@ -16215,6 +16257,9 @@ inline int serializeFunctionParams(std::ostream &os, uint32_t function,
1621516257
case UR_FUNCTION_PROGRAM_BUILD: {
1621616258
os << (const struct ur_program_build_params_t *)params;
1621716259
} break;
16260+
case UR_FUNCTION_PROGRAM_BUILD_EXP: {
16261+
os << (const struct ur_program_build_exp_params_t *)params;
16262+
} break;
1621816263
case UR_FUNCTION_PROGRAM_COMPILE: {
1621916264
os << (const struct ur_program_compile_params_t *)params;
1622016265
} break;

0 commit comments

Comments
 (0)