-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Enable parameter optimization for SYCL kernels #2236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
88c2708
cc96031
0b6a546
3b7e3d7
b800ac2
f41a03f
adb0a54
45a33b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1765,14 +1765,17 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler { | |
|
||
void addParam(const FieldDecl *FD, QualType ArgTy, | ||
SYCLIntegrationHeader::kernel_param_kind_t Kind) { | ||
assert(Kind != SYCLIntegrationHeader::kind_accessor && | ||
"Kernel parameter should not be an Accessor"); | ||
uint64_t Size; | ||
const ConstantArrayType *CAT = | ||
SemaRef.getASTContext().getAsConstantArrayType(ArgTy); | ||
if (CAT) | ||
ArgTy = CAT->getElementType(); | ||
Size = SemaRef.getASTContext().getTypeSizeInChars(ArgTy).getQuantity(); | ||
Header.addParamDesc(Kind, static_cast<unsigned>(Size), | ||
static_cast<unsigned>(CurOffset)); | ||
static_cast<unsigned>(CurOffset), | ||
/*NumOpenCLParams=*/1); | ||
} | ||
|
||
public: | ||
|
@@ -1783,6 +1786,13 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler { | |
Header.startKernel(Name, NameType, StableName, KernelObj->getLocation()); | ||
} | ||
|
||
unsigned getNumOpenCLParams(const CXXRecordDecl *AccessorTy) { | ||
assert(AccessorTy && "Accessor type must be a C++ record type"); | ||
CXXMethodDecl *InitMethod = getMethodByName(AccessorTy, InitMethodName); | ||
assert(InitMethod && "accessor must have __init method"); | ||
return InitMethod->param_size(); | ||
} | ||
|
||
bool handleSyclAccessorType(const CXXBaseSpecifier &BC, | ||
QualType FieldTy) final { | ||
const auto *AccTy = | ||
|
@@ -1792,7 +1802,8 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler { | |
int Dims = static_cast<int>( | ||
AccTy->getTemplateArgs()[1].getAsIntegral().getExtValue()); | ||
int Info = getAccessTarget(AccTy) | (Dims << 11); | ||
Header.addParamDesc(SYCLIntegrationHeader::kind_accessor, Info, CurOffset); | ||
Header.addParamDesc(SYCLIntegrationHeader::kind_accessor, Info, CurOffset, | ||
getNumOpenCLParams(AccTy)); | ||
return true; | ||
} | ||
|
||
|
@@ -1804,7 +1815,8 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler { | |
int Dims = static_cast<int>( | ||
AccTy->getTemplateArgs()[1].getAsIntegral().getExtValue()); | ||
int Info = getAccessTarget(AccTy) | (Dims << 11); | ||
Header.addParamDesc(SYCLIntegrationHeader::kind_accessor, Info, CurOffset); | ||
Header.addParamDesc(SYCLIntegrationHeader::kind_accessor, Info, CurOffset, | ||
getNumOpenCLParams(AccTy)); | ||
return true; | ||
} | ||
|
||
|
@@ -1813,11 +1825,11 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler { | |
assert(SamplerTy && "Sampler type must be a C++ record type"); | ||
CXXMethodDecl *InitMethod = getMethodByName(SamplerTy, InitMethodName); | ||
assert(InitMethod && "sampler must have __init method"); | ||
|
||
// sampler __init method has only one argument | ||
assert((InitMethod->param_size() == 1) && | ||
"sampler __init method should have only one argument"); | ||
const ParmVarDecl *SamplerArg = InitMethod->getParamDecl(0); | ||
assert(SamplerArg && "sampler __init method must have sampler parameter"); | ||
|
||
addParam(FD, SamplerArg->getType(), SYCLIntegrationHeader::kind_sampler); | ||
return true; | ||
} | ||
|
@@ -2682,19 +2694,43 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) { | |
} | ||
O << "};\n\n"; | ||
|
||
O << "// array representing kernel parameters used in all kernels defined in " | ||
"the\n"; | ||
O << "// corresponding source\n"; | ||
O << "static constexpr\n"; | ||
O << "const bool param_omit_table[] = {\n"; | ||
O << " // OMIT_TABLE_BEGIN\n"; | ||
for (const KernelDesc &K : KernelDescs) { | ||
O << " //--- " << K.Name << "\n"; | ||
O << " "; | ||
erichkeane marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (const KernelParamDesc &P : K.Params) | ||
for (unsigned J = 0; J < P.NumOpenCLParams; J++) | ||
O << "false, "; | ||
O << "\n"; | ||
} | ||
O << " // OMIT_TABLE_END\n"; | ||
O << " }; \n\n"; | ||
|
||
O << "// array representing signatures of all kernels defined in the\n"; | ||
O << "// corresponding source\n"; | ||
O << "static constexpr\n"; | ||
O << "const kernel_param_desc_t kernel_signatures[] = {\n"; | ||
|
||
for (unsigned I = 0; I < KernelDescs.size(); I++) { | ||
auto &K = KernelDescs[I]; | ||
unsigned CurIndex = 0; | ||
for (const KernelDesc &K : KernelDescs) { | ||
O << " //--- " << K.Name << "\n"; | ||
|
||
for (const auto &P : K.Params) { | ||
for (const KernelParamDesc &P : K.Params) { | ||
std::string TyStr = paramKind2Str(P.Kind); | ||
O << " { kernel_param_kind_t::" << TyStr << ", "; | ||
O << P.Info << ", " << P.Offset << " },\n"; | ||
O << P.Info << ", " << P.Offset << ", "; | ||
O << "param_omit_table[" << CurIndex << "]"; | ||
srividya-sundaram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
++CurIndex; | ||
for (unsigned X = 1; X < P.NumOpenCLParams; X++) { | ||
O << " | (param_omit_table[" << CurIndex << "] << " << X << ")"; | ||
++CurIndex; | ||
} | ||
O << "}"; | ||
O << ",\n"; | ||
} | ||
O << "\n"; | ||
} | ||
|
@@ -2789,14 +2825,11 @@ void SYCLIntegrationHeader::startKernel(StringRef KernelName, | |
} | ||
|
||
void SYCLIntegrationHeader::addParamDesc(kernel_param_kind_t Kind, int Info, | ||
unsigned Offset) { | ||
unsigned Offset, | ||
unsigned NumOpenCLParams) { | ||
auto *K = getCurKernelDesc(); | ||
assert(K && "no kernels"); | ||
K->Params.push_back(KernelParamDesc()); | ||
KernelParamDesc &PD = K->Params.back(); | ||
PD.Kind = Kind; | ||
PD.Info = Info; | ||
PD.Offset = Offset; | ||
K->Params.push_back({Kind, Info, Offset, NumOpenCLParams}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keryell : emplace_back doesn't support aggregate initialization until C++20, and our codebase is C++14. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then you know what you have to do. Please replace all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Wish I could! It was hard enough to get the LLVM project switched over from a terrible-subset-of C++11 to C++14. |
||
} | ||
|
||
void SYCLIntegrationHeader::endKernel() { | ||
|
Uh oh!
There was an error while loading. Please reload this page.