Skip to content

Commit 010e59b

Browse files
committed
Merge remote-tracking branch 'upstream/sycl' into sycl
2 parents 37c66e4 + 6957cdf commit 010e59b

File tree

183 files changed

+2729
-1448
lines changed

Some content is hidden

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

183 files changed

+2729
-1448
lines changed

.github/workflows/gh_pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Install deps
1616
run: |
1717
sudo apt-get install -y doxygen graphviz ssh ninja-build
18-
sudo pip3 install sphinx recommonmark sphinx_markdown_tables
18+
sudo pip3 install 'sphinx==3.0.0' 'recommonmark==0.6.0' 'sphinx_markdown_tables==0.0.12'
1919
- name: Build Docs
2020
run: |
2121
mkdir -p $GITHUB_WORKSPACE/build

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Home for Intel LLVM-based projects:
77
- oneAPI Data Parallel C++ compiler - see **sycl** branch. More information on
88
oneAPI and DPC++ is available at
99
([https://www.oneapi.com/](https://www.oneapi.com/))
10+
- [![Linux Post Commit Checks](https://github.com/intel/llvm/workflows/Linux%20Post%20Commit%20Checks/badge.svg)](https://github.com/intel/llvm/actions?query=workflow%3A%22Linux+Post+Commit+Checks%22) [![Generate Doxygen documentation](https://github.com/intel/llvm/workflows/Generate%20Doxygen%20documentation/badge.svg)](https://github.com/intel/llvm/actions?query=workflow%3A%22Generate+Doxygen+documentation%22)
11+
12+
1013

1114
## License
1215
See [LICENSE.txt](sycl/LICENSE.TXT) for details.

buildbot/check.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11
import argparse
22
import os
3+
import multiprocessing
34
import subprocess
45
import sys
56

67
DEFAULT_CPU_COUNT = 4
78

89
def do_check(args):
9-
ret = False
10-
11-
cpu_count = os.cpu_count()
12-
if cpu_count is None:
10+
try:
11+
cpu_count = multiprocessing.cpu_count()
12+
except NotImplementedError:
1313
cpu_count = DEFAULT_CPU_COUNT
1414

15+
# Get absolute path to source directory
16+
if args.src_dir:
17+
abs_src_dir = os.path.abspath(args.src_dir)
18+
else:
19+
abs_src_dir = os.path.abspath(os.path.join(__file__, "../.."))
20+
# Get absolute path to build directory
21+
if args.obj_dir:
22+
abs_obj_dir = os.path.abspath(args.obj_dir)
23+
else:
24+
abs_obj_dir = os.path.join(abs_src_dir, "build")
25+
26+
cmake_cmd = [
27+
"cmake",
28+
"--build", abs_obj_dir,
29+
"--",
30+
args.test_suite,
31+
"-j", str(cpu_count)]
32+
33+
print(cmake_cmd)
34+
1535
env_tmp=os.environ
1636
env_tmp["LIT_ARGS"]="\"{}\"".format("-v")
1737

18-
make_cmd = ["ninja", args.test_suite, "-j", str(cpu_count)]
19-
print(make_cmd)
20-
21-
subprocess.check_call(make_cmd, cwd=args.obj_dir, env=env_tmp)
38+
subprocess.check_call(cmake_cmd, cwd=abs_obj_dir, env=env_tmp)
2239

2340
ret = True
2441
return ret
@@ -34,8 +51,8 @@ def main():
3451
parser.add_argument("-w", "--builder-dir", metavar="BUILDER_DIR",
3552
help="builder directory, which is the directory contains source and build directories")
3653
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", help="source directory")
37-
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", required=True, help="build directory")
38-
parser.add_argument("-t", "--test-suite", metavar="TEST_SUITE", required=True, help="check-xxx target")
54+
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", help="build directory")
55+
parser.add_argument("-t", "--test-suite", metavar="TEST_SUITE", default="check-all", help="check-xxx target")
3956

4057
args = parser.parse_args()
4158

@@ -47,4 +64,3 @@ def main():
4764
ret = main()
4865
exit_code = 0 if ret else 1
4966
sys.exit(exit_code)
50-

buildbot/compile.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import multiprocessing
33
import subprocess
44
import sys
5+
import os
56

67
DEFAULT_CPU_COUNT = 4
78

@@ -12,10 +13,28 @@ def do_compile(args):
1213
except NotImplementedError:
1314
cpu_count = DEFAULT_CPU_COUNT
1415

15-
make_cmd = ["ninja", "-j", str(cpu_count), "deploy-sycl-toolchain", "deploy-opencl-aot"]
16-
print(make_cmd)
16+
# Get absolute path to source directory
17+
if args.src_dir:
18+
abs_src_dir = os.path.abspath(args.src_dir)
19+
else:
20+
abs_src_dir = os.path.abspath(os.path.join(__file__, "../.."))
21+
# Get absolute path to build directory
22+
if args.obj_dir:
23+
abs_obj_dir = os.path.abspath(args.obj_dir)
24+
else:
25+
abs_obj_dir = os.path.join(abs_src_dir, "build")
1726

18-
subprocess.check_call(make_cmd, cwd=args.obj_dir)
27+
cmake_cmd = [
28+
"cmake",
29+
"--build", abs_obj_dir,
30+
"--",
31+
"deploy-sycl-toolchain",
32+
"deploy-opencl-aot",
33+
"-j", str(cpu_count)]
34+
35+
print(cmake_cmd)
36+
37+
subprocess.check_call(cmake_cmd, cwd=abs_obj_dir)
1938

2039
return True
2140

@@ -31,7 +50,7 @@ def main():
3150
parser.add_argument("-w", "--builder-dir", metavar="BUILDER_DIR",
3251
help="builder directory, which is the directory contains source and build directories")
3352
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", help="source directory")
34-
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", required=True, help="build directory")
53+
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", help="build directory")
3554

3655
args = parser.parse_args()
3756

@@ -44,4 +63,3 @@ def main():
4463
ret = main()
4564
exit_code = 0 if ret else 1
4665
sys.exit(exit_code)
47-

buildbot/configure.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
import sys
55
import platform
66

7-
# TODO:
8-
# 1. Make all required options optional
9-
# 2. Create obj_dir from the script if it doesn't exist
10-
117
def do_configure(args):
128
ret = False
139

14-
# Get absolute paths
15-
abs_src_dir = os.path.abspath(args.src_dir)
16-
abs_obj_dir = os.path.abspath(args.obj_dir)
10+
# Get absolute path to source directory
11+
if args.src_dir:
12+
abs_src_dir = os.path.abspath(args.src_dir)
13+
else:
14+
abs_src_dir = os.path.abspath(os.path.join(__file__, "../.."))
15+
# Get absolute path to build directory
16+
if args.obj_dir:
17+
abs_obj_dir = os.path.abspath(args.obj_dir)
18+
else:
19+
abs_obj_dir = os.path.join(abs_src_dir, "build")
20+
if not os.path.isdir(abs_obj_dir):
21+
os.makedirs(abs_obj_dir)
1722

1823
llvm_dir = os.path.join(abs_src_dir, "llvm")
1924
sycl_dir = os.path.join(abs_src_dir, "sycl")
@@ -60,7 +65,7 @@ def do_configure(args):
6065

6166
cmake_cmd = [
6267
"cmake",
63-
"-G", "Ninja",
68+
"-G", args.cmake_gen,
6469
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
6570
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
6671
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
@@ -117,17 +122,18 @@ def main():
117122
parser.add_argument("-r", "--pr-number", metavar="PR_NUM", help="pull request number")
118123
parser.add_argument("-w", "--builder-dir", metavar="BUILDER_DIR",
119124
help="builder directory, which is the directory contains source and build directories")
120-
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", required=True, help="source directory")
121-
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", required=True, help="build directory")
125+
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", help="source directory (autodetected by default)")
126+
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", help="build directory. (<src>/build by default)")
122127
parser.add_argument("-t", "--build-type",
123-
metavar="BUILD_TYPE", required=True, help="build type, debug or release")
128+
metavar="BUILD_TYPE", default="Release", help="build type: Debug, Release")
124129
parser.add_argument("--cuda", action='store_true', help="switch from OpenCL to CUDA")
125130
parser.add_argument("--no-assertions", action='store_true', help="build without assertions")
126131
parser.add_argument("--docs", action='store_true', help="build Doxygen documentation")
127132
parser.add_argument("--system-ocl", action='store_true', help="use OpenCL deps from system (no download)")
128133
parser.add_argument("--no-werror", action='store_true', help="Don't treat warnings as errors")
129134
parser.add_argument("--shared-libs", action='store_true', help="Build shared libraries")
130135
parser.add_argument("--cmake-opt", action='append', help="Additional CMake option not configured via script parameters")
136+
parser.add_argument("--cmake-gen", default="Ninja", help="CMake generator")
131137

132138
args = parser.parse_args()
133139

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12455,6 +12455,7 @@ class Sema final {
1245512455
};
1245612456

1245712457
bool isKnownGoodSYCLDecl(const Decl *D);
12458+
void checkSYCLDeviceVarDecl(VarDecl *Var);
1245812459
void ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc, MangleContext &MC);
1245912460
void MarkDevice();
1246012461

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,9 +1217,9 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
12171217
if (JA.isOffloading(Action::OFK_Cuda))
12181218
getToolChain().AddCudaIncludeArgs(Args, CmdArgs);
12191219

1220-
if (Args.hasArg(options::OPT_fsycl_device_only)) {
1220+
if (JA.isOffloading(Action::OFK_SYCL) ||
1221+
Args.hasArg(options::OPT_fsycl_device_only))
12211222
toolchains::SYCLToolChain::AddSYCLIncludeArgs(D, Args, CmdArgs);
1222-
}
12231223

12241224
// If we are offloading to a target via OpenMP we need to include the
12251225
// openmp_wrappers folder which contains alternative system headers.
@@ -4115,6 +4115,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41154115
CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
41164116
}
41174117

4118+
Arg *SYCLStdArg = Args.getLastArg(options::OPT_sycl_std_EQ);
4119+
41184120
if (UseSYCLTriple) {
41194121
// We want to compile sycl kernels.
41204122
CmdArgs.push_back("-fsycl");
@@ -4147,21 +4149,24 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41474149
options::OPT_fno_sycl_allow_func_ptr, false)) {
41484150
CmdArgs.push_back("-fsycl-allow-func-ptr");
41494151
}
4150-
}
41514152

