Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
488dfb9
[SYCL] Implementation of loop attribute control_avg.
zahiraam Mar 29, 2021
b0f255e
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Mar 29, 2021
0324f5f
Fixing Attr name
zahiraam Mar 29, 2021
a3a8613
Complete implementation
zahiraam Apr 9, 2021
5abbbe6
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Apr 9, 2021
48d6df0
Adding test cases
zahiraam Apr 9, 2021
61fba57
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Apr 9, 2021
99cb85f
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Apr 12, 2021
44b8681
Indent
zahiraam Apr 12, 2021
7622568
Indent
zahiraam Apr 12, 2021
c3d8c59
Indent
zahiraam Apr 12, 2021
4dba2ea
CodeGen impl
zahiraam Apr 12, 2021
50a06c7
After review comments
zahiraam Apr 12, 2021
1bb84bc
Changing name
zahiraam Apr 12, 2021
40a3279
Format
zahiraam Apr 12, 2021
1f84add
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Apr 13, 2021
6ab3b07
After review
zahiraam Apr 13, 2021
a5ad650
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Apr 14, 2021
fd34d55
Formatting
zahiraam Apr 14, 2021
d812fa4
Formatting
zahiraam Apr 14, 2021
fd74842
Looks like the HasCustomTypeTransform is needed
zahiraam Apr 14, 2021
93cbc1d
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Apr 15, 2021
73f92a4
Added min/max
zahiraam Apr 16, 2021
80f372a
Added min/max
zahiraam Apr 19, 2021
639794e
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Apr 19, 2021
d2884f0
Indentation
zahiraam Apr 19, 2021
5ab429b
Added all 3 variants
zahiraam Apr 21, 2021
c73cd83
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Apr 21, 2021
86ae532
Added all 3 variants
zahiraam Apr 21, 2021
3044f88
Indentation
zahiraam Apr 21, 2021
453b654
Indentation
zahiraam Apr 21, 2021
9d46fc0
Indentation
zahiraam Apr 21, 2021
a44e1ce
Merge remote-tracking branch 'remote/sycl' into control-avg-attr
zahiraam Apr 27, 2021
1a20635
Fixes after review
zahiraam Apr 27, 2021
c10bfaf
Identation
zahiraam Apr 27, 2021
cefac8a
Fixes after review
zahiraam Apr 27, 2021
6ddf9ce
Fixes after review
zahiraam Apr 27, 2021
d0ddcdd
Fixes after review
zahiraam Apr 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,17 @@ def SYCLIntelFPGADisableLoopPipelining : DeclOrStmtAttr {
def : MutualExclusions<[SYCLIntelFPGAInitiationInterval,
SYCLIntelFPGADisableLoopPipelining]>;

def SYCLIntelFPGALoopControlAvg : StmtAttr {
let Spellings = [CXX11<"intelfpga","loop_control_avg">,
Comment thread
smanna12 marked this conversation as resolved.
Outdated
CXX11<"intel","loop_control_avg">];
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
ErrorDiag, "'for', 'while', and 'do' statements">;
let Args = [ExprArgument<"NTripCount">];
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
let HasCustomTypeTransform = 1;
Comment thread
AaronBallman marked this conversation as resolved.
Outdated
let Documentation = [SYCLIntelFPGALoopControlAvgAttrDocs];
}

def SYCLIntelFPGAMaxInterleaving : StmtAttr {
let Spellings = [CXX11<"intelfpga","max_interleaving">,
CXX11<"intel","max_interleaving">];
Expand Down
23 changes: 23 additions & 0 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,29 @@ max_concurrency, initiation_interval, or ivdep.
}];
}

