Skip to content

Commit e40b404

Browse files
committed
[SYCL][DOC] Apply comments
Renamed section describing interaction with the SPIR-V translator. Returned back section about interaction with the SPIR-V translator about composite spec constants. Returned back `__sycl_getCompositeSpecConstantValue` intrinsic. Improved an example of composite spec constant by adding vector into it.
1 parent 484a71f commit e40b404

File tree

1 file changed

+63
-14
lines changed

1 file changed

+63
-14
lines changed

sycl/doc/SpecializationConstants.md

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ the `__sycl_getSpecConstantValue` calls with constants - default values of
108108
the spec constant's type. No maps are generated, and SYCL program can't change
109109
the value of a spec constant.
110110
111-
#### LLVMIR-SPIR-V translator
111+
#### LLVM -> SPIR-V translation
112112
113113
Given the `__spirv_SpecConstant` intrinsic calls produced by the
114114
`SpecConstants` pass:
@@ -175,7 +175,7 @@ struct A {
175175
176176
struct POD {
177177
A a[2];
178-
int b;
178+
cl::sycl::vec<int, 2> b;
179179
};
180180
```
181181

@@ -187,7 +187,7 @@ and the user says
187187
{ goldi, goldf },
188188
{ goldi + 1, goldf + 1 },
189189
},
190-
goldi
190+
{ goldi, goldi }
191191
};
192192

193193
cl::sycl::ONEAPI::experimental::spec_constant<POD, MyConst> sc = program4.set_spec_constant<MyConst>(gold);
@@ -197,21 +197,27 @@ and the user says
197197
198198
##### The SpecConstant pass changes
199199
200-
- The SpecConstants pass in the post-link will have the following IR as input (`sret` conversion is omitted for clarity):
200+
The SpecConstants pass in the post-link will have the following IR as input
201+
(`sret` conversion is omitted for clarity):
201202
202203
```
203-
%struct.POD = type { [2 x %struct.A], i32 }
204+
%struct.POD = type { [2 x %struct.A], <2 x i32> }
204205
%struct.A = type { i32, float }
205206

206-
%spec_const = call %struct.POD __sycl_getSpecConstantValue<POD type mangling> ("MyConst_mangled")
207+
%spec_const = call %struct.POD __sycl_getCompositeSpecConstantValue<POD type mangling> ("MyConst_mangled")
207208
```
208209
209-
Based on the fact that `__sycl_getSpecConstantValue` returns `llvm::StructType`,
210-
it will be replaced with a set of `__spirv_SpecConstant` calls for each member
211-
of its return type plus one `__spirv_SpecConstantComposite` to gather members
212-
back into a single composite. If any composite member is another composite, then
213-
it will be also represented by number of `__spirv_SpecConstant` plus one
214-
`__spirv_SpecConstantComposite`:
210+
`__sycl_getCompositeSpecConstantValue` is a new "intrinsic" (in addition to
211+
`__sycl_getSpecConstantValue`) recognized by `SpecConstants` pass, which creates
212+
a value of a composite (of non-primitive type) specialization constant.
213+
It does not need a default value, because its default value consists of default
214+
values of its leaf specialization constants (see below).
215+
216+
`__sycl_getCompositeSpecConstantValue` will be replaced with a set of
217+
`__spirv_SpecConstant` calls for each member of its return type plus one
218+
`__spirv_SpecConstantComposite` to gather members back into a single composite.
219+
If any composite member is another composite, then it will be also represented
220+
by number of `__spirv_SpecConstant` plus one `__spirv_SpecConstantComposite`:
215221
216222
```
217223
%gold_POD_A0_x = call i32 __spirv_SpecConstant(i32 10, i32 0)
@@ -225,9 +231,12 @@ it will be also represented by number of `__spirv_SpecConstant` plus one
225231
%gold_POD_A1 = call %struct.A __spirv_SpecConstantComposite(i32 %gold_POD_A1_x, float %gold_POD_A1_y)
226232

227233
%gold_POD_A = call [2 x %struct.A] __spirv_SpecConstantComposite(%struct.A %gold_POD_A0, %struct.A %gold_POD_A1)
228-
%gold_POD_b = call i32 __spirv_SpecConstant(i32 14, i32 0)
229234

230-
%gold = call %struct.POD __spirv_SpecConstantComposite([2 x %struct.A] %gold_POD_A, i32 %gold_POD_b)
235+
%gold_POD_b0 = call i32 __spirv_SpecConstant(i32 14, i32 0)
236+
%gold_POD_b1 = call i32 __spirv_SpecConstant(i32 15, i32 0)
237+
%gold_POD_b = call <2 x i32> __spirv_SpecConstant(i32 %gold_POD_b0, i32 %gold_POD_b1)
238+
239+
%gold = call %struct.POD __spirv_SpecConstantComposite([2 x %struct.A] %gold_POD_A, <2 x i32> %gold_POD_b)
231240

232241
```
233242
@@ -236,6 +245,46 @@ it - it will use IDs of the leaves instead.
236245
Yet, the SPIR-V specification does not allow `SpecID` decoration for composite
237246
spec constants, because its defined by its members instead.
238247
248+
`__spirv_SpecConstantComposite` is a new "intrinsic", which represents composite
249+
specialization constant. Its arguments are LLVM IR valures corresponding to
250+
elements of composite type of the constant.
251+
252+
##### LLVM -> SPIR-V translation
253+
254+
Given the `__spirv_SpecConstantComposite` intrinsic calls produced by the
255+
`SpecConstants` pass:
256+
```
257+
258+
%struct.A = type { i32, float }
259+
260+
; Function Attrs: alwaysinline
261+
define dso_local spir_func void @get(%struct.A* sret %ret.ptr) local_unnamed_addr #0 {
262+
; args are "ID" and "default value":
263+
%1 = tail call spir_func i32 @_Z20__spirv_SpecConstantii(i32 42, i32 0)
264+
%2 = tail call spir_func i32 @_Z20__spirv_SpecConstantif(i32 43, float 0.000000e+00)
265+
%ret = tail call spir_func %struct.A @_Z29__spirv_SpecConstantCompositeif(%1, %2)
266+
store %struct.A %ret, %struct.A* %ret.ptr
267+
ret void
268+
}
269+
```
270+
271+
the translator will generate `OpSpecConstant` and `OpSpecConstantComposite`
272+
SPIR-V instructions with proper `SpecId` decorations:
273+
274+
```
275+
OpDecorate %i32 SpecId 42 ; ID
276+
OpDecorate %float SpecId 43 ; ID
277+
%i32 = OpSpecConstant %int.type 0 ; Default value
278+
%float = OpSpecConstant %float.type 0.0 ; Default value
279+
%struct = OpSpecConstantComposite %struct.type %i32 %float ; No ID, defined by its elements
280+
%1 = OpTypeFunction %struct.type
281+
282+
%get = OpFunction %struct.type None %1
283+
%2 = OpLabel
284+
OpReturnValue %struct
285+
OpFunctionEnd
286+
```
287+
239288
##### The post-link tool changes
240289

241290
For composite specialization constants the post link tool will additionally

0 commit comments

Comments
 (0)