-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Support per-object file compilation (#7595)
This change adds per-object compilation support for SYCL, also called non-relocatable device code mode. This is already supported in clang for HIP and CUDA. It adds a new option -f[no-]sycl-rdc. The default is -fsycl-rdc, which compiles code as today. Passing -fno-sycl-rdc activates the new mode. This is just an alias to the existing flag used by AMD/CUDA, f[no-]-gpu-rdc. The main implication is that we no longer link all device code together into one big module before post link. Instead, we execute all jobs after device linking on a per-object file basis. This means sycl-post-link and the later jobs execute multiple times, since we no longer have one big module. This can result in large improvement performance in the compiler runtime and memory usage, we see a max memory usage reduction for QUDA with -g from over 250GB to 4GB and a large compiler runtime improvement as well. Error cases: 1) Cross-object dependencies. Since we don't link device code together, each object file must be independent. I added an error in Sema to error if the user passes this flag and has cross-object dependencies. 2) Invalid architecture in fat object. We currently warn gracefully about this, in per-object-file mode llvm-foreach throws an error customers won't understand, so error out in that case instead of warning. Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
- Loading branch information
Showing
22 changed files
with
607 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// Tests driver errors for -no-sycl-rdc | ||
|
||
// RUN: %clang -target %itanium_abi_triple -c %s -o %t.o | ||
// RUN: %clang -target spir64_gen -emit-llvm -c %s -o %t | ||
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,sycl-spir64_gen-unknown-unknown -input=%t -input=%t.o -output=%t.fat.o | ||
// RUN: not %clang -### -fsycl -fno-sycl-rdc %t.fat.o 2>&1 | FileCheck -check-prefix=CHECK-ARCH %s | ||
|
||
// CHECK-ARCH: error: linked binaries do not contain expected 'spir64-unknown-unknown' target; found targets: 'spir64_gen-unknown-unknown', this is not supported with '-fno-sycl-rdc' | ||
|
||
// Some code so that we can create a binary out of this file. | ||
void test_func(void) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// test behaviors of passing a fat static lib with -fno-sycl-rdc | ||
// Build a fat static lib that will be used for all tests | ||
// RUN: echo "void foo(void) {}" > %t1.cpp | ||
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl %t1.cpp -c -o %t1_bundle.o | ||
// RUN: llvm-ar cr %t_lib.a %t1_bundle.o | ||
// RUN: %clang -### -fsycl -fno-sycl-rdc -fsycl-device-code-split=none --sysroot=%S/Inputs/SYCL %t_lib.a 2>&1 -ccc-print-phases | FileCheck %s | ||
// RUN: %clang -### -fsycl -fno-sycl-rdc -fsycl-device-code-split=auto --sysroot=%S/Inputs/SYCL %t_lib.a 2>&1 -ccc-print-phases | FileCheck %s | ||
// RUN: %clang -### -fsycl -fno-sycl-rdc -fsycl-device-code-split=per_kernel --sysroot=%S/Inputs/SYCL %t_lib.a 2>&1 -ccc-print-phases | FileCheck %s | ||
// RUN: %clang -### -fsycl -fno-sycl-rdc -fsycl-device-code-split=per_source --sysroot=%S/Inputs/SYCL %t_lib.a 2>&1 -ccc-print-phases | FileCheck %s | ||
// CHECK: 2: input, "{{.*}}_lib.a", archive | ||
// CHECK: 3: clang-offload-unbundler, {2}, tempfilelist | ||
// CHECK: 4: spirv-to-ir-wrapper, {3}, tempfilelist, (device-sycl) | ||
// CHECK: 5: input, "{{.*}}libsycl-crt{{.*}}", object | ||
// CHECK: 6: clang-offload-unbundler, {5}, object | ||
// CHECK: 7: offload, " (spir64-unknown-unknown)" {6}, object | ||
// CHECK: 65: linker, {7, {{.*}}}, ir, (device-sycl) | ||
// CHECK: 66: linker, {4, 65}, ir, (device-sycl) | ||
// CHECK: 67: foreach, {4, 66}, ir, (device-sycl) | ||
// CHECK: 68: file-table-tform, {4, 67}, tempfilelist, (device-sycl) | ||
// CHECK: 69: sycl-post-link, {68}, tempfiletable, (device-sycl) | ||
// CHECK: 70: foreach, {68, 69}, tempfiletable, (device-sycl) | ||
// CHECK: 71: file-table-tform, {70}, tempfilelist, (device-sycl) | ||
// CHECK: 72: file-table-tform, {70}, tempfilelist, (device-sycl) | ||
// CHECK: 73: foreach, {68, 72}, tempfilelist, (device-sycl) | ||
// CHECK: 74: file-table-tform, {73}, tempfilelist, (device-sycl) | ||
// CHECK: 75: llvm-spirv, {74}, tempfilelist, (device-sycl) | ||
// CHECK: 76: file-table-tform, {71, 75}, tempfiletable, (device-sycl) | ||
// CHECK: 77: clang-offload-wrapper, {76}, object, (device-sycl) | ||
// CHECK: 78: offload, "host-sycl (x86_64-unknown-linux-gnu)" {1}, "device-sycl (spir64-unknown-unknown)" {77}, image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/// Tests for -fno-sycl-rdc | ||
// RUN: touch %t1.cpp | ||
// RUN: touch %t2.cpp | ||
// RUN: %clang -### -fsycl -fno-sycl-rdc --sysroot=%S/Inputs/SYCL %t1.cpp %t2.cpp 2>&1 -ccc-print-phases | FileCheck %s | ||
|
||
// CHECK: 3: input, "{{.*}}1.cpp", c++, (device-sycl) | ||
// CHECK: 4: preprocessor, {3}, c++-cpp-output, (device-sycl) | ||
// CHECK: 5: compiler, {4}, ir, (device-sycl) | ||
// CHECK: 13: input, "{{.*}}2.cpp", c++, (device-sycl) | ||
// CHECK: 14: preprocessor, {13}, c++-cpp-output, (device-sycl) | ||
// CHECK: 15: compiler, {14}, ir, (device-sycl) | ||
|
||
// CHECK: 21: input, {{.*}}libsycl-crt{{.*}}, object | ||
// CHECK: 22: clang-offload-unbundler, {21}, object | ||
// CHECK: 23: offload, " (spir64-unknown-unknown)" {22}, object | ||
// CHECK: 81: linker, {23, {{.*}}}, ir, (device-sycl) | ||
// CHECK: 82: linker, {5, 81}, ir, (device-sycl) | ||
// CHECK: 83: sycl-post-link, {82}, tempfiletable, (device-sycl) | ||
// CHECK: 84: file-table-tform, {83}, tempfilelist, (device-sycl) | ||
// CHECK: 85: llvm-spirv, {84}, tempfilelist, (device-sycl) | ||
// CHECK: 86: file-table-tform, {83, 85}, tempfiletable, (device-sycl) | ||
// CHECK: 87: clang-offload-wrapper, {86}, object, (device-sycl) | ||
|
||
// CHECK: 88: linker, {15, 81}, ir, (device-sycl) | ||
// CHECK: 89: sycl-post-link, {88}, tempfiletable, (device-sycl) | ||
// CHECK: 90: file-table-tform, {89}, tempfilelist, (device-sycl) | ||
// CHECK: 91: llvm-spirv, {90}, tempfilelist, (device-sycl) | ||
// CHECK: 92: file-table-tform, {89, 91}, tempfiletable, (device-sycl) | ||
// CHECK: 93: clang-offload-wrapper, {92}, object, (device-sycl) | ||
|
||
// CHECK: 94: offload, "host-sycl (x86_64-unknown-linux-gnu)" {{{.*}}}, "device-sycl (spir64-unknown-unknown)" {87}, "device-sycl (spir64-unknown-unknown)" {93}, image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only -fno-gpu-rdc -internal-isystem %S/Inputs %s | ||
|
||
// Check that declarations of SYCL_EXTERNAL functions throw an error if -fno-gpu-rdc is passed | ||
#include "sycl.hpp" | ||
|
||
// expected-error@+1{{invalid declaration of SYCL_EXTERNAL function in non-relocatable device code mode}} | ||
SYCL_EXTERNAL void syclExternalDecl(); | ||
|
||
// expected-error@+1{{invalid definition of SYCL_EXTERNAL function in non-relocatable device code mode}} | ||
SYCL_EXTERNAL void syclExternalDefn() {} | ||
|
||
using namespace sycl; | ||
queue q; | ||
|
||
void kernel_wrapper() { | ||
q.submit([&](handler &h) { | ||
h.single_task([=] { | ||
}); | ||
}); | ||
} | ||
|
||
int main() { | ||
kernel_wrapper(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[11|12] | ||
44|55 | ||
66|77 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[11|12] | ||
00|11 | ||
22|33 | ||
44|55 | ||
66|77 |
Oops, something went wrong.