Skip to content

Commit ac226ca

Browse files
committed
Merge remote-tracking branch 'origin/sycl' into private/asachkov/cleanup-old-spec-constants-support
2 parents f07b511 + 0624465 commit ac226ca

36 files changed

+624
-159
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sycl/plugins/unified_runtime/ @intel/dpcpp-l0-pi-reviewers
4444
sycl/plugins/esimd_emulator/ @intel/dpcpp-esimd-reviewers
4545

4646
# CUDA plugin
47-
sycl/plugins/cuda/ @intel/llvm-reviewers-cuda
47+
sycl/plugins/**/cuda/ @intel/llvm-reviewers-cuda
4848

4949
# XPTI instrumentation utilities
5050
xpti/ @intel/llvm-reviewers-runtime

.github/workflows/sycl_precommit.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,13 @@ jobs:
3737
# actions/checkout fails without "--privileged".
3838
options: -u 1001:1001 --privileged
3939
steps:
40-
- name: Fake actions/checkout task
41-
uses: actions/checkout@v3
40+
- uses: actions/checkout@v3
4241
with:
43-
# cached_checkout below uses actions/checkout internally. However, when
44-
# actions/checkout is run from within another action step (not from
45-
# workflow), github seems to try to download from within the container
46-
# and doesn't have requried filesystem permissions. Make sure it's
47-
# already downloaded by the time it's needed by checking out some small
48-
# repository.
49-
repository: actions/checkout
50-
path: fake-checkout
51-
- name: 'PR commits + 1'
52-
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
53-
- name: Setup action
54-
# We can switch to `cp -r /actions .` once changes in cached_checkout are
55-
# propagated into the nightly container image.
56-
run: |
57-
mkdir -p actions/cached_checkout
58-
wget raw.githubusercontent.com/intel/llvm/sycl/devops/actions/cached_checkout/action.yml -P ./actions/cached_checkout
59-
- uses: ./actions/cached_checkout
42+
sparse-checkout: |
43+
devops/actions/cached_checkout
44+
- name: 'PR commits + 2'
45+
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 2 ))" >> "${GITHUB_ENV}"
46+
- uses: ./devops/actions/cached_checkout
6047
with:
6148
path: src
6249
fetch-depth: ${{ env.PR_FETCH_DEPTH }}

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ def err_drv_expecting_fsycl_with_sycl_opt : Error<
360360
"'%0' must be used in conjunction with '-fsycl' to enable offloading">;
361361
def err_drv_fsycl_with_c_type : Error<
362362
"'%0' must not be used in conjunction with '-fsycl', which expects C++ source">;
363+
def err_drv_fsycl_with_pch : Error<
364+
"Precompiled header generation is not supported with '-fsycl'">;
363365
def err_drv_fsycl_unsupported_with_opt
364366
: Error<"'%0' is not supported with '-fsycl'">;
365367
def err_drv_sycl_missing_amdgpu_arch : Error<

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 83 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -51,65 +51,6 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD,
5151
StringRef suffix) {
5252
SmallString<256> TypeName;
5353
llvm::raw_svector_ostream OS(TypeName);
54-
// If RD is spirv_JointMatrixINTEL type, mangle differently.
55-
if (CGM.getTriple().isSPIRV() || CGM.getTriple().isSPIR()) {
56-
if (RD->getQualifiedNameAsString() == "__spv::__spirv_JointMatrixINTEL") {
57-
if (auto TemplateDecl = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
58-
ArrayRef<TemplateArgument> TemplateArgs =
59-
TemplateDecl->getTemplateArgs().asArray();
60-
OS << "spirv.JointMatrixINTEL.";
61-
for (auto &TemplateArg : TemplateArgs) {
62-
OS << "_";
63-
if (TemplateArg.getKind() == TemplateArgument::Type) {
64-
llvm::Type *TTy = ConvertType(TemplateArg.getAsType());
65-
if (TTy->isIntegerTy()) {
66-
switch (TTy->getIntegerBitWidth()) {
67-
case 8:
68-
OS << "char";
69-
break;
70-
case 16:
71-
OS << "short";
72-
break;
73-
case 32:
74-
OS << "int";
75-
break;
76-
case 64:
77-
OS << "long";
78-
break;
79-
default:
80-
OS << "i" << TTy->getIntegerBitWidth();
81-
break;
82-
}
83-
} else if (TTy->isHalfTy()) {
84-
OS << "half";
85-
} else if (TTy->isFloatTy()) {
86-
OS << "float";
87-
} else if (TTy->isDoubleTy()) {
88-
OS << "double";
89-
} else if (TTy->isBFloatTy()) {
90-
OS << "bfloat16";
91-
} else if (TTy->isStructTy()) {
92-
StringRef LlvmTyName = TTy->getStructName();
93-
// Emit half/bfloat16/tf32 for sycl[::*]::{half,bfloat16,tf32}
94-
if (LlvmTyName.startswith("class.sycl::") ||
95-
LlvmTyName.startswith("class.__sycl_internal::"))
96-
LlvmTyName = LlvmTyName.rsplit("::").second;
97-
if (LlvmTyName != "half" && LlvmTyName != "bfloat16" &&
98-
LlvmTyName != "tf32")
99-
llvm_unreachable("Wrong matrix base type!");
100-
OS << LlvmTyName;
101-
} else {
102-
llvm_unreachable("Wrong matrix base type!");
103-
}
104-
} else if (TemplateArg.getKind() == TemplateArgument::Integral) {
105-
OS << TemplateArg.getAsIntegral();
106-
}
107-
}
108-
Ty->setName(OS.str());
109-
return;
110-
}
111-
}
112-
}
11354
OS << RD->getKindName() << '.';
11455

11556
// FIXME: We probably want to make more tweaks to the printing policy. For
@@ -460,6 +401,77 @@ llvm::Type *CodeGenTypes::ConvertFunctionTypeInternal(QualType QFT) {
460401
return ResultType;
461402
}
462403

404+
template <bool NeedTypeInterpret = false>
405+
llvm::Type *getJointMatrixINTELExtType(llvm::Type *CompTy,
406+
ArrayRef<TemplateArgument> TemplateArgs,
407+
const unsigned Val = 0) {
408+
// TODO: we should actually have exactly 5 template parameters: 1 for
409+
// type and 4 for type parameters. But in previous version of the SPIR-V
410+
// spec we have Layout matrix type parameter, that was later removed.
411+
// Once we update to the newest version of the spec - this should be updated.
412+
assert((TemplateArgs.size() == 5 || TemplateArgs.size() == 6) &&
413+
"Wrong JointMatrixINTEL template parameters number");
414+
// This is required to represent optional 'Component Type Interpretation'
415+
// parameter
416+
std::vector<unsigned> Params;
417+
for (size_t I = 1; I != TemplateArgs.size(); ++I) {
418+
assert(TemplateArgs[I].getKind() == TemplateArgument::Integral &&
419+
"Wrong JointMatrixINTEL template parameter");
420+
Params.push_back(TemplateArgs[I].getAsIntegral().getExtValue());
421+
}
422+
// Don't add type interpretation for legacy matrices.
423+
// Legacy matrices has 5 template parameters, while new representation
424+
// has 6.
425+
if (NeedTypeInterpret && TemplateArgs.size() != 5)
426+
Params.push_back(Val);
427+
428+
return llvm::TargetExtType::get(CompTy->getContext(),
429+
"spirv.JointMatrixINTEL", {CompTy}, Params);
430+
}
431+
432+
/// ConvertSYCLJointMatrixINTELType - Convert SYCL joint_matrix type
433+
/// which is represented as a pointer to a structure to LLVM extension type
434+
/// with the parameters that follow SPIR-V JointMatrixINTEL type.
435+
/// The expected representation is:
436+
/// target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
437+
/// %use%, (optional) %element_type_interpretation%)
438+
llvm::Type *CodeGenTypes::ConvertSYCLJointMatrixINTELType(RecordDecl *RD) {
439+
auto *TemplateDecl = cast<ClassTemplateSpecializationDecl>(RD);
440+
ArrayRef<TemplateArgument> TemplateArgs =
441+
TemplateDecl->getTemplateArgs().asArray();
442+
assert(TemplateArgs[0].getKind() == TemplateArgument::Type &&
443+
"1st JointMatrixINTEL template parameter must be type");
444+
llvm::Type *CompTy = ConvertType(TemplateArgs[0].getAsType());
445+
446+
// Per JointMatrixINTEL spec the type can have an optional
447+
// 'Component Type Interpretation' parameter. We should emit it in case
448+
// if on SYCL level joint matrix accepts 'bfloat16' or 'tf32' objects as
449+
// matrix's components. Yet 'bfloat16' should be represented as 'int16' and
450+
// 'tf32' as 'float' types.
451+
if (CompTy->isStructTy()) {
452+
StringRef LlvmTyName = CompTy->getStructName();
453+
// Emit half/int16/float for sycl[::*]::{half,bfloat16,tf32}
454+
if (LlvmTyName.startswith("class.sycl::") ||
455+
LlvmTyName.startswith("class.__sycl_internal::"))
456+
LlvmTyName = LlvmTyName.rsplit("::").second;
457+
if (LlvmTyName == "half") {
458+
CompTy = llvm::Type::getHalfTy(getLLVMContext());
459+
return getJointMatrixINTELExtType(CompTy, TemplateArgs);
460+
} else if (LlvmTyName == "tf32") {
461+
CompTy = llvm::Type::getFloatTy(getLLVMContext());
462+
// 'tf32' interpretation is mapped to '0'
463+
return getJointMatrixINTELExtType<true>(CompTy, TemplateArgs, 0);
464+
} else if (LlvmTyName == "bfloat16") {
465+
CompTy = llvm::Type::getInt16Ty(getLLVMContext());
466+
// 'bfloat16' interpretation is mapped to '1'
467+
return getJointMatrixINTELExtType<true>(CompTy, TemplateArgs, 1);
468+
} else {
469+
llvm_unreachable("Wrong matrix base type!");
470+
}
471+
}
472+
return getJointMatrixINTELExtType(CompTy, TemplateArgs);
473+
}
474+
463475
/// ConvertType - Convert the specified type to its LLVM form.
464476
llvm::Type *CodeGenTypes::ConvertType(QualType T) {
465477
T = Context.getCanonicalType(T);
@@ -754,6 +766,18 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
754766
llvm::Type *PointeeType = ConvertTypeForMem(ETy);
755767
if (PointeeType->isVoidTy())
756768
PointeeType = llvm::Type::getInt8Ty(getLLVMContext());
769+
if (CGM.getTriple().isSPIRV() || CGM.getTriple().isSPIR()) {
770+
const Type *ClangETy = ETy.getTypePtrOrNull();
771+
if (ClangETy && ClangETy->isStructureOrClassType()) {
772+
RecordDecl *RD = ClangETy->getAsCXXRecordDecl();
773+
if (RD && RD->getQualifiedNameAsString() ==
774+
"__spv::__spirv_JointMatrixINTEL") {
775+
ResultType = ConvertSYCLJointMatrixINTELType(RD);
776+
break;
777+
}
778+
}
779+
}
780+
757781
unsigned AS = getTargetAddressSpace(ETy);
758782
ResultType = llvm::PointerType::get(PointeeType, AS);
759783
break;

clang/lib/CodeGen/CodeGenTypes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ class CodeGenTypes {
133133
/// memory representation is usually i8 or i32, depending on the target.
134134
llvm::Type *ConvertTypeForMem(QualType T, bool ForBitField = false);
135135

136+
/// ConvertSYCLJointMatrixINTELType - Convert SYCL joint_matrix type
137+
/// which is represented as a pointer to a structure to LLVM extension type
138+
/// with the parameters that follow SPIR-V JointMatrixINTEL type.
139+
/// The expected representation is:
140+
/// target("spirv.JointMatrixINTEL", %element_type, %rows%, %cols%, %scope%,
141+
/// %use%, (optional) %element_type_interpretation%)
142+
llvm::Type *ConvertSYCLJointMatrixINTELType(RecordDecl *RD);
143+
136144
/// GetFunctionType - Get the LLVM function type for \arg Info.
137145
llvm::FunctionType *GetFunctionType(const CGFunctionInfo &Info);
138146

clang/lib/Driver/Driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9252,6 +9252,11 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
92529252
}
92539253
}
92549254

9255+
// Emit an error if PCH(Pre-Compiled Header) file generation is forced in
9256+
// -fsycl mode.
9257+
if (C.getArgs().hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false) &&
9258+
JA.getType() == types::TY_PCH)
9259+
Diag(clang::diag::err_drv_fsycl_with_pch);
92559260
// As an annoying special case, PCH generation doesn't strip the pathname.
92569261
if (JA.getType() == types::TY_PCH && !IsCLMode()) {
92579262
llvm::sys::path::remove_filename(BasePath);

clang/test/CodeGenSYCL/matrix.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
#include <stdint.h>
66

77
namespace __spv {
8-
template <typename T, size_t R, size_t C, uint32_t U, uint32_t S>
8+
template <typename T, size_t R, size_t C, uint32_t L, uint32_t S, uint32_t U>
99
struct __spirv_JointMatrixINTEL;
1010
}
1111

12-
// CHECK: @_Z2f1{{.*}}(%spirv.JointMatrixINTEL._float_5_10_0_1
13-
void f1(__spv::__spirv_JointMatrixINTEL<float, 5, 10, 0, 1> *matrix) {}
12+
// CHECK: @_Z2f1{{.*}}(target("spirv.JointMatrixINTEL", float, 5, 10, 0, 1, 0)
13+
void f1(__spv::__spirv_JointMatrixINTEL<float, 5, 10, 0, 1, 0> *matrix) {}
1414

15-
// CHECK: @_Z2f2{{.*}}(%spirv.JointMatrixINTEL._long_10_2_0_0
16-
void f2(__spv::__spirv_JointMatrixINTEL<uint64_t, 10, 2, 0, 0> *matrix) {}
15+
// CHECK: @_Z2f2{{.*}}(target("spirv.JointMatrixINTEL", i64, 10, 2, 0, 0, 0)
16+
void f2(__spv::__spirv_JointMatrixINTEL<uint64_t, 10, 2, 0, 0, 0> *matrix) {}
1717

18-
// CHECK: @_Z2f3{{.*}}(%spirv.JointMatrixINTEL._char_10_2_0_0
19-
void f3(__spv::__spirv_JointMatrixINTEL<char, 10, 2, 0, 0> *matrix) {}
18+
// CHECK: @_Z2f3{{.*}}(target("spirv.JointMatrixINTEL", i8, 10, 2, 0, 0, 0)
19+
void f3(__spv::__spirv_JointMatrixINTEL<char, 10, 2, 0, 0, 0> *matrix) {}
2020

2121
namespace sycl {
2222
class half {};
@@ -25,17 +25,17 @@ namespace sycl {
2525
}
2626
typedef sycl::half my_half;
2727

28-
// CHECK: @_Z2f4{{.*}}(%spirv.JointMatrixINTEL._half_10_2_0_0
29-
void f4(__spv::__spirv_JointMatrixINTEL<my_half, 10, 2, 0, 0> *matrix) {}
28+
// CHECK: @_Z2f4{{.*}}(target("spirv.JointMatrixINTEL", half, 10, 2, 0, 0, 0)
29+
void f4(__spv::__spirv_JointMatrixINTEL<my_half, 10, 2, 0, 0, 0> *matrix) {}
3030

31-
// CHECK: @_Z2f5{{.*}}(%spirv.JointMatrixINTEL._bfloat16_10_2_0_0
32-
void f5(__spv::__spirv_JointMatrixINTEL<sycl::bfloat16, 10, 2, 0, 0> *matrix) {}
31+
// CHECK: @_Z2f5{{.*}}(target("spirv.JointMatrixINTEL", i16, 10, 2, 0, 0, 0, 1)
32+
void f5(__spv::__spirv_JointMatrixINTEL<sycl::bfloat16, 10, 2, 0, 0, 0> *matrix) {}
3333

34-
// CHECK: @_Z2f6{{.*}}(%spirv.JointMatrixINTEL._i128_10_2_0_0
35-
void f6(__spv::__spirv_JointMatrixINTEL<_BitInt(128), 10, 2, 0, 0> *matrix) {}
34+
// CHECK: @_Z2f6{{.*}}(target("spirv.JointMatrixINTEL", i128, 10, 2, 0, 0, 0)
35+
void f6(__spv::__spirv_JointMatrixINTEL<_BitInt(128), 10, 2, 0, 0, 0> *matrix) {}
3636

37-
// CHECK: @_Z2f7{{.*}}(%spirv.JointMatrixINTEL._tf32_10_2_0_0
38-
void f7(__spv::__spirv_JointMatrixINTEL<sycl::tf32, 10, 2, 0, 0> *matrix) {}
37+
// CHECK: @_Z2f7{{.*}}(target("spirv.JointMatrixINTEL", float, 10, 2, 0, 0, 0, 0)
38+
void f7(__spv::__spirv_JointMatrixINTEL<sycl::tf32, 10, 2, 0, 0, 0> *matrix) {}
3939

40-
// CHECK: @_Z2f8{{.*}}(%spirv.JointMatrixINTEL._double_5_10_0_1
41-
void f8(__spv::__spirv_JointMatrixINTEL<double, 5, 10, 0, 1> *matrix) {}
40+
// CHECK: @_Z2f8{{.*}}(target("spirv.JointMatrixINTEL", double, 5, 10, 0, 1, 0)
41+
void f8(__spv::__spirv_JointMatrixINTEL<double, 5, 10, 0, 1, 0> *matrix) {}

clang/test/Driver/pch-fsycl-error.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This test checks that an error is emitted when
2+
// PCH(Precompiled Header) file generation is forced in -fsycl mode.
3+
4+
// RUN: touch %t.h
5+
6+
// Linux
7+
// RUN: %clang -c -fsycl -x c++-header %t.h -### %s 2> %t1.txt
8+
// RUN: FileCheck %s -input-file=%t1.txt
9+
// CHECK: Precompiled header generation is not supported with '-fsycl'
10+
11+
// Windows
12+
// RUN: %clang_cl -c -fsycl -x c++-header %t.h -### -- %s 2>&1 \
13+
// RUN: | FileCheck -check-prefix=CHECK-ERROR %s
14+
// CHECK-ERROR: Precompiled header generation is not supported with '-fsycl'
15+
16+
// /Yc
17+
// RUN: %clang_cl -fsycl /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
18+
// RUN: | FileCheck -check-prefix=CHECK-YC %s
19+
// CHECK-YC: Precompiled header generation is not supported with '-fsycl'

devops/actions/clang-format/action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ runs:
1212
shell: bash {0}
1313
run: |
1414
git config --global --add safe.directory ${{ inputs.path }}
15-
git -C ${{ inputs.path }} clang-format ${{ github.event.pull_request.base.sha }}
15+
# TODO: Should we just drop fetch-depth in the cached checkout?
16+
base=$(git -C ${{ inputs.path }} merge-base ${{ github.event.pull_request.base.sha }} HEAD)
17+
echo "::group::Debug"
18+
echo "HEAD:"
19+
git -C ${{ inputs.path }} log -1 HEAD
20+
echo "Merge-base:"
21+
git -C ${{ inputs.path }} log -1 $base
22+
echo "::endgroup::"
23+
git -C ${{ inputs.path }} clang-format $base
1624
git -C ${{ inputs.path }} diff > ./clang-format.patch
1725
# Add patch with formatting fixes to CI job artifacts
1826
- uses: actions/upload-artifact@v1

0 commit comments

Comments
 (0)