Skip to content

Commit

Permalink
Merge pull request #919 from igchor/multi_dev_build_0.7
Browse files Browse the repository at this point in the history
[UR][L0] Add support for passing device list to urProgramBuild
  • Loading branch information
kbenzie authored Oct 19, 2023
2 parents 47b6386 + 13aaca7 commit 32ff17d
Show file tree
Hide file tree
Showing 15 changed files with 1,510 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ jobs:
- name: Install prerequisites
run: python3 -m pip install -r third_party/requirements.txt

- name: Install doxygen
run: |
$WorkingDir = $PWD.Path
Invoke-WebRequest -Uri https://github.com/doxygen/doxygen/releases/download/Release_1_9_8/doxygen-1.9.8.windows.x64.bin.zip -OutFile "$WorkingDir\doxygen.zip"
Expand-Archive -Path "$WorkingDir\doxygen.zip"
Add-Content $env:GITHUB_PATH "$WorkingDir\doxygen"
- name: Configure CMake
run: >
cmake
Expand Down
52 changes: 52 additions & 0 deletions include/ur.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ class ur_function_v(IntEnum):
ADAPTER_RETAIN = 179 ## Enumerator for ::urAdapterRetain
ADAPTER_GET_LAST_ERROR = 180 ## Enumerator for ::urAdapterGetLastError
ADAPTER_GET_INFO = 181 ## Enumerator for ::urAdapterGetInfo
PROGRAM_BUILD_EXP = 197 ## Enumerator for ::urProgramBuildExp
PROGRAM_COMPILE_EXP = 198 ## Enumerator for ::urProgramCompileExp
PROGRAM_LINK_EXP = 199 ## Enumerator for ::urProgramLinkExp

class ur_function_t(c_int):
def __str__(self):
Expand Down Expand Up @@ -2248,6 +2251,11 @@ class ur_exp_command_buffer_sync_point_t(c_ulong):
class ur_exp_command_buffer_handle_t(c_void_p):
pass

###############################################################################
## @brief The extension string which defines support for test
## which is returned when querying device extensions.
UR_MULTI_DEVICE_COMPILE_EXTENSION_STRING_EXP = "ur_exp_multi_device_compile"

###############################################################################
## @brief Supported peer info
class ur_exp_peer_info_v(IntEnum):
Expand Down Expand Up @@ -2564,6 +2572,37 @@ class ur_program_dditable_t(Structure):
("pfnCreateWithNativeHandle", c_void_p) ## _urProgramCreateWithNativeHandle_t
]

###############################################################################
## @brief Function-pointer for urProgramBuildExp
if __use_win_types:
_urProgramBuildExp_t = WINFUNCTYPE( ur_result_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
else:
_urProgramBuildExp_t = CFUNCTYPE( ur_result_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )

###############################################################################
## @brief Function-pointer for urProgramCompileExp
if __use_win_types:
_urProgramCompileExp_t = WINFUNCTYPE( ur_result_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )
else:
_urProgramCompileExp_t = CFUNCTYPE( ur_result_t, ur_program_handle_t, c_ulong, POINTER(ur_device_handle_t), c_char_p )

###############################################################################
## @brief Function-pointer for urProgramLinkExp
if __use_win_types:
_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) )
else:
_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) )


###############################################################################
## @brief Table of ProgramExp functions pointers
class ur_program_exp_dditable_t(Structure):
_fields_ = [
("pfnBuildExp", c_void_p), ## _urProgramBuildExp_t
("pfnCompileExp", c_void_p), ## _urProgramCompileExp_t
("pfnLinkExp", c_void_p) ## _urProgramLinkExp_t
]

###############################################################################
## @brief Function-pointer for urKernelCreate
if __use_win_types:
Expand Down Expand Up @@ -3749,6 +3788,7 @@ class ur_dditable_t(Structure):
("Context", ur_context_dditable_t),
("Event", ur_event_dditable_t),
("Program", ur_program_dditable_t),
("ProgramExp", ur_program_exp_dditable_t),
("Kernel", ur_kernel_dditable_t),
("Sampler", ur_sampler_dditable_t),
("Mem", ur_mem_dditable_t),
Expand Down Expand Up @@ -3851,6 +3891,18 @@ def __init__(self, version : ur_api_version_t):
self.urProgramGetNativeHandle = _urProgramGetNativeHandle_t(self.__dditable.Program.pfnGetNativeHandle)
self.urProgramCreateWithNativeHandle = _urProgramCreateWithNativeHandle_t(self.__dditable.Program.pfnCreateWithNativeHandle)

# call driver to get function pointers
ProgramExp = ur_program_exp_dditable_t()
r = ur_result_v(self.__dll.urGetProgramExpProcAddrTable(version, byref(ProgramExp)))
if r != ur_result_v.SUCCESS:
raise Exception(r)
self.__dditable.ProgramExp = ProgramExp