4152-
if (IsSYCL) {
4153-
if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
4154-
A->render(Args, CmdArgs);
4155-
CmdArgs.push_back("-fsycl-std-layout-kernel-params");
4156-
} else {
4157-
// Ensure the default version in SYCL mode is 1.2.1 (aka 2017)
4158-
CmdArgs.push_back("-sycl-std=2017");
4153+
if (!SYCLStdArg) {
41594154
// The user had not pass SYCL version, thus we'll employ no-sycl-strict
41604155
// to allow address-space unqualified pointers in function params/return
41614156
// along with marking the same function with explicit SYCL_EXTERNAL
41624157
CmdArgs.push_back("-Wno-sycl-strict");
41634158
}
4159+
}
4160+
4161+
if (IsSYCL) {
4162+
if (SYCLStdArg) {
4163+
SYCLStdArg->render(Args, CmdArgs);
4164+
CmdArgs.push_back("-fsycl-std-layout-kernel-params");
4165+
} else {
4166+
// Ensure the default version in SYCL mode is 1.2.1 (aka 2017)
4167+
CmdArgs.push_back("-sycl-std=2017");
41644168
}
4169+
}
41654170

41664171
if (IsOpenMPDevice) {
41674172
// We have to pass the triple of the host if compiling for an OpenMP device.

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ void SYCLToolChain::AddSYCLIncludeArgs(const clang::driver::Driver &Driver,
545545

546546
void SYCLToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
547547
ArgStringList &CC1Args) const {
548-
AddSYCLIncludeArgs(getDriver(), DriverArgs, CC1Args);
549548
HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);
550549
}
551550

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12660,6 +12660,9 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
1266012660
}
1266112661
}
1266212662

