Skip to content

Commit

Permalink
[Clang] Fix passing -offload-compress when compiling and linking de…
Browse files Browse the repository at this point in the history
…vice images separately (#15997)

When compiling and linking device images separately, compression related
flags are not propagated correctly to `offload-wrapper`. This PR fixes
that and updates the test accordingly.
  • Loading branch information
uditagarwal97 authored Nov 7, 2024
1 parent 66867d4 commit b3fb5ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
57 changes: 36 additions & 21 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10353,33 +10353,48 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
assert(JA.getInputs().size() == Inputs.size() &&
"Not have inputs for all dependence actions??");

// For FPGA, we wrap the host objects before archiving them when using
// -fsycl-link. This allows for better extraction control from the
// archive when we need the host objects for subsequent compilations.
if (OffloadingKind == Action::OFK_None &&
C.getArgs().hasArg(options::OPT_fintelfpga) &&
C.getArgs().hasArg(options::OPT_fsycl_link_EQ)) {

// Add offload targets and inputs.
CmdArgs.push_back(C.getArgs().MakeArgString(
Twine("-kind=") + Action::GetOffloadKindName(OffloadingKind)));
CmdArgs.push_back(
TCArgs.MakeArgString(Twine("-target=") + Triple.getTriple()));
// For FPGA, we wrap the host objects before archiving them when using
// -fsycl-link. This allows for better extraction control from the
// archive when we need the host objects for subsequent compilations.
if (C.getArgs().hasArg(options::OPT_fintelfpga)) {

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 offload targets and inputs.
CmdArgs.push_back(C.getArgs().MakeArgString(
Twine("-kind=") + Action::GetOffloadKindName(OffloadingKind)));
CmdArgs.push_back(
TCArgs.MakeArgString(Twine("-target=") + Triple.getTriple()));

// Add input.
assert(Inputs[0].isFilename() && "Invalid input.");
CmdArgs.push_back(TCArgs.MakeArgString(Inputs[0].getFilename()));
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"));

C.addCommand(std::make_unique<Command>(
JA, *this, ResponseFileSupport::None(),
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
CmdArgs, Inputs));
return;
// Add input.
assert(Inputs[0].isFilename() && "Invalid input.");
CmdArgs.push_back(TCArgs.MakeArgString(Inputs[0].getFilename()));

C.addCommand(std::make_unique<Command>(
JA, *this, ResponseFileSupport::None(),
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
CmdArgs, Inputs));
return;
} else {
// When compiling and linking separately, we need to propagate the
// compression related CLI options to offload-wrapper. Don't propagate
// these options when wrapping objects for FPGA.
if (C.getInputArgs().getLastArg(options::OPT_offload_compress)) {
CmdArgs.push_back(
C.getArgs().MakeArgString(Twine("-offload-compress")));
// -offload-compression-level=<>
if (Arg *A = C.getInputArgs().getLastArg(
options::OPT_offload_compression_level_EQ))
CmdArgs.push_back(C.getArgs().MakeArgString(
Twine("-offload-compression-level=") + A->getValue()));
}
}
}

// Add offload targets and inputs.
Expand Down
7 changes: 7 additions & 0 deletions sycl/test-e2e/Compression/compression_separate_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
////////////////////// Link device images
// RUN: %clangxx --offload-compress -fsycl -fsycl-link -fsycl-targets=spir64_x86_64 -fPIC %t_kernel1_aot.o %t_kernel2_aot.o -o %t_compressed_image.o -v

// Make sure the clang-offload-wrapper is called with the --offload-compress
// option.
// RUN: %clangxx --offload-compress -fsycl -fsycl-link -fsycl-targets=spir64_x86_64 -fPIC %t_kernel1_aot.o %t_kernel2_aot.o -o %t_compressed_image.o -### &> %t_driver_opts.txt
// RUN: FileCheck -input-file=%t_driver_opts.txt %s --check-prefix=CHECK-DRIVER-OPTS

// CHECK-DRIVER-OPTS: clang-offload-wrapper{{.*}} "-offload-compress"

////////////////////// Compile the host program
// RUN: %clangxx -fsycl -std=c++17 -Wno-attributes -Wno-deprecated-declarations -fPIC -c %s -o %t_main.o

Expand Down

0 comments on commit b3fb5ad

Please sign in to comment.