Skip to content

Commit

Permalink
Merge branch 'sycl' into test-ur-hip-context-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JackAKirk committed Sep 20, 2024
2 parents 5909eaf + 2c9d980 commit 6b1bec0
Show file tree
Hide file tree
Showing 143 changed files with 2,807 additions and 1,245 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/sycl-linux-precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ jobs:
image_options: -u 1001 --device=/dev/dri --privileged --cap-add SYS_ADMIN
target_devices: level_zero:gpu;opencl:gpu;opencl:cpu
reset_intel_gpu: true
install_drivers: ${{ contains(needs.detect_changes.outputs.filters, 'drivers') }}
extra_lit_opts: --param gpu-intel-gen12=True
- name: E2E tests on Intel Arc A-Series Graphics
runner: '["Linux", "arc"]'
image: ghcr.io/intel/llvm/ubuntu2204_intel_drivers:latest
image_options: -u 1001 --device=/dev/dri --privileged --cap-add SYS_ADMIN
target_devices: level_zero:gpu;opencl:gpu
reset_intel_gpu: true
install_drivers: ${{ contains(needs.detect_changes.outputs.filters, 'drivers') }}
extra_lit_opts: --param matrix-xmx8=True --param gpu-intel-dg2=True
env: '{"LIT_FILTER":${{ needs.determine_arc_tests.outputs.arc_tests }} }'
- name: E2E tests with dev igc on Intel Arc A-Series Graphics
Expand All @@ -103,14 +101,9 @@ jobs:
image_options: -u 1001 --device=/dev/dri --privileged --cap-add SYS_ADMIN
target_devices: level_zero:gpu;opencl:gpu
reset_intel_gpu: true
install_drivers: >-
${{ contains(needs.detect_changes.outputs.filters, 'drivers') ||
contains(needs.detect_changes.outputs.filters, 'devigccfg') }}
use_dev_igc: ${{ contains(needs.detect_changes.outputs.filters, 'devigccfg') }}
extra_lit_opts: --param matrix-xmx8=True --param gpu-intel-dg2=True
env: '{"LIT_FILTER":${{ needs.determine_arc_tests.outputs.arc_tests }} }'
# Run only if the PR does not have the 'ci-no-devigc' label.
skip_run: ${{ contains(github.event.pull_request.labels.*.name, 'ci-no-devigc') }}
use_igc_dev: true

uses: ./.github/workflows/sycl-linux-run-tests.yml
with:
Expand All @@ -120,11 +113,13 @@ jobs:
image_options: ${{ matrix.image_options }}
target_devices: ${{ matrix.target_devices }}
reset_intel_gpu: ${{ matrix.reset_intel_gpu }}
install_drivers: ${{ matrix.install_drivers }}
use_dev_igc: ${{ matrix.use_dev_igc }}
extra_lit_opts: ${{ matrix.extra_lit_opts }}
env: ${{ matrix.env || '{}' }}
skip_run: ${{ matrix.skip_run || 'false' }}

install_igc_driver: ${{ contains(needs.detect_changes.outputs.filters, 'drivers') }}
install_dev_igc_driver: ${{ matrix.use_igc_dev && contains(needs.detect_changes.outputs.filters, 'devigccfg') || 'false' }}
# Run only if the PR does not have the 'ci-no-devigc' label.
skip_run: ${{matrix.use_igc_dev && contains(github.event.pull_request.labels.*.name, 'ci-no-devigc') || 'false'}}

ref: ${{ github.sha }}
merge_ref: ''
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/sycl-linux-run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ on:
reset_intel_gpu:
type: string
required: False
install_drivers:
install_igc_driver:
type: string
required: False
use_dev_igc:
install_dev_igc_driver:
type: string
required: False
env:
Expand Down Expand Up @@ -134,13 +134,13 @@ on:
Extra options to be added to LIT_OPTS.
default: ''

install_drivers:
install_igc_driver:
type: choice
options:
- false
- true

