Skip to content

Commit 9b8606f

Browse files
dmitryryintelsys_zuul
authored andcommitted
initial support of L0 binary in cmc
Change-Id: I7fbdf5b33ae8b51536e12a4305df4bafc7893aa5
1 parent e62470d commit 9b8606f

File tree

4 files changed

+118
-42
lines changed

4 files changed

+118
-42
lines changed

IGC/AdaptorOCL/OCL/sp/spp_g8.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,4 +404,20 @@ void CGen8CMProgram::CreateKernelBinaries()
404404
}
405405
}
406406

407+
void CGen8CMProgram::GetZEBinary(
408+
llvm::raw_pwrite_stream& programBinary, unsigned pointerSizeInBytes)
409+
{
410+
ZEBinaryBuilder zebuilder{m_Platform, pointerSizeInBytes == 8, *m_programInfo};
411+
412+
for (auto *kernel : m_kernels)
413+
{
414+
zebuilder.createKernel(
415+
reinterpret_cast<const char*>(kernel->m_prog.m_programBin),
416+
kernel->m_prog.m_programSize,
417+
kernel->m_kernelInfo,
418+
kernel->m_GRFSizeInBytes);
419+
}
420+
zebuilder.getBinaryObject(programBinary);
421+
}
422+
407423
} // namespace iOpenCL

IGC/AdaptorOCL/OCL/sp/spp_g8.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ class CGen8CMProgram : public CGen8OpenCLProgramBase {
127127
// Produce the final ELF binary with the given CM kernels
128128
// in OpenCL format.
129129
void CreateKernelBinaries();
130+
void GetZEBinary(llvm::raw_pwrite_stream& programBinary,
131+
unsigned pointerSizeInBytes) override;
130132

131133
// CM kernel list.
132134
std::vector<cmc::CMKernel*> m_kernels;

IGC/AdaptorOCL/cmc.cpp

Lines changed: 95 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,38 @@ CMKernel::~CMKernel()
8585
delete m_btiLayout.getModifiableLayout();
8686
}
8787

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+
88120
void CMKernel::createConstArgumentAnnotation(unsigned argNo, unsigned sizeInBytes, unsigned payloadPosition)
89121
{
90122
iOpenCL::ConstantArgumentAnnotation* constInput = new iOpenCL::ConstantArgumentAnnotation;
@@ -98,6 +130,10 @@ void CMKernel::createConstArgumentAnnotation(unsigned argNo, unsigned sizeInByte
98130
constInput->LocationCount = 0;
99131
constInput->IsEmulationArgument = false;
100132
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);
101137
}
102138

103139
// TODO: this is incomplete.
@@ -118,6 +154,9 @@ void CMKernel::createSamplerAnnotation(unsigned argNo)
118154
samplerArg->PayloadPosition = 0;
119155

120156
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");
121160
}
122161

123162
void CMKernel::createImageAnnotation(unsigned argNo, unsigned BTI, unsigned dim, bool isWriteable)
@@ -145,44 +184,44 @@ void CMKernel::createImageAnnotation(unsigned argNo, unsigned BTI, unsigned dim,
145184
imageInput->PayloadPosition = 0;
146185
imageInput->Writeable = isWriteable;
147186
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");
148190
}
149191

150192
void CMKernel::createImplicitArgumentsAnnotation(unsigned payloadPosition)
151193
{
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);
169197
}
170198

171-
void CMKernel::createPointerGlobalAnnotation(unsigned argNo, unsigned byteSize, unsigned payloadPosition, int BTI)
199+
void CMKernel::createPointerGlobalAnnotation(const cmc_arg_info &argInfo)
172200
{
173201
iOpenCL::PointerArgumentAnnotation* ptrAnnotation = new iOpenCL::PointerArgumentAnnotation;
174202
ptrAnnotation->IsStateless = true;
175203
ptrAnnotation->IsBindlessAccess = false;
176204
ptrAnnotation->AddressSpace = iOpenCL::KERNEL_ARGUMENT_ADDRESS_SPACE_GLOBAL;
177205
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;
182210
ptrAnnotation->LocationIndex = 0;
183211
ptrAnnotation->LocationCount = 0;
184212
ptrAnnotation->IsEmulationArgument = false;
185213
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+
}
186225
}
187226

188227
void CMKernel::createPrivateBaseAnnotation(
@@ -201,9 +240,12 @@ void CMKernel::createPrivateBaseAnnotation(
201240
ptrAnnotation->PayloadPosition = payloadPosition;
202241
ptrAnnotation->PayloadSizeInBytes = byteSize;
203242
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");
204246
}
205247

206-
void CMKernel::createBufferStatefulAnnotation(unsigned argNo)
248+
void CMKernel::createBufferStatefulAnnotation(unsigned argNo, cmc_access_kind accessKind)
207249
{
208250
iOpenCL::ConstantInputAnnotation* constInput = new iOpenCL::ConstantInputAnnotation;
209251

@@ -216,11 +258,24 @@ void CMKernel::createBufferStatefulAnnotation(unsigned argNo)
216258
constInput->LocationIndex = 0;
217259
constInput->LocationCount = 0;
218260
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+
}
219270
}
220271

