Skip to content

Commit a42a607

Browse files
nrspruitJaime Arteaga
authored andcommitted
[UR][L0] Add support for passing device list to urProgramBuild/Link/Compile
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. Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com> Co-authored-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
1 parent 1bb0543 commit a42a607

File tree

4 files changed

+129
-4
lines changed

4 files changed

+129
-4
lines changed

source/adapters/cuda/program.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ urProgramCompile(ur_context_handle_t hContext, ur_program_handle_t hProgram,
226226
return UR_RESULT_SUCCESS;
227227
}
228228

229+
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp(ur_context_handle_t,
230+
ur_program_handle_t,
231+
uint32_t,
232+
ur_device_handle_t *,
233+
const char *) {
234+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
235+
}
236+
237+
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(ur_context_handle_t,
238+
ur_program_handle_t,
239+
uint32_t,
240+
ur_device_handle_t *,
241+
const char *) {
242+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
243+
}
244+
229245
/// Loads the images from a UR program into a CUmodule that can be
230246
/// used later on to extract functions (kernels).
231247
/// See \ref ur_program_handle_t for implementation details.
@@ -248,6 +264,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(ur_context_handle_t hContext,
248264
return Result;
249265
}
250266

267+
UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
268+
ur_context_handle_t, uint32_t, const ur_program_handle_t *, uint32_t,
269+
ur_device_handle_t *, const char *, ur_program_handle_t *) {
270+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
271+
}
272+
251273
/// Creates a new UR program object that is the outcome of linking all input
252274
/// programs.
253275
/// \TODO Implement linker options, requires mapping of OpenCL to CUDA

source/adapters/hip/program.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,22 @@ urProgramCompile(ur_context_handle_t hContext, ur_program_handle_t hProgram,
245245
return urProgramBuild(hContext, hProgram, pOptions);
246246
}
247247

248+
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp(ur_context_handle_t,
249+
ur_program_handle_t,
250+
uint32_t,
251+
ur_device_handle_t *,
252+
const char *) {
253+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
254+
}
255+
256+
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(ur_context_handle_t,
257+
ur_program_handle_t,
258+
uint32_t,
259+
ur_device_handle_t *,
260+
const char *) {
261+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
262+
}
263+
248264
/// Loads the images from a UR program into a hipModule_t that can be
249265
/// used later on to extract functions (kernels).
250266
/// See \ref ur_program_handle_t for implementation details.
@@ -264,6 +280,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(ur_context_handle_t,
264280
return Result;
265281
}
266282

