Skip to content

Commit d7e4d2b

Browse files
aarongreigkbenzie
authored andcommitted
Refactor the compiler API.
The module object has been removed, and the program object now more closely mirrors its OpenCL and PI equivalents.
1 parent d32d8d6 commit d7e4d2b

File tree

20 files changed

+1133
-1790
lines changed

20 files changed

+1133
-1790
lines changed

include/ur.py

Lines changed: 87 additions & 136 deletions
Large diffs are not rendered by default.

include/ur_api.h

Lines changed: 252 additions & 335 deletions
Large diffs are not rendered by default.

include/ur_ddi.h

Lines changed: 31 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,11 @@ typedef ur_result_t(UR_APICALL *ur_pfnGetEventProcAddrTable_t)(
253253
ur_event_dditable_t *);
254254

255255
///////////////////////////////////////////////////////////////////////////////
256-
/// @brief Function-pointer for urProgramCreate
257-
typedef ur_result_t(UR_APICALL *ur_pfnProgramCreate_t)(
256+
/// @brief Function-pointer for urProgramCreateWithIL
257+
typedef ur_result_t(UR_APICALL *ur_pfnProgramCreateWithIL_t)(
258258
ur_context_handle_t,
259-
uint32_t,
260-
const ur_module_handle_t *,
261-
const char *,
259+
const void *,
260+
size_t,
262261
const ur_program_properties_t *,
263262
ur_program_handle_t *);
264263

@@ -272,6 +271,29 @@ typedef ur_result_t(UR_APICALL *ur_pfnProgramCreateWithBinary_t)(
272271
const ur_program_properties_t *,
273272
ur_program_handle_t *);
274273

274+
///////////////////////////////////////////////////////////////////////////////
275+
/// @brief Function-pointer for urProgramBuild
276+
typedef ur_result_t(UR_APICALL *ur_pfnProgramBuild_t)(
277+
ur_context_handle_t,
278+
ur_program_handle_t,
279+
const char *);
280+
281+
///////////////////////////////////////////////////////////////////////////////
282+
/// @brief Function-pointer for urProgramCompile
283+
typedef ur_result_t(UR_APICALL *ur_pfnProgramCompile_t)(
284+
ur_context_handle_t,
285+
ur_program_handle_t,
286+
const char *);
287+
288+
///////////////////////////////////////////////////////////////////////////////
289+
/// @brief Function-pointer for urProgramLink
290+
typedef ur_result_t(UR_APICALL *ur_pfnProgramLink_t)(
291+
ur_context_handle_t,
292+
uint32_t,
293+
const ur_program_handle_t *,
294+
const char *,
295+
ur_program_handle_t *);
296+
275297
///////////////////////////////////////////////////////////////////////////////
276298
/// @brief Function-pointer for urProgramRetain
277299
typedef ur_result_t(UR_APICALL *ur_pfnProgramRetain_t)(
@@ -332,8 +354,11 @@ typedef ur_result_t(UR_APICALL *ur_pfnProgramCreateWithNativeHandle_t)(
332354
///////////////////////////////////////////////////////////////////////////////
333355
/// @brief Table of Program functions pointers
334356
typedef struct ur_program_dditable_t {
335-
ur_pfnProgramCreate_t pfnCreate;
357+
ur_pfnProgramCreateWithIL_t pfnCreateWithIL;
336358
ur_pfnProgramCreateWithBinary_t pfnCreateWithBinary;
359+
ur_pfnProgramBuild_t pfnBuild;
360+
ur_pfnProgramCompile_t pfnCompile;
361+
ur_pfnProgramLink_t pfnLink;
337362
ur_pfnProgramRetain_t pfnRetain;
338363
ur_pfnProgramRelease_t pfnRelease;
339364
ur_pfnProgramGetFunctionPointer_t pfnGetFunctionPointer;
@@ -365,71 +390,6 @@ typedef ur_result_t(UR_APICALL *ur_pfnGetProgramProcAddrTable_t)(
365390
ur_api_version_t,
366391
ur_program_dditable_t *);
367392

368-
///////////////////////////////////////////////////////////////////////////////
369-
/// @brief Function-pointer for urModuleCreate
370-
typedef ur_result_t(UR_APICALL *ur_pfnModuleCreate_t)(
371-
ur_context_handle_t,
372-
const void *,
373-
size_t,
374-
const char *,
375-
ur_modulecreate_callback_t,
376-
void *,
377-
ur_module_handle_t *);
378-
379-
///////////////////////////////////////////////////////////////////////////////
380-
/// @brief Function-pointer for urModuleRetain
381-
typedef ur_result_t(UR_APICALL *ur_pfnModuleRetain_t)(
382-
ur_module_handle_t);
383-
384-
///////////////////////////////////////////////////////////////////////////////
385-
/// @brief Function-pointer for urModuleRelease
386-
typedef ur_result_t(UR_APICALL *ur_pfnModuleRelease_t)(
387-
ur_module_handle_t);
388-
389-
///////////////////////////////////////////////////////////////////////////////
390-
/// @brief Function-pointer for urModuleGetNativeHandle
391-
typedef ur_result_t(UR_APICALL *ur_pfnModuleGetNativeHandle_t)(
392-
ur_module_handle_t,
393-
ur_native_handle_t *);
394-
395-
///////////////////////////////////////////////////////////////////////////////
396-
/// @brief Function-pointer for urModuleCreateWithNativeHandle
397-
typedef ur_result_t(UR_APICALL *ur_pfnModuleCreateWithNativeHandle_t)(
398-
ur_native_handle_t,
399-
ur_context_handle_t,
400-
ur_module_handle_t *);
401-
402-
///////////////////////////////////////////////////////////////////////////////
403-
/// @brief Table of Module functions pointers
404-
typedef struct ur_module_dditable_t {
405-
ur_pfnModuleCreate_t pfnCreate;
406-
ur_pfnModuleRetain_t pfnRetain;
407-
ur_pfnModuleRelease_t pfnRelease;
408-
ur_pfnModuleGetNativeHandle_t pfnGetNativeHandle;
409-
ur_pfnModuleCreateWithNativeHandle_t pfnCreateWithNativeHandle;
410-
} ur_module_dditable_t;
411-
412-
///////////////////////////////////////////////////////////////////////////////
413-
/// @brief Exported function for filling application's Module table
414-
/// with current process' addresses
415-
///
416-
/// @returns
417-
/// - ::UR_RESULT_SUCCESS
418-
/// - ::UR_RESULT_ERROR_UNINITIALIZED
419-
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
420-
/// - ::UR_RESULT_ERROR_UNSUPPORTED_VERSION
421-
UR_DLLEXPORT ur_result_t UR_APICALL
422-
urGetModuleProcAddrTable(
423-
ur_api_version_t version, ///< [in] API version requested
424-
ur_module_dditable_t *pDdiTable ///< [in,out] pointer to table of DDI function pointers
425-
);
426-
427-
///////////////////////////////////////////////////////////////////////////////
428-
/// @brief Function-pointer for urGetModuleProcAddrTable
429-
typedef ur_result_t(UR_APICALL *ur_pfnGetModuleProcAddrTable_t)(
430-
ur_api_version_t,
431-
ur_module_dditable_t *);
432-
433393
///////////////////////////////////////////////////////////////////////////////
434394
/// @brief Function-pointer for urKernelCreate
435395
typedef ur_result_t(UR_APICALL *ur_pfnKernelCreate_t)(
@@ -1451,7 +1411,6 @@ typedef struct ur_dditable_t {
14511411
ur_context_dditable_t Context;
14521412
ur_event_dditable_t Event;
14531413
ur_program_dditable_t Program;
1454-
ur_module_dditable_t Module;
14551414
ur_kernel_dditable_t Kernel;
14561415
ur_sampler_dditable_t Sampler;
14571416
ur_mem_dditable_t Mem;
-33.2 KB
Binary file not shown.

scripts/assets/images/programs.png

36.7 KB
Loading
42.1 KB
Loading

scripts/core/PROG.rst

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -163,39 +163,46 @@ events, and programs are explicitly created against a context. A trivial work wi
163163
// Release the context handle
164164
${x}ContextRelease(hContext);
165165
166-
Modules and Programs
166+
Programs and Kernels
167167
====================
168168

169-
There are multiple levels of constructs needed for executing kernels on the device:
169+
There are two constructs we need to prepare code for execution on the device:
170170

171-
* Modules represent a single translation unit that consists of kernels and globals that have been compiled together.
172-
* Programs represent one or more modules that have been linked together.
173-
* Kernels represent the kernel within a program that will be launched onto the device.
171+
* Programs serve as containers for device code. They typically encapsulate a
172+
collection of functions and global variables represented in an intermediate
173+
language, and one or more device-native binaries compiled from that
174+
collection.
175+
* Kernels represent a handle to a function within a program that can be
176+
launched on a device.
174177

175-
.. image:: ../images/modules_programs.png
176178

177-
Modules and Programs
178-
--------------------
179+
Programs
180+
--------
179181

180-
A module is the compiled code or object for a single compilation unit. Modules can be created from a SPIR-V module. A program
181-
are a collection of modules that are linked together.
182+
Programs can be constructed with an intermediate language binary or a
183+
device-native binary. Programs constructed with IL must be further compiled
184+
through either ${x}ProgramCompile and ${x}ProgramLink or ${x}ProgramBuild
185+
before they can be used to create a kernel object.
182186

183187
.. parsed-literal::
184188
185-
// Create module
186-
${x}_module_handle_t hModule;
187-
${x}ModuleCreate(hContext, (const void*)pIL, length, nullptr, nullptr, nullptr, hModule);
188-
189-
// Create program from module
189+
// Create a program with IL
190190
${x}_program_handle_t hProgram;
191-
${x}ProgramCreate(hContext, 1, &hModule, nullptr, nullptr, hProgram);
191+
${x}ProgramCreateWithIL(hContext, ILBin, ILBinSize, nullptr, &hProgram);
192+
193+
// Build the program.
194+
${x}ProgramBuild(hContext, hProgram, nullptr);
195+
196+
The diagram below shows the possible paths to obtaining a program that can be
197+
used to create a kernel:
192198

199+
.. image:: ../images/programs.png
193200

194201
Kernels
195202
-------
196203

197-
A Kernel is a reference to a kernel within a module and it supports both explicit and implicit kernel
198-
arguments along with data needed for launch.
204+
A Kernel is a reference to a kernel within a program and it supports both
205+
explicit and implicit kernel arguments along with data needed for launch.
199206

200207
.. parsed-literal::
201208

scripts/core/common.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,7 @@ class: $xProgram
8383
name: "$x_program_handle_t"
8484
--- #--------------------------------------------------------------------------
8585
type: handle
86-
desc: "Handle of Module object"
87-
class: $xModule
88-
name: "$x_module_handle_t"
89-
--- #--------------------------------------------------------------------------
90-
type: handle
91-
desc: "Handle of module's Kernel object"
86+
desc: "Handle of program's Kernel object"
9287
class: $xKernel
9388
name: "$x_kernel_handle_t"
9489
--- #--------------------------------------------------------------------------
@@ -152,8 +147,6 @@ etors:
152147
desc: "Returned when the event wait list or the events in the wait list are invalid."
153148
- name: ERROR_MISALIGNED_SUB_BUFFER_OFFSET
154149
desc: "Misaligned sub buffer offset"
155-
- name: ERROR_BUILD_PROGRAM_FAILURE
156-
desc: "Build program failure"
157150
- name: ERROR_INVALID_WORK_GROUP_SIZE
158151
desc: "Invalid work group size"
159152
- name: ERROR_COMPILER_NOT_AVAILABLE
@@ -183,7 +176,7 @@ etors:
183176
- name: ERROR_INVALID_KERNEL
184177
desc: "Invalid kernel"
185178
- name: ERROR_INVALID_KERNEL_NAME
186-
desc: "[Validation] kernel name is not found in the module"
179+
desc: "[Validation] kernel name is not found in the program"
187180
- name: ERROR_INVALID_KERNEL_ARGUMENT_INDEX
188181
desc: "[Validation] kernel argument index is not valid for kernel"
189182
- name: ERROR_INVALID_KERNEL_ARGUMENT_SIZE
@@ -208,10 +201,10 @@ etors:
208201
desc: "Insufficient device memory to satisfy call"
209202
- name: ERROR_OUT_OF_RESOURCES
210203
desc: "Out of resources"
211-
- name: ERROR_MODULE_BUILD_FAILURE
212-
desc: "Error occurred when building module, see build log for details"
213-
- name: ERROR_MODULE_LINK_FAILURE
214-
desc: "Error occurred when linking modules, see build log for details"
204+
- name: ERROR_PROGRAM_BUILD_FAILURE
205+
desc: "Error occurred when building program, see build log for details"
206+
- name: ERROR_PROGRAM_LINK_FAILURE
207+
desc: "Error occurred when linking programs, see build log for details"
215208
- name: ERROR_UNSUPPORTED_VERSION
216209
desc: "[Validation] generic error code for unsupported versions"
217210
- name: ERROR_UNSUPPORTED_FEATURE
@@ -241,15 +234,15 @@ etors:
241234
- name: ERROR_INVALID_NATIVE_BINARY
242235
desc: "[Validation] native binary is not supported by the device"
243236
- name: ERROR_INVALID_GLOBAL_NAME
244-
desc: "[Validation] global variable is not found in the module"
237+
desc: "[Validation] global variable is not found in the program"
245238
- name: ERROR_INVALID_FUNCTION_NAME
246-
desc: "[Validation] function name is not found in the module"
239+
desc: "[Validation] function name is not found in the program"
247240
- name: ERROR_INVALID_GROUP_SIZE_DIMENSION
248241
desc: "[Validation] group size dimension is not valid for the kernel or device"
249242
- name: ERROR_INVALID_GLOBAL_WIDTH_DIMENSION
250243
desc: "[Validation] global width dimension is not valid for the kernel or device"
251-
- name: ERROR_MODULE_UNLINKED
252-
desc: "[Validation] module with imports needs to be linked before kernels can be created from it."
244+
- name: ERROR_PROGRAM_UNLINKED
245+
desc: "[Validation] compiled program or program with imports needs to be linked before kernels can be created from it."
253246
- name: ERROR_OVERLAPPING_REGIONS
254247
desc: "[Validation] copy operations do not support overlapping regions of memory"
255248
- name: ERROR_INVALID_HOST_PTR

scripts/core/device.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ name: SelectBinary
430430
decl: static
431431
ordinal: "0"
432432
details:
433-
- "The input binaries are various AOT images, and possibly a SPIR-V binary for JIT compilation."
433+
- "The input binaries are various AOT images, and possibly an IL binary for JIT compilation."
434434
- "The selected binary will be able to be run on the target device."
435435
- "If no suitable binary can be found then function returns ${X}_INVALID_BINARY."
436436
- "The application may call this function from simultaneous threads for the same device."

0 commit comments

Comments
 (0)