Skip to content

[SYCL][NATIVECPU] Support multiple SYCL targets in the same compiler invocation #10495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 131 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
18d5e8a
[WIP] skeleton for the native cpu pi plugin
PietroGhg Apr 25, 2023
c635b99
pimembuffercreate
PietroGhg Apr 26, 2023
e271fda
merge pietro/kernelhandler branch (only kernelhandler changes - no host
PietroGhg Apr 26, 2023
6a9e176
[WIP] enqueueing kernel
PietroGhg Apr 26, 2023
9f5d31d
pilereasemem, formatting
PietroGhg Apr 27, 2023
aa2a4e0
moving native cpu tests to test-e2e
PietroGhg Apr 27, 2023
5b52935
Revert "moving native cpu tests to test-e2e"
PietroGhg Apr 27, 2023
434d50a
pieneuquemapbuffermap, update tests
PietroGhg Apr 27, 2023
ad3dd49
update docs
PietroGhg May 8, 2023
80f51c8
using __sycl_register_lib in pi native cpu plugin
PietroGhg May 11, 2023
47a6c59
update pi_platform_backend
PietroGhg May 11, 2023
3908749
addressing review comments
PietroGhg May 12, 2023
2b090ae
get_global_range builtin
PietroGhg May 15, 2023
0ec6392
remove only the right function attrs
PietroGhg May 15, 2023
12c9f90
formatting
PietroGhg May 15, 2023
9c5cf57
update lit tests
PietroGhg May 15, 2023
15ba86b
remove debug print
PietroGhg May 15, 2023
1920e87
(NATIVECPU) fixes for Windows
uwedolinsky May 16, 2023
5c2ffde
fix Basic/device-selector.cpp test
PietroGhg May 18, 2023
ef83968
pienqueuemembufferfill
PietroGhg May 18, 2023
61d4a14
fix Basic/get_backend.cpp test
PietroGhg May 18, 2023
713f82c
fix Basic/aspects.cpp test
PietroGhg May 19, 2023
0458a7b
update Regression/device_num.cpp
PietroGhg May 19, 2023
bee8957
support local work items
PietroGhg May 17, 2023
0c0a1ae
update ParseAllowList.cpp test
PietroGhg May 19, 2023
1225f4d
enable e2e testing for Native CPU
PietroGhg May 19, 2023
a4e9f58
[SYCLNATIVECPU] -fsycl-native-cpu -> -fsycl-targets=native_cpu
PietroGhg May 19, 2023
3c7a72f
global offset builtin
PietroGhg May 23, 2023
1b0b618
formatting
PietroGhg May 23, 2023
12eca2c
piextusmalloc
PietroGhg May 23, 2023
b2ed8ab
Multiple TUs test
PietroGhg May 23, 2023
5946bd2
call host function from kernel
PietroGhg May 23, 2023
03b8b03
fix bug with kernels with one arg
PietroGhg May 23, 2023
750b756
adding REQUIRED for native cpu tests
PietroGhg May 23, 2023
2807468
addressing review comments
PietroGhg May 25, 2023
2245007
[SYCLNATIVECPU] Running example doc
PietroGhg May 25, 2023
45d21ce
Fixes for NativeCPU link issues on Windows
uwedolinsky May 29, 2023
18d557f
update e2e config for native cpu
PietroGhg May 29, 2023
e24ecfe
continue_no_impl for piextqueuecreate
PietroGhg May 29, 2023
6723f4e
formatting
PietroGhg May 29, 2023
65af8b7
remove REQUIRED from clang tests
PietroGhg May 29, 2023
be41c2d
[SYCLNATIVECPU] Fix linkage of device functions
PietroGhg May 30, 2023
ca2e400
(SYCLNATIVECPU) fixed typos
uwedolinsky May 30, 2023
653c0bc
formatting
PietroGhg May 30, 2023
650092c
formatting
PietroGhg May 30, 2023
c0ca050
[SYCLNATIVECPU] Move tests and update docs
PietroGhg May 31, 2023
93fecfa
formatting
PietroGhg May 31, 2023
c419d01
[SYCLNATIVECPU] cc1 option, builtin names
PietroGhg Jun 1, 2023
8b25d08
[WIP] checkpoint
PietroGhg Jun 5, 2023
5a8affb
[WIP] checkpoint
PietroGhg Jun 5, 2023
c2bb074
[WIP] basic test passing with multiple targets
PietroGhg Jun 5, 2023
45da288
update tests
PietroGhg Jun 6, 2023
fe688bd
better check for native cpu
PietroGhg Jun 6, 2023
ec27f6f
remove -D__SYCL_NATIVE_CPU___ from host compiler invocation
PietroGhg Jun 7, 2023
ea169ea
remove getPtr func
PietroGhg Jun 7, 2023
cab4e34
emit subhandler in llvm ir - needs test
PietroGhg Jun 7, 2023
d0e0ab7
add string to mangled name + update tests
PietroGhg Jun 8, 2023
39b1b44
Update branch
PietroGhg Jun 8, 2023
66f025f
Merge branch 'sycl' into pietro/pi_native_cpu
PietroGhg Jun 8, 2023
e4eb81a
[SYCLNATIVECPU] Address review comments
PietroGhg Jun 12, 2023
7265b32
Apply suggestions from code review
PietroGhg Jun 12, 2023
665026b
formatting
PietroGhg Jun 12, 2023
c22be42
move tests from semasycl to check_device_code, add basic test
PietroGhg Jun 13, 2023
7ef4a53
Merge branch 'sycl' into pietro/pi_native_cpu
PietroGhg Jun 14, 2023
3f47549
rebase and formatting
PietroGhg Jun 14, 2023
c000ab2
Merge branch 'pietro/pi_native_cpu' into pietro/subhandler_ir
PietroGhg Jun 14, 2023
b8b1ade
Merge branch 'pietro/multiple_targets' into pietro/subhandler_ir
PietroGhg Jun 15, 2023
1842b26
[WIP] add sycl-module-id attr to subhandler
PietroGhg Jun 15, 2023
fc9a17d
remove unused includes, removed unnecessary cmd args in test
PietroGhg Jun 15, 2023
ec8d7e6
Merge branch 'sycl' into pietro/pi_native_cpu
PietroGhg Jun 19, 2023
5f55988
Merge branch 'sycl' into pietro/pi_native_cpu
PietroGhg Jun 19, 2023
714449d
use sycl 2020 include path and sycl namespace in tests
PietroGhg Jun 19, 2023
3bd1244
formatting
PietroGhg Jun 19, 2023
a104d33
[WIP] use clang-offload-wrapper to emit binary info
PietroGhg Jun 20, 2023
be3e8b7
remove unnecessary compiler flags
PietroGhg Jun 21, 2023
b31f029
Merge branch 'sycl' into pietro/pi_native_cpu
PietroGhg Jun 21, 2023
9629c57
[WIP] use clang-offload-wrapper to emit binary info for native cpu
PietroGhg Jun 22, 2023
43e8aa2
remove debug in sycl post link
PietroGhg Jun 22, 2023
1813378
update comment
PietroGhg Jun 23, 2023
02bb9ec
renaming kernel function when lowering device module
PietroGhg Jun 23, 2023
0f6b237
remove emitsyclnativecpu header pass
PietroGhg Jun 23, 2023
42ebb40
enabling different order for multiple devices
PietroGhg Jun 26, 2023
8ab5708
Merge branch 'sycl' into pietro/pi_native_cpu
PietroGhg Jun 27, 2023
19fec76
Update CODEOWNERS file
PietroGhg Jun 27, 2023
3cb6946
add design doc to toctree
PietroGhg Jun 27, 2023
af29dba
Revert "Update CODEOWNERS file"
PietroGhg Jun 27, 2023
eff3200
Merge branch 'sycl' into pietro/pi_native_cpu
PietroGhg Jun 29, 2023
0cbf1eb
Fix post rebase error
PietroGhg Jun 29, 2023
9f811c2
Merge branch 'pietro/pi_native_cpu' into pietro/subhandler_ir
PietroGhg Jun 29, 2023
93fd8e5
update tests and docs
PietroGhg Jul 3, 2023
856158a
update driver lit test
PietroGhg Jul 5, 2023
e17e7b0
remove commented code
PietroGhg Jul 5, 2023
62c61f4
fix header inclusion order
PietroGhg Jul 5, 2023
ff2bbf7
typo in docs
PietroGhg Jul 5, 2023
2acb18b
add debug and exception options to test
PietroGhg Jul 5, 2023
a624e8a
Merge branch 'sycl' into pietro/subhandler_ir
PietroGhg Jul 13, 2023
7c0c585
fix post merge issues
PietroGhg Jul 13, 2023
2001d22
fix tests after rebase
PietroGhg Jul 17, 2023
546f7d8
Merge branch 'sycl' into pietro/subhandler_ir
PietroGhg Jul 17, 2023
9393c3a
remove emitsyclnativecpuheader pass
PietroGhg Jul 17, 2023
b4501d5
Merge branch 'sycl' into pietro/subhandler_ir
PietroGhg Jul 18, 2023
512d154
factor out native cpu check
PietroGhg Jul 18, 2023
55ec884
remove conflict markers
PietroGhg Jul 18, 2023
61614b7
using nullptr to identify end in binary array
PietroGhg Jul 18, 2023
603d603
better map for kernels in program
PietroGhg Jul 18, 2023
a235bce
change mangling
PietroGhg Jul 18, 2023
b695497
typos in tests
PietroGhg Jul 19, 2023
9f0c286
update docs
PietroGhg Jul 20, 2023
e0c230f
Removing -D__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ from test
PietroGhg Jul 20, 2023
be14dcd
Merge branch 'sycl' into pietro/subhandler_ir
PietroGhg Jul 20, 2023
1aab938
add missing defs for new PI functions
PietroGhg Jul 20, 2023
52c6470
formatting
PietroGhg Jul 20, 2023
fa0af68
address review comments
PietroGhg Jul 20, 2023
e426617
formatting
PietroGhg Jul 20, 2023
0f9fe4f
remove -D__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ from test
PietroGhg Jul 21, 2023
24b51ac
[SYCL][NATIVECPU] fixed rebase with UR integration
uwedolinsky Jul 28, 2023
cd7fbf4
Merge remote-tracking branch 'origin/sycl' into pietro/subhandler_ir
uwedolinsky Jul 28, 2023
5cbb773
[SYCL][NATIVECPU] put back original include order
uwedolinsky Jul 28, 2023
6a3a2a3
[SYCLNATIVECPU] patch from clang-format
uwedolinsky Jul 28, 2023
5ed8f11
[SYCLNATIVECPU] patch from clang-format
uwedolinsky Jul 28, 2023
4d4a0b8
[SYCLNATIVECPU] replaced string with Twine
uwedolinsky Aug 1, 2023
a32b961
[SYCLNATIVECPU] removed -native-cpu arg from OffloadWrapper
uwedolinsky Aug 1, 2023
6d95891
[SYCLNATIVECPU] added dyn_cast check
uwedolinsky Aug 2, 2023
cf14ab7
Merge branch 'pietro/subhandler_ir' of git.office.codeplay.com:oneapi…
PietroGhg Aug 7, 2023
7a8707a
update offload wrapper native cpu test
PietroGhg Aug 7, 2023
0cd7200
move nativecpu_entry struct to header
PietroGhg Aug 7, 2023
de4ca64
formatting
PietroGhg Aug 7, 2023
e7f6846
Merge branch 'sycl' into pietro/subhandler_ir
PietroGhg Aug 7, 2023
909f707
add comment for nativecpu_entry
PietroGhg Aug 8, 2023
2318ab0
typo
PietroGhg Aug 8, 2023
6dff0e1
formatting
PietroGhg Aug 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions clang/include/clang/Basic/SYCLNativeCPUHelpers.h

This file was deleted.

11 changes: 7 additions & 4 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SYCLNativeCPUHelpers.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/Targets/SPIR.h"
#include "clang/Frontend/FrontendDiagnostic.h"
Expand Down Expand Up @@ -47,10 +46,10 @@
#include "llvm/Passes/StandardInstrumentations.h"
#include "llvm/SYCLLowerIR/CompileTimePropertiesPass.h"
#include "llvm/SYCLLowerIR/ESIMD/ESIMDVerifier.h"
#include "llvm/SYCLLowerIR/EmitSYCLNativeCPUHeader.h"
#include "llvm/SYCLLowerIR/LowerWGLocalMemory.h"
#include "llvm/SYCLLowerIR/MutatePrintfAddrspace.h"
#include "llvm/SYCLLowerIR/PrepareSYCLNativeCPU.h"
#include "llvm/SYCLLowerIR/RenameKernelSYCLNativeCPU.h"
#include "llvm/SYCLLowerIR/SYCLAddOptLevelAttribute.h"
#include "llvm/SYCLLowerIR/SYCLPropagateAspectsUsage.h"
#include "llvm/Support/BuryPointer.h"
Expand Down Expand Up @@ -108,6 +107,10 @@ extern cl::opt<bool> DebugInfoCorrelate;
static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
"sanitizer-early-opt-ep", cl::Optional,
cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));

