Skip to content

Commit

Permalink
Merge remote-tracking branch 'intel/sycl' into steffen/enable_threadi…
Browse files Browse the repository at this point in the history
…ng_windows
  • Loading branch information
steffenlarsen committed Oct 14, 2024
2 parents 97e8f3a + a5161f2 commit a25c96a
Show file tree
Hide file tree
Showing 469 changed files with 6,898 additions and 2,930 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/sycl-linux-precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ jobs:
env: ${{ matrix.env || '{}' }}

# Do not install drivers on AMD and CUDA runners.
install_igc_driver: |
install_igc_driver: >-
${{ !contains(matrix.target_devices, 'ext_oneapi_cuda') &&
!contains(matrix.target_devices, 'ext_oneapi_hip') &&
contains(needs.detect_changes.outputs.filters, 'drivers') }}
install_dev_igc_driver: |
install_dev_igc_driver: >-
${{ !contains(matrix.target_devices, 'ext_oneapi_cuda') &&
!contains(matrix.target_devices, 'ext_oneapi_hip') &&
matrix.use_igc_dev && contains(needs.detect_changes.outputs.filters, 'devigccfg') ||
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sycl-linux-run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ permissions:

jobs:
run:
if: inputs.skip_run == 'false'
if: github.event_name == 'workflow_dispatch' || inputs.skip_run == 'false'
name: ${{ inputs.name }}
runs-on: ${{ fromJSON(inputs.runner) }}
container:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/sycl-windows-run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ jobs:
# Run E2E tests.
export LIT_OPTS="-v --no-progress-bar --show-unsupported --show-pass --show-xfail --max-time 3600 --time-tests ${{ inputs.extra_lit_opts }}"
cmake --build build-e2e --target check-sycl-e2e
- name: Detect hung tests
shell: powershell
run: |
$exitCode = 0
$hungTests = Get-Process | Where-Object { ($_.Path -match "llvm\\install") -or ($_.Path -match "llvm\\build-e2e") }
$hungTests | Foreach-Object {
$exitCode = 1
echo "Test $($_.Path) hung!"
Stop-Process -Force $_
}
exit $exitCode
- name: Cleanup
shell: cmd
if: always()
Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/Basic/LangOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ LANGOPT(SYCLAllowFuncPtr , 1, 0, "Allow function pointers in SYCL device code")
LANGOPT(SYCLStdLayoutKernelParams, 1, 0, "Enable standard layout requirement for SYCL kernel parameters")
LANGOPT(SYCLUnnamedLambda , 1, 0, "Allow unnamed lambda SYCL kernels")
LANGOPT(SYCLForceInlineKernelLambda , 1, 0, "Force inline SYCL kernel lambdas in entry point")
LANGOPT(SYCLAllowAllFeaturesInConstexpr, 1, 0, "Allow all C++ features in SYCL device code in manifestly constant-evaluated expressions")
LANGOPT(SYCLESIMDForceStatelessMem, 1, 0, "Make accessors use USM memory in ESIMD kernels")
LANGOPT(SYCLESIMDBuildHostCode, 1, 1, "Build the host implementation of ESIMD functions")
ENUM_LANGOPT(SYCLVersion , SYCLMajorVersion, 2, SYCL_None, "Version of the SYCL standard used")
Expand Down
5 changes: 0 additions & 5 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -8628,11 +8628,6 @@ def fsycl_is_native_cpu : Flag<["-"], "fsycl-is-native-cpu">,
HelpText<"Perform device compilation for Native CPU.">,
Visibility<[CC1Option]>,
MarshallingInfoFlag<LangOpts<"SYCLIsNativeCPU">>;
defm sycl_allow_all_features_in_constexpr
: BoolFOption<
"sycl-allow-all-features-in-constexpr", LangOpts<"SYCLAllowAllFeaturesInConstexpr">,
DefaultFalse,
PosFlag<SetTrue, [], [CC1Option], "Allow all C++ features in SYCL device code in manifestly constant-evaluated expressions">, NegFlag<SetFalse>>;

} // let Visibility = [CC1Option]

Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,10 @@ class ToolChain {
virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;

/// Add arguments to use SYCL specific includes.
virtual void AddSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;

/// Add arguments to use MCU GCC toolchain includes.
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
Expand Down
39 changes: 28 additions & 11 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6786,13 +6786,10 @@ class OffloadingActionBuilder final {
// Do not use unbundler if the Host does not depend on device action.
// Now that we have unbundled the object, when doing -fsycl-link we
// want to continue the host link with the input object.
// For unbundling of an FPGA AOCX binary, we want to link with the original
// FPGA device archive.
if ((OffloadKind == Action::OFK_None && CanUseBundler) ||
(Args.hasArg(options::OPT_fsycl_link_EQ) && !HasFPGATarget) ||
(HasFPGATarget && ((Args.hasArg(options::OPT_fsycl_link_EQ) &&
HostAction->getType() == types::TY_Object) ||
HostAction->getType() == types::TY_FPGA_AOCX)))
HostAction->getType() == types::TY_Object))))
if (auto *UA = dyn_cast<OffloadUnbundlingJobAction>(HostAction))
HostAction = UA->getInputs().back();

