Skip to content

Commit 46174fe

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents bb8d70b + e8f0b98 commit 46174fe

20 files changed

+367
-281
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ def SYCLIntelMaxWorkGroupSize : InheritableAttr {
12961296
def SYCLIntelMaxGlobalWorkDim : InheritableAttr {
12971297
let Spellings = [CXX11<"intelfpga","max_global_work_dim">,
12981298
CXX11<"intel","max_global_work_dim">];
1299-
let Args = [UnsignedArgument<"Number">];
1299+
let Args = [ExprArgument<"Value">];
13001300
let LangOpts = [SYCLIsDevice, SYCLIsHost];
13011301
let Subjects = SubjectList<[Function], ErrorDiag>;
13021302
let Documentation = [SYCLIntelMaxGlobalWorkDimAttrDocs];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11134,8 +11134,6 @@ def err_sycl_function_attribute_mismatch : Error<
1113411134
"SYCL kernel without %0 attribute can't call a function with this attribute">;
1113511135
def err_sycl_x_y_z_arguments_must_be_one : Error<
1113611136
"%0 X-, Y- and Z- sizes must be 1 when %1 attribute is used with value 0">;
11137-
def err_intel_attribute_argument_is_not_in_range: Error<
11138-
"The value of %0 attribute must be in range from 0 to 3">;
1113911137
def warn_boolean_attribute_argument_is_not_valid: Warning<
1114011138
"The value of %0 attribute should be 0 or 1. Adjusted to 1">,
1114111139
InGroup<AdjustedAttributes>;

clang/include/clang/Sema/Sema.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12963,10 +12963,25 @@ void Sema::addIntelSYCLSingleArgFunctionAttr(Decl *D,
1296312963
return;
1296412964
}
1296512965
int32_t ArgInt = ArgVal->getSExtValue();
12966-
if (ArgInt <= 0) {
12967-
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
12968-
<< CI.getAttrName() << /*positive*/ 0;
12969-
return;
12966+
if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelNumSimdWorkItems ||
12967+
CI.getParsedKind() == ParsedAttr::AT_IntelReqdSubGroupSize) {
12968+
if (ArgInt <= 0) {
12969+
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
12970+
<< CI.getAttrName() << /*positive*/ 0;
12971+
return;
12972+
}
12973+
}
12974+
if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) {
12975+
if (ArgInt < 0) {
12976+
Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
12977+
<< CI.getAttrName() << /*non-negative*/ 1;
12978+
return;
12979+
}
12980+
if (ArgInt > 3) {
12981+
Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range)
12982+
<< CI.getAttrName() << 0 << 3 << E->getSourceRange();
12983+
return;
12984+
}
1297012985
}
1297112986
}
1297212987

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,12 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
682682

683683
if (const SYCLIntelMaxGlobalWorkDimAttr *A =
684684
FD->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
685-
llvm::Metadata *AttrMDArgs[] = {
686-
llvm::ConstantAsMetadata::get(Builder.getInt32(A->getNumber()))};
685+
llvm::LLVMContext &Context = getLLVMContext();
686+
Optional<llvm::APSInt> ArgVal =
687+
A->getValue()->getIntegerConstantExpr(FD->getASTContext());
688+
assert(ArgVal.hasValue() && "Not an integer constant expression");
689+
llvm::Metadata *AttrMDArgs[] = {llvm::ConstantAsMetadata::get(
690+
Builder.getInt32(ArgVal->getSExtValue()))};
687691
Fn->setMetadata("max_global_work_dim",
688692
llvm::MDNode::get(Context, AttrMDArgs));
689693
}

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,10 +2925,13 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr,
29252925
return Result;
29262926
}
29272927

2928-
if (const auto *A = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>())
2929-
if (A->getNumber() == 0)
2928+
if (const auto *A = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
2929+
int64_t AttrValue =
2930+
A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue();
2931+
if (AttrValue == 0)
29302932
Result &= checkZeroDim(A, WGSize[0], WGSize[1], WGSize[2],
29312933
/*ReverseAttrs=*/true);
2934+
}
29322935