221-
void CMKernel::createSizeAnnotation(unsigned payloadPosition, int32_t Type)
272+
void CMKernel::createSizeAnnotation(unsigned initPayloadPosition,
273+
iOpenCL::DATA_PARAMETER_TOKEN Type)
222274
{
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+
{
224279
iOpenCL::ConstantInputAnnotation* constInput = new iOpenCL::ConstantInputAnnotation;
225280
DWORD sizeInBytes = iOpenCL::DATA_PARAMETER_DATA_SIZE;
226281

@@ -233,9 +288,11 @@ void CMKernel::createSizeAnnotation(unsigned payloadPosition, int32_t Type)
233288
constInput->LocationIndex = 0;
234289
constInput->LocationCount = 0;
235290
m_kernelInfo.m_constantInputAnnotation.push_back(constInput);
236-
237-
payloadPosition += sizeInBytes;
238291
}
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);
239296
}
240297

241298
// TODO: refactor this function with the OCL part.
@@ -391,30 +448,31 @@ static void generatePatchTokens_v2(const cmc_kernel_info_v2 *info,
391448

392449
for (unsigned i = 0; i < info->num_args; ++i) {
393450
IGC_ASSERT(info->arg_descs);
394-
cmc_arg_info& AI = info->arg_descs[i];
451+
cmc_arg_info AI = info->arg_descs[i];
395452
if (AI.offset > 0)
396453
maxArgEnd = std::max(AI.offset + AI.sizeInBytes, maxArgEnd);
397454
bool isWriteable = AI.access != cmc_access_kind::read_only;
455+
AI.offset -= constantPayloadStart;
398456

399457
switch (AI.kind) {
400458
default:
401459
break;
402460
case cmc_arg_kind::General:
403-
kernel.createConstArgumentAnnotation(AI.index, AI.sizeInBytes, AI.offset - constantPayloadStart);
461+
kernel.createConstArgumentAnnotation(AI.index, AI.sizeInBytes, AI.offset);
404462
break;
405463
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);
407465
break;
408466
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);
410468
break;
411469
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);
414472
kernel.m_kernelInfo.m_argIndexMap[AI.index] = AI.BTI;
415473
break;
416474
case cmc_arg_kind::SVM:
417-
kernel.createPointerGlobalAnnotation(AI.index, AI.sizeInBytes, AI.offset - constantPayloadStart, AI.BTI);
475+
kernel.createPointerGlobalAnnotation(AI);
418476
kernel.m_kernelInfo.m_argIndexMap[AI.index] = AI.BTI;
419477
break;
420478
case cmc_arg_kind::Sampler:
@@ -438,14 +496,14 @@ static void generatePatchTokens_v2(const cmc_kernel_info_v2 *info,
438496
kernel.m_kernelInfo.m_printfBufferAnnotation->AnnotationSize = sizeof(kernel.m_kernelInfo.m_printfBufferAnnotation);
439497
kernel.m_kernelInfo.m_argIndexMap[AI.index] = AI.BTI;
440498
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;
442500
kernel.m_kernelInfo.m_printfBufferAnnotation->Index = 0;
443501
kernel.m_kernelInfo.m_printfBufferAnnotation->DataSize = 8;
444502
break;
445503
case cmc_arg_kind::PrivateBase:
446504
if (info->StatelessPrivateMemSize) {
447505
kernel.createPrivateBaseAnnotation(AI.index, AI.sizeInBytes,
448-
AI.offset - constantPayloadStart, AI.BTI, info->StatelessPrivateMemSize);
506+
AI.offset, AI.BTI, info->StatelessPrivateMemSize);
449507
kernel.m_kernelInfo.m_argIndexMap[AI.index] = AI.BTI;
450508
}
451509
break;
@@ -484,6 +542,7 @@ static void populateKernelInfo_v2(const cmc_kernel_info_v2* info,
484542
llvm::ArrayRef<uint8_t> genBin,
485543
CMKernel& kernel)
486544
{
545+
kernel.m_GRFSizeInBytes = info->GRFByteSize;
487546
// ExecutionEnivronment:
488547
//
489548
auto& kInfo = kernel.m_kernelInfo;

IGC/AdaptorOCL/cmc.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CMKernel {
5555
IGC::SOpenCLKernelInfo m_kernelInfo;
5656
IGC::SProgramOutput m_prog;
5757
IGC::COCLBTILayout m_btiLayout;
58+
uint32_t m_GRFSizeInBytes;
5859

5960
// General argument
6061
void createConstArgumentAnnotation(unsigned argNo,
@@ -68,20 +69,18 @@ class CMKernel {
6869
bool isWriteable);
6970

7071
// add a pointer patch token.
71-
void createPointerGlobalAnnotation(unsigned argNo,
72-
unsigned byteSize,
73-
unsigned payloadPosition,
74-
int BTI);
72+
void createPointerGlobalAnnotation(const cmc_arg_info &argInfo);
7573

7674
void createPrivateBaseAnnotation(unsigned argNo, unsigned byteSize,
7775
unsigned payloadPosition, int BTI,
7876
unsigned statelessPrivateMemSize);
7977

8078
// add a stateful buffer patch token.
81-
void createBufferStatefulAnnotation(unsigned argNo);
79+
void createBufferStatefulAnnotation(unsigned argNo,
80+
cmc_access_kind accessKind);
8281

8382
// Local or global size
84-
void createSizeAnnotation(unsigned payloadPosition, int32_t type);
83+
void createSizeAnnotation(unsigned payloadPosition, iOpenCL::DATA_PARAMETER_TOKEN type);
8584

8685
// Global work offset/local work size
8786
void createImplicitArgumentsAnnotation(unsigned payloadPosition);

0 commit comments

Comments
 (0)