Skip to content

Commit 29a3479

Browse files
committed
Merge remote-tracking branch 'intel/sycl' into steffen/gen_builtins
2 parents 3969443 + 00533e0 commit 29a3479

File tree

303 files changed

+13449
-2943
lines changed

Some content is hidden

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

303 files changed

+13449
-2943
lines changed

.github/CODEOWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,8 @@ sycl/include/sycl/ext/oneapi/experimental/graph.hpp @intel/sycl-graphs-reviewers
120120
sycl/source/detail/graph_impl.cpp @intel/sycl-graphs-reviewers
121121
sycl/source/detail/graph_impl.hpp @intel/sycl-graphs-reviewers
122122
sycl/unittests/Extensions/CommandGraph.cpp @intel/sycl-graphs-reviewers
123+
124+
# syclcompat library
125+
sycl/**/syclcompat/ @intel/syclcompat-lib-reviewers
126+
sycl/cmake/modules/AddSYCLLibraryUnitTest.cmake @intel/syclcompat-lib-reviewers
127+
sycl/include/syclcompat.hpp @intel/syclcompat-lib-reviewers

.github/workflows/sycl_detect_changes.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ jobs:
5757
test_build:
5858
- *sycl
5959
- *drivers_and_configs
60+
# Temporary, until plugins are enabled in nightly image.
61+
- sycl/**

.github/workflows/sycl_linux_build_and_test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ on:
8282
description: 'Merge default branch after the checkout'
8383
type: boolean
8484
default: true
85+
retention-days:
86+
description: 'Artifacts retention period'
87+
type: string
88+
default: 3
8589

8690
jobs:
8791
build:
@@ -197,6 +201,7 @@ jobs:
197201
with:
198202
name: sycl_linux_${{ inputs.build_artifact_suffix }}
199203
path: ${{ inputs.artifact_archive_name }}
204+
retention-days: ${{ inputs.retention-days }}
200205

201206
aws-start:
202207
name: Start AWS

.github/workflows/sycl_nightly.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ on:
44
workflow_dispatch:
55
schedule:
66
- cron: '0 3 * * *'
7-
pull_request:
8-
paths:
9-
- 'devops/containers/ubuntu2204_preinstalled.Dockerfile'
10-
- '.github/workflows/sycl_nightly.yml'
117

128
jobs:
139
test_matrix:
1410
if: github.repository == 'intel/llvm'
1511
name: Generate Test Matrix
1612
uses: ./.github/workflows/sycl_gen_test_matrix.yml
1713
with:
18-
lts_config: "ocl_gen9;ocl_x64"
14+
# Restore once plugins are enabled in the build.
15+
# lts_config: "hip_amdgpu;ocl_gen9;ocl_x64;l0_gen9;esimd_emu;cuda_aws;win_l0_gen12"
16+
lts_config: "ocl_gen9;ocl_x64;l0_gen9;win_l0_gen12"
1917

2018
ubuntu2204_build_test:
2119
if: github.repository == 'intel/llvm'
@@ -25,8 +23,11 @@ jobs:
2523
with:
2624
build_cache_root: "/__w/"
2725
build_artifact_suffix: default-2204
28-
build_configure_extra_args: '--hip --cuda --enable-esimd-emulator'
2926
merge: false
27+
retention-days: 90
28+
lts_matrix: ${{ needs.test_matrix.outputs.lts_lx_matrix }}
29+
lts_aws_matrix: ${{ needs.test_matrix.outputs.lts_aws_matrix }}
30+
build_configure_extra_args: ''
3031

3132
ubuntu2204_opaque_pointers_build_test:
3233
if: github.repository == 'intel/llvm'
@@ -44,6 +45,10 @@ jobs:
4445
name: Windows
4546
if: github.repository == 'intel/llvm'
4647
uses: ./.github/workflows/sycl_windows_build_and_test.yml
48+
needs: test_matrix
49+
with:
50+
retention-days: 90
51+
lts_matrix: ${{ needs.test_matrix.outputs.lts_wn_matrix }}
4752

4853
ubuntu2204_docker_build_push:
4954
if: github.repository == 'intel/llvm'

.github/workflows/sycl_windows_build_and_test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ on:
2626
artifact_archive_name:
2727
type: string
2828
default: llvm_sycl.tar.gz
29+
retention-days:
30+
description: 'Artifacts retention period'
31+
type: string
32+
default: 3
2933

3034
jobs:
3135
build:
@@ -122,6 +126,7 @@ jobs:
122126
with:
123127
name: sycl_windows_default
124128
path: ${{ inputs.artifact_archive_name }}
129+
retention-days: ${{ inputs.retention-days }}
125130

126131
e2e-tests:
127132
needs: build

buildbot/configure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def do_configure(args):
2020
if sys.platform != "darwin":
2121
llvm_external_projects += ';libdevice'
2222

23-
libclc_amd_target_names = ';amdgcn--;amdgcn--amdhsa'
24-
libclc_nvidia_target_names = ';nvptx64--;nvptx64--nvidiacl'
23+
libclc_amd_target_names = ';amdgcn--amdhsa'
24+
libclc_nvidia_target_names = ';nvptx64--nvidiacl'
2525

2626
sycl_enable_fusion = "OFF"
2727
if not args.disable_fusion:

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def err_drv_bad_fpga_device_count : Error<
190190
def warn_drv_mismatch_fpga_archive : Warning<
191191
"FPGA archive '%0' does not contain matching emulation/hardware expectancy">,
192192
InGroup<SyclFPGAMismatch>;
193+
def warn_drv_sycl_native_cpu_and_targets: Warning<
194+
"-fsycl-targets=native_cpu overrides SYCL targets option">,
195+
InGroup<SyclNativeCPUTargets>;
193196
def err_drv_unsupported_opt_dpcpp : Error<"option '%0' unsupported with DPC++">;
194197
def err_drv_argument_only_allowed_with : Error<
195198
"invalid argument '%0' only allowed with '%1'">;

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,7 @@ def SyclStrict : DiagGroup<"sycl-strict", [ Sycl2017Compat, Sycl2020Compat]>;
12931293
def SyclTarget : DiagGroup<"sycl-target">;
12941294
def SyclFPGAMismatch : DiagGroup<"sycl-fpga-mismatch">;
12951295
def SyclAspectMismatch : DiagGroup<"sycl-aspect-mismatch">;
1296+
def SyclNativeCPUTargets: DiagGroup<"sycl-native-cpu-targets">;
12961297

12971298
// Backend warnings.
12981299
def BackendInlineAsm : DiagGroup<"inline-asm">;

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ LANGOPT(SYCLEnableIntHeaderDiags, 1, 0, "Enable diagnostics that require the "
295295
"SYCL integration header")
296296
LANGOPT(SYCLAllowVirtualFunctions, 1, 0,
297297
"Allow virtual functions calls in code for SYCL device")
298+
LANGOPT(SYCLIsNativeCPU , 1, 0, "Generate code for SYCL NativeCPU")
298299

299300
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
300301

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "clang/Basic/LangOptions.h"
2+
#include <string>
3+
namespace clang {
4+
inline std::string getNativeCPUHeaderName(const LangOptions &LangOpts) {
5+
return LangOpts.SYCLIntHeader + ".hc";
6+
}
7+
} // namespace clang

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6903,6 +6903,10 @@ def fsycl_use_main_file_name : Flag<["-"], "fsycl-use-main-file-name">,
69036903
def fsycl_allow_virtual_functions : Flag<["-"], "fsycl-allow-virtual-functions">,
69046904
HelpText<"Allow virtual functions calls in code for SYCL device">,
69056905
MarshallingInfoFlag<LangOpts<"SYCLAllowVirtualFunctions">>;
6906+
def fsycl_is_native_cpu : Flag<["-"], "fsycl-is-native-cpu">,
6907+
HelpText<"Perform device compilation for Native CPU.">,
6908+
Flags<[CC1Option, NoDriverOption]>,
6909+
MarshallingInfoFlag<LangOpts<"SYCLIsNativeCPU">>;
69066910

69076911
} // let Flags = [CC1Option, NoDriverOption]
69086912

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "clang/Basic/CodeGenOptions.h"
1111
#include "clang/Basic/Diagnostic.h"
1212
#include "clang/Basic/LangOptions.h"
13+
#include "clang/Basic/SYCLNativeCPUHelpers.h"
1314
#include "clang/Basic/TargetOptions.h"
1415
#include "clang/Basic/Targets/SPIR.h"
1516
#include "clang/Frontend/FrontendDiagnostic.h"
@@ -46,8 +47,10 @@
4647
#include "llvm/Passes/StandardInstrumentations.h"
4748
#include "llvm/SYCLLowerIR/CompileTimePropertiesPass.h"
4849
#include "llvm/SYCLLowerIR/ESIMD/ESIMDVerifier.h"
50+
#include "llvm/SYCLLowerIR/EmitSYCLNativeCPUHeader.h"
4951
#include "llvm/SYCLLowerIR/LowerWGLocalMemory.h"
5052
#include "llvm/SYCLLowerIR/MutatePrintfAddrspace.h"
53+
#include "llvm/SYCLLowerIR/PrepareSYCLNativeCPU.h"
5154
#include "llvm/SYCLLowerIR/SYCLAddOptLevelAttribute.h"
5255
#include "llvm/SYCLLowerIR/SYCLPropagateAspectsUsage.h"
5356
#include "llvm/Support/BuryPointer.h"
@@ -1071,6 +1074,12 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
10711074

10721075
// Process properties and annotations
10731076
MPM.addPass(CompileTimePropertiesPass());
1077+
1078+
if (LangOpts.SYCLIsNativeCPU) {
1079+
MPM.addPass(
1080+
EmitSYCLNativeCPUHeaderPass(getNativeCPUHeaderName(LangOpts)));
1081+
MPM.addPass(PrepareSYCLNativeCPUPass());
1082+
}
10741083
}
10751084
}
10761085

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,16 +1121,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
11211121
Fn->setMetadata("loop_fuse",
11221122
llvm::MDNode::get(getLLVMContext(), AttrMDArgs));
11231123
}
1124-
if (const auto *A = D->getAttr<SYCLUsesAspectsAttr>()) {
1125-
SmallVector<llvm::Metadata *, 4> AspectsMD;
1126-
for (auto *Aspect : A->aspects()) {
1127-
llvm::APSInt AspectInt = Aspect->EvaluateKnownConstInt(getContext());
1128-
AspectsMD.push_back(llvm::ConstantAsMetadata::get(
1129-
Builder.getInt32(AspectInt.getZExtValue())));
1130-
}
1131-
Fn->setMetadata("sycl_used_aspects",
1132-
llvm::MDNode::get(getLLVMContext(), AspectsMD));
1133-
}
11341124

11351125
// Source location of functions is required to emit required diagnostics in
11361126
// SYCLPropagateAspectsUsagePass. Save the token in a srcloc metadata node.

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,10 @@ void CodeGenModule::Release() {
894894
getTarget().getTargetOpts().NVVMCudaPrecSqrt);
895895
}
896896

897+
if (LangOpts.SYCLIsDevice && LangOpts.SYCLIsNativeCPU) {
898+
getModule().addModuleFlag(llvm::Module::Error, "is-native-cpu", 1);
899+
}
900+
897901
if (LangOpts.EHAsynch)
898902
getModule().addModuleFlag(llvm::Module::Warning, "eh-asynch", 1);
899903

@@ -2111,6 +2115,10 @@ void CodeGenModule::GenKernelArgMetadata(llvm::Function *Fn,
21112115
Fn->setMetadata("kernel_arg_exclusive_ptr",
21122116
llvm::MDNode::get(VMContext, argSYCLAccessorPtrs));
21132117
}
2118+
if (LangOpts.SYCLIsNativeCPU) {
2119+
Fn->setMetadata("kernel_arg_type",
2120+
llvm::MDNode::get(VMContext, argTypeNames));
2121+
}
21142122
} else {
21152123
if (getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
21162124
Fn->setMetadata("kernel_arg_addr_space",
@@ -2640,6 +2648,19 @@ void CodeGenModule::finalizeKCFITypes() {
26402648
}
26412649
}
26422650

2651+
template <typename AttrT>
2652+
void applySYCLAspectsMD(AttrT *A, ASTContext &ACtx, llvm::LLVMContext &LLVMCtx,
2653+
llvm::Function *F, StringRef MDName) {
2654+
SmallVector<llvm::Metadata *, 4> AspectsMD;
2655+
for (auto *Aspect : A->aspects()) {
2656+
llvm::APSInt AspectInt = Aspect->EvaluateKnownConstInt(ACtx);
2657+
auto *T = llvm::Type::getInt32Ty(LLVMCtx);
2658+
auto *C = llvm::Constant::getIntegerValue(T, AspectInt);
2659+
AspectsMD.push_back(llvm::ConstantAsMetadata::get(C));
2660+
}
2661+
F->setMetadata(MDName, llvm::MDNode::get(LLVMCtx, AspectsMD));
2662+
}
2663+
26432664
void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
26442665
bool IsIncompleteFunction,
26452666
bool IsThunk) {
@@ -2747,6 +2768,15 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
27472768
CalleeIdx, PayloadIndices,
27482769
/* VarArgsArePassed */ false)}));
27492770
}
2771+
2772+
// Apply SYCL specific attributes/metadata.
2773+
if (const auto *A = FD->getAttr<SYCLDeviceHasAttr>())
2774+
applySYCLAspectsMD(A, getContext(), getLLVMContext(), F,
2775+
"sycl_declared_aspects");
2776+
2777+
if (const auto *A = FD->getAttr<SYCLUsesAspectsAttr>())
2778+
applySYCLAspectsMD(A, getContext(), getLLVMContext(), F,
2779+
"sycl_used_aspects");
27502780
}
27512781

