Skip to content

Commit 5f8335c

Browse files
nrspruitJaime Arteaga
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 <[email protected]> Co-authored-by: Jaime Arteaga <[email protected]>
1 parent b38855e commit 5f8335c

File tree

4 files changed

+137
-4
lines changed

4 files changed

+137
-4
lines changed

source/adapters/cuda/program.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,26 @@ urProgramCompile(ur_context_handle_t hContext, ur_program_handle_t hProgram,
188188
return urProgramBuild(hContext, hProgram, pOptions);
189189
}
190190

191+
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp(
192+
ur_context_handle_t hContext, ur_program_handle_t hProgram,
193+
uint32_t numDevices, ur_device_handle_t *phDevices, const char *pOptions) {
194+
std::ignore = numDevices;
195+
std::ignore = phDevices;
196+
return urProgramBuild(hContext, hProgram, pOptions);
197+
}
198+
199+
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
200+
ur_context_handle_t Context, ///< [in] handle of the context instance.
201+
ur_program_handle_t Program, ///< [in] Handle of the program to build.
202+
uint32_t numDevices, ur_device_handle_t *phDevices,
203+
const char *Options ///< [in][optional] pointer to build options
204+
///< null-terminated string.
205+
) {
206+
std::ignore = numDevices;
207+
std::ignore = phDevices;
208+
return urProgramBuild(Context, Program, Options);
209+
}
210+
191211
/// Loads the images from a UR program into a CUmodule that can be
192212
/// used later on to extract functions (kernels).
193213
/// See \ref ur_program_handle_t for implementation details.
@@ -209,6 +229,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(ur_context_handle_t hContext,
209229
return Result;
210230
}
211231

232+
UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
233+
ur_context_handle_t, uint32_t, const ur_program_handle_t *, uint32_t,
234+
ur_device_handle_t *, const char *, ur_program_handle_t *) {
235+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
236+
}
237+
212238
/// Creates a new UR program object that is the outcome of linking all input
213239
/// programs.
214240
/// \TODO Implement linker options, requires mapping of OpenCL to CUDA

source/adapters/hip/program.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ urProgramCompile(ur_context_handle_t hContext, ur_program_handle_t hProgram,
9292
return urProgramBuild(hContext, hProgram, pOptions);
9393
}
9494

95+
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp(
96+
ur_context_handle_t hContext, ur_program_handle_t hProgram,
97+
uint32_t numDevices, ur_device_handle_t *phDevices, const char *pOptions) {
98+
std::ignore = numDevices;
99+
std::ignore = phDevices;
100+
return urProgramBuild(hContext, hProgram, pOptions);
101+
}
102+
103+
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
104+
ur_context_handle_t Context, ///< [in] handle of the context instance.
105+
ur_program_handle_t Program, ///< [in] Handle of the program to build.
106+
uint32_t numDevices, ur_device_handle_t *phDevices,
107+
const char *Options ///< [in][optional] pointer to build options
108+
///< null-terminated string.
109+
) {
110+
std::ignore = numDevices;
111+
std::ignore = phDevices;
112+
return urProgramBuild(Context, Program, Options);
113+
}
114+
95115
/// Loads the images from a UR program into a hipModule_t that can be
96116
/// used later on to extract functions (kernels).
97117
/// See \ref ur_program_handle_t for implementation details.
@@ -111,6 +131,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(ur_context_handle_t,
111131
return Result;
112132
}
113133

134+
UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
135+
ur_context_handle_t, uint32_t, const ur_program_handle_t *, uint32_t,
136+
ur_device_handle_t *, const char *, ur_program_handle_t *) {
137+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
138+
}
139+
114140
UR_APIEXPORT ur_result_t UR_APICALL urProgramLink(ur_context_handle_t, uint32_t,
115141
const ur_program_handle_t *,
116142
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
@@ -294,3 +294,41 @@ class UrReturnHelper {
294294
void *param_value;
295295
size_t *param_value_size_ret;
296296
};
297+
298+
// Needed to have compatibility with piProgramBuild
299+
// when passing a specific list of devices
300+
// See: https://github.com/oneapi-src/unified-runtime/issues/912
301+
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
302+
ur_context_handle_t hContext, ///< [in] handle of the context instance.
303+
ur_program_handle_t hProgram, ///< [in] Handle of the program to build.
304+
uint32_t numDevices, ur_device_handle_t *phDevices,
305+
const char *pOptions ///< [in][optional] pointer to build options
306+
///< null-terminated string.
307+
);
308+
309+
// Needed to have compatibility with piProgramCompile
310+
// when passing a specific list of devices
311+
// See: https://github.com/oneapi-src/unified-runtime/issues/912
312+
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp(
313+
ur_context_handle_t Context, ///< [in] handle of the context instance.
314+
ur_program_handle_t
315+
Program, ///< [in][out] handle of the program to compile.
316+
uint32_t numDevices, ur_device_handle_t *phDevices,
317+
const char *Options ///< [in][optional] pointer to build options
318+
///< null-terminated string.
319+
);
320+
321+
// Needed to have compatibility with piProgramLink
322+
// when passing a specific list of devices
323+
// See: https://github.com/oneapi-src/unified-runtime/issues/912
324+
UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
325+
ur_context_handle_t Context, ///< [in] handle of the context instance.
326+
uint32_t Count, ///< [in] number of program handles in `phPrograms`.
327+
const ur_program_handle_t *Programs, ///< [in][range(0, count)] pointer to
328+
///< array of program handles.
329+
uint32_t numDevices, ur_device_handle_t *phDevices,
330+
const char *Options, ///< [in][optional] pointer to linker options
331+
///< null-terminated string.
332+
ur_program_handle_t
333+
*Program ///< [out] pointer to handle of program object created.
334+
);

0 commit comments

Comments
 (0)