29332936
if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
29342937
if (!(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() &&
@@ -3087,34 +3090,23 @@ static void handleMaxGlobalWorkDimAttr(Sema &S, Decl *D,
30873090
if (D->isInvalidDecl())
30883091
return;
30893092

3090-
uint32_t MaxGlobalWorkDim;
3091-
const Expr *E = Attr.getArgAsExpr(0);
3092-
if (!checkUInt32Argument(S, Attr, E, MaxGlobalWorkDim, 0,
3093-
/*StrictlyUnsigned=*/true))
3094-
return;
3093+
Expr *E = Attr.getArgAsExpr(0);
30953094

3096-
if (MaxGlobalWorkDim > 3) {
3097-
S.Diag(Attr.getLoc(), diag::err_intel_attribute_argument_is_not_in_range)
3098-
<< Attr;
3095+
uint32_t WGSize[3] = {1, 1, 1};
3096+
if (!checkWorkGroupSizeValues(S, D, Attr, WGSize)) {
3097+
D->setInvalidDecl();
30993098
return;
31003099
}
31013100

3102-
if (MaxGlobalWorkDim == 0) {
3103-
uint32_t WGSize[3] = {1, 1, 1};
3104-
if (!checkWorkGroupSizeValues(S, D, Attr, WGSize)) {
3105-
D->setInvalidDecl();
3106-
return;
3107-
}
3108-
}
31093101
if (D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>())
31103102
S.Diag(Attr.getLoc(), diag::warn_duplicate_attribute) << Attr;
31113103

31123104
if (checkDeprecatedSYCLAttributeSpelling(S, Attr))
31133105
S.Diag(Attr.getLoc(), diag::note_spelling_suggestion)
31143106
<< "'intel::max_global_work_dim'";
31153107

3116-
D->addAttr(::new (S.Context) SYCLIntelMaxGlobalWorkDimAttr(
3117-
S.Context, Attr, MaxGlobalWorkDim));
3108+
S.addIntelSYCLSingleArgFunctionAttr<SYCLIntelMaxGlobalWorkDimAttr>(D, Attr,
3109+
E);
31183110
}
31193111

31203112
static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) {

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,6 +3013,7 @@ class SYCLKernelNameTypeVisitor
30133013

30143014
void VisitTemplateTemplateArgument(const TemplateArgument &TA) {
30153015
TemplateDecl *TD = TA.getAsTemplate().getAsTemplateDecl();
3016+
assert(TD && "template declaration must be available");
30163017
TemplateParameterList *TemplateParams = TD->getTemplateParameters();
30173018
for (NamedDecl *P : *TemplateParams) {
30183019
if (NonTypeTemplateParmDecl *TemplateParam =
@@ -3594,6 +3595,7 @@ class SYCLFwdDeclEmitter
35943595
// template class Foo specialized by class Baz<Bar>, not a template
35953596
// class template <template <typename> class> class T as it should.
35963597
TemplateDecl *TD = TA.getAsTemplate().getAsTemplateDecl();
3598+
assert(TD && "template declaration must be available");
35973599
TemplateParameterList *TemplateParams = TD->getTemplateParameters();
35983600
for (NamedDecl *P : *TemplateParams) {
35993601
// If template template parameter type has an enum value template

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,12 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
769769
*this, TemplateArgs, SYCLIntelSchedulerTargetFmaxMhz, New);
770770
continue;
771771
}
772+
if (const auto *SYCLIntelMaxGlobalWorkDim =
773+
dyn_cast<SYCLIntelMaxGlobalWorkDimAttr>(TmplAttr)) {
774+
instantiateIntelSYCLFunctionAttr<SYCLIntelMaxGlobalWorkDimAttr>(
775+
*this, TemplateArgs, SYCLIntelMaxGlobalWorkDim, New);
776+
continue;
777+
}
772778
// Existing DLL attribute on the instantiation takes precedence.
773779
if (TmplAttr->getKind() == attr::DLLExport ||
774780
TmplAttr->getKind() == attr::DLLImport) {
Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
2+
3+
#include "sycl.hpp"
4+
5+
using namespace cl::sycl;
6+
queue q;
27

38
class Foo {
49
public:
510
[[intel::max_global_work_dim(1)]] void operator()() const {}
611
};
712

8-
template <typename name, typename Func>
9-
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
10-
kernelFunc();
11-
}
13+
template <int SIZE>
14+
class Functor {
15+
public:
16+
[[intel::max_global_work_dim(SIZE)]] void operator()() const {}
17+
};
18+
19+
int main() {
20+
q.submit([&](handler &h) {
21+
Foo boo;
22+
h.single_task<class kernel_name1>(boo);
1223

13-
void bar() {
14-
Foo boo;
15-
kernel<class kernel_name1>(boo);
24+
h.single_task<class kernel_name2>(
25+
[]() [[intel::max_global_work_dim(2)]]{});
1626

17-
kernel<class kernel_name2>(
18-
[]() [[intel::max_global_work_dim(2)]]{});
27+
Functor<2> f;
28+
h.single_task<class kernel_name3>(f);
29+
});
30+
return 0;
1931
}
2032

21-
// CHECK: define spir_kernel void @{{.*}}kernel_name1() {{.*}} !max_global_work_dim ![[NUM1:[0-9]+]]
22-
// CHECK: define spir_kernel void @{{.*}}kernel_name2() {{.*}} !max_global_work_dim ![[NUM8:[0-9]+]]
33+
// CHECK: define spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !max_global_work_dim ![[NUM1:[0-9]+]]
34+
// CHECK: define spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !max_global_work_dim ![[NUM2:[0-9]+]]
35+
// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !max_global_work_dim ![[NUM2]]
2336
// CHECK: ![[NUM1]] = !{i32 1}
24-
// CHECK: ![[NUM8]] = !{i32 2}
37+
// CHECK: ![[NUM2]] = !{i32 2}
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
2+
3+
#include "sycl.hpp"
4+
5+
using namespace cl::sycl;
6+
queue q;
27

38
class Foo {
49
public:
@@ -11,25 +16,23 @@ class Functor {
1116
[[intel::num_simd_work_items(SIZE)]] void operator()() const {}
1217
};
1318

14-
template <typename name, typename Func>
15-
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
16-
kernelFunc();
17-
}
18-
19-
void bar() {
20-
Foo boo;
21-
kernel<class kernel_name1>(boo);
19+
int main() {
20+
q.submit([&](handler &h) {
21+
Foo boo;
22+
h.single_task<class kernel_name1>(boo);
2223

23-
kernel<class kernel_name2>(
24-
[]() [[intel::num_simd_work_items(42)]]{});
24+
h.single_task<class kernel_name2>(
25+
[]() [[intel::num_simd_work_items(42)]]{});
2526

26-
Functor<2> f;
27-
kernel<class kernel_name3>(f);
27+
Functor<2> f;
28+
h.single_task<class kernel_name3>(f);
29+
});
30+
return 0;
2831
}
2932

30-
// CHECK: define spir_kernel void @{{.*}}kernel_name1() {{.*}} !num_simd_work_items ![[NUM1:[0-9]+]]
31-
// CHECK: define spir_kernel void @{{.*}}kernel_name2() {{.*}} !num_simd_work_items ![[NUM42:[0-9]+]]
32-
// CHECK: define spir_kernel void @{{.*}}kernel_name3() {{.*}} !num_simd_work_items ![[NUM2:[0-9]+]]
33+
// CHECK: define spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !num_simd_work_items ![[NUM1:[0-9]+]]
34+
// CHECK: define spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !num_simd_work_items ![[NUM42:[0-9]+]]
35+
// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !num_simd_work_items ![[NUM2:[0-9]+]]
3336
// CHECK: ![[NUM1]] = !{i32 1}
3437
// CHECK: ![[NUM42]] = !{i32 42}
3538
// CHECK: ![[NUM2]] = !{i32 2}

clang/test/CodeGenSYCL/reqd-sub-group-size.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -disable-llvm-passes -triple spir64-unknown-unknown-sycldevice -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -disable-llvm-passes -triple spir64-unknown-unknown-sycldevice -emit-llvm -o - %s | FileCheck %s
2+
3+
#include "sycl.hpp"
4+
5+
using namespace cl::sycl;
6+
queue q;
27

38
class Functor16 {
49
public:
@@ -7,42 +12,40 @@ class Functor16 {
712

813
[[intel::reqd_sub_group_size(8)]] void foo() {}
914

10-
class Functor {
15+
class Functor8 {
1116
public:
1217
void operator()() const {
1318
foo();
1419
}
1520
};
1621

1722
template <int SIZE>
18-
class Functor5 {
23+
class Functor2 {
1924
public:
2025
[[intel::reqd_sub_group_size(SIZE)]] void operator()() const {}
2126
};
2227

23-
template <typename name, typename Func>
24-
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
25-
kernelFunc();
26-
}
27-
28-
void bar() {
29-
Functor16 f16;
30-
kernel<class kernel_name1>(f16);
28+
int main() {
29+
q.submit([&](handler &h) {
30+
Functor16 f16;
31+
h.single_task<class kernel_name1>(f16);
3132

32-
Functor f;
33-
kernel<class kernel_name2>(f);
33+
Functor8 f8;
34+
h.single_task<class kernel_name2>(f8);
3435

35-
kernel<class kernel_name3>(
36-
[]() [[intel::reqd_sub_group_size(4)]]{});
36+
h.single_task<class kernel_name3>(
37+
[]() [[intel::reqd_sub_group_size(4)]]{});
3738

38-
Functor5<2> f5;
39-
kernel<class kernel_name4>(f5);
39+
Functor2<2> f2;
40+
h.single_task<class kernel_name4>(f2);
41+
});
42+
return 0;
4043
}
4144

42-
// CHECK: define spir_kernel void @{{.*}}kernel_name1() {{.*}} !intel_reqd_sub_group_size ![[SGSIZE16:[0-9]+]]
43-
// CHECK: define spir_kernel void @{{.*}}kernel_name2() {{.*}} !intel_reqd_sub_group_size ![[SGSIZE8:[0-9]+]]
44-
// CHECK: define spir_kernel void @{{.*}}kernel_name3() {{.*}} !intel_reqd_sub_group_size ![[SGSIZE4:[0-9]+]]
45-
// CHECK: define spir_kernel void @{{.*}}kernel_name4() {{.*}} !intel_reqd_sub_group_size ![[SGSIZE2:[0-9]+]]
45+
// CHECK: define spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE16:[0-9]+]]
46+
// CHECK: define spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE8:[0-9]+]]
47+
// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE4:[0-9]+]]
48+
// CHECK: define spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !intel_reqd_sub_group_size ![[SGSIZE2:[0-9]+]]
4649
// CHECK: ![[SGSIZE16]] = !{i32 16}
4750
// CHECK: ![[SGSIZE8]] = !{i32 8}
4851
// CHECK: ![[SGSIZE4]] = !{i32 4}

0 commit comments

Comments
 (0)