static cl::opt<bool> SYCLNativeCPURename(
"sycl-native-cpu-rename", cl::init(false),
cl::desc("Rename kernel functions for SYCL Native CPU"));
}

namespace {
Expand Down Expand Up @@ -1048,6 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
MPM = PB.buildPerModuleDefaultPipeline(Level);
}

if (SYCLNativeCPURename)
MPM.addPass(RenameKernelSYCLNativeCPUPass());
if (LangOpts.SYCLIsDevice) {
MPM.addPass(SYCLMutatePrintfAddrspacePass());
if (LangOpts.EnableDAEInSpirKernels)
Expand Down Expand Up @@ -1078,8 +1083,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
MPM.addPass(CompileTimePropertiesPass());

if (LangOpts.SYCLIsNativeCPU) {
MPM.addPass(
EmitSYCLNativeCPUHeaderPass(getNativeCPUHeaderName(LangOpts)));
MPM.addPass(PrepareSYCLNativeCPUPass());
}
}
Expand Down
79 changes: 35 additions & 44 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,23 +1169,19 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
checkSingleArgValidity(DeviceCodeSplit,
{"per_kernel", "per_source", "auto", "off"});

bool IsSYCLNativeCPU = isSYCLNativeCPU(C.getInputArgs());
Arg *SYCLForceTarget =
getArgRequiringSYCLRuntime(options::OPT_fsycl_force_target_EQ);
if (SYCLForceTarget) {
StringRef Val(SYCLForceTarget->getValue());
llvm::Triple TT(MakeSYCLDeviceTriple(Val));
// Todo: we skip the check for the valid SYCL target, because currently
// setting native_cpu as a target overrides all the other targets,
// re-enable the check once native_cpu can coexist.
if (!IsSYCLNativeCPU && !isValidSYCLTriple(TT))
if (!isValidSYCLTriple(TT))
Diag(clang::diag::err_drv_invalid_sycl_target) << Val;
}
bool HasSYCLTargetsOption = SYCLTargets || SYCLLinkTargets || SYCLAddTargets;