27522782
void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
@@ -4565,20 +4595,8 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
45654595
}
45664596

45674597
assert(F->getName() == MangledName && "name was uniqued!");
4568-
if (D) {
4598+
if (D)
45694599
SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk);
4570-
if (const auto *A = D->getAttr<SYCLDeviceHasAttr>()) {
4571-
SmallVector<llvm::Metadata *, 4> AspectsMD;
4572-
for (auto *Aspect : A->aspects()) {
4573-
llvm::APSInt AspectInt = Aspect->EvaluateKnownConstInt(getContext());
4574-
auto *T = llvm::Type::getInt32Ty(getLLVMContext());
4575-
auto *C = llvm::Constant::getIntegerValue(T, AspectInt);
4576-
AspectsMD.push_back(llvm::ConstantAsMetadata::get(C));
4577-
}
4578-
F->setMetadata("sycl_declared_aspects",
4579-
llvm::MDNode::get(getLLVMContext(), AspectsMD));
4580-
}
4581-
}
45824600
if (ExtraAttrs.hasFnAttrs()) {
45834601
llvm::AttrBuilder B(F->getContext(), ExtraAttrs.getFnAttrs());
45844602
F->addFnAttrs(B);

clang/lib/Driver/Driver.cpp

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,18 +1160,23 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11601160
checkSingleArgValidity(DeviceCodeSplit,
11611161
{"per_kernel", "per_source", "auto", "off"});
11621162

1163+
bool IsSYCLNativeCPU = isSYCLNativeCPU(C.getInputArgs());
11631164
Arg *SYCLForceTarget =
11641165
getArgRequiringSYCLRuntime(options::OPT_fsycl_force_target_EQ);
11651166
if (SYCLForceTarget) {
11661167
StringRef Val(SYCLForceTarget->getValue());
11671168
llvm::Triple TT(MakeSYCLDeviceTriple(Val));
1168-
if (!isValidSYCLTriple(TT))
1169+
// Todo: we skip the check for the valid SYCL target, because currently
1170+
// setting native_cpu as a target overrides all the other targets,
1171+
// re-enable the check once native_cpu can coexist.
1172+
if (!IsSYCLNativeCPU && !isValidSYCLTriple(TT))
11691173
Diag(clang::diag::err_drv_invalid_sycl_target) << Val;
11701174
}
11711175
bool HasSYCLTargetsOption = SYCLTargets || SYCLLinkTargets || SYCLAddTargets;
1176+
11721177
llvm::StringMap<StringRef> FoundNormalizedTriples;
11731178
llvm::SmallVector<llvm::Triple, 4> UniqueSYCLTriplesVec;
1174-
if (HasSYCLTargetsOption) {
1179+
if (!IsSYCLNativeCPU && HasSYCLTargetsOption) {
11751180
// At this point, we know we have a valid combination
11761181
// of -fsycl*target options passed
11771182
Arg *SYCLTargetsValues = SYCLTargets ? SYCLTargets : SYCLLinkTargets;
@@ -1273,6 +1278,11 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
12731278
Diag(clang::diag::warn_drv_empty_joined_argument)
12741279
<< SYCLAddTargets->getAsString(C.getInputArgs());
12751280
}
1281+
} else if (IsSYCLNativeCPU) {
1282+
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
1283+
llvm::Triple HostTriple = HostTC->getTriple();
1284+
UniqueSYCLTriplesVec.push_back(HostTriple);
1285+
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec);
12761286
} else {
12771287
// If -fsycl is supplied without -fsycl-*targets we will assume SPIR-V
12781288
// unless -fintelfpga is supplied, which uses SPIR-V with fpga AOT.
@@ -5684,6 +5694,19 @@ class OffloadingActionBuilder final {
56845694
} else
56855695
FullDeviceLinkAction = FullLinkObject;
56865696

5697+
bool IsSYCLNativeCPU = isSYCLNativeCPU(Args);
5698+
if (IsSYCLNativeCPU) {
5699+
// for SYCL Native CPU, we just take the linked device
5700+
// modules, lower them to an object file , and link it to the host
5701+
// object file.
5702+
auto *backendAct = C.MakeAction<BackendJobAction>(
5703+
FullDeviceLinkAction, types::TY_PP_Asm);
5704+
auto *asmAct =
5705+
C.MakeAction<AssembleJobAction>(backendAct, types::TY_Object);
5706+
DA.add(*asmAct, *TC, BoundArch, Action::OFK_SYCL);
5707+
return;
5708+
}
5709+
56875710
// reflects whether current target is ahead-of-time and can't
56885711
// support runtime setting of specialization constants
56895712
bool isAOT = isNVPTX || isAMDGCN || isSpirvAOT;
@@ -6062,7 +6085,17 @@ class OffloadingActionBuilder final {
60626085
bool GpuInitHasErrors = false;
60636086
bool HasSYCLTargetsOption =
60646087
SYCLAddTargets || SYCLTargets || SYCLLinkTargets;
6065-
if (HasSYCLTargetsOption) {
6088+
bool IsSYCLNativeCPU = isSYCLNativeCPU(C.getInputArgs());
6089+
6090+
// check if multiple targets are passed along with native_cpu:
6091+
// currently native_cpu overrides all the other targets, so we emit a
6092+
// warning
6093+
if (IsSYCLNativeCPU) {
6094+
auto *SYCLTargets = Args.getLastArg(options::OPT_fsycl_targets_EQ);
6095+
if (SYCLTargets->getNumValues() > 1)
6096+
C.getDriver().Diag(clang::diag::warn_drv_sycl_native_cpu_and_targets);
6097+
}
6098+
if (!IsSYCLNativeCPU && HasSYCLTargetsOption) {
60666099
if (SYCLTargets || SYCLLinkTargets) {
60676100
Arg *SYCLTargetsValues = SYCLTargets ? SYCLTargets : SYCLLinkTargets;
60686101
// Fill SYCLTripleList
@@ -6182,6 +6215,14 @@ class OffloadingActionBuilder final {
61826215
GpuArchList.emplace_back(TT, nullptr);
61836216
}
61846217
}
6218+
} else if (IsSYCLNativeCPU) {
6219+
const ToolChain *HostTC =
6220+
C.getSingleOffloadToolChain<Action::OFK_Host>();
6221+
llvm::Triple TT = HostTC->getTriple();
6222+
auto TCIt = llvm::find_if(
6223+
ToolChains, [&](auto &TC) { return TT == TC->getTriple(); });
6224+
SYCLTripleList.push_back(TT);
6225+
SYCLTargetInfoList.emplace_back(*TCIt, nullptr);
61856226
} else if (HasValidSYCLRuntime) {
61866227
// -fsycl is provided without -fsycl-*targets.
61876228
bool SYCLfpga = C.getInputArgs().hasArg(options::OPT_fintelfpga);
@@ -9704,6 +9745,10 @@ const ToolChain &Driver::getOffloadingDeviceToolChain(const ArgList &Args,
97049745
*this, Target, HostTC, Args, TargetDeviceOffloadKind);
97059746
break;
97069747
default:
9748+
if (isSYCLNativeCPU(Args)) {
9749+
TC = std::make_unique<toolchains::SYCLToolChain>(*this, Target,
9750+
HostTC, Args);
9751+
}
97079752
break;
97089753
}
97099754
break;

0 commit comments

Comments
 (0)