@@ -92,6 +92,122 @@ getZEArgAccessType(vc::ocl::ArgAccessKind accessKind)
9292 }
9393}
9494
95+ namespace {
96+ class KernelArgInfoBuilder
97+ {
98+ struct AccessQualifiers
99+ {
100+ static constexpr const char * None = " NONE" ;
101+ static constexpr const char * ReadOnly = " read_only" ;
102+ static constexpr const char * WriteOnly = " write_only" ;
103+ static constexpr const char * ReadWrite = " read_write" ;
104+
105+ static const char * get (vc::ocl::ArgAccessKind AccessKindID)
106+ {
107+ switch (AccessKindID)
108+ {
109+ case vc::ocl::ArgAccessKind::None:
110+ return None;
111+ case vc::ocl::ArgAccessKind::ReadOnly:
112+ return ReadOnly;
113+ case vc::ocl::ArgAccessKind::WriteOnly:
114+ return WriteOnly;
115+ case vc::ocl::ArgAccessKind::ReadWrite:
116+ default :
117+ return ReadWrite;
118+ }
119+ }
120+ };
121+ struct AddressQualifiers
122+ {
123+ static constexpr const char * Global = " __global" ;
124+ static constexpr const char * Local = " __local" ;
125+ static constexpr const char * Private = " __private" ;
126+ static constexpr const char * Constant = " __constant" ;
127+ static constexpr const char * NotSpecified = " not_specified" ;
128+
129+ static const char * get (vc::ocl::ArgKind ArgKindID)
130+ {
131+ switch (ArgKindID)
132+ {
133+ case vc::ocl::ArgKind::General:
134+ return Local;
135+ case vc::ocl::ArgKind::Buffer:
136+ case vc::ocl::ArgKind::SVM:
137+ case vc::ocl::ArgKind::Image1d:
138+ case vc::ocl::ArgKind::Image2d:
139+ case vc::ocl::ArgKind::Image3d:
140+ return Global;
141+ case vc::ocl::ArgKind::Sampler:
142+ return Constant;
143+ default :
144+ IGC_ASSERT_EXIT_MESSAGE (0 , " implicit args cannot appear in kernel arg info" );
145+ }
146+ }
147+ };
148+ struct TypeQualifiers
149+ {
150+ static constexpr const char * None = " NONE" ;
151+ static constexpr const char * Const = " const" ;
152+ static constexpr const char * Volatile = " volatile" ;
153+ static constexpr const char * Restrict = " restrict" ;
154+ static constexpr const char * Pipe = " pipe" ;
155+ };
156+ using ArgInfoSeq = std::vector<iOpenCL::KernelArgumentInfoAnnotation*>;
157+ ArgInfoSeq ArgInfos;
158+
159+ public:
160+ void insert (int Index, vc::ocl::ArgKind ArgKindID, vc::ocl::ArgAccessKind AccessKindID)
161+ {
162+ resizeStorageIfRequired (Index + 1 );
163+ ArgInfos[Index] = get (ArgKindID, AccessKindID);
164+ }
165+
166+ // It is users responsibility to delete the annotation.
167+ static iOpenCL::KernelArgumentInfoAnnotation* get (vc::ocl::ArgKind ArgKindID,
168+ vc::ocl::ArgAccessKind AccessKind = vc::ocl::ArgAccessKind::None)
169+ {
170+ auto * Annotation = new iOpenCL::KernelArgumentInfoAnnotation;
171+ Annotation->AddressQualifier = AddressQualifiers::get (ArgKindID);
172+ Annotation->AccessQualifier = AccessQualifiers::get (AccessKind);
173+ Annotation->ArgumentName = " " ;
174+ Annotation->TypeName = " " ;
175+ Annotation->TypeQualifier = TypeQualifiers::None;
176+ return Annotation;
177+ }
178+
179+ ArgInfoSeq emit () const &
180+ {
181+ IGC_ASSERT_MESSAGE (checkArgInfosCorrectness (),
182+ " arg info token is incorrect" );
183+ return ArgInfos;
184+ }
185+
186+ ArgInfoSeq emit () &&
187+ {
188+ IGC_ASSERT_MESSAGE (checkArgInfosCorrectness (),
189+ " arg info token is incorrect" );
190+ return std::move (ArgInfos);
191+ }
192+
193+ private:
194+ void resizeStorageIfRequired (int RequiredSize)
195+ {
196+ IGC_ASSERT_MESSAGE (RequiredSize > 0 , " invalid required size" );
197+ if (RequiredSize <= static_cast <int >(ArgInfos.size ()))
198+ return ;
199+ ArgInfos.resize (RequiredSize, nullptr );
200+ }
201+
202+ // Returns whether arg infos are correct.
203+ bool checkArgInfosCorrectness () const
204+ {
205+ return std::none_of (ArgInfos.begin (), ArgInfos.end (),
206+ [](iOpenCL::KernelArgumentInfoAnnotation* ArgInfo){ return ArgInfo == nullptr ; });
207+ }
208+ };
209+ } // anonymous namespace
210+
95211void CMKernel::createConstArgumentAnnotation (unsigned argNo, unsigned sizeInBytes, unsigned payloadPosition)
96212{
97213 iOpenCL::ConstantArgumentAnnotation* constInput = new iOpenCL::ConstantArgumentAnnotation;
@@ -365,6 +481,28 @@ static void generateSymbols(const vc::ocl::KernelInfo& info,
365481 kernelProgram.m_symbols .local = info.ZEBinInfo .Symbols .Local ;
366482}
367483
484+ void generateKernelArgInfo (const std::vector<vc::ocl::ArgInfo> &Args,
485+ std::vector<iOpenCL::KernelArgumentInfoAnnotation*> &ArgsAnnotation)
486+ {
487+ KernelArgInfoBuilder ArgsAnnotationBuilder;
488+ for (auto &Arg : Args)
489+ switch (Arg.Kind )
490+ {
491+ case vc::ocl::ArgKind::General:
492+ case vc::ocl::ArgKind::Buffer:
493+ case vc::ocl::ArgKind::SVM:
494+ case vc::ocl::ArgKind::Sampler:
495+ case vc::ocl::ArgKind::Image1d:
496+ case vc::ocl::ArgKind::Image2d:
497+ case vc::ocl::ArgKind::Image3d:
498+ ArgsAnnotationBuilder.insert (Arg.Index , Arg.Kind , Arg.AccessKind );
499+ break ;
500+ default :
501+ continue ;
502+ }
503+ ArgsAnnotation = std::move (ArgsAnnotationBuilder).emit ();
504+ }
505+
368506static void generatePatchTokens_v2 (const vc::ocl::KernelInfo& info,
369507 const vc::ocl::GTPinInfo* ginfo,
370508 CMKernel& kernel)
@@ -474,6 +612,7 @@ static void generatePatchTokens_v2(const vc::ocl::KernelInfo& info,
474612 break ;
475613 }
476614 }
615+ generateKernelArgInfo (info.Args , kernel.m_kernelInfo .m_kernelArgInfo );
477616
478617 const unsigned maxArgEnd = std::accumulate (
479618 info.Args .begin (), info.Args .end (), constantPayloadStart,
0 commit comments