use_dev_igc:
install_dev_igc_driver:
type: choice
options:
- false
Expand Down Expand Up @@ -193,15 +193,15 @@ jobs:
run: |
git -C khronos_sycl_cts submodule update --init
- name: Install drivers
if: inputs.install_drivers == 'true'
if: inputs.install_igc_driver == 'true' || inputs.install_dev_igc_driver == 'true'
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
if [ "${{ inputs.use_dev_igc }}" = "true" ]; then
if [ "${{ inputs.install_dev_igc_driver }}" = "true" ]; then
# If libllvm14 is already installed (dev igc docker), still return true.
sudo apt-get install -yqq libllvm14 || true;
fi
sudo -E bash devops/scripts/install_drivers.sh llvm/devops/dependencies.json ${{ inputs.use_dev_igc == 'true' && 'llvm/devops/dependencies-igc-dev.json --use-dev-igc' || '' }} --all
sudo -E bash devops/scripts/install_drivers.sh llvm/devops/dependencies.json ${{ inputs.install_dev_igc_driver == 'true' && 'llvm/devops/dependencies-igc-dev.json --use-dev-igc' || '' }} --all
- name: Source OneAPI TBB vars.sh
shell: bash
run: |
Expand Down
67 changes: 27 additions & 40 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5564,7 +5564,7 @@ class OffloadingActionBuilder final {
SYCLDeviceLibLinked = addSYCLDeviceLibs(
TC, SYCLDeviceLibs, UseAOTLink,
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(),
IsSYCLNativeCPU, NativeCPULib);
IsSYCLNativeCPU, NativeCPULib, BoundArch);
}
JobAction *LinkSYCLLibs =
C.MakeAction<LinkJobAction>(SYCLDeviceLibs, types::TY_LLVM_BC);
Expand Down Expand Up @@ -5842,7 +5842,7 @@ class OffloadingActionBuilder final {

bool addSYCLDeviceLibs(const ToolChain *TC, ActionList &DeviceLinkObjects,
bool isSpirvAOT, bool isMSVCEnv, bool isNativeCPU,
Action *&NativeCPULib) {
Action *&NativeCPULib, const char *BoundArch) {
int NumOfDeviceLibLinked = 0;
SmallVector<SmallString<128>, 4> LibLocCandidates;
SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates);
Expand All @@ -5852,14 +5852,10 @@ class OffloadingActionBuilder final {
tools::SYCL::getDeviceLibraries(C, TC->getTriple(), isSpirvAOT);

for (const auto &DeviceLib : DeviceLibraries) {
bool LibLocSelected = false;
for (const auto &LLCandidate : LibLocCandidates) {
if (LibLocSelected)
break;
SmallString<128> LibName(LLCandidate);
llvm::sys::path::append(LibName, DeviceLib);
if (llvm::sys::fs::exists(LibName)) {

// NativeCPU currently only needs libsycl-nativecpu_utils and
// libclc, so temporarily skip other device libs in invocation.
// Todo: remove once NativeCPU tests the other libraries.
Expand Down Expand Up @@ -5897,8 +5893,6 @@ class OffloadingActionBuilder final {
C.MakeAction<InputAction>(*InputArg, types::TY_LLVM_BC);
DeviceLinkObjects.push_back(SYCLDeviceLibsInputAction);
}
if (!LibLocSelected)
LibLocSelected = !LibLocSelected;

// The device link stage may remove symbols not referenced in the
// source code. Since libsycl-nativecpu_utils contains such symbols
Expand All @@ -5909,22 +5903,26 @@ class OffloadingActionBuilder final {
NativeCPULib = DeviceLinkObjects.back();
DeviceLinkObjects.pop_back();
}

break;
}
}
}

// For NVPTX backend we need to also link libclc and CUDA libdevice
// at the same stage that we link all of the unbundled SYCL libdevice
// objects together.
if ((TC->getTriple().isNVPTX() || isNativeCPU) && NumOfDeviceLibLinked) {
if (!NumOfDeviceLibLinked)
return false;

// For NVPTX and NativeCPU we need to also link libclc at the same stage
// that we link all of the unbundled SYCL libdevice objects together.
if (TC->getTriple().isNVPTX() || isNativeCPU) {
std::string LibSpirvFile;
if (Args.hasArg(options::OPT_fsycl_libspirv_path_EQ)) {
auto ProvidedPath =
Args.getLastArgValue(options::OPT_fsycl_libspirv_path_EQ).str();
if (llvm::sys::fs::exists(ProvidedPath))
LibSpirvFile = ProvidedPath;
} else {
SmallVector<StringRef, 8> LibraryPaths;
SmallVector<StringRef, 2> LibraryPaths;

// Expected path w/out install.
SmallString<256> WithoutInstallPath(C.getDriver().ResourceDir);
Expand All @@ -5936,22 +5934,17 @@ class OffloadingActionBuilder final {
llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc"));
LibraryPaths.emplace_back(WithInstallPath.c_str());

// TODO: check if the isNVPTX() path can also use
// TC->getTripleString() so that the conditional could be removed
const std::string TrStr =
isNativeCPU ? TC->getTripleString() : "nvptx64-nvidia-cuda";

// Select remangled libclc variant
StringRef LibSpirvTargetNamePref =
TC->getAuxTriple()->isOSWindows()
? "remangled-l32-signed_char.libspirv-"
: "remangled-l64-signed_char.libspirv-";
llvm::Twine LibSpirvTargetNameTemp = LibSpirvTargetNamePref + TrStr;
llvm::Twine LibSpirvTargetName = LibSpirvTargetNameTemp + ".bc";

for (StringRef LibraryPath : LibraryPaths) {
SmallString<128> LibSpirvTargetFile(LibraryPath);
llvm::sys::path::append(LibSpirvTargetFile, LibSpirvTargetName);
llvm::sys::path::append(LibSpirvTargetFile,
LibSpirvTargetNamePref +
TC->getTripleString() + ".bc");
if (llvm::sys::fs::exists(LibSpirvTargetFile) ||
Args.hasArg(options::OPT__HASH_HASH_HASH)) {
LibSpirvFile = std::string(LibSpirvTargetFile.str());
Expand All @@ -5966,30 +5959,24 @@ class OffloadingActionBuilder final {
C.MakeAction<InputAction>(*LibClcInputArg, types::TY_LLVM_BC);
DeviceLinkObjects.push_back(SYCLLibClcInputAction);
}
}

if (isNativeCPU) {
// return here to not generate cuda actions
return NumOfDeviceLibLinked != 0;
}

// For NVPTX we also need to link with the CUDA libdevice
if (TC->getTriple().isNVPTX() && !Args.hasArg(options::OPT_nogpulib)) {
const toolchains::CudaToolChain *CudaTC =
static_cast<const toolchains::CudaToolChain *>(TC);
for (const auto &LinkInputEnum : enumerate(DeviceLinkerInputs)) {
const char *BoundArch =
SYCLTargetInfoList[LinkInputEnum.index()].BoundArch;
std::string LibDeviceFile =
CudaTC->CudaInstallation.getLibDeviceFile(BoundArch);
if (!LibDeviceFile.empty()) {
Arg *CudaDeviceLibInputArg =
MakeInputArg(Args, C.getDriver().getOpts(),
Args.MakeArgString(LibDeviceFile));
auto *SYCLDeviceLibInputAction = C.MakeAction<InputAction>(
*CudaDeviceLibInputArg, types::TY_LLVM_BC);
DeviceLinkObjects.push_back(SYCLDeviceLibInputAction);
}
std::string LibDeviceFile =
CudaTC->CudaInstallation.getLibDeviceFile(BoundArch);
if (!LibDeviceFile.empty()) {
Arg *CudaDeviceLibInputArg = MakeInputArg(
Args, C.getDriver().getOpts(), Args.MakeArgString(LibDeviceFile));
auto *SYCLDeviceLibInputAction = C.MakeAction<InputAction>(
*CudaDeviceLibInputArg, types::TY_LLVM_BC);
DeviceLinkObjects.push_back(SYCLDeviceLibInputAction);
}
}
return NumOfDeviceLibLinked != 0;

return true;
}

void appendLinkDependences(OffloadAction::DeviceDependences &DA) override {
Expand Down
34 changes: 18 additions & 16 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10115,12 +10115,12 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
ArgStringList WrapperArgs;

const auto &WrapperJob = *llvm::dyn_cast<OffloadWrapperJobAction>(&JA);
bool LlcCompileEnabled = WrapperJob.getCompileStep();
bool WrapperCompileEnabled = WrapperJob.getCompileStep();
SmallString<128> OutOpt("-o=");
std::string OutTmpName = C.getDriver().GetTemporaryPath("wrapper", "bc");
const char *WrapperFileName =
C.addTempFile(C.getArgs().MakeArgString(OutTmpName));
OutOpt += LlcCompileEnabled ? WrapperFileName : Output.getFilename();
OutOpt += WrapperCompileEnabled ? WrapperFileName : Output.getFilename();
WrapperArgs.push_back(C.getArgs().MakeArgString(OutOpt));

SmallString<128> HostTripleOpt("-host=");
Expand Down Expand Up @@ -10218,28 +10218,30 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
WrapperArgs, std::nullopt);
C.addCommand(std::move(Cmd));

if (LlcCompileEnabled) {
// Construct llc command.
// The output is an object file
ArgStringList LlcArgs{"-filetype=obj", "-o", Output.getFilename(),
WrapperFileName};
if (WrapperCompileEnabled) {
// TODO Use TC.SelectTool().
ArgStringList ClangArgs{
TCArgs.MakeArgString("--target=" + TC.getAuxTriple()->str()), "-c",
"-o", Output.getFilename(), WrapperFileName};
llvm::Reloc::Model RelocationModel;
unsigned PICLevel;
bool IsPIE;
std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(getToolChain(), TCArgs);
if (PICLevel > 0 || TCArgs.hasArg(options::OPT_shared)) {
LlcArgs.push_back("-relocation-model=pic");
if (!TC.getAuxTriple()->isOSWindows())
ClangArgs.push_back("-fPIC");
}
if (Arg *A = C.getArgs().getLastArg(options::OPT_mcmodel_EQ))
LlcArgs.push_back(
TCArgs.MakeArgString(Twine("--code-model=") + A->getValue()));

SmallString<128> LlcPath(C.getDriver().Dir);
llvm::sys::path::append(LlcPath, "llc");
const char *Llc = C.getArgs().MakeArgString(LlcPath);
C.addCommand(std::make_unique<Command>(
JA, *this, ResponseFileSupport::None(), Llc, LlcArgs, std::nullopt));
ClangArgs.push_back(
TCArgs.MakeArgString(Twine("-mcmodel=") + A->getValue()));

SmallString<128> ClangPath(C.getDriver().Dir);
llvm::sys::path::append(ClangPath, "clang");
const char *Clang = C.getArgs().MakeArgString(ClangPath);
C.addCommand(std::make_unique<Command>(JA, *this,
ResponseFileSupport::None(), Clang,
ClangArgs, std::nullopt));
}
return;
} // end of SYCL flavor of offload wrapper command creation
Expand Down
15 changes: 0 additions & 15 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,21 +713,6 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
return OutputFileName;
}

void SYCL::Linker::constructLlcCommand(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const char *InputFileName) const {
// Construct llc command.
// The output is an object file.
ArgStringList LlcArgs{"-filetype=obj", "-o", Output.getFilename(),
InputFileName};
SmallString<128> LlcPath(C.getDriver().Dir);
llvm::sys::path::append(LlcPath, "llc");
const char *Llc = C.getArgs().MakeArgString(LlcPath);
C.addCommand(std::make_unique<Command>(JA, *this,
ResponseFileSupport::AtFileUTF8(), Llc,
LlcArgs, std::nullopt));
}

// For SYCL the inputs of the linker job are SPIR-V binaries and output is
// a single SPIR-V binary. Input can also be bitcode when specified by
// the user.
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Driver/ToolChains/SYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
llvm::StringRef SubArchName,
llvm::StringRef OutputFilePrefix,
const InputInfoList &InputFiles) const;
void constructLlcCommand(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const char *InputFile) const;
};

/// Directly call FPGA Compiler and Linker
Expand Down
10 changes: 5 additions & 5 deletions clang/test/Driver/linker-wrapper-sycl-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// CHK-CMDS-NEXT: "{{.*}}sycl-post-link.exe"{{.*}} SYCL_POST_LINK_OPTIONS -o [[SYCLPOSTLINKOUT:.*]].table [[SECONDLLVMLINKOUT]].bc
// CHK-CMDS-NEXT: "{{.*}}llvm-spirv.exe"{{.*}} LLVM_SPIRV_OPTIONS -o {{.*}}
// CHK-CMDS-NEXT: offload-wrapper: input: {{.*}}, output: [[WRAPPEROUT:.*]].bc
// CHK-CMDS-NEXT: "{{.*}}llc.exe" -filetype=obj -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-NEXT: "{{.*}}clang.exe"{{.*}} -c -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-NEXT: "{{.*}}/ld" -- HOST_LINKER_FLAGS -dynamic-linker HOST_DYN_LIB -o a.out [[LLCOUT]].o HOST_LIB_PATH HOST_STAT_LIB {{.*}}.o

/// Check for list of commands for standalone clang-linker-wrapper run for sycl (AOT for Intel GPU)
Expand All @@ -44,7 +44,7 @@
// CHK-CMDS-AOT-GEN-NEXT: "{{.*}}llvm-spirv.exe"{{.*}} LLVM_SPIRV_OPTIONS -o {{.*}}
// CHK-CMDS-AOT-GEN-NEXT: "{{.*}}ocloc{{.*}} -output_no_suffix -spirv_input -device pvc -output {{.*}} -file {{.*}}
// CHK-CMDS-AOT-GEN-NEXT: offload-wrapper: input: {{.*}}, output: [[WRAPPEROUT:.*]].bc
// CHK-CMDS-AOT-GEN-NEXT: "{{.*}}llc.exe" -filetype=obj -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-AOT-GEN-NEXT: "{{.*}}clang.exe"{{.*}} -c -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-AOT-GEN-NEXT: "{{.*}}/ld" -- HOST_LINKER_FLAGS -dynamic-linker HOST_DYN_LIB -o a.out [[LLCOUT]].o HOST_LIB_PATH HOST_STAT_LIB {{.*}}.o

/// Check for list of commands for standalone clang-linker-wrapper run for sycl (AOT for Intel CPU)
Expand All @@ -68,7 +68,7 @@
// CHK-CMDS-AOT-CPU-NEXT: "{{.*}}llvm-spirv.exe"{{.*}} LLVM_SPIRV_OPTIONS -o {{.*}}
// CHK-CMDS-AOT-CPU-NEXT: "{{.*}}opencl-aot.exe"{{.*}} --device=cpu -o {{.*}}
// CHK-CMDS-AOT-CPU-NEXT: offload-wrapper: input: {{.*}}, output: [[WRAPPEROUT:.*]].bc
// CHK-CMDS-AOT-CPU-NEXT: "{{.*}}llc.exe" -filetype=obj -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-AOT-CPU-NEXT: "{{.*}}clang.exe"{{.*}} -c -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-AOT-CPU-NEXT: "{{.*}}/ld" -- HOST_LINKER_FLAGS -dynamic-linker HOST_DYN_LIB -o a.out [[LLCOUT]].o HOST_LIB_PATH HOST_STAT_LIB {{.*}}.o

/// Check for list of commands for standalone clang-linker-wrapper run for sycl (AOT for NVPTX)
Expand All @@ -93,7 +93,7 @@
// CHK-CMDS-AOT-NV-NEXT: "{{.*}}ptxas"{{.*}} --output-file [[PTXASOUT:.*]] [[CLANGOUT]]
// CHK-CMDS-AOT-NV-NEXT: "{{.*}}fatbinary"{{.*}} --create [[FATBINOUT:.*]] --image=profile={{.*}},file=[[CLANGOUT]] --image=profile={{.*}},file=[[PTXASOUT]]
// CHK-CMDS-AOT-NV-NEXT: offload-wrapper: input: [[FATBINOUT]], output: [[WRAPPEROUT:.*]].bc
// CHK-CMDS-AOT-NV-NEXT: "{{.*}}llc.exe" -filetype=obj -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-AOT-NV-NEXT: "{{.*}}clang.exe"{{.*}} -c -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-AOT-NV-NEXT: "{{.*}}ld" -- HOST_LINKER_FLAGS -dynamic-linker HOST_DYN_LIB -o a.out [[LLCOUT]].o HOST_LIB_PATH HOST_STAT_LIB {{.*}}.o
/// Check for list of commands for standalone clang-linker-wrapper run for sycl (AOT for AMD)
// -------
Expand All @@ -110,5 +110,5 @@
// CHK-CMDS-AOT-AMD-NEXT: "{{.*}}clang.exe"{{.*}} -o [[CLANGOUT:.*]] --target=amdgcn-amd-amdhsa -mcpu={{.*}}
// CHK-CMDS-AOT-AMD-NEXT: "{{.*}}clang-offload-bundler.exe"{{.*}} -input=[[CLANGOUT]] -output=[[BUNDLEROUT:.*]]
// CHK-CMDS-AOT-AMD-NEXT: offload-wrapper: input: [[BUNDLEROUT]], output: [[WRAPPEROUT:.*]].bc
// CHK-CMDS-AOT-AMD-NEXT: "{{.*}}llc.exe" -filetype=obj -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-AOT-AMD-NEXT: "{{.*}}clang.exe"{{.*}} -c -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
// CHK-CMDS-AOT-AMD-NEXT: "{{.*}}ld" -- HOST_LINKER_FLAGS -dynamic-linker HOST_DYN_LIB -o a.out [[LLCOUT]].o HOST_LIB_PATH HOST_STAT_LIB {{.*}}.o
Loading

0 comments on commit 6b1bec0

Please sign in to comment.