Skip to content

Commit 5d81e30

Browse files
authored
[SYCL-MLIR] Pretty print SYCL grid operations (#8122)
- 1-D Grid operations: `attr-dict : type($result)`; - 3-D Grid operations: `$dimension attr-dict : type($result)`; Signed-off-by: Victor Perez <[email protected]>
1 parent 1282556 commit 5d81e30

File tree

5 files changed

+101
-150
lines changed

5 files changed

+101
-150
lines changed

mlir-sycl/include/mlir/Dialect/SYCL/IR/SYCLOps.td

Lines changed: 35 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -427,52 +427,57 @@ def VectorSplatArg : MemRefOf<[VectorEltTy]>;
427427
// SYCL GRID OPERATIONS
428428
////////////////////////////////////////////////////////////////////////////////
429429

430-
def SYCLNumWorkItemsOp : SYCL_Op<"num_work_items", [SYCLIndexSpaceGetRange]> {
430+
class SYCL1DGridOp<string mnemonic, list<Trait> traits = []>
431+
: SYCL_Op<mnemonic, traits> {
432+
let arguments = (ins);
433+
let results = (outs I32:$result);
434+
let assemblyFormat = "attr-dict `:` type($result)";
435+
}
436+
437+
class SYCL3DGridOp<string mnemonic, list<Trait> traits = []>
438+
: SYCL_Op<mnemonic, traits> {
439+
let arguments = (ins Optional<I32>:$dimension);
440+
let assemblyFormat = "$dimension attr-dict `:` type($result)";
441+
}
442+
443+
class SYCL3DIDGridOp<string mnemonic>
444+
: SYCL3DGridOp<mnemonic, [SYCLIndexSpaceGetID]> {
445+
let results = (outs SYCLIndexSpaceGetIDResult:$result);
446+
}
447+
448+
class SYCL3DRangeGridOp<string mnemonic>
449+
: SYCL3DGridOp<mnemonic, [SYCLIndexSpaceGetRange]> {
450+
let results = (outs SYCLIndexSpaceGetRangeResult:$result);
451+
}
452+
453+
def SYCLNumWorkItemsOp : SYCL3DRangeGridOp<"num_work_items"> {
431454
let summary = "Retrieve the number of work-items.";
432455
let description = [{
433456
This operation returns the number of work-items in the index space. If the
434457
optional argument is passed, the number of work-items in the given dimension
435458
is returned.
436459
}];
437-
438-
let arguments = (ins Optional<I32>:$dimension);
439-
let results = (outs SYCLIndexSpaceGetRangeResult:$result);
440-
let assemblyFormat = [{
441-
`(` operands `)` attr-dict `:` functional-type(operands, results)
442-
}];
443460
}
444461

445-
def SYCLGlobalIDOp : SYCL_Op<"global_id", [SYCLIndexSpaceGetID]> {
462+
def SYCLGlobalIDOp : SYCL3DIDGridOp<"global_id"> {
446463
let summary = "Retrieve the global ID of the item.";
447464
let description = [{
448465
This operation returns the global ID of the item in the index space. If the
449466
optional argument is passed, the global ID of the item in the given
450467
dimension is returned.
451468
}];
452-
453-
let arguments = (ins Optional<I32>:$dimension);
454-
let results = (outs SYCLIndexSpaceGetIDResult:$result);
455-
let assemblyFormat = [{
456-
`(` operands `)` attr-dict `:` functional-type(operands, results)
457-
}];
458469
}
459470

460-
def SYCLLocalIDOp : SYCL_Op<"local_id", [SYCLIndexSpaceGetID]> {
471+
def SYCLLocalIDOp : SYCL3DIDGridOp<"local_id"> {
461472
let summary = "Retrieve the local ID of the item.";
462473
let description = [{
463474
This operation returns the local ID of the item within the work-group. If
464475
the optional argument is passed, the local ID of the item in the given
465476
dimension is returned.
466477
}];
467-
468-
let arguments = (ins Optional<I32>:$dimension);
469-
let results = (outs SYCLIndexSpaceGetIDResult:$result);
470-
let assemblyFormat = [{
471-
`(` operands `)` attr-dict `:` functional-type(operands, results)
472-
}];
473478
}
474479

475-
def SYCLGlobalOffsetOp : SYCL_Op<"global_offset", [SYCLIndexSpaceGetID]>,
480+
def SYCLGlobalOffsetOp : SYCL3DIDGridOp<"global_offset">,
476481
Deprecated<"deprecated in SYCL 2020"> {
477482
let summary = "Retrieve the global offset of the item.";
478483
let description = [{
@@ -482,121 +487,67 @@ def SYCLGlobalOffsetOp : SYCL_Op<"global_offset", [SYCLIndexSpaceGetID]>,
482487

483488
Note that this is deprecated in SYCL 2020.
484489
}];
485-
486-
let arguments = (ins Optional<I32>:$dimension);
487-
let results = (outs SYCLIndexSpaceGetIDResult:$result);
488-
let assemblyFormat = [{
489-
`(` operands `)` attr-dict `:` functional-type(operands, results)
490-
}];
491490
}
492491

493-
def SYCLNumWorkGroupsOp : SYCL_Op<"num_work_groups", [SYCLIndexSpaceGetRange]> {
492+
def SYCLNumWorkGroupsOp : SYCL3DRangeGridOp<"num_work_groups"> {
494493
let summary = "Retrieve the number of work-groups.";
495494
let description = [{
496495
This operation returns the number of work-groups in the index space. If the
497496
optional argument is passed, the number of work-groups in the given
498497
dimension is returned.
499498
}];
500-
501-
let arguments = (ins Optional<I32>:$dimension);
502-
let results = (outs SYCLIndexSpaceGetRangeResult:$result);
503-
let assemblyFormat = [{
504-
`(` operands `)` attr-dict `:` functional-type(operands, results)
505-
}];
506499
}
507500

508-
def SYCLWorkGroupSizeOp : SYCL_Op<"work_group_size", [SYCLIndexSpaceGetRange]> {
501+
def SYCLWorkGroupSizeOp : SYCL3DRangeGridOp<"work_group_size"> {
509502
let summary = "Retrieve the number of work-items in a work-group.";
510503
let description = [{
511504
This operation returns the number of work-items per work-group. If the
512505
optional argument is passed, the number of work-items per work-group in the
513506
given dimension is returned.
514507
}];
515-
516-
let arguments = (ins Optional<I32>:$dimension);
517-
let results = (outs SYCLIndexSpaceGetRangeResult:$result);
518-
let assemblyFormat = [{
519-
`(` operands `)` attr-dict `:` functional-type(operands, results)
520-
}];
521508
}
522509

523-
def SYCLWorkGroupIDOp : SYCL_Op<"work_group_id", [SYCLIndexSpaceGetID]> {
510+
def SYCLWorkGroupIDOp : SYCL3DIDGridOp<"work_group_id"> {
524511
let summary = "Retrieve the ID of the work-group.";
525512
let description = [{
526513
This operation returns the ID of the work-group. If the optional argument is
527514
passed, the ID of the work-group in the given dimension is returned.
528515
}];
529-
530-
let arguments = (ins Optional<I32>:$dimension);
531-
let results = (outs SYCLIndexSpaceGetIDResult:$result);
532-
let assemblyFormat = [{
533-
`(` operands `)` attr-dict `:` functional-type(operands, results)
534-
}];
535516
}
536517

537-
def SYCLNumSubGroupsOp : SYCL_Op<"num_sub_groups"> {
518+
def SYCLNumSubGroupsOp : SYCL1DGridOp<"num_sub_groups"> {
538519
let summary = "Retrieve the number of sub-groups.";
539520
let description = [{
540521
This operation returns the number of sub-groups.
541522
}];
542-
543-
let arguments = (ins);
544-
let results = (outs I32:$result);
545-
let assemblyFormat = [{
546-
attr-dict `:` functional-type(operands, results)
547-
}];
548523
}
549524

550-
def SYCLSubGroupMaxSizeOp : SYCL_Op<"sub_group_max_size"> {
525+
def SYCLSubGroupMaxSizeOp : SYCL1DGridOp<"sub_group_max_size"> {
551526
let summary = "Retrieve the maximum size of a sub-group.";
552527
let description = [{
553528
This operation returns the maximum size of a sub-group.
554529
}];
555-
556-
let arguments = (ins);
557-
let results = (outs I32:$result);
558-
let assemblyFormat = [{
559-
attr-dict `:` functional-type(operands, results)
560-
}];
561530
}
562531

563-
def SYCLSubGroupSizeOp : SYCL_Op<"sub_group_size"> {
532+
def SYCLSubGroupSizeOp : SYCL1DGridOp<"sub_group_size"> {
564533
let summary = "Retrieve the sub-group size.";
565534
let description = [{
566535
This operation returns the sub-group size.
567536
}];
568-
569-
let arguments = (ins);
570-
let results = (outs I32:$result);
571-
let assemblyFormat = [{
572-
attr-dict `:` functional-type(operands, results)
573-
}];
574537
}
575538

576-
def SYCLSubGroupIDOp : SYCL_Op<"sub_group_id"> {
539+
def SYCLSubGroupIDOp : SYCL1DGridOp<"sub_group_id"> {
577540
let summary = "Retrieve the ID of the sub-group.";
578541
let description = [{
579542
This operation returns the ID of the sub-group.
580543
}];
581-
582-
let arguments = (ins);
583-
let results = (outs I32:$result);
584-
let assemblyFormat = [{
585-
attr-dict `:` functional-type(operands, results)
586-
}];
587544
}
588545

589-
def SYCLSubGroupLocalIDOp : SYCL_Op<"sub_group_local_id"> {
546+
def SYCLSubGroupLocalIDOp : SYCL1DGridOp<"sub_group_local_id"> {
590547
let summary = "Retrieve the local ID of the sub-group.";
591548
let description = [{
592549
This operation returns the local ID of the sub-group.
593550
}];
594-
595-
let arguments = (ins);
596-
let results = (outs I32:$result);
597-
let assemblyFormat = [{
598-
attr-dict `:` functional-type(operands, results)
599-
}];
600551
}
601552

602553
////////////////////////////////////////////////////////////////////////////////

mlir-sycl/test/Conversion/SYCLToGPU/grid-ops.mlir

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// CHECK-NEXT: return %[[VAL_2]] : !sycl_range_1_
2020
// CHECK-NEXT: }
2121
func.func @test_num_work_items() -> !sycl_range_1_ {
22-
%0 = sycl.num_work_items() : () -> !sycl_range_1_
22+
%0 = sycl.num_work_items : !sycl_range_1_
2323
return %0 : !sycl_range_1_
2424
}
2525

@@ -40,7 +40,7 @@ func.func @test_num_work_items() -> !sycl_range_1_ {
4040
// CHECK-NEXT: return %[[VAL_9]] : index
4141
// CHECK-NEXT: }
4242
func.func @test_num_work_items_dim(%i: i32) -> index {
43-
%0 = sycl.num_work_items(%i) : (i32) -> index
43+
%0 = sycl.num_work_items %i : index
4444
return %0 : index
4545
}
4646

@@ -61,7 +61,7 @@ func.func @test_num_work_items_dim(%i: i32) -> index {
6161
// CHECK-NEXT: return %[[VAL_2]] : !sycl_id_2_
6262
// CHECK-NEXT: }
6363
func.func @test_global_id() -> !sycl_id_2_ {
64-
%0 = sycl.global_id() : () -> !sycl_id_2_
64+
%0 = sycl.global_id : !sycl_id_2_
6565
return %0 : !sycl_id_2_
6666
}
6767

@@ -82,7 +82,7 @@ func.func @test_global_id() -> !sycl_id_2_ {
8282
// CHECK-NEXT: return %[[VAL_9]] : index
8383
// CHECK-NEXT: }
8484
func.func @test_global_id_dim(%i: i32) -> index {
85-
%0 = sycl.global_id(%i) : (i32) -> index
85+
%0 = sycl.global_id %i : index
8686
return %0 : index
8787
}
8888

@@ -108,7 +108,7 @@ func.func @test_global_id_dim(%i: i32) -> index {
108108
// CHECK-NEXT: return %[[VAL_2]] : !sycl_id_3_
109109
// CHECK-NEXT: }
110110
func.func @test_local_id() -> !sycl_id_3_ {
111-
%0 = sycl.local_id() : () -> !sycl_id_3_
111+
%0 = sycl.local_id : !sycl_id_3_
112112
return %0 : !sycl_id_3_
113113
}
114114

@@ -129,7 +129,7 @@ func.func @test_local_id() -> !sycl_id_3_ {
129129
// CHECK-NEXT: return %[[VAL_9]] : index
130130
// CHECK-NEXT: }
131131
func.func @test_local_id_dim(%i: i32) -> index {
132-
%0 = sycl.local_id(%i) : (i32) -> index
132+
%0 = sycl.local_id %i : index
133133
return %0 : index
134134
}
135135

@@ -155,7 +155,7 @@ func.func @test_local_id_dim(%i: i32) -> index {
155155
// CHECK-NEXT: return %[[VAL_2]] : !sycl_range_3_
156156
// CHECK-NEXT: }
157157
func.func @test_work_group_size() -> !sycl_range_3_ {
158-
%0 = sycl.work_group_size() : () -> !sycl_range_3_
158+
%0 = sycl.work_group_size : !sycl_range_3_
159159
return %0 : !sycl_range_3_
160160
}
161161

@@ -176,7 +176,7 @@ func.func @test_work_group_size() -> !sycl_range_3_ {
176176
// CHECK-NEXT: return %[[VAL_9]] : index
177177
// CHECK-NEXT: }
178178
func.func @test_work_group_size_dim(%i: i32) -> index {
179-
%0 = sycl.work_group_size(%i) : (i32) -> index
179+
%0 = sycl.work_group_size %i : index
180180
return %0 : index
181181
}
182182

@@ -192,7 +192,7 @@ func.func @test_work_group_size_dim(%i: i32) -> index {
192192
// CHECK-NEXT: return %[[VAL_2]] : !sycl_id_1_
193193
// CHECK-NEXT: }
194194
func.func @test_work_group_id() -> !sycl_id_1_ {
195-
%0 = sycl.work_group_id() : () -> !sycl_id_1_
195+
%0 = sycl.work_group_id : !sycl_id_1_
196196
return %0 : !sycl_id_1_
197197
}
198198

@@ -213,7 +213,7 @@ func.func @test_work_group_id() -> !sycl_id_1_ {
213213
// CHECK-NEXT: return %[[VAL_9]] : index
214214
// CHECK-NEXT: }
215215
func.func @test_work_group_id_dim(%i: i32) -> index {
216-
%0 = sycl.work_group_id(%i) : (i32) -> index
216+
%0 = sycl.work_group_id %i : index
217217
return %0 : index
218218
}
219219

@@ -223,7 +223,7 @@ func.func @test_work_group_id_dim(%i: i32) -> index {
223223
// CHECK-NEXT: return %[[VAL_1]] : i32
224224
// CHECK-NEXT: }
225225
func.func @test_num_sub_groups() -> i32 {
226-
%0 = sycl.num_sub_groups : () -> i32
226+
%0 = sycl.num_sub_groups : i32
227227
return %0 : i32
228228
}
229229

@@ -233,7 +233,7 @@ func.func @test_num_sub_groups() -> i32 {
233233
// CHECK-NEXT: return %[[VAL_1]] : i32
234234
// CHECK-NEXT: }
235235
func.func @test_sub_group_size() -> i32 {
236-
%0 = sycl.sub_group_size : () -> i32
236+
%0 = sycl.sub_group_size : i32
237237
return %0 : i32
238238
}
239239

@@ -243,6 +243,6 @@ func.func @test_sub_group_size() -> i32 {
243243
// CHECK-NEXT: return %[[VAL_1]] : i32
244244
// CHECK-NEXT: }
245245
func.func @test_sub_group_id() -> i32 {
246-
%0 = sycl.sub_group_id : () -> i32
246+
%0 = sycl.sub_group_id : i32
247247
return %0 : i32
248248
}

mlir-sycl/test/Conversion/SYCLToSPIRV/grid-ops.mlir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module attributes {gpu.container_module} {
2626
// CHECK-NEXT }
2727
gpu.func @test_global_offset() kernel
2828
attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} {
29-
%0 = sycl.global_offset() : () -> !sycl_id_1_
29+
%0 = sycl.global_offset : !sycl_id_1_
3030
gpu.return
3131
}
3232

@@ -53,7 +53,7 @@ module attributes {gpu.container_module} {
5353
// CHECK-NEXT }
5454
gpu.func @test_global_offset_dim(%i: i32) kernel
5555
attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} {
56-
%0 = sycl.global_offset(%i) : (i32) -> index
56+
%0 = sycl.global_offset %i : index
5757
gpu.return
5858
}
5959

@@ -77,7 +77,7 @@ module attributes {gpu.container_module} {
7777
// CHECK-NEXT }
7878
gpu.func @test_num_work_groups() kernel
7979
attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} {
80-
%0 = sycl.num_work_groups() : () -> !sycl_range_2_
80+
%0 = sycl.num_work_groups : !sycl_range_2_
8181
gpu.return
8282
}
8383

@@ -104,7 +104,7 @@ module attributes {gpu.container_module} {
104104
// CHECK-NEXT }
105105
gpu.func @test_num_work_groups_dim(%i: i32) kernel
106106
attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} {
107-
%0 = sycl.num_work_groups(%i) : (i32) -> index
107+
%0 = sycl.num_work_groups %i : index
108108
gpu.return
109109
}
110110

@@ -115,7 +115,7 @@ module attributes {gpu.container_module} {
115115
// CHECK-NEXT }
116116
gpu.func @test_sub_group_max_size() kernel
117117
attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} {
118-
%0 = sycl.sub_group_max_size : () -> i32
118+
%0 = sycl.sub_group_max_size : i32
119119
gpu.return
120120
}
121121

@@ -126,7 +126,7 @@ module attributes {gpu.container_module} {
126126
// CHECK-NEXT }
127127
gpu.func @test_sub_group_local_id() kernel
128128
attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} {
129-
%0 = sycl.sub_group_local_id : () -> i32
129+
%0 = sycl.sub_group_local_id : i32
130130
gpu.return
131131
}
132132
}

0 commit comments

Comments
 (0)