# attach function interface to function address
self.urProgramBuildExp = _urProgramBuildExp_t(self.__dditable.ProgramExp.pfnBuildExp)
self.urProgramCompileExp = _urProgramCompileExp_t(self.__dditable.ProgramExp.pfnCompileExp)
self.urProgramLinkExp = _urProgramLinkExp_t(self.__dditable.ProgramExp.pfnLinkExp)

# call driver to get function pointers
Kernel = ur_kernel_dditable_t()
r = ur_result_v(self.__dll.urGetKernelProcAddrTable(version, byref(Kernel)))
Expand Down
164 changes: 164 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ typedef enum ur_function_t {
UR_FUNCTION_ADAPTER_RETAIN = 179, ///< Enumerator for ::urAdapterRetain
UR_FUNCTION_ADAPTER_GET_LAST_ERROR = 180, ///< Enumerator for ::urAdapterGetLastError
UR_FUNCTION_ADAPTER_GET_INFO = 181, ///< Enumerator for ::urAdapterGetInfo
UR_FUNCTION_PROGRAM_BUILD_EXP = 197, ///< Enumerator for ::urProgramBuildExp
UR_FUNCTION_PROGRAM_COMPILE_EXP = 198, ///< Enumerator for ::urProgramCompileExp
UR_FUNCTION_PROGRAM_LINK_EXP = 199, ///< Enumerator for ::urProgramLinkExp
/// @cond
UR_FUNCTION_FORCE_UINT32 = 0x7fffffff
/// @endcond
Expand Down Expand Up @@ -8025,6 +8028,131 @@ urCommandBufferEnqueueExp(
///< command-buffer execution instance.
);

#if !defined(__GNUC__)
#pragma endregion
#endif
// Intel 'oneAPI' Unified Runtime Experimental APIs for multi-device compile
#if !defined(__GNUC__)
#pragma region multi device compile(experimental)
#endif
///////////////////////////////////////////////////////////////////////////////
#ifndef UR_MULTI_DEVICE_COMPILE_EXTENSION_STRING_EXP
/// @brief The extension string which defines support for test
/// which is returned when querying device extensions.
#define UR_MULTI_DEVICE_COMPILE_EXTENSION_STRING_EXP "ur_exp_multi_device_compile"
#endif // UR_MULTI_DEVICE_COMPILE_EXTENSION_STRING_EXP

///////////////////////////////////////////////////////////////////////////////
/// @brief Produces an executable program from one program, negates need for the
/// linking step.
///
/// @details
/// - The application may call this function from simultaneous threads.
/// - Following a successful call to this entry point, the program passed
/// will contain a binary of the ::UR_PROGRAM_BINARY_TYPE_EXECUTABLE type
/// for each device in `phDevices`.
///
/// @remarks
/// _Analogues_
/// - **clBuildProgram**
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hProgram`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phDevices`
/// - ::UR_RESULT_ERROR_INVALID_PROGRAM
/// + If `hProgram` isn't a valid program object.
/// - ::UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE
/// + If an error occurred when building `hProgram`.
UR_APIEXPORT ur_result_t UR_APICALL
urProgramBuildExp(
ur_program_handle_t hProgram, ///< [in] Handle of the program to build.
uint32_t numDevices, ///< [in] number of devices
ur_device_handle_t *phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
const char *pOptions ///< [in][optional] pointer to build options null-terminated string.
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Produces an executable program from one or more programs.
///
/// @details
/// - The application may call this function from simultaneous threads.
/// - Following a successful call to this entry point `hProgram` will
/// contain a binary of the ::UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT type
/// for each device in `phDevices`.
///
/// @remarks
/// _Analogues_
/// - **clCompileProgram**
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hProgram`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phDevices`
/// - ::UR_RESULT_ERROR_INVALID_PROGRAM
/// + If `hProgram` isn't a valid program object.
/// - ::UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE
/// + If an error occurred while compiling `hProgram`.
UR_APIEXPORT ur_result_t UR_APICALL
urProgramCompileExp(
ur_program_handle_t hProgram, ///< [in][out] handle of the program to compile.
uint32_t numDevices, ///< [in] number of devices
ur_device_handle_t *phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
const char *pOptions ///< [in][optional] pointer to build options null-terminated string.
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Produces an executable program from one or more programs.
///
/// @details
/// - The application may call this function from simultaneous threads.
/// - Following a successful call to this entry point the program returned
/// in `phProgram` will contain a binary of the
/// ::UR_PROGRAM_BINARY_TYPE_EXECUTABLE type for each device in
/// `phDevices`.
///
/// @remarks
/// _Analogues_
/// - **clLinkProgram**
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `NULL == hContext`
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `NULL == phDevices`
/// + `NULL == phPrograms`
/// + `NULL == phProgram`
/// - ::UR_RESULT_ERROR_INVALID_PROGRAM
/// + If one of the programs in `phPrograms` isn't a valid program object.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `count == 0`
/// - ::UR_RESULT_ERROR_PROGRAM_LINK_FAILURE
/// + If an error occurred while linking `phPrograms`.
UR_APIEXPORT ur_result_t UR_APICALL
urProgramLinkExp(
ur_context_handle_t hContext, ///< [in] handle of the context instance.
uint32_t numDevices, ///< [in] number of devices
ur_device_handle_t *phDevices, ///< [in][range(0, numDevices)] pointer to array of device handles
uint32_t count, ///< [in] number of program handles in `phPrograms`.
const ur_program_handle_t *phPrograms, ///< [in][range(0, count)] pointer to array of program handles.
const char *pOptions, ///< [in][optional] pointer to linker options null-terminated string.
ur_program_handle_t *phProgram ///< [out] pointer to handle of program object created.
);

#if !defined(__GNUC__)
#pragma endregion
#endif
Expand Down Expand Up @@ -8526,6 +8654,17 @@ typedef struct ur_program_build_params_t {
const char **ppOptions;
} ur_program_build_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urProgramBuildExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_program_build_exp_params_t {
ur_program_handle_t *phProgram;
uint32_t *pnumDevices;
ur_device_handle_t **pphDevices;
const char **ppOptions;
} ur_program_build_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urProgramCompile
/// @details Each entry is a pointer to the parameter passed to the function;
Expand All @@ -8536,6 +8675,17 @@ typedef struct ur_program_compile_params_t {
const char **ppOptions;
} ur_program_compile_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urProgramCompileExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_program_compile_exp_params_t {
ur_program_handle_t *phProgram;
uint32_t *pnumDevices;
ur_device_handle_t **pphDevices;
const char **ppOptions;
} ur_program_compile_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urProgramLink
/// @details Each entry is a pointer to the parameter passed to the function;
Expand All @@ -8548,6 +8698,20 @@ typedef struct ur_program_link_params_t {
ur_program_handle_t **pphProgram;
} ur_program_link_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urProgramLinkExp
/// @details Each entry is a pointer to the parameter passed to the function;
/// allowing the callback the ability to modify the parameter's value
typedef struct ur_program_link_exp_params_t {
ur_context_handle_t *phContext;
uint32_t *pnumDevices;
ur_device_handle_t **pphDevices;
uint32_t *pcount;
const ur_program_handle_t **pphPrograms;
const char **ppOptions;
ur_program_handle_t **pphProgram;
} ur_program_link_exp_params_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Function parameters for urProgramRetain
/// @details Each entry is a pointer to the parameter passed to the function;
Expand Down
57 changes: 57 additions & 0 deletions include/ur_ddi.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,62 @@ typedef ur_result_t(UR_APICALL *ur_pfnGetProgramProcAddrTable_t)(
ur_api_version_t,
ur_program_dditable_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urProgramBuildExp
typedef ur_result_t(UR_APICALL *ur_pfnProgramBuildExp_t)(
ur_program_handle_t,
uint32_t,
ur_device_handle_t *,
const char *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urProgramCompileExp
typedef ur_result_t(UR_APICALL *ur_pfnProgramCompileExp_t)(
ur_program_handle_t,
uint32_t,
ur_device_handle_t *,
const char *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urProgramLinkExp
typedef ur_result_t(UR_APICALL *ur_pfnProgramLinkExp_t)(
ur_context_handle_t,
uint32_t,
ur_device_handle_t *,
uint32_t,
const ur_program_handle_t *,
const char *,
ur_program_handle_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Table of ProgramExp functions pointers
typedef struct ur_program_exp_dditable_t {
ur_pfnProgramBuildExp_t pfnBuildExp;
ur_pfnProgramCompileExp_t pfnCompileExp;
ur_pfnProgramLinkExp_t pfnLinkExp;
} ur_program_exp_dditable_t;

///////////////////////////////////////////////////////////////////////////////
/// @brief Exported function for filling application's ProgramExp table
/// with current process' addresses
///
/// @returns
/// - ::UR_RESULT_SUCCESS
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// - ::UR_RESULT_ERROR_UNSUPPORTED_VERSION
UR_DLLEXPORT ur_result_t UR_APICALL
urGetProgramExpProcAddrTable(
ur_api_version_t version, ///< [in] API version requested
ur_program_exp_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers
);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urGetProgramExpProcAddrTable
typedef ur_result_t(UR_APICALL *ur_pfnGetProgramExpProcAddrTable_t)(
ur_api_version_t,
ur_program_exp_dditable_t *);

///////////////////////////////////////////////////////////////////////////////
/// @brief Function-pointer for urKernelCreate
typedef ur_result_t(UR_APICALL *ur_pfnKernelCreate_t)(
Expand Down Expand Up @@ -2139,6 +2195,7 @@ typedef struct ur_dditable_t {
ur_context_dditable_t Context;
ur_event_dditable_t Event;
ur_program_dditable_t Program;
ur_program_exp_dditable_t ProgramExp;
ur_kernel_dditable_t Kernel;
ur_sampler_dditable_t Sampler;
ur_mem_dditable_t Mem;
Expand Down
Loading

0 comments on commit 32ff17d

Please sign in to comment.