Skip to content

Commit cf9a934

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: jaime.a.arteaga.molina@intel.com
1 parent 47b6386 commit cf9a934

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
@@ -196,6 +196,7 @@ class ur_function_v(IntEnum):
196196
ADAPTER_RETAIN = 179 ## Enumerator for ::urAdapterRetain
197197
ADAPTER_GET_LAST_ERROR = 180 ## Enumerator for ::urAdapterGetLastError
198198
ADAPTER_GET_INFO = 181 ## Enumerator for ::urAdapterGetInfo
199+
PROGRAM_BUILD_EXP = 197 ## Enumerator for ::urProgramBuildExp
199200

200201
class ur_function_t(c_int):
201202
def __str__(self):
@@ -2564,6 +2565,21 @@ class ur_program_dditable_t(Structure):
25642565
("pfnCreateWithNativeHandle", c_void_p) ## _urProgramCreateWithNativeHandle_t
25652566
]
25662567

2568+
###############################################################################
2569+
## @brief Function-pointer for urProgramBuildExp
2570+
if __use_win_types:
2571+
_urProgramBuildExp_t = WINFUNCTYPE( ur_result_t, ur_context_handle_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2572+
else:
2573+
_urProgramBuildExp_t = CFUNCTYPE( ur_result_t, ur_context_handle_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2574+
2575+
2576+
###############################################################################
2577+
## @brief Table of ProgramExp functions pointers
2578+
class ur_program_exp_dditable_t(Structure):
2579+
_fields_ = [
2580+
("pfnBuildExp", c_void_p) ## _urProgramBuildExp_t
2581+
]
2582+
25672583
###############################################################################
25682584
## @brief Function-pointer for urKernelCreate
25692585
if __use_win_types:
@@ -3749,6 +3765,7 @@ class ur_dditable_t(Structure):
37493765
("Context", ur_context_dditable_t),
37503766
("Event", ur_event_dditable_t),
37513767
("Program", ur_program_dditable_t),
3768+
("ProgramExp", ur_program_exp_dditable_t),
37523769
("Kernel", ur_kernel_dditable_t),
37533770
("Sampler", ur_sampler_dditable_t),
37543771
("Mem", ur_mem_dditable_t),
@@ -3851,6 +3868,16 @@ def __init__(self, version : ur_api_version_t):
38513868
self.urProgramGetNativeHandle = _urProgramGetNativeHandle_t(self.__dditable.Program.pfnGetNativeHandle)
38523869
self.urProgramCreateWithNativeHandle = _urProgramCreateWithNativeHandle_t(self.__dditable.Program.pfnCreateWithNativeHandle)
38533870

3871+
# call driver to get function pointers
3872+
ProgramExp = ur_program_exp_dditable_t()
3873+
r = ur_result_v(self.__dll.urGetProgramExpProcAddrTable(version, byref(ProgramExp)))
3874+
if r != ur_result_v.SUCCESS:
3875+
raise Exception(r)
3876+
self.__dditable.ProgramExp = ProgramExp
3877+
3878+
# attach function interface to function address
3879+
self.urProgramBuildExp = _urProgramBuildExp_t(self.__dditable.ProgramExp.pfnBuildExp)
3880+
38543881
# call driver to get function pointers
38553882
Kernel = ur_kernel_dditable_t()
38563883
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
@@ -205,6 +205,7 @@ typedef enum ur_function_t {
205205
UR_FUNCTION_ADAPTER_RETAIN = 179, ///< Enumerator for ::urAdapterRetain
206206
UR_FUNCTION_ADAPTER_GET_LAST_ERROR = 180, ///< Enumerator for ::urAdapterGetLastError
207207
UR_FUNCTION_ADAPTER_GET_INFO = 181, ///< Enumerator for ::urAdapterGetInfo
208+
UR_FUNCTION_PROGRAM_BUILD_EXP = 197, ///< Enumerator for ::urProgramBuildExp
208209
/// @cond
209210
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
210211
/// @endcond
@@ -3993,6 +3994,43 @@ urProgramBuild(
39933994
const char *pOptions ///< [in][optional] pointer to build options null-terminated string.
39943995
);
39953996

3997+
///////////////////////////////////////////////////////////////////////////////
3998+
/// @brief Produces an executable program from one program, negates need for the
3999+
/// linking step.
4000+
///
4001+
/// @details
4002+
/// - The application may call this function from simultaneous threads.
4003+
/// - Following a successful call to this entry point, the program passed
4004+
/// will contain a binary of the ::UR_PROGRAM_BINARY_TYPE_EXECUTABLE type
4005+
/// for each device in `hContext`.
4006+
///
4007+
/// @remarks
4008+
/// _Analogues_
4009+
/// - **clBuildProgram**
4010+
///
4011+
/// @returns
4012+
/// - ::UR_RESULT_SUCCESS
4013+
/// - ::UR_RESULT_ERROR_UNINITIALIZED
4014+
/// - ::UR_RESULT_ERROR_DEVICE_LOST
4015+
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
4016+
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
4017+
/// + `NULL == hContext`
4018+
/// + `NULL == hProgram`
4019+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
4020+
/// + `NULL == phDevices`
4021+
/// - ::UR_RESULT_ERROR_INVALID_PROGRAM
4022+
/// + If `hProgram` isn't a valid program object.
4023+
/// - ::UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE
4024+
/// + If an error occurred when building `hProgram`.
4025+
UR_APIEXPORT ur_result_t UR_APICALL
4026+
urProgramBuildExp(
4027+
ur_context_handle_t hContext, ///< [in] handle of the context instance.
4028+
ur_program_handle_t hProgram, ///< [in] Handle of the program to build.
4029+
uint32_t numDevices, ///< [in] number of devices
4030+
ur_device_handle_t *phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
4031+
const char *pOptions ///< [in][optional] pointer to build options null-terminated string.
4032+
);
4033+
39964034
///////////////////////////////////////////////////////////////////////////////
39974035
/// @brief Produces an executable program from one or more programs.
39984036
///
@@ -8526,6 +8564,18 @@ typedef struct ur_program_build_params_t {
85268564
const char **ppOptions;
85278565
} ur_program_build_params_t;
85288566

8567+
///////////////////////////////////////////////////////////////////////////////
8568+
/// @brief Function parameters for urProgramBuildExp
8569+
/// @details Each entry is a pointer to the parameter passed to the function;
8570+
/// allowing the callback the ability to modify the parameter's value
8571+
typedef struct ur_program_build_exp_params_t {
8572+
ur_context_handle_t *phContext;
8573+
ur_program_handle_t *phProgram;
8574+
uint32_t *pnumDevices;
8575+
ur_device_handle_t **pphDevices;
8576+
const char **ppOptions;
8577+
} ur_program_build_exp_params_t;
8578+
85298579
///////////////////////////////////////////////////////////////////////////////
85308580
/// @brief Function parameters for urProgramCompile
85318581
/// @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)(
@@ -2139,6 +2175,7 @@ typedef struct ur_dditable_t {
21392175
ur_context_dditable_t Context;
21402176
ur_event_dditable_t Event;
21412177
ur_program_dditable_t Program;
2178+
ur_program_exp_dditable_t ProgramExp;
21422179
ur_kernel_dditable_t Kernel;
21432180
ur_sampler_dditable_t Sampler;
21442181
ur_mem_dditable_t Mem;

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
@@ -529,6 +529,9 @@ etors:
529529
- name: ADAPTER_GET_INFO
530530
desc: Enumerator for $xAdapterGetInfo
531531
value: '181'
532+
- name: PROGRAM_BUILD_EXP
533+
desc: Enumerator for $xProgramBuildExp
534+
value: '197'
532535
---
533536
type: enum
534537
desc: Defines structure types

source/adapters/null/ur_nullddi.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,33 @@ __urdlllocal ur_result_t UR_APICALL urProgramBuild(
17921792
return exceptionToResult(std::current_exception());
17931793
}
17941794

1795+
///////////////////////////////////////////////////////////////////////////////
1796+
/// @brief Intercept function for urProgramBuildExp
1797+
__urdlllocal ur_result_t UR_APICALL urProgramBuildExp(
1798+
ur_context_handle_t hContext, ///< [in] handle of the context instance.
1799+
ur_program_handle_t hProgram, ///< [in] Handle of the program to build.
1800+
uint32_t numDevices, ///< [in] number of devices
1801+
ur_device_handle_t *
1802+
phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
1803+
const char *
1804+
pOptions ///< [in][optional] pointer to build options null-terminated string.
1805+
) try {
1806+
ur_result_t result = UR_RESULT_SUCCESS;
1807+
1808+
// if the driver has created a custom function, then call it instead of using the generic path
1809+
auto pfnBuildExp = d_context.urDdiTable.ProgramExp.pfnBuildExp;
1810+
if (nullptr != pfnBuildExp) {
1811+
result =
1812+
pfnBuildExp(hContext, hProgram, numDevices, phDevices, pOptions);
1813+
} else {
1814+
// generic implementation
1815+
}
1816+
1817+
return result;
1818+
} catch (...) {
1819+
return exceptionToResult(std::current_exception());
1820+
}
1821+
17951822
///////////////////////////////////////////////////////////////////////////////
17961823
/// @brief Intercept function for urProgramCompile
17971824
__urdlllocal ur_result_t UR_APICALL urProgramCompile(
@@ -5614,6 +5641,36 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramProcAddrTable(
56145641
return exceptionToResult(std::current_exception());
56155642
}
56165643

5644+
///////////////////////////////////////////////////////////////////////////////
5645+
/// @brief Exported function for filling application's ProgramExp table
5646+
/// with current process' addresses
5647+
///
5648+
/// @returns
5649+
/// - ::UR_RESULT_SUCCESS
5650+
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
5651+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_VERSION
5652+
UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramExpProcAddrTable(
5653+
ur_api_version_t version, ///< [in] API version requested
5654+
ur_program_exp_dditable_t
5655+
*pDdiTable ///< [in,out] pointer to table of DDI function pointers
5656+
) try {
5657+
if (nullptr == pDdiTable) {
5658+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
5659+
}
5660+
5661+
if (driver::d_context.version < version) {
5662+
return UR_RESULT_ERROR_UNSUPPORTED_VERSION;
5663+
}
5664+
5665+
ur_result_t result = UR_RESULT_SUCCESS;
5666+
5667+
pDdiTable->pfnBuildExp = driver::urProgramBuildExp;
5668+
5669+
return result;
5670+
} catch (...) {
5671+
return exceptionToResult(std::current_exception());
5672+
}
5673+
56175674
///////////////////////////////////////////////////////////////////////////////
56185675
/// @brief Exported function for filling application's Queue table
56195676
/// with current process' addresses

source/common/ur_params.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,10 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) {
11411141
case UR_FUNCTION_ADAPTER_GET_INFO:
11421142
os << "UR_FUNCTION_ADAPTER_GET_INFO";
11431143
break;
1144+
1145+
case UR_FUNCTION_PROGRAM_BUILD_EXP:
1146+
os << "UR_FUNCTION_PROGRAM_BUILD_EXP";
1147+
break;
11441148
default:
11451149
os << "unknown enumerator";
11461150
break;
@@ -13989,6 +13993,44 @@ operator<<(std::ostream &os, const struct ur_program_build_params_t *params) {
1398913993
return os;
1399013994
}
1399113995

13996+
inline std::ostream &
13997+
operator<<(std::ostream &os,
13998+
const struct ur_program_build_exp_params_t *params) {
13999+
14000+
os << ".hContext = ";
14001+
14002+
ur_params::serializePtr(os, *(params->phContext));
14003+
14004+
os << ", ";
14005+
os << ".hProgram = ";
14006+
14007+
ur_params::serializePtr(os, *(params->phProgram));
14008+
14009+
os << ", ";
14010+
os << ".numDevices = ";
14011+
14012+
os << *(params->pnumDevices);
14013+
14014+
os << ", ";
14015+
os << ".phDevices = {";
14016+
for (size_t i = 0;
14017+
*(params->pphDevices) != NULL && i < *params->pnumDevices; ++i) {
14018+
if (i != 0) {
14019+
os << ", ";
14020+
}
14021+
14022+
ur_params::serializePtr(os, (*(params->pphDevices))[i]);
14023+
}
14024+
os << "}";
14025+
14026+
os << ", ";
14027+
os << ".pOptions = ";
14028+
14029+
ur_params::serializePtr(os, *(params->ppOptions));
14030+
14031+
return os;
14032+
}
14033+
1399214034
inline std::ostream &
1399314035
operator<<(std::ostream &os, const struct ur_program_compile_params_t *params) {
1399414036

@@ -15713,6 +15755,9 @@ inline int serializeFunctionParams(std::ostream &os, uint32_t function,
1571315755
case UR_FUNCTION_PROGRAM_BUILD: {
1571415756
os << (const struct ur_program_build_params_t *)params;
1571515757
} break;
15758+
case UR_FUNCTION_PROGRAM_BUILD_EXP: {
15759+
os << (const struct ur_program_build_exp_params_t *)params;
15760+
} break;
1571615761
case UR_FUNCTION_PROGRAM_COMPILE: {
1571715762
os << (const struct ur_program_compile_params_t *)params;
1571815763
} break;

0 commit comments

Comments
 (0)