283+
UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
284+
ur_context_handle_t, uint32_t, const ur_program_handle_t *, uint32_t,
285+
ur_device_handle_t *, const char *, ur_program_handle_t *) {
286+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
287+
}
288+
267289
UR_APIEXPORT ur_result_t UR_APICALL urProgramLink(ur_context_handle_t, uint32_t,
268290
const ur_program_handle_t *,
269291
const char *,

source/adapters/level_zero/program.cpp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(
112112
ur_program_handle_t Program, ///< [in] Handle of the program to build.
113113
const char *Options ///< [in][optional] pointer to build options
114114
///< null-terminated string.
115+
) {
116+
return urProgramBuildExp(Context, Program, 1, Context->Devices.data(),
117+
Options);
118+
}
119+
120+
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
121+
ur_context_handle_t Context, ///< [in] handle of the context instance.
122+
ur_program_handle_t Program, ///< [in] Handle of the program to build.
123+
uint32_t numDevices, ur_device_handle_t *phDevices,
124+
const char *Options ///< [in][optional] pointer to build options
125+
///< null-terminated string.
115126
) {
116127
// TODO
117128
// Check if device belongs to associated context.
@@ -142,8 +153,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(
142153
ZeModuleDesc.pBuildFlags = Options;
143154
ZeModuleDesc.pConstants = Shim.ze();
144155

145-
ze_device_handle_t ZeDevice = Context->Devices[0]->ZeDevice;
156+
ze_device_handle_t ZeDevice = phDevices[0]->ZeDevice;
146157
ze_context_handle_t ZeContext = Program->Context->ZeContext;
158+
std::ignore = Context;
159+
std::ignore = numDevices;
147160
ze_module_handle_t ZeModule = nullptr;
148161

149162
ur_result_t Result = UR_RESULT_SUCCESS;
@@ -185,6 +198,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(
185198
return Result;
186199
}
187200

201+
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp(
202+
ur_context_handle_t Context, ///< [in] handle of the context instance.
203+
ur_program_handle_t
204+
Program, ///< [in][out] handle of the program to compile.
205+
uint32_t numDevices, ur_device_handle_t *phDevices,
206+
const char *Options ///< [in][optional] pointer to build options
207+
///< null-terminated string.
208+
) {
209+
std::ignore = numDevices;
210+
std::ignore = phDevices;
211+
return urProgramCompile(Context, Program, Options);
212+
}
213+
188214
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompile(
189215
ur_context_handle_t Context, ///< [in] handle of the context instance.
190216
ur_program_handle_t
@@ -225,7 +251,24 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLink(
225251
ur_program_handle_t
226252
*Program ///< [out] pointer to handle of program object created.
227253
) {
228-
UR_ASSERT(Context->isValidDevice(Context->Devices[0]),
254+
return urProgramLinkExp(Context, Count, Programs, 1, Context->Devices.data(),
255+
Options, Program);
256+
}
257+
258+
UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
259+
ur_context_handle_t Context, ///< [in] handle of the context instance.
260+
uint32_t Count, ///< [in] number of program handles in `phPrograms`.
261+
const ur_program_handle_t *Programs, ///< [in][range(0, count)] pointer to
262+
///< array of program handles.
263+
uint32_t numDevices, ur_device_handle_t *phDevices,
264+
const char *Options, ///< [in][optional] pointer to linker options
265+
///< null-terminated string.
266+
ur_program_handle_t
267+
*Program ///< [out] pointer to handle of program object created.
268+
) {
269+
std::ignore = numDevices;
270+
271+
UR_ASSERT(Context->isValidDevice(phDevices[0]),
229272
UR_RESULT_ERROR_INVALID_DEVICE);
230273

231274
// We do not support any link flags at this time because the Level Zero API
@@ -320,7 +363,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLink(
320363
// input module.
321364
//
322365
// TODO: Remove this workaround when the driver is fixed.
323-
if (!Context->Devices[0]->Platform->ZeDriverModuleProgramExtensionFound ||
366+
if (!phDevices[0]->Platform->ZeDriverModuleProgramExtensionFound ||
324367
(Count == 1)) {
325368
if (Count == 1) {
326369
ZeModuleDesc.pNext = nullptr;
@@ -336,7 +379,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLink(
336379
}
337380

338381
// Call the Level Zero API to compile, link, and create the module.
339-
ze_device_handle_t ZeDevice = Context->Devices[0]->ZeDevice;
382+
ze_device_handle_t ZeDevice = phDevices[0]->ZeDevice;
340383
ze_context_handle_t ZeContext = Context->ZeContext;
341384
ze_module_handle_t ZeModule = nullptr;
342385
ze_module_build_log_handle_t ZeBuildLog = nullptr;

source/ur/ur.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,41 @@ class UrReturnHelper {
295295
void *param_value;
296296
size_t *param_value_size_ret;
297297
};
298+
299+
// Needed to have compatibility with piProgramBuild
300+
// when passing a specific list of devices
301+
// See: https://github.com/oneapi-src/unified-runtime/issues/912
302+
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
303+
ur_context_handle_t hContext, ///< [in] handle of the context instance.
304+
ur_program_handle_t hProgram, ///< [in] Handle of the program to build.
305+
uint32_t numDevices, ur_device_handle_t *phDevices,
306+
const char *pOptions ///< [in][optional] pointer to build options
307+
///< null-terminated string.
308+
);
309+
310+
// Needed to have compatibility with piProgramCompile
311+
// when passing a specific list of devices
312+
// See: https://github.com/oneapi-src/unified-runtime/issues/912
313+
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp(
314+
ur_context_handle_t Context, ///< [in] handle of the context instance.
315+
ur_program_handle_t
316+
Program, ///< [in][out] handle of the program to compile.
317+
uint32_t numDevices, ur_device_handle_t *phDevices,
318+
const char *Options ///< [in][optional] pointer to build options
319+
///< null-terminated string.
320+
);
321+
322+
// Needed to have compatibility with piProgramLink
323+
// when passing a specific list of devices
324+
// See: https://github.com/oneapi-src/unified-runtime/issues/912
325+
UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
326+
ur_context_handle_t Context, ///< [in] handle of the context instance.
327+
uint32_t Count, ///< [in] number of program handles in `phPrograms`.
328+
const ur_program_handle_t *Programs, ///< [in][range(0, count)] pointer to
329+
///< array of program handles.
330+
uint32_t numDevices, ur_device_handle_t *phDevices,
331+
const char *Options, ///< [in][optional] pointer to linker options
332+
///< null-terminated string.
333+
ur_program_handle_t
334+
*Program ///< [out] pointer to handle of program object created.
335+
);

0 commit comments

Comments
 (0)