@@ -85,6 +85,38 @@ CMKernel::~CMKernel()
85
85
delete m_btiLayout.getModifiableLayout ();
86
86
}
87
87
88
+ static zebin::PreDefinedAttrGetter::ArgType getZEArgType (iOpenCL::DATA_PARAMETER_TOKEN type) {
89
+ switch (type) {
90
+ case iOpenCL::DATA_PARAMETER_ENQUEUED_LOCAL_WORK_SIZE:
91
+ return zebin::PreDefinedAttrGetter::ArgType::local_size;
92
+ case iOpenCL::DATA_PARAMETER_GLOBAL_WORK_OFFSET:
93
+ return zebin::PreDefinedAttrGetter::ArgType::global_id_offset;
94
+ case iOpenCL::DATA_PARAMETER_NUM_WORK_GROUPS:
95
+ // copied from OCL behavior
96
+ return zebin::PreDefinedAttrGetter::ArgType::group_size;
97
+ default :
98
+ IGC_ASSERT_MESSAGE (0 , " unsupported argument type" );
99
+ return zebin::PreDefinedAttrGetter::ArgType::arg_byvalue;
100
+ }
101
+ }
102
+
103
+ static zebin::PreDefinedAttrGetter::ArgAccessType getZEArgAccessType (cmc_access_kind accessKind)
104
+ {
105
+ switch (accessKind)
106
+ {
107
+ case cmc_access_kind::read_only:
108
+ return zebin::PreDefinedAttrGetter::ArgAccessType::readonly;
109
+ case cmc_access_kind::write_only:
110
+ return zebin::PreDefinedAttrGetter::ArgAccessType::writeonly;
111
+ case cmc_access_kind::read_write:
112
+ return zebin::PreDefinedAttrGetter::ArgAccessType::readwrite;
113
+ case cmc_access_kind::undef:
114
+ default :
115
+ IGC_ASSERT_MESSAGE (0 , " invalid access type" );
116
+ return zebin::PreDefinedAttrGetter::ArgAccessType::readwrite;
117
+ }
118
+ }
119
+
88
120
void CMKernel::createConstArgumentAnnotation (unsigned argNo, unsigned sizeInBytes, unsigned payloadPosition)
89
121
{
90
122
iOpenCL::ConstantArgumentAnnotation* constInput = new iOpenCL::ConstantArgumentAnnotation;
@@ -98,6 +130,10 @@ void CMKernel::createConstArgumentAnnotation(unsigned argNo, unsigned sizeInByte
98
130
constInput->LocationCount = 0 ;
99
131
constInput->IsEmulationArgument = false ;
100
132
m_kernelInfo.m_constantArgumentAnnotation .push_back (constInput);
133
+
134
+ if (IGC_IS_FLAG_ENABLED (EnableZEBinary))
135
+ zebin::ZEInfoBuilder::addPayloadArgumentByValue (m_kernelInfo.m_zePayloadArgs ,
136
+ payloadPosition, sizeInBytes, argNo);
101
137
}
102
138
103
139
// TODO: this is incomplete.
@@ -118,6 +154,9 @@ void CMKernel::createSamplerAnnotation(unsigned argNo)
118
154
samplerArg->PayloadPosition = 0 ;
119
155
120
156
m_kernelInfo.m_samplerArgument .push_back (samplerArg);
157
+
158
+ if (IGC_IS_FLAG_ENABLED (EnableZEBinary))
159
+ IGC_ASSERT_MESSAGE (0 , " not yet supported for L0 binary" );
121
160
}
122
161
123
162
void CMKernel::createImageAnnotation (unsigned argNo, unsigned BTI, unsigned dim, bool isWriteable)
@@ -145,44 +184,44 @@ void CMKernel::createImageAnnotation(unsigned argNo, unsigned BTI, unsigned dim,
145
184
imageInput->PayloadPosition = 0 ;
146
185
imageInput->Writeable = isWriteable;
147
186
m_kernelInfo.m_imageInputAnnotations .push_back (imageInput);
187
+
188
+ if (IGC_IS_FLAG_ENABLED (EnableZEBinary))
189
+ IGC_ASSERT_MESSAGE (0 , " not yet supported for L0 binary" );
148
190
}
149
191
150
192
void CMKernel::createImplicitArgumentsAnnotation (unsigned payloadPosition)
151
193
{
152
- for (int i = 0 ; i < 6 ; ++i) {
153
- iOpenCL::ConstantInputAnnotation* constInput = new iOpenCL::ConstantInputAnnotation;
154
- DWORD sizeInBytes = iOpenCL::DATA_PARAMETER_DATA_SIZE;
155
-
156
- constInput->AnnotationSize = sizeof (constInput);
157
- constInput->ConstantType = (i < 3 ? iOpenCL::DATA_PARAMETER_GLOBAL_WORK_OFFSET
158
- : iOpenCL::DATA_PARAMETER_LOCAL_WORK_SIZE);
159
- constInput->Offset = (i % 3 ) * sizeInBytes;
160
- constInput->PayloadPosition = payloadPosition;
161
- constInput->PayloadSizeInBytes = sizeInBytes;
162
- constInput->ArgumentNumber = 0 ;
163
- constInput->LocationIndex = 0 ;
164
- constInput->LocationCount = 0 ;
165
- m_kernelInfo.m_constantInputAnnotation .push_back (constInput);
166
-
167
- payloadPosition += sizeInBytes;
168
- }
194
+ createSizeAnnotation (payloadPosition, iOpenCL::DATA_PARAMETER_GLOBAL_WORK_OFFSET);
195
+ payloadPosition += 3 * iOpenCL::DATA_PARAMETER_DATA_SIZE;
196
+ createSizeAnnotation (payloadPosition, iOpenCL::DATA_PARAMETER_LOCAL_WORK_SIZE);
169
197
}
170
198
171
- void CMKernel::createPointerGlobalAnnotation (unsigned argNo, unsigned byteSize, unsigned payloadPosition, int BTI )
199
+ void CMKernel::createPointerGlobalAnnotation (const cmc_arg_info &argInfo )
172
200
{
173
201
iOpenCL::PointerArgumentAnnotation* ptrAnnotation = new iOpenCL::PointerArgumentAnnotation;
174
202
ptrAnnotation->IsStateless = true ;
175
203
ptrAnnotation->IsBindlessAccess = false ;
176
204
ptrAnnotation->AddressSpace = iOpenCL::KERNEL_ARGUMENT_ADDRESS_SPACE_GLOBAL;
177
205
ptrAnnotation->AnnotationSize = sizeof (ptrAnnotation);
178
- ptrAnnotation->ArgumentNumber = argNo ;
179
- ptrAnnotation->BindingTableIndex = BTI;
180
- ptrAnnotation->PayloadPosition = payloadPosition ;
181
- ptrAnnotation->PayloadSizeInBytes = byteSize ;
206
+ ptrAnnotation->ArgumentNumber = argInfo. index ;
207
+ ptrAnnotation->BindingTableIndex = argInfo. BTI ;
208
+ ptrAnnotation->PayloadPosition = argInfo. offset ;
209
+ ptrAnnotation->PayloadSizeInBytes = argInfo. sizeInBytes ;
182
210
ptrAnnotation->LocationIndex = 0 ;
183
211
ptrAnnotation->LocationCount = 0 ;
184
212
ptrAnnotation->IsEmulationArgument = false ;
185
213
m_kernelInfo.m_pointerArgument .push_back (ptrAnnotation);
214
+
215
+ if (IGC_IS_FLAG_ENABLED (EnableZEBinary))
216
+ {
217
+ zebin::ZEInfoBuilder::addPayloadArgumentByPointer (m_kernelInfo.m_zePayloadArgs ,
218
+ argInfo.offset , argInfo.sizeInBytes , argInfo.index ,
219
+ zebin::PreDefinedAttrGetter::ArgAddrMode::stateless,
220
+ zebin::PreDefinedAttrGetter::ArgAddrSpace::global,
221
+ getZEArgAccessType (argInfo.access ));
222
+ zebin::ZEInfoBuilder::addBindingTableIndex (m_kernelInfo.m_zeBTIArgs ,
223
+ argInfo.BTI , argInfo.index );
224
+ }
186
225
}
187
226
188
227
void CMKernel::createPrivateBaseAnnotation (
@@ -201,9 +240,12 @@ void CMKernel::createPrivateBaseAnnotation(
201
240
ptrAnnotation->PayloadPosition = payloadPosition;
202
241
ptrAnnotation->PayloadSizeInBytes = byteSize;
203
242
m_kernelInfo.m_pointerInput .push_back (ptrAnnotation);
243
+
244
+ if (IGC_IS_FLAG_ENABLED (EnableZEBinary))
245
+ IGC_ASSERT_MESSAGE (0 , " not yet supported for L0 binary" );
204
246
}
205
247
206
- void CMKernel::createBufferStatefulAnnotation (unsigned argNo)
248
+ void CMKernel::createBufferStatefulAnnotation (unsigned argNo, cmc_access_kind accessKind )
207
249
{
208
250
iOpenCL::ConstantInputAnnotation* constInput = new iOpenCL::ConstantInputAnnotation;
209
251
@@ -216,11 +258,24 @@ void CMKernel::createBufferStatefulAnnotation(unsigned argNo)
216
258
constInput->LocationIndex = 0 ;
217
259
constInput->LocationCount = 0 ;
218
260
m_kernelInfo.m_constantInputAnnotation .push_back (constInput);
261
+
262
+ if (IGC_IS_FLAG_ENABLED (EnableZEBinary))
263
+ {
264
+ zebin::ZEInfoBuilder::addPayloadArgumentByPointer (m_kernelInfo.m_zePayloadArgs ,
265
+ 0 , 0 , argNo,
266
+ zebin::PreDefinedAttrGetter::ArgAddrMode::stateful,
267
+ zebin::PreDefinedAttrGetter::ArgAddrSpace::global,
268
+ getZEArgAccessType (accessKind));
269
+ }
219
270
}
220
271
221
- void CMKernel::createSizeAnnotation (unsigned payloadPosition, int32_t Type)
272
+ void CMKernel::createSizeAnnotation (unsigned initPayloadPosition,
273
+ iOpenCL::DATA_PARAMETER_TOKEN Type)
222
274
{
223
- for (int i = 0 ; i < 3 ; ++i) {
275
+ for (int i = 0 , payloadPosition = initPayloadPosition;
276
+ i < 3 ;
277
+ ++i, payloadPosition += iOpenCL::DATA_PARAMETER_DATA_SIZE)
278
+ {
224
279
iOpenCL::ConstantInputAnnotation* constInput = new iOpenCL::ConstantInputAnnotation;
225
280
DWORD sizeInBytes = iOpenCL::DATA_PARAMETER_DATA_SIZE;
226
281
@@ -233,9 +288,11 @@ void CMKernel::createSizeAnnotation(unsigned payloadPosition, int32_t Type)
233
288
constInput->LocationIndex = 0 ;
234
289
constInput->LocationCount = 0 ;
235
290
m_kernelInfo.m_constantInputAnnotation .push_back (constInput);
236
-
237
- payloadPosition += sizeInBytes;
238
291
}
292
+ if (IGC_IS_FLAG_ENABLED (EnableZEBinary))
293
+ zebin::ZEInfoBuilder::addPayloadArgumentImplicit (m_kernelInfo.m_zePayloadArgs ,
294
+ getZEArgType (Type), initPayloadPosition,
295
+ iOpenCL::DATA_PARAMETER_DATA_SIZE * 3 );
239
296
}
240
297
241
298
// TODO: refactor this function with the OCL part.
@@ -391,30 +448,31 @@ static void generatePatchTokens_v2(const cmc_kernel_info_v2 *info,
391
448
392
449
for (unsigned i = 0 ; i < info->num_args ; ++i) {
393
450
IGC_ASSERT (info->arg_descs );
394
- cmc_arg_info& AI = info->arg_descs [i];
451
+ cmc_arg_info AI = info->arg_descs [i];
395
452
if (AI.offset > 0 )
396
453
maxArgEnd = std::max (AI.offset + AI.sizeInBytes , maxArgEnd);
397
454
bool isWriteable = AI.access != cmc_access_kind::read_only;
455
+ AI.offset -= constantPayloadStart;
398
456
399
457
switch (AI.kind ) {
400
458
default :
401
459
break ;
402
460
case cmc_arg_kind::General:
403
- kernel.createConstArgumentAnnotation (AI.index , AI.sizeInBytes , AI.offset - constantPayloadStart );
461
+ kernel.createConstArgumentAnnotation (AI.index , AI.sizeInBytes , AI.offset );
404
462
break ;
405
463
case cmc_arg_kind::LocalSize:
406
- kernel.createSizeAnnotation (AI.offset - constantPayloadStart , iOpenCL::DATA_PARAMETER_ENQUEUED_LOCAL_WORK_SIZE);
464
+ kernel.createSizeAnnotation (AI.offset , iOpenCL::DATA_PARAMETER_ENQUEUED_LOCAL_WORK_SIZE);
407
465
break ;
408
466
case cmc_arg_kind::GroupCount:
409
- kernel.createSizeAnnotation (AI.offset - constantPayloadStart , iOpenCL::DATA_PARAMETER_NUM_WORK_GROUPS);
467
+ kernel.createSizeAnnotation (AI.offset , iOpenCL::DATA_PARAMETER_NUM_WORK_GROUPS);
410
468
break ;
411
469
case cmc_arg_kind::Buffer:
412
- kernel.createPointerGlobalAnnotation (AI. index , AI. sizeInBytes , AI. offset - constantPayloadStart, AI. BTI );
413
- kernel.createBufferStatefulAnnotation (AI.index );
470
+ kernel.createPointerGlobalAnnotation (AI);
471
+ kernel.createBufferStatefulAnnotation (AI.index , AI. access );
414
472
kernel.m_kernelInfo .m_argIndexMap [AI.index ] = AI.BTI ;
415
473
break ;
416
474
case cmc_arg_kind::SVM:
417
- kernel.createPointerGlobalAnnotation (AI. index , AI. sizeInBytes , AI. offset - constantPayloadStart, AI. BTI );
475
+ kernel.createPointerGlobalAnnotation (AI);
418
476
kernel.m_kernelInfo .m_argIndexMap [AI.index ] = AI.BTI ;
419
477
break ;
420
478
case cmc_arg_kind::Sampler:
@@ -438,14 +496,14 @@ static void generatePatchTokens_v2(const cmc_kernel_info_v2 *info,
438
496
kernel.m_kernelInfo .m_printfBufferAnnotation ->AnnotationSize = sizeof (kernel.m_kernelInfo .m_printfBufferAnnotation );
439
497
kernel.m_kernelInfo .m_argIndexMap [AI.index ] = AI.BTI ;
440
498
kernel.m_kernelInfo .m_printfBufferAnnotation ->ArgumentNumber = AI.index ;
441
- kernel.m_kernelInfo .m_printfBufferAnnotation ->PayloadPosition = AI.offset - constantPayloadStart ;
499
+ kernel.m_kernelInfo .m_printfBufferAnnotation ->PayloadPosition = AI.offset ;
442
500
kernel.m_kernelInfo .m_printfBufferAnnotation ->Index = 0 ;
443
501
kernel.m_kernelInfo .m_printfBufferAnnotation ->DataSize = 8 ;
444
502
break ;
445
503
case cmc_arg_kind::PrivateBase:
446
504
if (info->StatelessPrivateMemSize ) {
447
505
kernel.createPrivateBaseAnnotation (AI.index , AI.sizeInBytes ,
448
- AI.offset - constantPayloadStart , AI.BTI , info->StatelessPrivateMemSize );
506
+ AI.offset , AI.BTI , info->StatelessPrivateMemSize );
449
507
kernel.m_kernelInfo .m_argIndexMap [AI.index ] = AI.BTI ;
450
508
}
451
509
break ;
@@ -484,6 +542,7 @@ static void populateKernelInfo_v2(const cmc_kernel_info_v2* info,
484
542
llvm::ArrayRef<uint8_t > genBin,
485
543
CMKernel& kernel)
486
544
{
545
+ kernel.m_GRFSizeInBytes = info->GRFByteSize ;
487
546
// ExecutionEnivronment:
488
547
//
489
548
auto & kInfo = kernel.m_kernelInfo ;
0 commit comments