@@ -113,16 +113,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(
113
113
const char *Options // /< [in][optional] pointer to build options
114
114
// /< null-terminated string.
115
115
) {
116
- return urProgramBuildExp (Context, Program, 1 , Context->Devices .data (),
117
- Options);
116
+ return urProgramBuildExp (Program, 1 , Context->Devices .data (), Options);
118
117
}
119
118
120
119
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.
120
+ ur_program_handle_t hProgram, // /< [in] Handle of the program to build.
121
+ uint32_t numDevices, // /< [in] number of devices
122
+ ur_device_handle_t *phDevices, // /< [in][range(0, numDevices)] pointer to
123
+ // /< array of device handles
124
+ const char *pOptions // /< [in][optional] pointer to build options
125
+ // /< null-terminated string.
126
126
) {
127
127
// TODO
128
128
// Check if device belongs to associated context.
@@ -131,43 +131,42 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
131
131
// UR_RESULT_ERROR_INVALID_VALUE);
132
132
133
133
// We should have either IL or native device code.
134
- UR_ASSERT (Program ->Code , UR_RESULT_ERROR_INVALID_PROGRAM);
134
+ UR_ASSERT (hProgram ->Code , UR_RESULT_ERROR_INVALID_PROGRAM);
135
135
136
136
// It is legal to build a program created from either IL or from native
137
137
// device code.
138
- if (Program ->State != ur_program_handle_t_::IL &&
139
- Program ->State != ur_program_handle_t_::Native) {
138
+ if (hProgram ->State != ur_program_handle_t_::IL &&
139
+ hProgram ->State != ur_program_handle_t_::Native) {
140
140
return UR_RESULT_ERROR_INVALID_OPERATION;
141
141
}
142
142
143
- std::scoped_lock<ur_shared_mutex> Guard (Program ->Mutex );
143
+ std::scoped_lock<ur_shared_mutex> Guard (hProgram ->Mutex );
144
144
145
145
// Ask Level Zero to build and load the native code onto the device.
146
146
ZeStruct<ze_module_desc_t > ZeModuleDesc;
147
- ur_program_handle_t_::SpecConstantShim Shim (Program );
148
- ZeModuleDesc.format = (Program ->State == ur_program_handle_t_::IL)
147
+ ur_program_handle_t_::SpecConstantShim Shim (hProgram );
148
+ ZeModuleDesc.format = (hProgram ->State == ur_program_handle_t_::IL)
149
149
? ZE_MODULE_FORMAT_IL_SPIRV
150
150
: ZE_MODULE_FORMAT_NATIVE;
151
- ZeModuleDesc.inputSize = Program ->CodeLength ;
152
- ZeModuleDesc.pInputModule = Program ->Code .get ();
153
- ZeModuleDesc.pBuildFlags = Options ;
151
+ ZeModuleDesc.inputSize = hProgram ->CodeLength ;
152
+ ZeModuleDesc.pInputModule = hProgram ->Code .get ();
153
+ ZeModuleDesc.pBuildFlags = pOptions ;
154
154
ZeModuleDesc.pConstants = Shim.ze ();
155
155
156
156
ze_device_handle_t ZeDevice = phDevices[0 ]->ZeDevice ;
157
- ze_context_handle_t ZeContext = Program->Context ->ZeContext ;
158
- std::ignore = Context;
157
+ ze_context_handle_t ZeContext = hProgram->Context ->ZeContext ;
159
158
std::ignore = numDevices;
160
159
ze_module_handle_t ZeModule = nullptr ;
161
160
162
161
ur_result_t Result = UR_RESULT_SUCCESS;
163
- Program ->State = ur_program_handle_t_::Exe;
162
+ hProgram ->State = ur_program_handle_t_::Exe;
164
163
ze_result_t ZeResult =
165
164
ZE_CALL_NOCHECK (zeModuleCreate, (ZeContext, ZeDevice, &ZeModuleDesc,
166
- &ZeModule, &Program ->ZeBuildLog ));
165
+ &ZeModule, &hProgram ->ZeBuildLog ));
167
166
if (ZeResult != ZE_RESULT_SUCCESS) {
168
167
// We adjust ur_program below to avoid attempting to release zeModule when
169
168
// RT calls urProgramRelease().
170
- Program ->State = ur_program_handle_t_::Invalid;
169
+ hProgram ->State = ur_program_handle_t_::Invalid;
171
170
Result = ze2urResult (ZeResult);
172
171
if (ZeModule) {
173
172
ZE_CALL_NOCHECK (zeModuleDestroy, (ZeModule));
@@ -179,9 +178,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
179
178
// call to zeModuleDynamicLink. However, modules created with
180
179
// urProgramBuild are supposed to be fully linked and ready to use.
181
180
// Therefore, do an extra check now for unresolved symbols.
182
- ZeResult = checkUnresolvedSymbols (ZeModule, &Program ->ZeBuildLog );
181
+ ZeResult = checkUnresolvedSymbols (ZeModule, &hProgram ->ZeBuildLog );
183
182
if (ZeResult != ZE_RESULT_SUCCESS) {
184
- Program ->State = ur_program_handle_t_::Invalid;
183
+ hProgram ->State = ur_program_handle_t_::Invalid;
185
184
Result = (ZeResult == ZE_RESULT_ERROR_MODULE_LINK_FAILURE)
186
185
? UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE
187
186
: ze2urResult (ZeResult);
@@ -193,22 +192,23 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(
193
192
}
194
193
195
194
// We no longer need the IL / native code.
196
- Program ->Code .reset ();
197
- Program ->ZeModule = ZeModule;
195
+ hProgram ->Code .reset ();
196
+ hProgram ->ZeModule = ZeModule;
198
197
return Result;
199
198
}
200
199
201
200
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp (
202
- ur_context_handle_t Context, // /< [in] handle of the context instance.
203
201
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.
202
+ hProgram, // /< [in][out] handle of the program to compile.
203
+ uint32_t numDevices, // /< [in] number of devices
204
+ ur_device_handle_t *phDevices, // /< [in][range(0, numDevices)] pointer to
205
+ // /< array of device handles
206
+ const char *pOptions // /< [in][optional] pointer to build options
207
+ // /< null-terminated string.
208
208
) {
209
209
std::ignore = numDevices;
210
210
std::ignore = phDevices;
211
- return urProgramCompile (Context, Program, Options );
211
+ return urProgramCompile (hProgram-> Context , hProgram, pOptions );
212
212
}
213
213
214
214
UR_APIEXPORT ur_result_t UR_APICALL urProgramCompile (
@@ -251,38 +251,37 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLink(
251
251
ur_program_handle_t
252
252
*Program // /< [out] pointer to handle of program object created.
253
253
) {
254
- return urProgramLinkExp (Context, Count, Programs, 1 , Context->Devices .data (),
254
+ return urProgramLinkExp (Context, Count, Context->Devices .data (), 1 , Programs ,
255
255
Options, Program);
256
256
}
257
257
258
258
UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp (
259
- ur_context_handle_t Context, // /< [in] handle of the context instance.
259
+ ur_context_handle_t hContext, // /< [in] handle of the context instance.
260
260
uint32_t numDevices, // /< [in] number of devices
261
261
ur_device_handle_t *phDevices, // /< [in][range(0, numDevices)] pointer to
262
262
// /< array of device handles
263
- uint32_t Count , // /< [in] number of program handles in `phPrograms`.
264
- const ur_program_handle_t *Programs , // /< [in][range(0, count)] pointer to
265
- // /< array of program handles.
266
- const char *Options , // /< [in][optional] pointer to linker options
267
- // /< null-terminated string.
263
+ uint32_t count , // /< [in] number of program handles in `phPrograms`.
264
+ const ur_program_handle_t *phPrograms , // /< [in][range(0, count)] pointer to
265
+ // /< array of program handles.
266
+ const char *pOptions , // /< [in][optional] pointer to linker options
267
+ // /< null-terminated string.
268
268
ur_program_handle_t
269
- *Program // /< [out] pointer to handle of program object created.
269
+ *phProgram // /< [out] pointer to handle of program object created.
270
270
) {
271
271
std::ignore = numDevices;
272
-
273
- UR_ASSERT (Context->isValidDevice (phDevices[0 ]),
272
+ UR_ASSERT (hContext->isValidDevice (phDevices[0 ]),
274
273
UR_RESULT_ERROR_INVALID_DEVICE);
275
274
276
275
// We do not support any link flags at this time because the Level Zero API
277
276
// does not have any way to pass flags that are specific to linking.
278
- if (Options && *Options != ' \0 ' ) {
277
+ if (pOptions && *pOptions != ' \0 ' ) {
279
278
std::string ErrorMessage (
280
279
" Level Zero does not support kernel link flags: \" " );
281
- ErrorMessage.append (Options );
280
+ ErrorMessage.append (pOptions );
282
281
ErrorMessage.push_back (' \" ' );
283
282
ur_program_handle_t_ *UrProgram = new ur_program_handle_t_ (
284
- ur_program_handle_t_::Invalid, Context , ErrorMessage);
285
- *Program = reinterpret_cast <ur_program_handle_t >(UrProgram);
283
+ ur_program_handle_t_::Invalid, hContext , ErrorMessage);
284
+ *phProgram = reinterpret_cast <ur_program_handle_t >(UrProgram);
286
285
return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
287
286
}
288
287
@@ -299,11 +298,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
299
298
// potential if there was some other code that holds more than one of these
300
299
// locks simultaneously with "exclusive" access. However, there is no such
301
300
// code like that, so this is also not a danger.
302
- std::vector<std::shared_lock<ur_shared_mutex>> Guards (Count );
303
- for (uint32_t I = 0 ; I < Count ; I++) {
304
- std::shared_lock<ur_shared_mutex> Guard (Programs [I]->Mutex );
301
+ std::vector<std::shared_lock<ur_shared_mutex>> Guards (count );
302
+ for (uint32_t I = 0 ; I < count ; I++) {
303
+ std::shared_lock<ur_shared_mutex> Guard (phPrograms [I]->Mutex );
305
304
Guards[I].swap (Guard);
306
- if (Programs [I]->State != ur_program_handle_t_::Object) {
305
+ if (phPrograms [I]->State != ur_program_handle_t_::Object) {
307
306
return UR_RESULT_ERROR_INVALID_OPERATION;
308
307
}
309
308
}
@@ -316,23 +315,23 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
316
315
// Construct a ze_module_program_exp_desc_t which contains information about
317
316
// all of the modules that will be linked together.
318
317
ZeStruct<ze_module_program_exp_desc_t > ZeExtModuleDesc;
319
- std::vector<size_t > CodeSizes (Count );
320
- std::vector<const uint8_t *> CodeBufs (Count );
321
- std::vector<const char *> BuildFlagPtrs (Count );
322
- std::vector<const ze_module_constants_t *> SpecConstPtrs (Count );
318
+ std::vector<size_t > CodeSizes (count );
319
+ std::vector<const uint8_t *> CodeBufs (count );
320
+ std::vector<const char *> BuildFlagPtrs (count );
321
+ std::vector<const ze_module_constants_t *> SpecConstPtrs (count );
323
322
std::vector<ur_program_handle_t_::SpecConstantShim> SpecConstShims;
324
- SpecConstShims.reserve (Count );
323
+ SpecConstShims.reserve (count );
325
324
326
- for (uint32_t I = 0 ; I < Count ; I++) {
327
- ur_program_handle_t Program = Programs [I];
325
+ for (uint32_t I = 0 ; I < count ; I++) {
326
+ ur_program_handle_t Program = phPrograms [I];
328
327
CodeSizes[I] = Program->CodeLength ;
329
328
CodeBufs[I] = Program->Code .get ();
330
329
BuildFlagPtrs[I] = Program->BuildFlags .c_str ();
331
330
SpecConstShims.emplace_back (Program);
332
331
SpecConstPtrs[I] = SpecConstShims[I].ze ();
333
332
}
334
333
335
- ZeExtModuleDesc.count = Count ;
334
+ ZeExtModuleDesc.count = count ;
336
335
ZeExtModuleDesc.inputSizes = CodeSizes.data ();
337
336
ZeExtModuleDesc.pInputModules = CodeBufs.data ();
338
337
ZeExtModuleDesc.pBuildFlags = BuildFlagPtrs.data ();
@@ -366,8 +365,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
366
365
//
367
366
// TODO: Remove this workaround when the driver is fixed.
368
367
if (!phDevices[0 ]->Platform ->ZeDriverModuleProgramExtensionFound ||
369
- (Count == 1 )) {
370
- if (Count == 1 ) {
368
+ (count == 1 )) {
369
+ if (count == 1 ) {
371
370
ZeModuleDesc.pNext = nullptr ;
372
371
ZeModuleDesc.inputSize = ZeExtModuleDesc.inputSizes [0 ];
373
372
ZeModuleDesc.pInputModule = ZeExtModuleDesc.pInputModules [0 ];
@@ -382,7 +381,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
382
381
383
382
// Call the Level Zero API to compile, link, and create the module.
384
383
ze_device_handle_t ZeDevice = phDevices[0 ]->ZeDevice ;
385
- ze_context_handle_t ZeContext = Context ->ZeContext ;
384
+ ze_context_handle_t ZeContext = hContext ->ZeContext ;
386
385
ze_module_handle_t ZeModule = nullptr ;
387
386
ze_module_build_log_handle_t ZeBuildLog = nullptr ;
388
387
ze_result_t ZeResult =
@@ -420,8 +419,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramLinkExp(
420
419
? ur_program_handle_t_::Exe
421
420
: ur_program_handle_t_::Invalid;
422
421
ur_program_handle_t_ *UrProgram =
423
- new ur_program_handle_t_ (State, Context , ZeModule, ZeBuildLog);
424
- *Program = reinterpret_cast <ur_program_handle_t >(UrProgram);
422
+ new ur_program_handle_t_ (State, hContext , ZeModule, ZeBuildLog);
423
+ *phProgram = reinterpret_cast <ur_program_handle_t >(UrProgram);
425
424
} catch (const std::bad_alloc &) {
426
425
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
427
426
} catch (...) {
0 commit comments