llvm::StringMap<StringRef> FoundNormalizedTriples;
llvm::SmallVector<llvm::Triple, 4> UniqueSYCLTriplesVec;
if (!IsSYCLNativeCPU && HasSYCLTargetsOption) {
if (HasSYCLTargetsOption) {
// At this point, we know we have a valid combination
// of -fsycl*target options passed
Arg *SYCLTargetsValues = SYCLTargets ? SYCLTargets : SYCLLinkTargets;
Expand Down Expand Up @@ -1220,6 +1216,12 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
continue;
}
UserTargetName = "amdgcn-amd-amdhsa";
} else if (Val == "native_cpu") {
const ToolChain *HostTC =
C.getSingleOffloadToolChain<Action::OFK_Host>();
llvm::Triple HostTriple = HostTC->getTriple();
UniqueSYCLTriplesVec.push_back(HostTriple);
continue;
}

if (!isValidSYCLTriple(MakeSYCLDeviceTriple(UserTargetName))) {
Expand Down Expand Up @@ -1287,11 +1289,6 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
Diag(clang::diag::warn_drv_empty_joined_argument)
<< SYCLAddTargets->getAsString(C.getInputArgs());
}
} else if (IsSYCLNativeCPU) {
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
llvm::Triple HostTriple = HostTC->getTriple();
UniqueSYCLTriplesVec.push_back(HostTriple);
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec);
} else {
// If -fsycl is supplied without -fsycl-*targets we will assume SPIR-V
// unless -fintelfpga is supplied, which uses SPIR-V with fpga AOT.
Expand Down Expand Up @@ -5496,6 +5493,9 @@ class OffloadingActionBuilder final {
bool isSpirvAOT = TT.getSubArch() == llvm::Triple::SPIRSubArch_fpga ||
TT.getSubArch() == llvm::Triple::SPIRSubArch_gen ||
TT.getSubArch() == llvm::Triple::SPIRSubArch_x86_64;
const bool isSYCLNativeCPU =
TC->getAuxTriple() &&
driver::isSYCLNativeCPU(TT, *TC->getAuxTriple());
for (const auto &Input : LI) {
if (TT.getSubArch() == llvm::Triple::SPIRSubArch_fpga &&
types::isFPGA(Input->getType())) {
Expand Down Expand Up @@ -5717,26 +5717,14 @@ class OffloadingActionBuilder final {
} else
FullDeviceLinkAction = FullLinkObject;

bool IsSYCLNativeCPU = isSYCLNativeCPU(Args);
if (IsSYCLNativeCPU) {
// for SYCL Native CPU, we just take the linked device
// modules, lower them to an object file , and link it to the host
// object file.
auto *backendAct = C.MakeAction<BackendJobAction>(
FullDeviceLinkAction, types::TY_PP_Asm);
auto *asmAct =
C.MakeAction<AssembleJobAction>(backendAct, types::TY_Object);
DA.add(*asmAct, *TC, BoundArch, Action::OFK_SYCL);
return;
}

// reflects whether current target is ahead-of-time and can't
// support runtime setting of specialization constants
bool isAOT = isNVPTX || isAMDGCN || isSpirvAOT;
bool isAOT = isNVPTX || isAMDGCN || isSpirvAOT || isSYCLNativeCPU;

// post link is not optional - even if not splitting, always need to
// process specialization constants
types::ID PostLinkOutType = isSPIR ? types::TY_Tempfiletable
types::ID PostLinkOutType = isSPIR || isSYCLNativeCPU
? types::TY_Tempfiletable
: types::TY_LLVM_BC;
auto createPostLinkAction = [&]() {
// For SPIR-V targets, force TY_Tempfiletable.
Expand All @@ -5746,6 +5734,20 @@ class OffloadingActionBuilder final {
return TypedPostLinkAction;
};
Action *PostLinkAction = createPostLinkAction();
if (isSYCLNativeCPU) {
// for SYCL Native CPU, we just take the linked device
// modules, lower them to an object file , and link it to the host
// object file.
auto *backendAct = C.MakeAction<BackendJobAction>(
FullDeviceLinkAction, types::TY_PP_Asm);
auto *asmAct =
C.MakeAction<AssembleJobAction>(backendAct, types::TY_Object);
DA.add(*asmAct, *TC, BoundArch, Action::OFK_SYCL);
auto *DeviceWrappingAction = C.MakeAction<OffloadWrapperJobAction>(
PostLinkAction, types::TY_Object);
DA.add(*DeviceWrappingAction, *TC, BoundArch, Action::OFK_SYCL);
continue;
}
if (isNVPTX && Args.hasArg(options::OPT_fsycl_embed_ir)) {
// When compiling for Nvidia/CUDA devices and the user requested the
// IR to be embedded in the application (via option), run the output
Expand Down Expand Up @@ -6119,17 +6121,8 @@ class OffloadingActionBuilder final {
bool GpuInitHasErrors = false;
bool HasSYCLTargetsOption =
SYCLAddTargets || SYCLTargets || SYCLLinkTargets;
bool IsSYCLNativeCPU = isSYCLNativeCPU(C.getInputArgs());

// check if multiple targets are passed along with native_cpu:
// currently native_cpu overrides all the other targets, so we emit a
// warning
if (IsSYCLNativeCPU) {
auto *SYCLTargets = Args.getLastArg(options::OPT_fsycl_targets_EQ);
if (SYCLTargets->getNumValues() > 1)
C.getDriver().Diag(clang::diag::warn_drv_sycl_native_cpu_and_targets);
}
if (!IsSYCLNativeCPU && HasSYCLTargetsOption) {
if (HasSYCLTargetsOption) {
if (SYCLTargets || SYCLLinkTargets) {
Arg *SYCLTargetsValues = SYCLTargets ? SYCLTargets : SYCLLinkTargets;
// Fill SYCLTripleList
Expand Down Expand Up @@ -6163,6 +6156,12 @@ class OffloadingActionBuilder final {
C.getDriver().MakeSYCLDeviceTriple("amdgcn-amd-amdhsa"),
ValidDevice->data());
UserTargetName = "amdgcn-amd-amdhsa";
} else if (Val == "native_cpu") {
const ToolChain *HostTC =
C.getSingleOffloadToolChain<Action::OFK_Host>();
llvm::Triple TT = HostTC->getTriple();
SYCLTripleList.push_back(TT);
continue;
}

llvm::Triple TT(C.getDriver().MakeSYCLDeviceTriple(Val));
Expand Down Expand Up @@ -6249,14 +6248,6 @@ class OffloadingActionBuilder final {
GpuArchList.emplace_back(TT, nullptr);
}
}
} else if (IsSYCLNativeCPU) {
const ToolChain *HostTC =
C.getSingleOffloadToolChain<Action::OFK_Host>();
llvm::Triple TT = HostTC->getTriple();
auto TCIt = llvm::find_if(
ToolChains, [&](auto &TC) { return TT == TC->getTriple(); });
SYCLTripleList.push_back(TT);
SYCLTargetInfoList.emplace_back(*TCIt, nullptr);
} else if (HasValidSYCLRuntime) {
// -fsycl is provided without -fsycl-*targets.
bool SYCLfpga = C.getInputArgs().hasArg(options::OPT_fintelfpga);
Expand Down
10 changes: 9 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4977,7 +4977,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
bool IsFPGASYCLOffloadDevice =
IsSYCLOffloadDevice &&
Triple.getSubArch() == llvm::Triple::SPIRSubArch_fpga;
bool IsSYCLNativeCPU = isSYCLNativeCPU(Args);
const bool IsSYCLNativeCPU = isSYCLNativeCPU(TC, C.getDefaultToolChain());

// Perform the SYCL host compilation using an external compiler if the user
// requested.
Expand Down Expand Up @@ -5468,6 +5468,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-emit-obj");
CollectArgsForIntegratedAssembler(C, Args, CmdArgs, D);
}
if (IsSYCLOffloadDevice && IsSYCLNativeCPU) {
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-sycl-native-cpu-rename");
}

// Also ignore explicit -force_cpusubtype_ALL option.
(void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
Expand Down Expand Up @@ -9409,6 +9413,10 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
TargetTripleOpt = ("llvm_" + TargetTripleOpt).str();
}

const bool IsSYCLNativeCPU = isSYCLNativeCPU(TC, C.getDefaultToolChain());
if (IsSYCLNativeCPU) {
TargetTripleOpt = "native_cpu";
}
WrapperArgs.push_back(
C.getArgs().MakeArgString(Twine("-target=") + TargetTripleOpt));

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ void SYCL::x86_64::BackendCompiler::ConstructJob(
SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
const ToolChain &HostTC, const ArgList &Args)
: ToolChain(D, Triple, Args), HostTC(HostTC),
IsSYCLNativeCPU(isSYCLNativeCPU(Args)) {
IsSYCLNativeCPU(Triple == HostTC.getTriple()) {
// Lookup binaries into the driver directory, this is used to
// discover the clang-offload-bundler executable.
getProgramPaths().push_back(getDriver().Dir);
Expand Down
10 changes: 9 additions & 1 deletion clang/lib/Driver/ToolChains/SYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain {
llvm::opt::ArgStringList &CC1Args) const override;

const ToolChain &HostTC;
const bool IsSYCLNativeCPU;

protected:
Tool *buildBackendCompiler() const override;
Tool *buildLinker() const override;

private:
bool IsSYCLNativeCPU;
void TranslateGPUTargetOpt(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs,
llvm::opt::OptSpecifier Opt_EQ) const;
Expand All @@ -223,6 +223,14 @@ template <typename ArgListT> bool isSYCLNativeCPU(const ArgListT &Args) {
}
return false;
}

inline bool isSYCLNativeCPU(const llvm::Triple HostT, const llvm::Triple DevT) {
return HostT == DevT;
}

inline bool isSYCLNativeCPU(const ToolChain &TC1, const ToolChain &TC2) {
return isSYCLNativeCPU(TC1.getTriple(), TC2.getTriple());
}
} // end namespace driver
} // end namespace clang

Expand Down
34 changes: 10 additions & 24 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "clang/Basic/Attributes.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SYCLNativeCPUHelpers.h"
#include "clang/Basic/Version.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Sema.h"
Expand Down Expand Up @@ -1028,15 +1027,6 @@ static QualType calculateKernelNameType(ASTContext &Ctx,
return TAL->get(0).getAsType().getCanonicalType();
}

// Kernel names are currently mangled as type names which
// may collide (in the IR) with the "real" type names generated
// for RTTI etc when compiling host and device code together.
// Therefore the mangling of the kernel function is changed for
// NativeCPU to avoid such potential collision.
static void changeManglingForNativeCPU(std::string &Name) {
Name.append("_NativeCPUKernel");
}

// Gets a name for the OpenCL kernel function, calculated from the first
// template argument of the kernel caller function.
static std::pair<std::string, std::string>
Expand All @@ -1054,12 +1044,18 @@ constructKernelName(Sema &S, const FunctionDecl *KernelCallerFunc,
std::string StableName =
SYCLUniqueStableNameExpr::ComputeName(S.getASTContext(), KernelNameType);

// When compiling for the SYCLNativeCPU device we need a C++ identifier
// as the kernel name and cannot use the name produced by some manglers
// including the MS mangler.
// For NativeCPU the kernel name is set to the stable GNU-mangled name
// because the default mangling may be different, for example on Windows.
// This is needed for compiling kernels for multiple SYCL targets to ensure
// the same kernel name can be used for kernel lookup in different target
// binaries. This assumes that all SYCL targets use the same mangling
// produced for the stable name.
// Todo: Check if this assumption is valid, and if it would be better
// instead to always compile the NativeCPU device code in GNU mode which
// may cause issues when compiling headers with non-standard extensions
// written for compilers with different C++ ABIs (like MS VS).
if (S.getLangOpts().SYCLIsNativeCPU) {
MangledName = StableName;
changeManglingForNativeCPU(MangledName);
}

return {MangledName, StableName};
Expand Down Expand Up @@ -5682,16 +5678,6 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
}
}

if (S.getLangOpts().SYCLIsNativeCPU) {
// This is a temporary workaround for the integration header file
// being emitted too early.
std::string HCName = getNativeCPUHeaderName(S.getLangOpts());

OS << "\n// including the kernel handlers calling the kernels\n";
OS << "\n#include \"";
OS << HCName;
OS << "\"\n\n";
}
if (EmittedFirstSpecConstant)
OS << "#include <sycl/detail/spec_const_integration.hpp>\n";

Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGenSYCL/native_cpu_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void gen() {
}

// Check name mangling
// CHECK-DAG: @_ZTS6init_aIiE_NativeCPUKernel_NativeCPUKernel({{.*}})
// CHECK-DAG: @_ZTS6init_aIfE_NativeCPUKernel_NativeCPUKernel({{.*}})
// CHECK-DAG: @_ZTS6init_aIiE.NativeCPUKernel({{.*}})
// CHECK-DAG: @_ZTS6init_aIfE.NativeCPUKernel({{.*}})

// Check Native CPU module flag
// CHECK-DAG: !{{[0-9]*}} = !{i32 1, !"is-native-cpu", i32 1}
13 changes: 10 additions & 3 deletions clang/test/Driver/sycl-native-cpu-fsycl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
//CHECK_ACTIONS:| +- 11: linker, {5}, ir, (device-sycl)
//CHECK_ACTIONS:| +- 12: backend, {11}, assembler, (device-sycl)
//CHECK_ACTIONS:|- 13: assembler, {12}, object, (device-sycl)
//CHECK_ACTIONS:14: offload, "host-sycl ({{.*}})" {10}, "device-sycl ({{.*}})" {13}, image
//call sycl-post-link and clang-offload-wrapper
//CHECK_ACTIONS:| +- 14: sycl-post-link, {11}, tempfiletable, (device-sycl)
//CHECK_ACTIONS:|- 15: clang-offload-wrapper, {14}, object, (device-sycl)
//CHECK_ACTIONS:16: offload, "host-sycl ({{.*}})" {10}, "device-sycl ({{.*}})" {13}, "device-sycl ({{.*}})" {15}, image


//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["{{.*}}sycl-native-cpu-fsycl.cpp"], output: "[[KERNELIR:.*]].bc"
//CHECK_BINDINGS:# "{{.*}}" - "SYCL::Linker", inputs: ["[[KERNELIR]].bc"], output: "[[KERNELLINK:.*]].bc"
//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["[[KERNELLINK]].bc"], output: "[[KERNELOBJ:.*]].o"
//CHECK_BINDINGS:# "{{.*}}" - "SYCL post link", inputs: ["[[KERNELLINK]].bc"], output: "[[TABLEFILE:.*]].table"
//CHECK_BINDINGS:# "{{.*}}" - "offload wrapper", inputs: ["[[TABLEFILE]].table"], output: "[[WRAPPEROBJ:.*]].o"
//CHECK_BINDINGS:# "{{.*}}" - "Append Footer to source", inputs: ["{{.*}}sycl-native-cpu-fsycl.cpp"], output: "[[SRCWFOOTER:.*]].cpp"
//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["[[SRCWFOOTER]].cpp", "[[KERNELIR]].bc"], output: "[[HOSTOBJ:.*]].o"
//CHECK_BINDINGS:# "{{.*}}" - "{{.*}}::Linker", inputs: ["[[HOSTOBJ]].o", "[[KERNELOBJ]].o"], output: "a.{{.*}}"
//CHECK_BINDINGS:# "{{.*}}" - "{{.*}}::Linker", inputs: ["[[HOSTOBJ]].o", "[[KERNELOBJ]].o", "[[WRAPPEROBJ]].o"], output: "a.{{.*}}"

//CHECK_INVO:{{.*}}clang{{.*}}-fsycl-is-device{{.*}}"-fsycl-is-native-cpu" "-D" "__SYCL_NATIVE_CPU__"
//CHECK_INVO:{{.*}}clang{{.*}}"-x" "ir"
Expand All @@ -48,4 +53,6 @@
//CHECK_ACTIONS-AARCH64:| +- 11: linker, {5}, ir, (device-sycl)
//CHECK_ACTIONS-AARCH64:| +- 12: backend, {11}, assembler, (device-sycl)
//CHECK_ACTIONS-AARCH64:|- 13: assembler, {12}, object, (device-sycl)
//CHECK_ACTIONS-AARCH64:14: offload, "host-sycl (aarch64-unknown-linux-gnu)" {10}, "device-sycl (aarch64-unknown-linux-gnu)" {13}, image
//CHECK_ACTIONS-AARCH64:| +- 14: sycl-post-link, {11}, tempfiletable, (device-sycl)
//CHECK_ACTIONS-AARCH64:|- 15: clang-offload-wrapper, {14}, object, (device-sycl)
//CHECK_ACTIONS-AARCH64:16: offload, "host-sycl (aarch64-unknown-linux-gnu)" {10}, "device-sycl (aarch64-unknown-linux-gnu)" {13}, "device-sycl (aarch64-unknown-linux-gnu)" {15}, image
5 changes: 0 additions & 5 deletions clang/test/Driver/sycl-native-cpu-warn.cpp

This file was deleted.

Loading