def SYCLIntelFPGALoopControlAvgAttrDocs : Documentation {
let Category = DocCatVariable;
let Heading = "intel::loo_control_avg";
Comment thread
AaronBallman marked this conversation as resolved.
Outdated
let Content = [{
This attribute applies to a loop. Its purpose is to pass to the optimizer the
average trip count of a loop. This will allow the optimizer to figure out if
Comment thread
AaronBallman marked this conversation as resolved.
Outdated
the optimization is beneficial.

.. code-block:: c++
Comment thread
AaronBallman marked this conversation as resolved.

void foo() {
int a[10];
[[intel::loop_control_avg(40)] for (int i = 0; i < 10; ++i) a[i] = 0;
}

template<int N>
void bar() {
[[intel::loop_control_avg(N)]] for(;;) { }
}

}];
}

def SYCLIntelFPGAMaxInterleavingAttrDocs : Documentation {
let Category = DocCatVariable;
let Heading = "intel::max_interleaving";
Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -13419,7 +13419,9 @@ FPGALoopAttrT *Sema::BuildSYCLIntelFPGALoopAttr(const AttributeCommonInfo &A,
A.getParsedKind() ==
ParsedAttr::AT_SYCLIntelFPGAMaxInterleaving ||
A.getParsedKind() ==
ParsedAttr::AT_SYCLIntelFPGASpeculatedIterations) {
ParsedAttr::AT_SYCLIntelFPGASpeculatedIterations ||
A.getParsedKind() ==
ParsedAttr::AT_SYCLIntelFPGALoopControlAvg) {
if (Val < 0) {
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
<< A.getAttrName() << /* non-negative */ 1;
Expand Down
25 changes: 22 additions & 3 deletions clang/lib/CodeGen/CGLoopInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,13 @@ MDNode *LoopInfo::createMetadata(
LoopProperties.push_back(MDNode::get(Ctx, Vals));
}

if (Attrs.SYCLIntelFPGALoopControlAverageEnable) {
Metadata *Vals[] = {MDString::get(Ctx, "llvm.loop.intel.loopcount_average"),
ConstantAsMetadata::get(ConstantInt::get(
llvm::Type::getInt32Ty(Ctx),
Attrs.SYCLIntelFPGALoopControlAverage))};
LoopProperties.push_back(MDNode::get(Ctx, Vals));
}
LoopProperties.insert(LoopProperties.end(), AdditionalLoopProperties.begin(),
AdditionalLoopProperties.end());
return createFullUnrollMetadata(Attrs, LoopProperties, HasUserTransforms);
Expand All @@ -621,7 +628,8 @@ LoopAttributes::LoopAttributes(bool IsParallel)
SYCLLoopCoalesceNLevels(0), SYCLLoopPipeliningDisable(false),
SYCLMaxInterleavingEnable(false), SYCLMaxInterleavingNInvocations(0),
SYCLSpeculatedIterationsEnable(false),
SYCLSpeculatedIterationsNIterations(0), UnrollCount(0),
SYCLSpeculatedIterationsNIterations(0),
SYCLIntelFPGALoopControlAverageEnable(false), UnrollCount(0),
UnrollAndJamCount(0), DistributeEnable(LoopAttributes::Unspecified),
PipelineDisabled(false), PipelineInitiationInterval(0),
SYCLNofusionEnable(false), MustProgress(false) {}
Expand All @@ -643,6 +651,7 @@ void LoopAttributes::clear() {
SYCLMaxInterleavingNInvocations = 0;
SYCLSpeculatedIterationsEnable = false;
SYCLSpeculatedIterationsNIterations = 0;
SYCLIntelFPGALoopControlAverageEnable = false;
UnrollCount = 0;
UnrollAndJamCount = 0;
VectorizeEnable = LoopAttributes::Unspecified;
Expand Down Expand Up @@ -680,8 +689,10 @@ LoopInfo::LoopInfo(BasicBlock *Header, const LoopAttributes &Attrs,
Attrs.SYCLMaxInterleavingNInvocations == 0 &&
Attrs.SYCLSpeculatedIterationsEnable == false &&
Attrs.SYCLSpeculatedIterationsNIterations == 0 &&
Attrs.UnrollCount == 0 && Attrs.UnrollAndJamCount == 0 &&
!Attrs.PipelineDisabled && Attrs.PipelineInitiationInterval == 0 &&
Attrs.SYCLIntelFPGALoopControlAverageEnable == 0 &&
Attrs.UnrollCount == 0 &&
Attrs.UnrollAndJamCount == 0 && !Attrs.PipelineDisabled &&
Attrs.PipelineInitiationInterval == 0 &&
Attrs.VectorizePredicateEnable == LoopAttributes::Unspecified &&
Attrs.VectorizeEnable == LoopAttributes::Unspecified &&
Attrs.UnrollEnable == LoopAttributes::Unspecified &&
Expand Down Expand Up @@ -1030,6 +1041,14 @@ void LoopInfoStack::push(BasicBlock *Header, clang::ASTContext &Ctx,
->getSExtValue());
}

if (const auto *IntelFPGALoopControlAvg =
dyn_cast<SYCLIntelFPGALoopControlAvgAttr>(A)) {
setSYCLIntelFPGALoopControlAvgEnable();
setSYCLIntelFPGALoopControlAverage(IntelFPGALoopControlAvg->getNTripCount()
->getIntegerConstantExpr(Ctx)
->getSExtValue());
}

if (const auto *IntelFPGALoopCoalesce =
dyn_cast<SYCLIntelFPGALoopCoalesceAttr>(A)) {
if (auto *LCE = IntelFPGALoopCoalesce->getNExpr())
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/CodeGen/CGLoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ struct LoopAttributes {
/// Value for llvm.loop.max_concurrency.count metadata.
unsigned SYCLMaxConcurrencyNThreads;

/// Flag for llvm.loop.intel.loopcount_average metadata.
bool SYCLIntelFPGALoopControlAverageEnable;

/// Value for llvm.loop.intel.loopcount_average metadata.
unsigned SYCLIntelFPGALoopControlAverage;

/// Flag for llvm.loop.coalesce metadata.
bool SYCLLoopCoalesceEnable;

Expand Down Expand Up @@ -404,6 +410,17 @@ class LoopInfoStack {
StagedAttrs.SYCLSpeculatedIterationsNIterations = C;
}

/// Set flag of loop_control_avg for the next loop pushed.
void setSYCLIntelFPGALoopControlAvgEnable() {
StagedAttrs.SYCLIntelFPGALoopControlAverageEnable = true;
}

/// Set value of loop control average for the next loop pushed.
void setSYCLIntelFPGALoopControlAverage(unsigned C) {
StagedAttrs.SYCLIntelFPGALoopControlAverage = C;
}


/// Set the unroll count for the next loop pushed.
void setUnrollCount(unsigned C) { StagedAttrs.UnrollCount = C; }

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaStmtAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ static void CheckForIncompatibleSYCLLoopAttributes(
Attrs);
CheckForDuplicationSYCLLoopAttribute<SYCLIntelFPGASpeculatedIterationsAttr>(
S, Attrs);
CheckForDuplicationSYCLLoopAttribute<SYCLIntelFPGALoopControlAvgAttr>(S,
Attrs);
CheckForDuplicationSYCLLoopAttribute<LoopUnrollHintAttr>(S, Attrs, false);
CheckMutualExclusionSYCLLoopAttribute<SYCLIntelFPGADisableLoopPipeliningAttr,
SYCLIntelFPGAMaxInterleavingAttr>(
Expand Down Expand Up @@ -716,6 +718,8 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
case ParsedAttr::AT_SYCLIntelFPGASpeculatedIterations:
return handleIntelFPGALoopAttr<SYCLIntelFPGASpeculatedIterationsAttr>(S, St,
A);
case ParsedAttr::AT_SYCLIntelFPGALoopControlAvg:
return handleIntelFPGALoopAttr<SYCLIntelFPGALoopControlAvgAttr>(S, St, A);
case ParsedAttr::AT_OpenCLUnrollHint:
case ParsedAttr::AT_LoopUnrollHint:
return handleLoopUnrollHint(S, St, A, Range);
Expand Down
12 changes: 12 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,9 @@ namespace {
const SYCLIntelFPGASpeculatedIterationsAttr *
TransformSYCLIntelFPGASpeculatedIterationsAttr(
const SYCLIntelFPGASpeculatedIterationsAttr *SI);
const SYCLIntelFPGALoopControlAvgAttr *
TransformSYCLIntelFPGALoopControlAvgAttr(
const SYCLIntelFPGALoopControlAvgAttr *SI);

ExprResult TransformPredefinedExpr(PredefinedExpr *E);
ExprResult TransformDeclRefExpr(DeclRefExpr *E);
Expand Down Expand Up @@ -1618,6 +1621,15 @@ TemplateInstantiator::TransformSYCLIntelFPGASpeculatedIterationsAttr(
*SI, TransformedExpr);
}

const SYCLIntelFPGALoopControlAvgAttr *
TemplateInstantiator::TransformSYCLIntelFPGALoopControlAvgAttr(
const SYCLIntelFPGALoopControlAvgAttr *LCA) {
Expr *TransformedExpr =
getDerived().TransformExpr(LCA->getNTripCount()).get();
return getSema().BuildSYCLIntelFPGALoopAttr<SYCLIntelFPGALoopControlAvgAttr>(
*LCA, TransformedExpr);
}

const LoopUnrollHintAttr *TemplateInstantiator::TransformLoopUnrollHintAttr(
const LoopUnrollHintAttr *LU) {
Expr *TransformedExpr =
Expand Down
16 changes: 16 additions & 0 deletions clang/test/CodeGenSYCL/intel-fpga-loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// CHECK: br label %for.cond2, !llvm.loop ![[MD_MI_2:[0-9]+]]
// CHECK: br label %for.cond, !llvm.loop ![[MD_SI:[0-9]+]]
// CHECK: br label %for.cond2, !llvm.loop ![[MD_SI_2:[0-9]+]]
// CHECK: br label %for.cond, !llvm.loop ![[MD_LCA:[0-9]+]]
// CHECK: br label %for.cond2, !llvm.loop ![[MD_LCA_1:[0-9]+]]

void disable_loop_pipelining() {
int a[10];
Expand Down Expand Up @@ -109,6 +111,19 @@ void speculated_iterations() {
a[i] = 0;
}

template <int A>
void loop_control_avg() {
int a[10];
// CHECK: ![[MD_LCA]] = distinct !{![[MD_LCA]], ![[MP:[0-9]+]], ![[MD_lca:[0-9]+]]}
// CHECK-NEXT: ![[MD_lca]] = !{!"llvm.loop.intel.loopcount_average", i32 12}
[[intel::loop_control_avg(A)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// CHECK: ![[MD_LCA_1]] = distinct !{![[MD_LCA_1]], ![[MP:[0-9]+]], ![[MD_lca_1:[0-9]+]]}
// CHECK-NEXT: ![[MD_lca_1]] = !{!"llvm.loop.intel.loopcount_average", i32 4}
[[intel::loop_control_avg(4)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
}

template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
kernelFunc();
Expand All @@ -123,6 +138,7 @@ int main() {
loop_coalesce<2>();
max_interleaving<3>();
speculated_iterations<4>();
loop_control_avg<12>();
});
return 0;
}
45 changes: 44 additions & 1 deletion clang/test/SemaSYCL/intel-fpga-loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void foo() {
[[intel::speculated_iterations(6)]] int j[10];
// expected-error@+1 {{'nofusion' attribute cannot be applied to a declaration}}
[[intel::nofusion]] int k[10];
// expected-error@+1{{'loop_control_avg' attribute cannot be applied to a declaration}}
[[intel::loop_control_avg(6)]] int p[10];
}

// Test for deprecated spelling of Intel FPGA loop attributes
Expand Down Expand Up @@ -66,6 +68,11 @@ void foo_deprecated() {
// expected-note@+1 {{did you mean to use 'intel::speculated_iterations' instead?}}
[[intelfpga::speculated_iterations(6)]] for (int i = 0; i != 10; ++i)
a[i] = 0;

// expected-warning@+2 {{attribute 'intelfpga::loop_control_avg' is deprecated}}
// expected-note@+1 {{did you mean to use 'intel::loop_control_avg' instead?}}
[[intelfpga::loop_control_avg(6)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
Comment thread
smanna12 marked this conversation as resolved.
Outdated
}

// Test for incorrect number of arguments for Intel FPGA loop attributes
Expand Down Expand Up @@ -119,6 +126,9 @@ void boo() {
// expected-error@+1 {{'nofusion' attribute takes no arguments}}
[[intel::nofusion(0)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'loop_control_avg' attribute takes one argument}}
[[intel::loop_control_avg(3, 6)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
}

// Test for incorrect argument value for Intel FPGA loop attributes
Expand Down Expand Up @@ -196,6 +206,15 @@ void goo() {
// no diagnostics are expected
[[intel::nofusion]] for (int i = 0; i != 10; ++i)
a[i] = 0;

[[intel::loop_control_avg(0)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'loop_control_avg' attribute requires a non-negative integral compile time constant expression}}
[[intel::loop_control_avg(-1)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
// expected-error@+1 {{'loop_control_avg' attribute requires an integer constant}}
[[intel::loop_control_avg("abc")]] for (int i = 0; i != 10; ++i)
a[i] = 0;
}
Comment thread
smanna12 marked this conversation as resolved.

// Test for Intel FPGA loop attributes duplication
Expand Down Expand Up @@ -304,6 +323,11 @@ void zoo() {
// expected-error@+1 {{duplicate Intel FPGA loop attribute 'nofusion'}}
[[intel::nofusion]] for (int i = 0; i != 10; ++i)
a[i] = 0;

[[intel::loop_control_avg(2)]]
// expected-error@+1{{duplicate Intel FPGA loop attribute 'loop_control_avg'}}
[[intel::loop_control_avg(2)]] for (int i = 0; i != 10; ++i)
a[i] = 0;
Comment thread
smanna12 marked this conversation as resolved.
Outdated
}

// Test for Intel FPGA loop attributes compatibility
Expand Down Expand Up @@ -397,6 +421,22 @@ void max_concurrency_dependent() {
a[i] = 0;
}

template<int A, int B, int C>
void loop_control_avg_dependent() {
int a[10];

//expected-error@+1{{'loop_control_avg' attribute requires a non-negative integral compile time constant expression}}
[[intel::loop_control_avg(C)]]
for (int i = 0; i != 10; ++i)
a[i] = 0;

[[intel::loop_control_avg(A)]]
//expected-error@+1{{duplicate Intel FPGA loop attribute 'loop_control_avg'}}
[[intel::loop_control_avg(B)]] for (int i = 0; i != 10; ++i)
a[i] = 0;

}

Comment thread
smanna12 marked this conversation as resolved.
int main() {
deviceQueue.submit([&](sycl::handler &h) {
h.single_task<class kernel_function>([]() {
Expand All @@ -414,7 +454,10 @@ int main() {
//expected-note@-1 +{{in instantiation of function template specialization}}
max_concurrency_dependent<1, 4, -2>();
//expected-note@-1 +{{in instantiation of function template specialization}}
});

loop_control_avg_dependent<3, 2, -1>();
//expected-note@-1{{in instantiation of function template specialization 'loop_control_avg_dependent<3, 2, -1>' requested here}}
});
});

return 0;
Expand Down