Skip to content

Commit 0de6d9a

Browse files
mdtoguchibader
authored andcommitted
[SYCL] Improve integration of llvm-no-spir-kernel tool with -fintelfpga
When using FPGA device archives, any additional object passed in needs to be scrutinized for SPIR kernel device code. To accomplish this, the kernel checker has been modified to work within the driver toolchain flow (input/output). Signed-off-by: Michael D Toguchi <michael.d.toguchi@intel.com>
1 parent f48c33c commit 0de6d9a

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

clang/lib/Driver/Driver.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -3340,12 +3340,10 @@ class OffloadingActionBuilder final {
33403340
ActionList DeviceObjects;
33413341
for (const auto &I : LI) {
33423342
if (I->getType() == types::TY_Object) {
3343-
// FIXME - Checker does not work well inline with the tool
3344-
// chain, but it needs to be here for real time checking
3345-
// auto *DeviceCheckAction =
3346-
// C.MakeAction<SPIRCheckJobAction>(I, types::TY_Object);
3347-
// DeviceObjects.push_back(DeviceCheckAction);
3348-
DeviceObjects.push_back(I);
3343+
// Perform a check for SPIR kernel.
3344+
auto *DeviceCheckAction =
3345+
C.MakeAction<SPIRCheckJobAction>(I, types::TY_Object);
3346+
DeviceObjects.push_back(DeviceCheckAction);
33493347
} else {
33503348
// Do not perform a device link and only pass the aocr
33513349
// file to the offline compilation before wrapping. Just

clang/lib/Driver/ToolChains/Clang.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -6709,6 +6709,11 @@ void SPIRCheck::ConstructJob(Compilation &C, const JobAction &JA,
67096709
CheckArgs.push_back(I.getFilename());
67106710
}
67116711

6712+
// Add output file, which is just a copy of the input to better fit in the
6713+
// toolchain flow.
6714+
CheckArgs.push_back("-o");
6715+
CheckArgs.push_back(Output.getFilename());
6716+
67126717
C.addCommand(llvm::make_unique<Command>(JA, *this,
67136718
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
67146719
CheckArgs, None));

clang/test/Driver/sycl-offload-intelfpga.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@
4848
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-inputs=[[INPUT]]" "-outputs=[[OUTPUT1:.+\.txt]]" "-unbundle"
4949
// CHK-FPGA-LINK-LIB: llvm-ar{{.*}} "cr" {{.*}} "@[[OUTPUT1]]"
5050

51+
/// -fintelfpga with AOCR library and additional object
52+
// RUN: touch %t2.o
53+
// RUN: %clang++ -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %t.a %t2.o 2>&1 \
54+
// RUN: | FileCheck -check-prefixes=CHK-FPGA %s
55+
// CHK-FPGA: aoc{{.*}} "-o" {{.*}} "-sycl"
56+
// CHK-FPGA: llc{{.*}} "-filetype=obj" "-o" "[[FINALLINK:.*\.o]]"
57+
// CHK-FPGA: clang-offload-bundler{{.*}} "-type=o" "-targets=host-x86_64-unknown-linux-gnu,sycl-spir64_fpga-unknown-{{linux|windows}}-sycldevice" {{.*}} "-outputs=[[FINALLINK2:.+\.o]],[[OUTPUT1:.+\.o]]" "-unbundle"
58+
// CHK-FPGA: llvm-no-spir-kernel{{.*}} "[[OUTPUT1]]" "-o" "[[OUTPUT3:.+\.o]]"
59+
// CHK-FPGA: llvm-link{{.*}} "[[OUTPUT3]]" "-o" "[[OUTPUT4:.+\.bc]]"
60+
// CHK-FPGA: llvm-spirv{{.*}} "-o" "[[OUTPUT5:.+\.spv]]" "[[OUTPUT4]]"
61+
// CHK-FPGA: clang-offload-wrapper{{.*}} "-o=[[OUTPUT6:.+\.bc]]" "-host=x86_64-unknown-linux-gnu" "-kind=sycl" "[[OUTPUT5]]"
62+
// CHK-FPGA: llc{{.*}} "-filetype=obj" "-o" "[[FINALLINK3:.+\.o]]" "[[OUTPUT6]]"
63+
// CHK-FPGA: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" {{.*}} "-outputs=[[FINALLINK4:.+\.txt]]" "-unbundle"
64+
// CHK-FPGA: {{link|ld}}{{.*}} "@[[FINALLINK4]]" "[[FINALLINK2]]" "[[FINALLINK]]" "[[FINALLINK3]]"
65+
5166
/// -fintelfpga -fsycl-link from source
5267
// RUN: touch %t.cpp
5368
// RUN: %clang++ -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \

llvm/tools/llvm-no-spir-kernel/llvm-no-spir-kernel.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
//===----------------------------------------------------------------------===//
88
//
99
// This utility checks if the input module contains functions that is a spir
10-
// kernel. Return 0 if no, return 1 if yes.
11-
// Usage: llvm-no-spir-kernel input.bc/input.ll
10+
// kernel. Return 0 if no, return 1 if yes. Use of an output file is not
11+
// required for a successful check. It is used to allow for proper input and
12+
// output flow within the driver toolchain.
13+
//
14+
// Usage: llvm-no-spir-kernel input.bc/input.ll -o output.bc/output.ll
1215
//
1316
//===----------------------------------------------------------------------===//
1417

@@ -27,6 +30,12 @@ static cl::opt<std::string> InputFilename(cl::Positional,
2730
cl::init("-"),
2831
cl::value_desc("filename"));
2932

33+
// Output - The filename to output to.
34+
static cl::opt<std::string> Output("o",
35+
cl::desc("<output filename>"),
36+
cl::value_desc("filename"));
37+
38+
3039
int main(int argc, char **argv) {
3140
InitLLVM X(argc, argv);
3241

@@ -48,5 +57,10 @@ int main(int argc, char **argv) {
4857
}
4958
}
5059

60+
// When given an output file, just copy the input to the output
61+
if (!Output.empty() && !InputFilename.empty()) {
62+
llvm::sys::fs::copy_file(InputFilename, Output);
63+
}
64+
5165
return 0;
52-
}
66+
}

0 commit comments

Comments
 (0)