-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][SCLA] Add
sycl::aspect::ext_oneapi_private_alloca
(#13181)
Add aspect to check for `sycl_ext_oneapi_private_alloca` extension support. Only SPIR-V (OpenCL and Level Zero) devices have this aspect. In CodeGen, propagate this aspect when creating the `llvm.sycl.alloca.*` intrinsic. In `sycl-post-link`, do not assert on unsupported targets. Instead, assume the default value for the size specialization constant is used and handle the error at runtime. SPIR-V AOT compilation should fail in the frontend, so no need to fail here. --------- Signed-off-by: Victor Perez <victor.perez@codeplay.com>
- Loading branch information
1 parent
edafb97
commit d3c76d3
Showing
26 changed files
with
251 additions
and
28 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
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
24 changes: 24 additions & 0 deletions
24
llvm/test/tools/sycl-post-link/spec-constants/SYCL-alloca-error.ll
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: sycl-post-link -spec-const=emulation %s 2>&1 | FileCheck %s | ||
|
||
; This test checks the `-spec-const` pass on SPIR-V targets and emulation mode, | ||
; i.e., on AOT SPIR-V targets. In this scenario, 'llvm.sycl.alloca' intrinsics | ||
; must be left unmodified. | ||
|
||
; Note that coming from clang this case should never be reached. | ||
|
||
; CHECK: sycl-post-link NOTE: no modifications to the input LLVM IR have been made | ||
|
||
target triple = "spir64_x86_64" | ||
|
||
%"class.sycl::_V1::specialization_id" = type { i64 } | ||
|
||
@size_i64 = addrspace(1) constant %"class.sycl::_V1::specialization_id" { i64 10 }, align 8 | ||
|
||
@size_i64_stable_name = private unnamed_addr constant [36 x i8] c"_ZTS14name_generatorIL_Z8size_i64EE\00", align 1 | ||
|
||
define dso_local void @private_alloca() { | ||
call ptr @llvm.sycl.alloca.p0.p4.p4.p4.f64(ptr addrspace(4) addrspacecast (ptr @size_i64_stable_name to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @size_i64 to ptr addrspace(4)), ptr addrspace(4) null, double 0.000000e+00, i64 8) | ||
ret void | ||
} | ||
|
||
declare ptr @llvm.sycl.alloca.p0.p4.p4.p4.f32(ptr addrspace(4), ptr addrspace(4), ptr addrspace(4), float, i64) |
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
32 changes: 32 additions & 0 deletions
32
llvm/test/tools/sycl-post-link/spec-constants/default-value/SYCL-alloca.ll
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,32 @@ | ||
; RUN: sycl-post-link -split=auto -spec-const=native -S -o %t.table %s -generate-device-image-default-spec-consts | ||
; RUN: FileCheck %s -input-file %t_1.ll --implicit-check-not="SpecConst" | ||
|
||
; This test checks that the post link tool is able to correctly transform | ||
; SYCL alloca intrinsics in SPIR-V devices when using default values. | ||
|
||
%"class.sycl::_V1::specialization_id" = type { i64 } | ||
%"class.sycl::_V1::specialization_id.0" = type { i32 } | ||
%"class.sycl::_V1::specialization_id.1" = type { i16 } | ||
%my_range = type { ptr addrspace(4), ptr addrspace(4) } | ||
|
||
@size_i64 = internal addrspace(1) constant %"class.sycl::_V1::specialization_id" { i64 10 }, align 8 | ||
@size_i32 = internal addrspace(1) constant %"class.sycl::_V1::specialization_id.0" { i32 120 }, align 4 | ||
@size_i16 = internal addrspace(1) constant %"class.sycl::_V1::specialization_id.1" { i16 1 }, align 2 | ||
|
||
@size_i64_stable_name = private unnamed_addr constant [36 x i8] c"_ZTS14name_generatorIL_Z8size_i64EE\00", align 1 | ||
@size_i32_stable_name = private unnamed_addr constant [36 x i8] c"_ZTS14name_generatorIL_Z8size_i32EE\00", align 1 | ||
@size_i16_stable_name = private unnamed_addr constant [36 x i8] c"_ZTS14name_generatorIL_Z8size_i16EE\00", align 1 | ||
|
||
define dso_local void @private_alloca() { | ||
; CHECK: alloca double, i32 120, align 8 | ||
call ptr @llvm.sycl.alloca.p0.p4.p4.p4.f64(ptr addrspace(4) addrspacecast (ptr @size_i32_stable_name to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @size_i32 to ptr addrspace(4)), ptr addrspace(4) null, double 0.000000e+00, i64 8) | ||
; CHECK: alloca float, i64 10, align 8 | ||
call ptr @llvm.sycl.alloca.p0.p4.p4.p4.f32(ptr addrspace(4) addrspacecast (ptr @size_i64_stable_name to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @size_i64 to ptr addrspace(4)), ptr addrspace(4) null, float 0.000000e+00, i64 8) | ||
; CHECK: alloca %my_range, i16 1, align 64 | ||
call ptr @llvm.sycl.alloca.p0.p4.p4.p4.s_my_range(ptr addrspace(4) addrspacecast (ptr @size_i16_stable_name to ptr addrspace(4)), ptr addrspace(4) addrspacecast (ptr addrspace(1) @size_i16 to ptr addrspace(4)), ptr addrspace(4) null, %my_range zeroinitializer, i64 64) | ||
ret void | ||
} | ||
|
||
declare ptr @llvm.sycl.alloca.p0.p4.p4.p4.f32(ptr addrspace(4), ptr addrspace(4), ptr addrspace(4), float, i64) | ||
declare ptr @llvm.sycl.alloca.p0.p4.p4.p4.f64(ptr addrspace(4), ptr addrspace(4), ptr addrspace(4), double, i64) | ||
declare ptr @llvm.sycl.alloca.p0.p4.p4.p4.s_my_range(ptr addrspace(4), ptr addrspace(4), ptr addrspace(4), %my_range, i64) |
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
40 changes: 40 additions & 0 deletions
40
sycl/test-e2e/PrivateAlloca/UnsupportedDevice/exception_unsupported_backend.cpp
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,40 @@ | ||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
// Check that an exception with an exception with the `errc::invalid` error code | ||
// thrown when trying to use `sycl_ext_oneapi_private_alloca` and no device | ||
// supports the aspect. | ||
|
||
#include <sycl/detail/core.hpp> | ||
|
||
#include <sycl/ext/oneapi/experimental/alloca.hpp> | ||
#include <sycl/specialization_id.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
class Kernel; | ||
|
||
constexpr sycl::specialization_id<int> Size(10); | ||
|
||
static std::error_code test() { | ||
sycl::queue Queue; | ||
sycl::buffer<int> B(10); | ||
|
||
try { | ||
Queue.submit([&](sycl::handler &Cgh) { | ||
sycl::accessor Acc(B, Cgh, sycl::write_only, sycl::no_init); | ||
Cgh.parallel_for<Kernel>(10, [=](sycl::id<1>, sycl::kernel_handler Kh) { | ||
sycl::ext::oneapi::experimental::private_alloca< | ||
int, Size, sycl::access::decorated::no>(Kh); | ||
}); | ||
}); | ||
} catch (sycl::exception &Exception) { | ||
return Exception.code(); | ||
} | ||
assert(false && "Exception not thrown"); | ||
} | ||
|
||
int main() { | ||
assert(test() == sycl::errc::invalid && "Unexpected error code"); | ||
|
||
return 0; | ||
} |
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 @@ | ||
config.required_features += ['!aspect-ext_oneapi_private_alloca'] |
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 @@ | ||
config.required_features += ['aspect-ext_oneapi_private_alloca'] |
1 change: 0 additions & 1 deletion
1
...rivateAlloca/private_alloca_bool_size.cpp → ...a/ValidUsage/private_alloca_bool_size.cpp
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
Oops, something went wrong.