Expand Down Expand Up @@ -7443,16 +7440,36 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,

// For an FPGA archive, we add the unbundling step above to take care of
// the device side, but also unbundle here to extract the host side
bool EarlyLink = false;
if (const Arg *A = Args.getLastArg(options::OPT_fsycl_link_EQ))
EarlyLink = A->getValue() == StringRef("early");
for (auto &LI : LinkerInputs) {
Action *UnbundlerInput = nullptr;
auto wrapObject = [&] {
if (EarlyLink && Args.hasArg(options::OPT_fintelfpga)) {
// Only wrap the object with -fsycl-link=early
auto *BC = C.MakeAction<OffloadWrapperJobAction>(LI, types::TY_LLVM_BC);
auto *ASM = C.MakeAction<BackendJobAction>(BC, types::TY_PP_Asm);
if (Args.hasArg(options::OPT_fsycl_link_EQ) &&
Args.hasArg(options::OPT_fintelfpga)) {
// Wrap the object when creating an FPGA AOCX or AOCR binary.
// When the input file is an AOCR (early) archive, the unbundled host
// binary consists of a list of objects. We cannot directly wrap that
// binary to be consumed later - this has to go through each listed
// object.
bool FPGAEarly = true;
if (auto *A = C.getInputArgs().getLastArg(options::OPT_fsycl_link_EQ))
FPGAEarly = A->getValue() == StringRef("early");

Action *WrapperAction;
if ((LI->getType() == types::TY_FPGA_AOCR ||
LI->getType() == types::TY_FPGA_AOCR_EMU) &&
!FPGAEarly) {
auto *RenameAction = C.MakeAction<FileTableTformJobAction>(
LI, types::TY_Tempfilelist, types::TY_Tempfilelist);
RenameAction->addRenameColumnTform(FileTableTformJobAction::COL_ZERO,
FileTableTformJobAction::COL_CODE);
ActionList WrapperItems({RenameAction});
WrapperAction = C.MakeAction<OffloadWrapperJobAction>(
WrapperItems, types::TY_LLVM_BC);
} else
WrapperAction =
C.MakeAction<OffloadWrapperJobAction>(LI, types::TY_LLVM_BC);
auto *ASM =
C.MakeAction<BackendJobAction>(WrapperAction, types::TY_PP_Asm);
auto *OBJ = C.MakeAction<AssembleJobAction>(ASM, types::TY_Object);
OffloadAction::HostDependence HDep(
*OBJ, *C.getSingleOffloadToolChain<Action::OFK_Host>(),
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,9 @@ void ToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
void ToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {}

void ToolChain::AddSYCLIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {}

llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12>
ToolChain::getDeviceLibs(
const ArgList &DriverArgs,
Expand Down
11 changes: 8 additions & 3 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
getToolChain().AddHIPIncludeArgs(Args, CmdArgs);

if (JA.isOffloading(Action::OFK_SYCL)) {
toolchains::SYCLToolChain::AddSYCLIncludeArgs(D, Args, CmdArgs);
getToolChain().AddSYCLIncludeArgs(Args, CmdArgs);
if (Inputs[0].getType() == types::TY_CUDA) {
// Include __clang_cuda_runtime_wrapper.h in .cu SYCL compilation.
getToolChain().AddCudaIncludeArgs(Args, CmdArgs);
Expand Down Expand Up @@ -10216,7 +10216,7 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,

if (I.getType() == types::TY_Tempfiletable ||
I.getType() == types::TY_Tempfilelist || IsEmbeddedIR)
// wrapper actual input files are passed via the batch job file table:
// Input files are passed via the batch job file table.
WrapperArgs.push_back(C.getArgs().MakeArgString("-batch"));
WrapperArgs.push_back(C.getArgs().MakeArgString(I.getFilename()));

Expand Down Expand Up @@ -10283,6 +10283,11 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(
TCArgs.MakeArgString(Twine("-target=") + Triple.getTriple()));

if (Inputs[0].getType() == types::TY_Tempfiletable ||
Inputs[0].getType() == types::TY_Tempfilelist)
// Input files are passed via the batch job file table.
CmdArgs.push_back(C.getArgs().MakeArgString("-batch"));

// Add input.
assert(Inputs[0].isFilename() && "Invalid input.");
CmdArgs.push_back(TCArgs.MakeArgString(Inputs[0].getFilename()));
Expand Down Expand Up @@ -10320,7 +10325,7 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,

if (Inputs[I].getType() == types::TY_Tempfiletable ||
Inputs[I].getType() == types::TY_Tempfilelist)
// wrapper actual input files are passed via the batch job file table:
// Input files are passed via the batch job file table.
CmdArgs.push_back(C.getArgs().MakeArgString("-batch"));

// Add input.
Expand Down
17 changes: 12 additions & 5 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
const ToolChain &HostTC, const ArgList &Args,
const Action::OffloadKind OK)
: NVPTXToolChain(D, Triple, HostTC.getTriple(), Args), HostTC(HostTC),
OK(OK) {}
SYCLInstallation(D), OK(OK) {}

void CudaToolChain::addClangTargetOptions(
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
Expand All @@ -941,11 +941,19 @@ void CudaToolChain::addClangTargetOptions(
// If we are compiling SYCL kernels for Nvidia GPUs, we do not support Cuda
// device code compatability, hence we do not set Cuda mode in that instance.
if (DeviceOffloadingKind == Action::OFK_SYCL) {
toolchains::SYCLToolChain::AddSYCLIncludeArgs(getDriver(), DriverArgs,
CC1Args);
SYCLInstallation.AddSYCLIncludeArgs(DriverArgs, CC1Args);

if (DriverArgs.hasArg(options::OPT_fsycl_fp32_prec_sqrt))
CC1Args.push_back("-fcuda-prec-sqrt");

bool FastRelaxedMath = DriverArgs.hasFlag(
options::OPT_ffast_math, options::OPT_fno_fast_math, false);
bool UnsafeMathOpt =
DriverArgs.hasFlag(options::OPT_funsafe_math_optimizations,
options::OPT_fno_unsafe_math_optimizations, false);
if (FastRelaxedMath || UnsafeMathOpt)
CC1Args.append({"-mllvm", "--nvptx-prec-divf32=0", "-mllvm",
"--nvptx-prec-sqrtf32=0"});
} else {
CC1Args.append(
{"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
Expand Down Expand Up @@ -1196,8 +1204,7 @@ CudaToolChain::GetCXXStdlibType(const ArgList &Args) const {
void CudaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_fsycl)) {
toolchains::SYCLToolChain::AddSYCLIncludeArgs(getDriver(), DriverArgs,
CC1Args);
SYCLInstallation.AddSYCLIncludeArgs(DriverArgs, CC1Args);
}
HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);

Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ class LLVM_LIBRARY_VISIBILITY CudaToolChain : public NVPTXToolChain {
Tool *SelectTool(const JobAction &JA) const override;
const ToolChain &HostTC;

SYCLInstallationDetector SYCLInstallation;

protected:
Tool *buildAssembler() const override; // ptxas
Tool *buildLinker() const override; // fatbinary (ok, not really a linker)
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3190,7 +3190,8 @@ bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: ToolChain(D, Triple, Args), GCCInstallation(D),
CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args) {
CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args),
SYCLInstallation(D) {
getProgramPaths().push_back(getDriver().Dir);
}

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains/Gnu.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
GCCInstallationDetector GCCInstallation;
LazyDetector<CudaInstallationDetector> CudaInstallation;
LazyDetector<RocmInstallationDetector> RocmInstallation;
SYCLInstallationDetector SYCLInstallation;

public:
Generic_GCC(const Driver &D, const llvm::Triple &Triple,
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Driver/ToolChains/HIPAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ void AMDGCN::Linker::ConstructJob(Compilation &C, const JobAction &JA,
HIPAMDToolChain::HIPAMDToolChain(const Driver &D, const llvm::Triple &Triple,
const ToolChain &HostTC, const ArgList &Args,
const Action::OffloadKind OK)
: ROCMToolChain(D, Triple, Args), HostTC(HostTC), OK(OK) {
: ROCMToolChain(D, Triple, Args), HostTC(HostTC), SYCLInstallation(D),
OK(OK) {
// Lookup binaries into the driver directory, this is used to
// discover the clang-offload-bundler executable.
getProgramPaths().push_back(getDriver().Dir);
Expand Down Expand Up @@ -318,8 +319,7 @@ void HIPAMDToolChain::addClangTargetOptions(
CC1Args.push_back("-fembed-bitcode=marker");

if (DeviceOffloadingKind == Action::OFK_SYCL) {
toolchains::SYCLToolChain::AddSYCLIncludeArgs(getDriver(), DriverArgs,
CC1Args);
SYCLInstallation.AddSYCLIncludeArgs(DriverArgs, CC1Args);
}

auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/HIPAMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class LLVM_LIBRARY_VISIBILITY HIPAMDToolChain final : public ROCMToolChain {
void checkTargetID(const llvm::opt::ArgList &DriverArgs) const override;
Tool *SelectTool(const JobAction &JA) const override;

SYCLInstallationDetector SYCLInstallation;

protected:
Tool *buildLinker() const override;

Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/Linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
}
}

void Linux::AddSYCLIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
SYCLInstallation.AddSYCLIncludeArgs(DriverArgs, CC1Args);
}

bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const {
return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() ||
getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE();
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
llvm::opt::ArgStringList &CmdArgs) const override;
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
void AddSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
RuntimeLibType GetDefaultRuntimeLibType() const override;
unsigned GetDefaultDwarfVersion() const override;
CXXStdlibType GetDefaultCXXStdlibType() const override;
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Driver/ToolChains/MSVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args),
RocmInstallation(D, Triple, Args) {
RocmInstallation(D, Triple, Args), SYCLInstallation(D) {
getProgramPaths().push_back(getDriver().Dir);

std::optional<llvm::StringRef> VCToolsDir, VCToolsVersion;
Expand Down Expand Up @@ -586,6 +586,11 @@ void MSVCToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
}

void MSVCToolChain::AddSYCLIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
SYCLInstallation.AddSYCLIncludeArgs(DriverArgs, CC1Args);
}

void MSVCToolChain::AddHIPRuntimeLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
CmdArgs.append({Args.MakeArgString(StringRef("-libpath:") +
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/MSVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
void AddHIPRuntimeLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;

void AddSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;

bool getWindowsSDKLibraryPath(
const llvm::opt::ArgList &Args, std::string &path) const;
bool getUniversalCRTLibraryPath(const llvm::opt::ArgList &Args,
Expand Down Expand Up @@ -144,6 +147,7 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
llvm::ToolsetLayout VSLayout = llvm::ToolsetLayout::OlderVS;
LazyDetector<CudaInstallationDetector> CudaInstallation;
LazyDetector<RocmInstallationDetector> RocmInstallation;
SYCLInstallationDetector SYCLInstallation;
};

} // end namespace toolchains
Expand Down
Loading

0 comments on commit a25c96a

Please sign in to comment.