Skip to content

Commit 575da1c

Browse files
author
JackAKirk
committed
Merge branch 'sycl' into bfloat16-joint-matrix
2 parents 9106ddc + 7baf152 commit 575da1c

File tree

80 files changed

+4726
-798
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4726
-798
lines changed

.github/workflows/sycl_linux_build_and_test.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,13 @@ jobs:
172172
outputs:
173173
lts: ${{ steps.work.outputs.lts }}
174174
steps:
175-
- name: Download scripts
175+
- name: Download scripts and configs
176176
run: |
177177
wget raw.githubusercontent.com/intel/llvm/${{ github.sha }}/devops/scripts/generate_test_matrix.js
178178
wget raw.githubusercontent.com/intel/llvm/${{ github.sha }}/devops/test_configs.json
179+
wget raw.githubusercontent.com/intel/llvm/sycl/devops/dependencies.json
180+
mv dependencies.json dependencies.sycl.json
181+
wget raw.githubusercontent.com/intel/llvm/${{ github.sha }}/devops/dependencies.json
179182
- id: work
180183
uses: actions/github-script@v6
181184
name: Generate matrix
@@ -196,6 +199,7 @@ jobs:
196199
include: ${{ fromJSON(needs.resolve_matrix.outputs.lts) }}
197200
name: ${{ matrix.name }}
198201
runs-on: ${{ matrix.runs-on }}
202+
env: ${{ matrix.env }}
199203
container:
200204
image: ${{ matrix.image }}
201205
options: ${{ matrix.container_options }}
@@ -208,6 +212,15 @@ jobs:
208212
- run: cp -r /actions .
209213
- name: Register cleanup after job is finished
210214
uses: ./actions/cleanup
215+
- name: Install drivers
216+
if: env.compute_runtime_tag != ''
217+
run: |
218+
if [ -e /opt/install_drivers.sh ]; then
219+
# TODO pack this script into container
220+
wget raw.githubusercontent.com/intel/llvm/${{ github.sha }}/devops/scripts/get_release.py
221+
sudo mv get_release.py /opt/
222+
sudo -E /opt/install_drivers.sh --all
223+
fi
211224
# FIXME cached_checkout fails here, but works everywhere else
212225
- uses: actions/checkout@v2
213226
with:

.github/workflows/sycl_nightly.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jobs:
1616
with:
1717
build_cache_root: "/__w/"
1818
build_artifact_suffix: default
19-
lts_config: "ocl_gen9;ocl_x64;hip_amdgpu"
19+
build_configure_extra_args: ''
20+
lts_config: "ocl_gen9;ocl_x64"
2021

2122
windows_default:
2223
name: Windows

clang/include/clang/Basic/Attr.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,16 @@ def SYCLAddIRAttributesGlobalVariable : InheritableAttr {
16891689
let Documentation = [SYCLAddIRAttributesGlobalVariableDocs];
16901690
}
16911691

1692+
def SYCLAddIRAnnotationsMember : InheritableAttr {
1693+
let Spellings = [CXX11<"__sycl_detail__", "add_ir_annotations_member">];
1694+
let Args = [VariadicExprArgument<"Args">];
1695+
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
1696+
let Subjects = SubjectList<[Field], ErrorDiag>;
1697+
let AcceptsExprPack = 1;
1698+
let AdditionalMembers = SYCLAddIRAttrCommonMembers.MemberCode;
1699+
let Documentation = [SYCLAddIRAnnotationsMemberDocs];
1700+
}
1701+
16921702
def C11NoReturn : InheritableAttr {
16931703
let Spellings = [Keyword<"_Noreturn">];
16941704
let Subjects = SubjectList<[Function], ErrorDiag>;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,6 +3611,85 @@ where the last N*2 are as described above.
36113611
}];
36123612
}
36133613

