Skip to content

Commit c4bf648

Browse files
Address review comments.
1 parent dc5b928 commit c4bf648

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ def err_drv_sycl_missing_amdgpu_arch : Error<
399399
def err_drv_sycl_thinlto_split_off: Error<
400400
"'%0' is not supported when '%1' is set with '-fsycl'">;
401401
def err_drv_sycl_offload_arch_new_driver: Error<
402-
"'--offload-arch' is supported when '-fsycl' is set with '--offload-new-driver'">;
402+
"'--offload-arch' is supported when '-fsycl' is set with '--offload-new-driver'">;
403+
def err_drv_sycl_offload_arch_missing_value : Error<
404+
"must pass in an explicit cpu or gpu architecture to '--offload-arch'">;
403405
def warn_drv_sycl_offload_target_duplicate : Warning<
404406
"SYCL offloading target '%0' is similar to target '%1' already specified; "
405407
"will be ignored">, InGroup<SyclTarget>;

clang/lib/Driver/Driver.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,19 +1296,20 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
12961296
// If the user specified --offload-arch, deduce the offloading
12971297
// target triple(s) from the set of architecture(s).
12981298
// Create a toolchain for each valid triple.
1299+
// We do not support SYCL offloading if any of the inputs is a
1300+
// .cu (for CUDA type) or .hip (for HIP type) file.
12991301
else if (HasValidSYCLRuntime &&
13001302
C.getInputArgs().hasArg(options::OPT_offload_arch_EQ) && !IsHIP &&
13011303
!IsCuda) {
1302-
// SYCL offloading to AOT Targets with ``--offload-arch``
1303-
// is currently enabled only with ``--offload-new-driver`` option.
1304-
// Emit a diagnostic if ``--offload-arch`` is invoked without
1305-
// ``--offload-new driver`` option.
1306-
if (!C.getInputArgs().hasFlag(options::OPT_offload_new_driver,
1307-
options::OPT_no_offload_new_driver,
1308-
false)) {
1309-
Diag(clang::diag::err_drv_sycl_offload_arch_new_driver);
1310-
return;
1311-
}
1304+
// SYCL offloading to AOT Targets with ``--offload-arch``
1305+
// is currently enabled only with ``--offload-new-driver`` option.
1306+
// Emit a diagnostic if ``--offload-arch`` is invoked without
1307+
// ``--offload-new driver`` option.
1308+
if (!C.getInputArgs().hasFlag(options::OPT_offload_new_driver,
1309+
options::OPT_no_offload_new_driver, false)) {
1310+
Diag(clang::diag::err_drv_sycl_offload_arch_new_driver);
1311+
return;
1312+
}
13121313
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
13131314
auto AMDTriple = getHIPOffloadTargetTriple(*this, C.getInputArgs());
13141315
auto NVPTXTriple = getNVIDIAOffloadTargetTriple(*this, C.getInputArgs(),
@@ -1350,6 +1351,12 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
13501351
Arch);
13511352
} else if (IsSYCLSupportedIntelGPUArch(StringToOffloadArchSYCL(Arch))) {
13521353
StringRef IntelGPUArch;
1354+
// For Intel Graphics AOT target, valid values for ``--offload-arch``
1355+
// are mapped to valid device names accepted by OCLOC (the Intel GPU AOT
1356+
// compiler) via the ``-device`` option. The mapIntelGPUArchName
1357+
// function maps the accepted values for `--offload-arch` to enable SYCL
1358+
// offloading to Intel GPUs and the corresponding `-device` value passed
1359+
// to OCLOC.
13531360
IntelGPUArch = mapIntelGPUArchName(Arch).data();
13541361
DerivedArchs[MakeSYCLDeviceTriple("spir64_gen").getTriple()].insert(
13551362
IntelGPUArch);
@@ -1358,9 +1365,10 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
13581365
return;
13591366
}
13601367
}
1361-
// If the set is empty then we failed to find a native architecture.
1368+
// Emit an error if architecture value is not provided
1369+
// to --offload-arch.
13621370
if (Archs.empty()) {
1363-
Diag(clang::diag::err_drv_invalid_sycl_target) << "native";
1371+
Diag(clang::diag::err_drv_sycl_offload_arch_missing_value);
13641372
return;
13651373
}
13661374

clang/test/Driver/sycl-offload-arch-intel-cpu.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,13 @@
5858
// TARGET-TRIPLE-CPU: "-D__SYCL_TARGET_INTEL_X86_64__"
5959
// CLANG-OFFLOAD-PACKAGER-CPU: clang-offload-packager{{.*}} "--image={{.*}}triple=spir64_x86_64-unknown-unknown,arch=[[DEV_STR]],kind=sycl"
6060

61+
// Tests for handling a missing architecture.
62+
//
63+
// RUN: not %clangxx --offload-new-driver -fsycl --offload-arch= %s -### 2>&1 \
64+
// RUN: | FileCheck -check-prefix=MISSING %s
65+
// RUN: not %clang_cl --offload-new-driver -fsycl --offload-arch= %s -### 2>&1 \
66+
// RUN: | FileCheck -check-prefix=MISSING %s
67+
68+
// MISSING: error: must pass in an explicit cpu or gpu architecture to '--offload-arch'
69+
70+

0 commit comments

Comments
 (0)