-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Implement per-aspect device code split #7302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pvchupin
merged 24 commits into
intel:sycl
from
AlexeySachkov:private/asachkov/per-aspect-device-code-split
Nov 21, 2022
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e139505
WIP
AlexeySachkov 981c726
Refactor sycl-post-link part
AlexeySachkov 03a4db5
Refactor/generalize some code
AlexeySachkov f7de004
Renaming; better names for split modules
AlexeySachkov cc01839
Move device code split tests into a separate directory
AlexeySachkov f266933
Fix DenseMap helpers
AlexeySachkov eca5ca4
Fix cross module device globals detection
AlexeySachkov 731f6f7
revert changes in device_requirments test
AlexeySachkov df73f90
Add a couple of LIT tests
AlexeySachkov 18ba12c
KernelProperties -> UsedOptionalFeatures
AlexeySachkov 7d7fd45
Cache UsedOptionalFeatures hash
AlexeySachkov bd2ae95
Aspects order shouldn't matter
AlexeySachkov b706a70
Merge remote-tracking branch 'origin/sycl' into private/asachkov/per-…
AlexeySachkov 496ee74
More renamings
AlexeySachkov c3b975d
Make test more strict
AlexeySachkov 2331196
Merge remote-tracking branch 'origin/sycl' into private/asachkov/per-…
AlexeySachkov 8cac6b8
Apply clang-format
AlexeySachkov 4be7927
Refactor tests a bit
AlexeySachkov 01c88f4
Add test for SYCL_EXTERNAL functions
AlexeySachkov 7272fee
Merge remote-tracking branch 'origin/sycl' into private/asachkov/per-…
AlexeySachkov 12e2622
Do not always perform per-aspect split
AlexeySachkov b39798b
Apply review comments
AlexeySachkov 0cc45b2
Apply comments
AlexeySachkov 61ec5e9
Apply comments
AlexeySachkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
llvm/test/tools/sycl-post-link/device-code-split/per-aspect-split-1.ll
This file contains hidden or 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,133 @@ | ||
; This test emulates two translation units with 3 kernels: | ||
; TU0_kernel0 - 1st translation unit, no aspects used | ||
; TU0_kernel1 - 1st translation unit, aspect 1 is used | ||
; TU1_kernel2 - 2nd translation unit, no aspects used | ||
|
||
; The test is intended to check that sycl-post-link correctly separates kernels | ||
; that use aspects from kernels which doesn't use aspects regardless of device | ||
; code split mode | ||
|
||
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-M0-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-M1-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.ll --check-prefixes CHECK-M2-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-M0-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-M1-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.sym --check-prefixes CHECK-M2-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
|
||
; RUN: sycl-post-link -split=source -symbols -S %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-M0-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-M1-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.ll --check-prefixes CHECK-M2-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-M0-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-M1-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.sym --check-prefixes CHECK-M2-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
|
||
; RUN: sycl-post-link -split=kernel -symbols -S %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-M0-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-M1-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.ll --check-prefixes CHECK-M2-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-M0-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-M1-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
; RUN: FileCheck %s -input-file=%t_2.sym --check-prefixes CHECK-M2-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 | ||
|
||
; Regardless of device code split mode, each kernel should go into a separate | ||
; device image | ||
|
||
; CHECK-M2-IR: define {{.*}} @TU0_kernel0 | ||
; CHECK-M2-SYMS: TU0_kernel0 | ||
|
||
; CHECK-M1-IR: define {{.*}} @TU0_kernel1 | ||
; CHECK-M1-SYMS: TU0_kernel1 | ||
|
||
; CHECK-M0-IR: define {{.*}} @TU1_kernel2 | ||
; CHECK-M0-SYMS: TU1_kernel2 | ||
|
||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir64-unknown-linux" | ||
|
||
; FIXME: device globals should also be properly distributed across device images | ||
; if they are of optional type | ||
@_ZL2GV = internal addrspace(1) constant [1 x i32] [i32 42], align 4 | ||
|
||
define dso_local spir_kernel void @TU0_kernel0() #0 { | ||
entry: | ||
call spir_func void @foo() | ||
ret void | ||
} | ||
|
||
define dso_local spir_func void @foo() { | ||
entry: | ||
%a = alloca i32, align 4 | ||
%call = call spir_func i32 @bar(i32 1) | ||
%add = add nsw i32 2, %call | ||
store i32 %add, i32* %a, align 4 | ||
ret void | ||
} | ||
|
||
; Function Attrs: nounwind | ||
define linkonce_odr dso_local spir_func i32 @bar(i32 %arg) { | ||
entry: | ||
%arg.addr = alloca i32, align 4 | ||
store i32 %arg, i32* %arg.addr, align 4 | ||
%0 = load i32, i32* %arg.addr, align 4 | ||
ret i32 %0 | ||
} | ||
|
||
define dso_local spir_kernel void @TU0_kernel1() #0 !sycl_used_aspects !2 { | ||
entry: | ||
call spir_func void @foo1() | ||
ret void | ||
} | ||
|
||
; Function Attrs: nounwind | ||
define dso_local spir_func void @foo1() { | ||
entry: | ||
%a = alloca i32, align 4 | ||
store i32 2, i32* %a, align 4 | ||
ret void | ||
} | ||
|
||
define dso_local spir_kernel void @TU1_kernel2() #1 { | ||
entry: | ||
call spir_func void @foo2() | ||
ret void | ||
} | ||
|
||
; Function Attrs: nounwind | ||
define dso_local spir_func void @foo2() { | ||
entry: | ||
%a = alloca i32, align 4 | ||
%0 = load i32, i32 addrspace(4)* getelementptr inbounds ([1 x i32], [1 x i32] addrspace(4)* addrspacecast ([1 x i32] addrspace(1)* @_ZL2GV to [1 x i32] addrspace(4)*), i64 0, i64 0), align 4 | ||
%add = add nsw i32 4, %0 | ||
store i32 %add, i32* %a, align 4 | ||
ret void | ||
} | ||
|
||
attributes #0 = { "sycl-module-id"="TU1.cpp" } | ||
attributes #1 = { "sycl-module-id"="TU2.cpp" } | ||
|
||
!opencl.spir.version = !{!0, !0} | ||
!spirv.Source = !{!1, !1} | ||
|
||
!0 = !{i32 1, i32 2} | ||
!1 = !{i32 4, i32 100000} | ||
!2 = !{i32 1} |
59 changes: 59 additions & 0 deletions
59
llvm/test/tools/sycl-post-link/device-code-split/per-aspect-split-2.ll
This file contains hidden or 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,59 @@ | ||
; The test is intended to check that sycl-post-link correctly groups kernels | ||
; by unique sets of aspects used in them | ||
|
||
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t.table --check-prefix CHECK-TABLE | ||
; | ||
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefix CHECK-M0-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel1 \ | ||
; RUN: --implicit-check-not kernel2 | ||
; | ||
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefix CHECK-M1-SYMS \ | ||
; RUN: --implicit-check-not kernel3 --implicit-check-not kernel1 \ | ||
; RUN: --implicit-check-not kernel2 | ||
; | ||
; RUN: FileCheck %s -input-file=%t_2.sym --check-prefix CHECK-M2-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not kernel3 | ||
|
||
; CHECK-TABLE: Code | ||
; CHECK-TABLE-NEXT: _0.sym | ||
; CHECK-TABLE-NEXT: _1.sym | ||
; CHECK-TABLE-NEXT: _2.sym | ||
; CHECK-TABLE-EMPTY: | ||
|
||
; CHECK-M0-SYMS: kernel3 | ||
|
||
; CHECK-M1-SYMS: kernel0 | ||
|
||
; CHECK-M2-SYMS: kernel1 | ||
; CHECK-M2-SYMS: kernel2 | ||
|
||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir64-unknown-linux" | ||
|
||
define dso_local spir_kernel void @kernel0() #0 !sycl_used_aspects !1 { | ||
entry: | ||
ret void | ||
} | ||
|
||
define dso_local spir_kernel void @kernel1() #0 !sycl_used_aspects !2 { | ||
entry: | ||
ret void | ||
} | ||
|
||
define dso_local spir_kernel void @kernel2() #0 !sycl_used_aspects !3 { | ||
entry: | ||
ret void | ||
} | ||
|
||
define dso_local spir_kernel void @kernel3() #0 !sycl_used_aspects !4 { | ||
entry: | ||
ret void | ||
} | ||
|
||
attributes #0 = { "sycl-module-id"="TU1.cpp" } | ||
|
||
!1 = !{i32 1} | ||
!2 = !{i32 1, i32 2} | ||
!3 = !{i32 2, i32 1} | ||
!4 = !{i32 2, i32 3, i32 4} |
94 changes: 94 additions & 0 deletions
94
llvm/test/tools/sycl-post-link/device-code-split/per-aspect-split-3.ll
This file contains hidden or 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,94 @@ | ||
; This test is intended to check that per-aspect device code split works as | ||
; expected with SYCL_EXTERNAL functions | ||
|
||
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t.table --check-prefix CHECK-TABLE | ||
; | ||
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefix CHECK-M0-SYMS \ | ||
; RUN: --implicit-check-not foo --implicit-check-not kernel1 | ||
; | ||
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefix CHECK-M1-SYMS \ | ||
; RUN: --implicit-check-not foo --implicit-check-not kernel0 | ||
; | ||
; RUN: FileCheck %s -input-file=%t_2.sym --check-prefix CHECK-M2-SYMS \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not foo \ | ||
; RUN: --implicit-check-not bar | ||
; | ||
; RUN: FileCheck %s -input-file=%t_2.ll --check-prefix CHECK-M2-IR \ | ||
; RUN: --implicit-check-not kernel0 --implicit-check-not bar | ||
|
||
; We expect to see 3 modules generated: | ||
; | ||
; CHECK-TABLE: Code | ||
; CHECK-TABLE-NEXT: _0.sym | ||
; CHECK-TABLE-NEXT: _1.sym | ||
; CHECK-TABLE-NEXT: _2.sym | ||
; CHECK-TABLE-EMPTY: | ||
|
||
; sycl-post-link aims to achieve two goals while doing splitting: | ||
; - each kernel must be self-contained, i.e. all functions called from a | ||
; kernel must reside in the same device image | ||
; - each entry point should be assigned to a correct device image in | ||
; accordance with selected device code split mode | ||
; | ||
; In this test @bar and @foo are SYCL_EXTERNAL functions and they are treated | ||
; as entry points. | ||
; | ||
; @bar uses the same list of aspects as @kernel0 which calls it and therefore | ||
; they can be put into the same device image. There also goes @baz, because of | ||
; the same list of used aspects. | ||
; | ||
; CHECK-M0-SYMS: bar | ||
; CHECK-M0-SYMS: baz | ||
; CHECK-M0-SYMS: kernel0 | ||
; | ||
; List of aspects used by @foo is different from the one attached to @kernel1 | ||
; which calls @foo (for example, @kernel1 uses an extra optional feature besides | ||
; ones used in @foo). As a result, @foo should be both included into the same | ||
; device image as @kernel1 to make it self contained, but at the same time it | ||
; should also present in a separate device image, because it is an entry point | ||
; with unique set of used aspects. | ||
; | ||
; CHECK-M1-SYMS: foo | ||
; | ||
; CHECK-M2-SYMS: kernel1 | ||
; | ||
; @kernel1 uses @foo and therefore @foo should be present in the same module as | ||
; @kernel1 as well | ||
; CHECK-M2-IR-DAG: define spir_func void @foo | ||
; CHECK-M2-IR-DAG: define spir_kernel void @kernel1 | ||
|
||
|
||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir64-unknown-linux" | ||
|
||
define spir_func void @foo() #0 !sycl_used_aspects !1 { | ||
sarnex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ret void | ||
} | ||
|
||
define spir_func void @bar() #1 !sycl_used_aspects !2 { | ||
ret void | ||
} | ||
|
||
define spir_func void @baz() #1 !sycl_used_aspects !2 { | ||
ret void | ||
} | ||
|
||
define spir_kernel void @kernel0() #1 !sycl_used_aspects !2 { | ||
entry: | ||
call void @bar() | ||
ret void | ||
} | ||
|
||
define spir_kernel void @kernel1() #0 !sycl_used_aspects !3 { | ||
entry: | ||
call void @foo() | ||
ret void | ||
} | ||
|
||
attributes #0 = { "sycl-module-id"="TU1.cpp" } | ||
attributes #1 = { "sycl-module-id"="TU2.cpp" } | ||
|
||
!1 = !{i32 1} | ||
!2 = !{i32 2} | ||
!3 = !{i32 3, i32 1} |
55 changes: 55 additions & 0 deletions
55
llvm/test/tools/sycl-post-link/device-code-split/per-aspect-split-4.ll
This file contains hidden or 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,55 @@ | ||
; This test is intended to check that we do not perform per-aspect split if | ||
; it was disabled through one or another sycl-post-link option | ||
|
||
; RUN: sycl-post-link -symbols -S %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t.table --check-prefix CHECK-TABLE | ||
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefix CHECK-IR | ||
; | ||
; -lower-esimd is needed so sycl-post-link does not complain about no actions | ||
; specified | ||
; RUN: sycl-post-link -lower-esimd -ir-output-only -S %s -o %t.ll | ||
sarnex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; RUN: FileCheck %s -input-file=%t.ll --check-prefix CHECK-IR | ||
|
||
; We expect to see only one module generated: | ||
; | ||
; CHECK-TABLE: Code | ||
; CHECK-TABLE-NEXT: _0.ll | ||
; CHECK-TABLE-EMPTY: | ||
|
||
; Regardless of used aspects and sycl-module-id metadata, all kernel and | ||
; functions should still be present. | ||
|
||
; CHECK-IR-DAG: define spir_func void @foo | ||
; CHECK-IR-DAG: define spir_func void @bar | ||
; CHECK-IR-DAG: define spir_kernel void @kernel0 | ||
; CHECK-IR-DAG: define spir_kernel void @kernel1 | ||
|
||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir64-unknown-linux" | ||
|
||
define spir_func void @foo() #0 !sycl_used_aspects !1 { | ||
ret void | ||
} | ||
|
||
define spir_func void @bar() #1 !sycl_used_aspects !2 { | ||
ret void | ||
} | ||
|
||
define spir_kernel void @kernel0() #1 !sycl_used_aspects !2 { | ||
entry: | ||
ret void | ||
} | ||
|
||
define spir_kernel void @kernel1() #0 !sycl_used_aspects !3 { | ||
entry: | ||
call void @foo() | ||
ret void | ||
} | ||
|
||
attributes #0 = { "sycl-module-id"="TU1.cpp" } | ||
attributes #1 = { "sycl-module-id"="TU2.cpp" } | ||
|
||
!1 = !{i32 1} | ||
!2 = !{i32 2} | ||
!3 = !{i32 3, i32 1} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.