3614+
def SYCLAddIRAnnotationsMemberDocs : Documentation {
3615+
let Category = DocCatVariable;
3616+
let Heading = "add_ir_annotations_member";
3617+
let Content = [{
3618+
This attribute can be applied to a non-static field. Access to a field with this
3619+
attribute will generate a call to ``llvm.ptr.annotation`` with the arguments
3620+
paired.
3621+
The attribute must contain N*2 arguments. Each of the first N of these arguments
3622+
must be either string literals or ``constexpr const char *``. The following N
3623+
must be integer, floating point, character, boolean, ``const char *``, or an
3624+
enumeration as either a literal or ``constexpr`` value. The first N arguments
3625+
and the second N arguments are zipped into pairs when creating the call to
3626+
``llvm.ptr.annotation``, i.e. in the constant global variable pointed to by the
3627+
generated annotation intrinsic call, the N+1'th argument of the attribute will
3628+
occur after the first argument of the attribute, the N+2'th argument of the
3629+
attribute will occur after the second argument of the attribute, etc.
3630+
The generated call to ``llvm.ptr.annotation`` will have the following arguments
3631+
in this order:
3632+
3633+
* First argument is a pointer to the field.
3634+
* A pointer to a string literal in a constant global variable. This will
3635+
always be "sycl-properties".
3636+
* A pointer to a string literal in a constant global variable with the name of
3637+
the source file.
3638+
* The line number of the field declaration in the source file.
3639+
* A pointer to a constant global variable containing pointers to string
3640+
literals in constant global variables. These pointers to string literals
3641+
occur in pairs. If the second value of a pair was a ``nullptr`` or an empty
3642+
string then the pointer will be a null-pointer.
3643+
3644+
A pair will not be in the call to ``llvm.ptr.annotation`` if the first value of
3645+
the pair is an empty string.
3646+
3647+
.. code-block:: c++
3648+
3649+
struct Foo {
3650+
int *ptr
3651+
#ifdef __SYCL_DEVICE_ONLY__
3652+
[[__sycl_detail__::add_ir_annotations_member(
3653+
"Attr1", "Attr2", "Attribute value", 3.14)]]
3654+
#endif
3655+
;
3656+
};
3657+
// Accessing the 'ptr' field of 'Foo' will result in a call to
3658+
// 'llvm.ptr.annotation' with the second argument pointing to a constant
3659+
// global variable containing "sycl-properties" and the fifth argument
3660+
// pointing to a constant global variable with pointers to string literals
3661+
// "Attr1", "Attribute value", "Attr2", "3.14" in that order.
3662+
3663+
Optionally, the first argument of the attribute can be an initializer list
3664+
containing only string literals. This initializer list acts as a filter,
3665+
allowing only pairs with the first value in the initializer list to be
3666+
generated. If this intializer list is present, the attribute must have N*2+1
3667+
arguments, where the last N*2 are as described above.
3668+
3669+
.. code-block:: c++
3670+
3671+
struct Foo {
3672+
int *ptr
3673+
#ifdef __SYCL_DEVICE_ONLY__
3674+
[[__sycl_detail__::add_ir_annotations_member(
3675+
{"Attr2"}, "Attr1", "Attr2", "Attribute value", 3.14)]]
3676+
#endif
3677+
;
3678+
};
3679+
// Accessing the 'ptr' field of 'Foo' will result in a call to
3680+
// 'llvm.ptr.annotation' with the second argument pointing to a constant
3681+
// global variable containing "sycl-properties" and the fifth argument
3682+
// pointing to a constant global variable with pointers to string literals
3683+
// "Attr2", "3.14" in that order.
3684+
3685+
.. Note:: This attribute will only generate a call to ``llvm.ptr.annotation`` in
3686+
SYCL device code.
3687+
3688+
.. Note:: This attribute is intended as an internal implementation detail and is
3689+
not intended to be used by external users.
3690+
}];
3691+
}
3692+
36143693
def SYCLDeviceIndirectlyCallableDocs : Documentation {
36153694
let Category = DocCatFunction;
36163695
let Heading = "intel::device_indirectly_callable";

clang/include/clang/Sema/Sema.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10666,6 +10666,11 @@ class Sema final {
1066610666
void AddSYCLAddIRAttributesGlobalVariableAttr(Decl *D,
1066710667
const AttributeCommonInfo &CI,
1066810668
MutableArrayRef<Expr *> Args);
10669+
SYCLAddIRAnnotationsMemberAttr *
10670+
MergeSYCLAddIRAnnotationsMemberAttr(Decl *D,
10671+
const SYCLAddIRAnnotationsMemberAttr &A);
10672+
void AddSYCLAddIRAnnotationsMemberAttr(Decl *D, const AttributeCommonInfo &CI,
10673+
MutableArrayRef<Expr *> Args);
1066910674
void AddReqdWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI,
1067010675
Expr *XDim, Expr *YDim, Expr *ZDim);
1067110676
ReqdWorkGroupSizeAttr *

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4524,6 +4524,9 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
45244524

45254525
// Emit attribute annotation for a field.
45264526
if (getLangOpts().SYCLIsDevice) {
4527+
if (field->hasAttr<SYCLAddIRAnnotationsMemberAttr>())
4528+
addr = EmitFieldSYCLAnnotations(field, addr);
4529+
45274530
SmallString<256> AnnotStr;
45284531
CGM.generateIntelFPGAAnnotation(field, AnnotStr);
45294532
if (!AnnotStr.empty())

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,40 @@ Address CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,
27202720
return Address(V, Addr.getElementType(), Addr.getAlignment());
27212721
}
27222722

2723+
llvm::Value *CodeGenFunction::EmitSYCLAnnotationCall(
2724+
llvm::Function *AnnotationFn, llvm::Value *AnnotatedVal,
2725+
SourceLocation Location, const SYCLAddIRAnnotationsMemberAttr *Attr) {
2726+
SmallVector<llvm::Value *, 5> Args = {
2727+
AnnotatedVal,
2728+
Builder.CreateBitCast(CGM.EmitAnnotationString("sycl-properties"),
2729+
Int8PtrTy),
2730+
Builder.CreateBitCast(CGM.EmitAnnotationUnit(Location), Int8PtrTy),
2731+
CGM.EmitAnnotationLineNo(Location), CGM.EmitSYCLAnnotationArgs(Attr)};
2732+
return Builder.CreateCall(AnnotationFn, Args);
2733+
}
2734+
2735+
Address CodeGenFunction::EmitFieldSYCLAnnotations(const FieldDecl *D,
2736+
Address Addr) {
2737+
const auto *SYCLAnnotAttr = D->getAttr<SYCLAddIRAnnotationsMemberAttr>();
2738+
assert(SYCLAnnotAttr && "no add_ir_annotations_member attribute");
2739+
llvm::Value *V = Addr.getPointer();
2740+
llvm::Type *VTy = V->getType();
2741+
auto *PTy = dyn_cast<llvm::PointerType>(VTy);
2742+
unsigned AS = PTy ? PTy->getAddressSpace() : 0;
2743+
llvm::Type *IntrType = VTy;
2744+
if (!VTy->getPointerElementType()->isIntegerTy())
2745+
IntrType = llvm::PointerType::getWithSamePointeeType(CGM.Int8PtrTy, AS);
2746+
llvm::Function *F =
2747+
CGM.getIntrinsic(llvm::Intrinsic::ptr_annotation, IntrType);
2748+
2749+
if (VTy != IntrType)
2750+
V = Builder.CreateBitCast(V, IntrType);
2751+
V = EmitSYCLAnnotationCall(F, V, D->getLocation(), SYCLAnnotAttr);
2752+
if (VTy != IntrType)
2753+
V = Builder.CreateBitCast(V, VTy);
2754+
return Address(V, Addr.getElementType(), Addr.getAlignment());
2755+
}
2756+
27232757
Address CodeGenFunction::EmitIntelFPGAFieldAnnotations(const FieldDecl *D,
27242758
Address Addr,
27252759
StringRef AnnotStr) {

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4508,6 +4508,16 @@ class CodeGenFunction : public CodeGenTypeCache {
45084508
/// annotation result.
45094509
Address EmitFieldAnnotations(const FieldDecl *D, Address V);
45104510

4511+
/// Emit a "sycl-properties" annotation call (intrinsic).
4512+
llvm::Value *
4513+
EmitSYCLAnnotationCall(llvm::Function *AnnotationFn,
4514+
llvm::Value *AnnotatedVal, SourceLocation Location,
4515+
const SYCLAddIRAnnotationsMemberAttr *Attr);
4516+
4517+
/// Emit sycl field annotations for given field & value. Returns the
4518+
/// annotation result.
4519+
Address EmitFieldSYCLAnnotations(const FieldDecl *D, Address V);
4520+
45114521
/// Emit Intel FPGA field annotations for the given field and value. Returns
45124522
/// the annotation result.
45134523
Address EmitIntelFPGAFieldAnnotations(const FieldDecl *D, Address V,

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,6 +2873,55 @@ void CodeGenModule::AddGlobalAnnotations(const ValueDecl *D,
28732873
Annotations.push_back(EmitAnnotateAttr(GV, I, D->getLocation()));
28742874
}
28752875

2876+
llvm::Constant *CodeGenModule::EmitSYCLAnnotationArgs(
2877+
const SYCLAddIRAnnotationsMemberAttr *Attr) {
2878+
llvm::SmallVector<std::pair<std::string, std::string>, 4>
2879+
AnnotationNameValPairs =
2880+
Attr->getFilteredAttributeNameValuePairs(getContext());
2881+
if (AnnotationNameValPairs.empty())
2882+
return llvm::ConstantPointerNull::get(GlobalsInt8PtrTy);
2883+
2884+
// For each name-value pair of the SYCL annotation attribute, create an
2885+
// annotation string for it. This will be the annotation arguments. If the
2886+
// value is the empty string, use a null-pointer instead.
2887+
llvm::SmallVector<llvm::Constant *, 4> LLVMArgs;
2888+
llvm::FoldingSetNodeID ID;
2889+
LLVMArgs.reserve(AnnotationNameValPairs.size() * 2);
2890+
for (const std::pair<std::string, std::string> &NVP :
2891+
AnnotationNameValPairs) {
2892+
llvm::Constant *NameStrC = EmitAnnotationString(NVP.first);
2893+
llvm::Constant *ValueStrC =
2894+
NVP.second == "" ? llvm::ConstantPointerNull::get(GlobalsInt8PtrTy)
2895+
: EmitAnnotationString(NVP.second);
2896+
LLVMArgs.push_back(NameStrC);
2897+
LLVMArgs.push_back(ValueStrC);
2898+
ID.Add(NameStrC);
2899+
ID.Add(ValueStrC);
2900+
}
2901+
2902+
// If another SYCL annotation had the same arguments we can reuse the
2903+
// annotation value it created.
2904+
llvm::Constant *&LookupRef = SYCLAnnotationArgs[ID.ComputeHash()];
2905+
if (LookupRef)
2906+
return LookupRef;
2907+
2908+
// Create an anonymous struct global variable pointing to the annotation
2909+
// arguments in the order they were added above. This is the final constant
2910+
// used as the annotation value.
2911+
auto *Struct = llvm::ConstantStruct::getAnon(LLVMArgs);
2912+
auto *GV = new llvm::GlobalVariable(getModule(), Struct->getType(), true,
2913+
llvm::GlobalValue::PrivateLinkage, Struct,
2914+
".args");
2915+
GV->setSection(AnnotationSection);
2916+
GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2917+
auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, GlobalsInt8PtrTy);
2918+
2919+
// Set the look-up reference to the final annotation value for future
2920+
// annotations to reuse.
2921+
LookupRef = Bitcasted;
2922+
return Bitcasted;
2923+
}
2924+
28762925
void CodeGenModule::AddGlobalSYCLIRAttributes(llvm::GlobalVariable *GV,
28772926
const RecordDecl *RD) {
28782927
const auto *A = RD->getAttr<SYCLAddIRAttributesGlobalVariableAttr>();

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ class CodeGenModule : public CodeGenTypeCache {
410410
/// Used for uniquing of annotation arguments.
411411
llvm::DenseMap<unsigned, llvm::Constant *> AnnotationArgs;
412412

413+
/// Used for uniquing of SYCL annotation arguments. SYCL annotations are
414+
/// handled differently than regular annotations so they cannot share map.
415+
llvm::DenseMap<unsigned, llvm::Constant *> SYCLAnnotationArgs;
416+
413417
llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
414418

415419
llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
@@ -1310,6 +1314,10 @@ class CodeGenModule : public CodeGenTypeCache {
13101314
/// annotations are emitted during finalization of the LLVM code.
13111315
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
13121316

1317+
/// Emit additional args of the annotation.
1318+
llvm::Constant *
1319+
EmitSYCLAnnotationArgs(const SYCLAddIRAnnotationsMemberAttr *Attr);
1320+
13131321
/// Add attributes from add_ir_attributes_global_variable on TND to GV.
13141322
void AddGlobalSYCLIRAttributes(llvm::GlobalVariable *GV,
13151323
const RecordDecl *RD);

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,6 +2816,8 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
28162816
else if (const auto *A =
28172817
dyn_cast<SYCLAddIRAttributesGlobalVariableAttr>(Attr))
28182818
NewAttr = S.MergeSYCLAddIRAttributesGlobalVariableAttr(D, *A);
2819+
else if (const auto *A = dyn_cast<SYCLAddIRAnnotationsMemberAttr>(Attr))
2820+
NewAttr = S.MergeSYCLAddIRAnnotationsMemberAttr(D, *A);
28192821
else if (const auto *A = dyn_cast<ReqdWorkGroupSizeAttr>(Attr))
28202822
NewAttr = S.MergeReqdWorkGroupSizeAttr(D, *A);
28212823
else if (Attr->shouldInheritEvenIfAlreadyPresent() || !DeclHasAttr(D, Attr))

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7911,6 +7911,38 @@ static void handleSYCLAddIRAttributesGlobalVariableAttr(Sema &S, Decl *D,
79117911
S.AddSYCLAddIRAttributesGlobalVariableAttr(D, A, Args);
79127912
}
79137913

7914+
SYCLAddIRAnnotationsMemberAttr *Sema::MergeSYCLAddIRAnnotationsMemberAttr(
7915+
Decl *D, const SYCLAddIRAnnotationsMemberAttr &A) {
7916+
if (const auto *ExistingAttr = D->getAttr<SYCLAddIRAnnotationsMemberAttr>()) {
7917+
checkSYCLAddIRAttributesMergeability(A, *ExistingAttr, *this);
7918+
return nullptr;
7919+
}
7920+
return A.clone(Context);
7921+
}
7922+
7923+
void Sema::AddSYCLAddIRAnnotationsMemberAttr(Decl *D,
7924+
const AttributeCommonInfo &CI,
7925+
MutableArrayRef<Expr *> Args) {
7926+
auto *Attr = SYCLAddIRAnnotationsMemberAttr::Create(Context, Args.data(),
7927+
Args.size(), CI);
7928+
if (evaluateAddIRAttributesArgs(Attr->args_begin(), Attr->args_size(), *this,
7929+
CI))
7930+
return;
7931+
D->addAttr(Attr);
7932+
}
7933+
7934+
static void handleSYCLAddIRAnnotationsMemberAttr(Sema &S, Decl *D,
7935+
const ParsedAttr &A) {
7936+
llvm::SmallVector<Expr *, 4> Args;
7937+
Args.reserve(A.getNumArgs());
7938+
for (unsigned I = 0; I < A.getNumArgs(); I++) {
7939+
assert(A.getArgAsExpr(I));
7940+
Args.push_back(A.getArgAsExpr(I));
7941+
}
7942+
7943+
S.AddSYCLAddIRAnnotationsMemberAttr(D, A, Args);
7944+
}
7945+
79147946
namespace {
79157947
struct IntrinToName {
79167948
uint32_t Id;
@@ -11389,6 +11421,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
1138911421
case ParsedAttr::AT_SYCLAddIRAttributesGlobalVariable:
1139011422
handleSYCLAddIRAttributesGlobalVariableAttr(S, D, AL);
1139111423
break;
11424+
case ParsedAttr::AT_SYCLAddIRAnnotationsMember:
11425+
handleSYCLAddIRAnnotationsMemberAttr(S, D, AL);
11426+
break;
1139211427

1139311428
// Swift attributes.
1139411429
case ParsedAttr::AT_SwiftAsyncName:

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,15 +2122,18 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
21222122

21232123
bool handlePointerType(FieldDecl *FD, QualType FieldTy) final {
21242124
// USM allows to use raw pointers instead of buffers/accessors, but these
2125-
// pointers point to the specially allocated memory. For pointer fields we
2126-
// add a kernel argument with the same type as field but global address
2127-
// space, because OpenCL requires it.
2125+
// pointers point to the specially allocated memory. For pointer fields,
2126+
// except for function pointer fields, we add a kernel argument with the
2127+
// same type as field but global address space, because OpenCL requires it.
2128+
// Function pointers should have program address space. This is set in
2129+
// CodeGen.
21282130
QualType PointeeTy = FieldTy->getPointeeType();
21292131
Qualifiers Quals = PointeeTy.getQualifiers();
21302132
auto AS = Quals.getAddressSpace();
21312133
// Leave global_device and global_host address spaces as is to help FPGA
21322134
// device in memory allocations
2133-
if (AS != LangAS::sycl_global_device && AS != LangAS::sycl_global_host)
2135+
if (!PointeeTy->isFunctionType() && AS != LangAS::sycl_global_device &&
2136+
AS != LangAS::sycl_global_host)
21342137
Quals.setAddressSpace(LangAS::sycl_global);
21352138
PointeeTy = SemaRef.getASTContext().getQualifiedType(
21362139
PointeeTy.getUnqualifiedType(), Quals);

0 commit comments

Comments
 (0)