Skip to content

Commit c5d18d7

Browse files
committed
Complete draft patch and add a test
1 parent 9aa340d commit c5d18d7

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class AttributeCommonInfo {
162162
(ParsedAttr == AT_ReqdWorkGroupSize && isCXX11Attribute()) ||
163163
(ParsedAttr == AT_IntelReqdSubGroupSize && isCXX11Attribute()) ||
164164
ParsedAttr == AT_SYCLIntelNumSimdWorkItems ||
165+
ParsedAttr == AT_SYCLIntelSchedulerTargetFmaxMhz ||
165166
ParsedAttr == AT_SYCLIntelMaxWorkGroupSize ||
166167
ParsedAttr == AT_SYCLIntelMaxGlobalWorkDim ||
167168
ParsedAttr == AT_SYCLIntelNoGlobalWorkOffset)

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,6 +3005,30 @@ static void handleNumSimdWorkItemsAttr(Sema &S, Decl *D,
30053005
S.addIntelSYCLSingleArgFunctionAttr<SYCLIntelNumSimdWorkItemsAttr>(D, Attr,
30063006
E);
30073007
}
3008+
// Handles scheduler_target_fmax_mhz
3009+
static void handleSchedulerTargetFmaxMhzAttr(Sema &S, Decl *D,
3010+
const ParsedAttr &Attr) {
3011+
if (D->isInvalidDecl())
3012+
return;
3013+
3014+
uint32_t TargetFmaxMhz = 0;
3015+
const Expr *E = Attr.getArgAsExpr(0);
3016+
if (!checkUInt32Argument(S, Attr, E, TargetFmaxMhz, 0,
3017+
/*StrictlyUnsigned=*/true))
3018+
return;
3019+
3020+
if (TargetFmaxMhz == 0) {
3021+
S.Diag(Attr.getLoc(), diag::err_attribute_argument_is_zero)
3022+
<< Attr << E->getSourceRange();
3023+
return;
3024+
}
3025+
3026+
if (D->getAttr<SYCLIntelSchedulerTargetFmaxMhzAttr>())
3027+
S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute) << Attr;
3028+
3029+
D->addAttr(::new (S.Context) SYCLIntelSchedulerTargetFmaxMhzAttr(
3030+
S.Context, Attr, TargetFmaxMhz));
3031+
}
30083032

30093033
// Handles max_global_work_dim.
30103034
static void handleMaxGlobalWorkDimAttr(Sema &S, Decl *D,
@@ -7893,6 +7917,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
78937917
case ParsedAttr::AT_SYCLIntelNumSimdWorkItems:
78947918
handleNumSimdWorkItemsAttr(S, D, AL);
78957919
break;
7920+
case ParsedAttr::AT_SYCLIntelSchedulerTargetFmaxMhz:
7921+
handleSchedulerTargetFmaxMhzAttr(S, D, AL);
7922+
break;
78967923
case ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim:
78977924
handleMaxGlobalWorkDimAttr(S, D, AL);
78987925
break;

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
531531
if (auto *A = FD->getAttr<SYCLIntelNumSimdWorkItemsAttr>())
532532
Attrs.insert(A);
533533

534+
if (auto *A = FD->getAttr<SYCLIntelSchedulerTargetFmaxMhzAttr>())
535+
Attrs.insert(A);
536+
534537
if (auto *A = FD->getAttr<SYCLIntelMaxWorkGroupSizeAttr>())
535538
Attrs.insert(A);
536539

@@ -3166,6 +3169,7 @@ void Sema::MarkDevice(void) {
31663169
}
31673170
case attr::Kind::SYCLIntelKernelArgsRestrict:
31683171
case attr::Kind::SYCLIntelNumSimdWorkItems:
3172+
case attr::Kind::SYCLIntelSchedulerTargetFmaxMhz:
31693173
case attr::Kind::SYCLIntelMaxGlobalWorkDim:
31703174
case attr::Kind::SYCLIntelNoGlobalWorkOffset:
31713175
case attr::Kind::SYCLSimd: {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -triple spir64 -Wno-sycl-2017-compat -verify
2+
// RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -triple spir64 -DTRIGGER_ERROR -Wno-sycl-2017-compat -verify
3+
// RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -triple spir64 -Wno-sycl-2017-compat | FileCheck %s
4+
5+
#include "Inputs/sycl.hpp"
6+
#ifndef TRIGGER_ERROR
7+
[[intelfpga::scheduler_target_fmax_mhz(2)]] // expected-no-diagnostics
8+
void
9+
func() {}
10+
#endif // TRIGGER_ERROR
11+
12+
int main() {
13+
#ifndef TRIGGER_ERROR
14+
// CHECK-LABEL: -FunctionDecl {{.*}}test_kernel1 'void ()'
15+
// CHECK: SYCLIntelSchedulerTargetFmaxMhzAttr {{.*}} 5
16+
cl::sycl::kernel_single_task<class test_kernel1>(
17+
[]() [[intelfpga::scheduler_target_fmax_mhz(5)]]{});
18+
19+
// CHECK-LABEL: `-FunctionDecl {{.*}}test_kernel2 'void ()'
20+
// CHECK: -SYCLIntelSchedulerTargetFmaxMhzAttr {{.*}} 2
21+
cl::sycl::kernel_single_task<class test_kernel2>(
22+
[]() { func(); });
23+
24+
#else
25+
[[intelfpga::scheduler_target_fmax_mhz(0)]] int Var = 0; // expected-error{{'scheduler_target_fmax_mhz' attribute only applies to functions}}
26+
27+
cl::sycl::kernel_single_task<class test_kernel3>(
28+
[]() [[intelfpga::scheduler_target_fmax_mhz(0)]]{}); // expected-error{{'scheduler_target_fmax_mhz' attribute must be greater than 0}}
29+
30+
cl::sycl::kernel_single_task<class test_kernel4>(
31+
[]() [[intelfpga::scheduler_target_fmax_mhz(-4)]]{}); // expected-error{{'scheduler_target_fmax_mhz' attribute requires a non-negative integral compile time constant expression}}
32+
33+
cl::sycl::kernel_single_task<class test_kernel5>(
34+
[]() [[intelfpga::scheduler_target_fmax_mhz(1), intelfpga::scheduler_target_fmax_mhz(2)]]{}); // expected-warning{{attribute 'scheduler_target_fmax_mhz' is already applied with different parameters}}
35+
#endif // TRIGGER_ERROR
36+
}

0 commit comments

Comments
 (0)