Skip to content

Commit c583ecc

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 534071e commit c583ecc

File tree

15 files changed

+586
-0
lines changed

15 files changed

+586
-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 = 182 ## Enumerator for ::urProgramBuildExp
199200

200201
class ur_function_t(c_int):
201202
def __str__(self):
@@ -2569,6 +2570,21 @@ class ur_program_dditable_t(Structure):
25692570
("pfnCreateWithNativeHandle", c_void_p) ## _urProgramCreateWithNativeHandle_t
25702571
]
25712572

2573+
###############################################################################
2574+
## @brief Function-pointer for urProgramBuildExp
2575+
if __use_win_types:
2576+
_urProgramBuildExp_t = WINFUNCTYPE( ur_result_t, ur_context_handle_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2577+
else:
2578+
_urProgramBuildExp_t = CFUNCTYPE( ur_result_t, ur_context_handle_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
2579+
2580+
2581+
###############################################################################
2582+
## @brief Table of ProgramExp functions pointers
2583+
class ur_program_exp_dditable_t(Structure):
2584+
_fields_ = [
2585+
("pfnBuildExp", c_void_p) ## _urProgramBuildExp_t
2586+
]
2587+
25722588
###############################################################################
25732589
## @brief Function-pointer for urKernelCreate
25742590
if __use_win_types:
@@ -3754,6 +3770,7 @@ class ur_dditable_t(Structure):
37543770
("Context", ur_context_dditable_t),
37553771
("Event", ur_event_dditable_t),
37563772
("Program", ur_program_dditable_t),
3773+
("ProgramExp", ur_program_exp_dditable_t),
37573774
("Kernel", ur_kernel_dditable_t),
37583775
("Sampler", ur_sampler_dditable_t),
37593776
("Mem", ur_mem_dditable_t),
@@ -3856,6 +3873,16 @@ def __init__(self, version : ur_api_version_t):
38563873
self.urProgramGetNativeHandle = _urProgramGetNativeHandle_t(self.__dditable.Program.pfnGetNativeHandle)
38573874
self.urProgramCreateWithNativeHandle = _urProgramCreateWithNativeHandle_t(self.__dditable.Program.pfnCreateWithNativeHandle)
38583875

3876+
# call driver to get function pointers
3877+
ProgramExp = ur_program_exp_dditable_t()
3878+
r = ur_result_v(self.__dll.urGetProgramExpProcAddrTable(version, byref(ProgramExp)))
3879+
if r != ur_result_v.SUCCESS:
3880+
raise Exception(r)
3881+
self.__dditable.ProgramExp = ProgramExp
3882+
3883+
# attach function interface to function address
3884+
self.urProgramBuildExp = _urProgramBuildExp_t(self.__dditable.ProgramExp.pfnBuildExp)
3885+
38593886
# call driver to get function pointers
38603887
Kernel = ur_kernel_dditable_t()
38613888
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 = 182, ///< Enumerator for ::urProgramBuildExp
208209
/// @cond
209210
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
210211
/// @endcond
@@ -4000,6 +4001,43 @@ urProgramBuild(
40004001
const char *pOptions ///< [in][optional] pointer to build options null-terminated string.
40014002
);
40024003

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

8572+
///////////////////////////////////////////////////////////////////////////////
8573+
/// @brief Function parameters for urProgramBuildExp
8574+
/// @details Each entry is a pointer to the parameter passed to the function;
8575+
/// allowing the callback the ability to modify the parameter's value
8576+
typedef struct ur_program_build_exp_params_t {
8577+
ur_context_handle_t *phContext;
8578+
ur_program_handle_t *phProgram;
8579+
uint32_t *pnumDevices;
8580+
ur_device_handle_t **pphDevices;
8581+
const char **ppOptions;
8582+
} ur_program_build_exp_params_t;
8583+
85348584
///////////////////////////////////////////////////////////////////////////////
85358585
/// @brief Function parameters for urProgramCompile
85368586
/// @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: '182'
532535
---
533536
type: enum
534537
desc: Defines structure types

source/adapters/adapter.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ EXPORTS
1111
urGetPhysicalMemProcAddrTable
1212
urGetPlatformProcAddrTable
1313
urGetProgramProcAddrTable
14+
urGetProgramExpProcAddrTable
1415
urGetQueueProcAddrTable
1516
urGetSamplerProcAddrTable
1617
urGetUSMProcAddrTable

source/adapters/adapter.map.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
urGetPhysicalMemProcAddrTable;
1212
urGetPlatformProcAddrTable;
1313
urGetProgramProcAddrTable;
14+
urGetProgramExpProcAddrTable;
1415
urGetQueueProcAddrTable;
1516
urGetSamplerProcAddrTable;
1617
urGetUSMProcAddrTable;

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;
@@ -14007,6 +14011,44 @@ operator<<(std::ostream &os, const struct ur_program_build_params_t *params) {
1400714011
return os;
1400814012
}
1400914013

14014+
inline std::ostream &
14015+
operator<<(std::ostream &os,
14016+
const struct ur_program_build_exp_params_t *params) {
14017+
14018+
os << ".hContext = ";
14019+
14020+
ur_params::serializePtr(os, *(params->phContext));
14021+
14022+
os << ", ";
14023+
os << ".hProgram = ";
14024+
14025+
ur_params::serializePtr(os, *(params->phProgram));
14026+
14027+
os << ", ";
14028+
os << ".numDevices = ";
14029+
14030+
os << *(params->pnumDevices);
14031+
14032+
os << ", ";
14033+
os << ".phDevices = {";
14034+
for (size_t i = 0;
14035+
*(params->pphDevices) != NULL && i < *params->pnumDevices; ++i) {
14036+
if (i != 0) {
14037+
os << ", ";
14038+
}
14039+
14040+
ur_params::serializePtr(os, (*(params->pphDevices))[i]);
14041+
}
14042+
os << "}";
14043+
14044+
os << ", ";
14045+
os << ".pOptions = ";
14046+
14047+
ur_params::serializePtr(os, *(params->ppOptions));
14048+
14049+
return os;
14050+
}
14051+
1401014052
inline std::ostream &
1401114053
operator<<(std::ostream &os, const struct ur_program_compile_params_t *params) {
1401214054

@@ -15731,6 +15773,9 @@ inline int serializeFunctionParams(std::ostream &os, uint32_t function,
1573115773
case UR_FUNCTION_PROGRAM_BUILD: {
1573215774
os << (const struct ur_program_build_params_t *)params;
1573315775
} break;
15776+
case UR_FUNCTION_PROGRAM_BUILD_EXP: {
15777+
os << (const struct ur_program_build_exp_params_t *)params;
15778+
} break;
1573415779
case UR_FUNCTION_PROGRAM_COMPILE: {
1573515780
os << (const struct ur_program_compile_params_t *)params;
1573615781
} break;

0 commit comments

Comments
 (0)