12663+
if (getLangOpts().SYCLIsDevice)
12664+
checkSYCLDeviceVarDecl(var);
12665+
1266312666
// In Objective-C, don't allow jumps past the implicit initialization of a
1266412667
// local retaining variable.
1266512668
if (getLangOpts().ObjC &&

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,84 @@ bool Sema::isKnownGoodSYCLDecl(const Decl *D) {
200200
return false;
201201
}
202202

203+
static bool isZeroSizedArray(QualType Ty) {
204+
if (const auto *CATy = dyn_cast<ConstantArrayType>(Ty))
205+
return CATy->getSize() == 0;
206+
return false;
207+
}
208+
209+
static Sema::DeviceDiagBuilder
210+
emitDeferredDiagnosticAndNote(Sema &S, SourceRange Loc, unsigned DiagID,
211+
SourceRange UsedAtLoc) {
212+
Sema::DeviceDiagBuilder builder =
213+
S.SYCLDiagIfDeviceCode(Loc.getBegin(), DiagID);
214+
if (UsedAtLoc.isValid())
215+
S.SYCLDiagIfDeviceCode(UsedAtLoc.getBegin(), diag::note_sycl_used_here);
216+
return builder;
217+
}
218+
219+
static void checkSYCLVarType(Sema &S, QualType Ty, SourceRange Loc,
220+
llvm::DenseSet<QualType> Visited,
221+
SourceRange UsedAtLoc = SourceRange()) {
222+
// Not all variable types are supported inside SYCL kernels,
223+
// for example the quad type __float128 will cause errors in the
224+
// SPIR-V translation phase.
225+
// Here we check any potentially unsupported declaration and issue
226+
// a deferred diagnostic, which will be emitted iff the declaration
227+
// is discovered to reside in kernel code.
228+
// The optional UsedAtLoc param is used when the SYCL usage is at a
229+
// different location than the variable declaration and we need to
230+
// inform the user of both, e.g. struct member usage vs declaration.
231+
232+
//--- check types ---
233+
234+
// zero length arrays
235+
if (isZeroSizedArray(Ty))
236+
emitDeferredDiagnosticAndNote(S, Loc, diag::err_typecheck_zero_array_size,
237+
UsedAtLoc);
238+
239+
// Sub-reference array or pointer, then proceed with that type.
240+
while (Ty->isAnyPointerType() || Ty->isArrayType())
241+
Ty = QualType{Ty->getPointeeOrArrayElementType(), 0};
242+
243+
// __int128, __int128_t, __uint128_t, __float128
244+
if (Ty->isSpecificBuiltinType(BuiltinType::Int128) ||
245+
Ty->isSpecificBuiltinType(BuiltinType::UInt128) ||
246+
(Ty->isSpecificBuiltinType(BuiltinType::Float128) &&
247+
!S.Context.getTargetInfo().hasFloat128Type()))
248+
emitDeferredDiagnosticAndNote(S, Loc, diag::err_type_unsupported, UsedAtLoc)
249+
<< Ty.getUnqualifiedType().getCanonicalType();
250+
251+
//--- now recurse ---
252+
// Pointers complicate recursion. Add this type to Visited.
253+
// If already there, bail out.
254+
if (!Visited.insert(Ty).second)
255+
return;
256+
257+
if (const auto *ATy = dyn_cast<AttributedType>(Ty))
258+
return checkSYCLVarType(S, ATy->getModifiedType(), Loc, Visited);
259+
260+
if (const auto *RD = Ty->getAsRecordDecl()) {
261+
for (const auto &Field : RD->fields())
262+
checkSYCLVarType(S, Field->getType(), Field->getSourceRange(), Visited,
263+
Loc);
264+
} else if (const auto *FPTy = dyn_cast<FunctionProtoType>(Ty)) {
265+
for (const auto &ParamTy : FPTy->param_types())
266+
checkSYCLVarType(S, ParamTy, Loc, Visited);
267+
checkSYCLVarType(S, FPTy->getReturnType(), Loc, Visited);
268+
}
269+
}
270+
271+
void Sema::checkSYCLDeviceVarDecl(VarDecl *Var) {
272+
assert(getLangOpts().SYCLIsDevice &&
273+
"Should only be called during SYCL compilation");
274+
QualType Ty = Var->getType();
275+
SourceRange Loc = Var->getLocation();
276+
llvm::DenseSet<QualType> Visited;
277+
278+
checkSYCLVarType(*this, Ty, Loc, Visited);
279+
}
280+
203281
class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
204282
public:
205283
MarkDeviceFunction(Sema &S)

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,12 +1527,8 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
15271527
break;
15281528
case DeclSpec::TST_float128:
15291529
if (!S.Context.getTargetInfo().hasFloat128Type() &&
1530-
S.getLangOpts().SYCLIsDevice)
1531-
S.SYCLDiagIfDeviceCode(DS.getTypeSpecTypeLoc(),
1532-
diag::err_type_unsupported)
1533-
<< "__float128";
1534-
else if (!S.Context.getTargetInfo().hasFloat128Type() &&
1535-
!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice))
1530+
!S.getLangOpts().SYCLIsDevice &&
1531+
!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice))
15361532
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
15371533
<< "__float128";
15381534
Result = Context.Float128Ty;
@@ -2350,12 +2346,6 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
23502346
<< ArraySize->getSourceRange();
23512347
ASM = ArrayType::Normal;
23522348
}
2353-
2354-
// Zero length arrays are disallowed in SYCL device code.
2355-
if (getLangOpts().SYCLIsDevice)
2356-
SYCLDiagIfDeviceCode(ArraySize->getBeginLoc(),
2357-
diag::err_typecheck_zero_array_size)
2358-
<< ArraySize->getSourceRange();
23592349
} else if (!T->isDependentType() && !T->isVariablyModifiedType() &&
23602350
!T->isIncompleteType() && !T->isUndeducedType()) {
23612351
// Is the array too large?

0 commit comments

Comments
 (0)