Skip to content

Commit 1f0dc36

Browse files
authored
[SYCL] Correct handling of enumeration specialization constants (#12925)
Lower enumeration specialization constants to `SpecConstant` in SPIR-V instead of `SpecConstantComposite`, thus handling them using their underlying integral types. --------- Signed-off-by: Victor Perez <victor.perez@codeplay.com>
1 parent 0d2fe31 commit 1f0dc36

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

sycl/include/sycl/kernel_handler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class __SYCL_TYPE(kernel_handler) kernel_handler {
6767
template <
6868
auto &S,
6969
typename T = typename std::remove_reference_t<decltype(S)>::value_type,
70-
std::enable_if_t<std::is_fundamental_v<T>> * = nullptr>
70+
std::enable_if_t<std::is_scalar_v<T>> * = nullptr>
7171
__SYCL_ALWAYS_INLINE T getSpecializationConstantOnDevice() {
7272
const char *SymbolicID = __builtin_sycl_unique_stable_id(S);
7373
return __sycl_getScalar2020SpecConstantValue<T>(
@@ -76,7 +76,7 @@ class __SYCL_TYPE(kernel_handler) kernel_handler {
7676
template <
7777
auto &S,
7878
typename T = typename std::remove_reference_t<decltype(S)>::value_type,
79-
std::enable_if_t<std::is_compound_v<T>> * = nullptr>
79+
std::enable_if_t<!std::is_scalar_v<T>> * = nullptr>
8080
__SYCL_ALWAYS_INLINE T getSpecializationConstantOnDevice() {
8181
const char *SymbolicID = __builtin_sycl_unique_stable_id(S);
8282
return __sycl_getComposite2020SpecConstantValue<T>(

sycl/test/basic_tests/SYCL-2020-spec-constants.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: sycl-post-link %t.bc -spec-const=emulation -o %t-split2.txt
55
// RUN: cat %t-split2_0.prop | FileCheck %s -check-prefixes=CHECK,CHECK-DEF
66
// RUN: llvm-spirv -o %t-split1_0.spv -spirv-max-version=1.1 -spirv-ext=+all %t-split1_0.bc
7-
// RUN: llvm-spirv -o %t-split2_0.spv -spirv-max-version=1.1 -spirv-ext=+all %t-split2_0.bc
7+
// RUN: llvm-spirv -o - --to-text %t-split1_0.spv | FileCheck %s -check-prefixes=CHECK-SPV
88
//
99
//==----------- SYCL-2020-spec-constants.cpp -------------------------------==//
1010
//
@@ -61,6 +61,10 @@ struct composite {
6161

6262
constexpr sycl::specialization_id<composite> composite_id(12, 13);
6363

64+
enum class enumeration { a, b, c };
65+
66+
constexpr sycl::specialization_id<enumeration> enumeration_id(enumeration::c);
67+
6468
class SpecializedKernel;
6569

6670
int main() {
@@ -88,11 +92,12 @@ int main() {
8892
auto f32 = kh.get_specialization_constant<float_id>();
8993
auto f64 = kh.get_specialization_constant<double_id>();
9094
auto c = kh.get_specialization_constant<composite_id>();
95+
auto e = kh.get_specialization_constant<enumeration_id>();
9196

9297
// see FIXMEs above about bool and half types support
9398
acc[0] = /*i1 +*/ i8 + u8 + i16 + u16 + i32 + u32 + i64 + u64 +
94-
//f16.get() +
95-
f32 + f64 + c.a + c.b;
99+
// f16.get() +
100+
f32 + f64 + c.a + c.b + static_cast<float>(e);
96101
});
97102
});
98103
}
@@ -114,6 +119,7 @@ int main() {
114119
// CHECK-DAG: [[UNIQUE_PREFIX]]____ZL9uint16_id=2|
115120
// CHECK-DAG: [[UNIQUE_PREFIX]]____ZL9uint32_id=2|
116121
// CHECK-DAG: [[UNIQUE_PREFIX]]____ZL9uint64_id=2|
122+
// CHECK-DAG: [[UNIQUE_PREFIX]]____ZL14enumeration_id=2|
117123
// FIXME: check line for half constant
118124

119125
// CHECK-RT: [SYCL/specialization constants default values]
@@ -133,6 +139,7 @@ int main() {
133139
// CHECK-NEXT-LOG:[[UNIQUE_PREFIX]]____ZL9double_id={9, 0, 8}
134140
// CHECK-NEXT-LOG:[[UNIQUE_PREFIX]]____ZL12composite_id={10, 0, 4}
135141
// CHECK-NEXT-LOG:[[UNIQUE_PREFIX]]____ZL12composite_id={11, 4, 4}
142+
// CHECK-NEXT-LOG:[[UNIQUE_PREFIX]]____ZL14enumeration_id={12, 0, 4}
136143
// CHECK-NEXT-LOG:{0, 1, 42}
137144
// CHECK-NEXT-LOG:{1, 1, 26}
138145
// CHECK-NEXT-LOG:{2, 2, 34}
@@ -145,3 +152,40 @@ int main() {
145152
// CHECK-NEXT-LOG:{34, 8, 1.100000e+01}
146153
// CHECK-NEXT-LOG:{42, 4, 12}
147154
// CHECK-NEXT-LOG:{46, 4, 13}
155+
// CHECK-NEXT-LOG:{50, 4, 2}
156+
157+
// CHECK-SPV-DAG: Decorate [[#SPEC0:]] SpecId 0
158+
// CHECK-SPV-DAG: Decorate [[#SPEC1:]] SpecId 1
159+
// CHECK-SPV-DAG: Decorate [[#SPEC2:]] SpecId 2
160+
// CHECK-SPV-DAG: Decorate [[#SPEC3:]] SpecId 3
161+
// CHECK-SPV-DAG: Decorate [[#SPEC4:]] SpecId 4
162+
// CHECK-SPV-DAG: Decorate [[#SPEC5:]] SpecId 5
163+
// CHECK-SPV-DAG: Decorate [[#SPEC6:]] SpecId 6
164+
// CHECK-SPV-DAG: Decorate [[#SPEC7:]] SpecId 7
165+
// CHECK-SPV-DAG: Decorate [[#SPEC8:]] SpecId 8
166+
// CHECK-SPV-DAG: Decorate [[#SPEC9:]] SpecId 9
167+
// CHECK-SPV-DAG: Decorate [[#SPEC10:]] SpecId 10
168+
// CHECK-SPV-DAG: Decorate [[#SPEC11:]] SpecId 11
169+
// CHECK-SPV-DAG: Decorate [[#SPEC12:]] SpecId 12
170+
171+
// CHECK-SPV-DAG: TypeInt [[#I64TY:]] 64 0
172+
// CHECK-SPV-DAG: TypeInt [[#I32TY:]] 32 0
173+
// CHECK-SPV-DAG: TypeInt [[#I8TY:]] 8 0
174+
// CHECK-SPV-DAG: TypeInt [[#I16TY:]] 16 0
175+
// CHECK-SPV-DAG: TypeFloat [[#F32TY:]] 32
176+
// CHECK-SPV-DAG: TypeFloat [[#F64TY:]] 64
177+
// CHECK-SPV-DAG: TypeStruct [[#COMPTY:]] [[#I32TY]] [[#I32TY]]
178+
// CHECK-SPV-DAG: SpecConstant [[#I8TY]] [[#SPEC0]] 42
179+
// CHECK-SPV-DAG: SpecConstant [[#I8TY]] [[#SPEC1]] 26
180+
// CHECK-SPV-DAG: SpecConstant [[#I16TY]] [[#SPEC2]] 34
181+
// CHECK-SPV-DAG: SpecConstant [[#I16TY]] [[#SPEC3]] 14
182+
// CHECK-SPV-DAG: SpecConstant [[#I32TY]] [[#SPEC4]] 52
183+
// CHECK-SPV-DAG: SpecConstant [[#I32TY]] [[#SPEC5]] 46
184+
// CHECK-SPV-DAG: SpecConstant [[#I64TY]] [[#SPEC6]] 27 0
185+
// CHECK-SPV-DAG: SpecConstant [[#I64TY]] [[#SPEC7]] 81 0
186+
// CHECK-SPV-DAG: SpecConstant [[#F32TY]] [[#SPEC8]] 1144094720
187+
// CHECK-SPV-DAG: SpecConstant [[#F64TY]] [[#SPEC9]] 0 1076232192
188+
// CHECK-SPV-DAG: SpecConstant [[#I32TY]] [[#SPEC10]] 12
189+
// CHECK-SPV-DAG: SpecConstant [[#I32TY]] [[#SPEC11]] 13
190+
// CHECK-SPV-DAG: SpecConstant [[#I32TY]] [[#SPEC12]] 2
191+
// CHECK-SPV-DAG: SpecConstantComposite [[#COMPTY]] {{.*}} [[#SPEC10]] [[#SPEC11]]

0 commit comments

Comments
 (0)