@@ -185,6 +185,9 @@ def DistributeLayoutAttr: AttrInterface<"DistributeLayoutAttr"> {
185
185
InterfaceMethod<"Check the availability of workgroup level layouts",
186
186
"bool",
187
187
"isForWorkgroup">,
188
+ InterfaceMethod<"Check the availability of subgroup level layouts",
189
+ "bool",
190
+ "isForSubgroup">,
188
191
InterfaceMethod<"Get the rank of attribute",
189
192
"int64_t",
190
193
"getRank">,
@@ -197,14 +200,26 @@ def DistributeLayoutAttr: AttrInterface<"DistributeLayoutAttr"> {
197
200
return 0;
198
201
}], [{}]>,
199
202
InterfaceMethod<"Get the SgLayout field of the attribute as integer array",
200
- "std::optional< SmallVector<int64_t> >",
203
+ "SmallVector<int64_t>",
201
204
"getSgLayoutAsInt">,
202
205
InterfaceMethod<"Get the SgData field of the attribute as integer array",
203
- "std::optional< SmallVector<int64_t> >",
206
+ "SmallVector<int64_t>",
204
207
"getSgDataAsInt">,
208
+ InterfaceMethod<"Get the InstData field of the attribute as integer array",
209
+ "SmallVector<int64_t>",
210
+ "getInstDataAsInt">,
211
+ InterfaceMethod<"Get the LaneLayout field of the attribute as integer array",
212
+ "SmallVector<int64_t>",
213
+ "getLaneLayoutAsInt">,
214
+ InterfaceMethod<"Get the LaneData field of the attribute as integer array",
215
+ "SmallVector<int64_t>",
216
+ "getLaneDataAsInt">,
205
217
InterfaceMethod<"Derive a new layout by dropping sgLayout and sgData",
206
218
"xegpu::DistributeLayoutAttr",
207
219
"dropSgLayoutAndData">,
220
+ InterfaceMethod<"Derive a new layout by dropping InstData",
221
+ "xegpu::DistributeLayoutAttr",
222
+ "dropInstData">,
208
223
InterfaceMethod<[{Delinearizes a linear subgroup ID into its multidimensional
209
224
indices based on the effective subgroup layout.}],
210
225
"FailureOr<SmallVector<Value>>",
@@ -376,16 +391,34 @@ def XeGPU_LayoutAttr : XeGPUAttr<"Layout", "layout", [DistributeLayoutAttr]> {
376
391
getLaneLayout(), getLaneData(), getOrder());
377
392
}
378
393
379
- std::optional< SmallVector<int64_t> > getSgLayoutAsInt() const {
394
+ SmallVector<int64_t> getSgLayoutAsInt() const {
380
395
if (DenseI32ArrayAttr layout = getSgLayout())
381
396
return llvm::to_vector_of<int64_t>(layout.asArrayRef());
382
- return std::nullopt ;
397
+ return {} ;
383
398
}
384
399
385
- std::optional< SmallVector<int64_t> > getSgDataAsInt() const {
400
+ SmallVector<int64_t> getSgDataAsInt() const {
386
401
if (DenseI32ArrayAttr data = getSgData())
387
402
return llvm::to_vector_of<int64_t>(data.asArrayRef());
388
- return std::nullopt;
403
+ return {};
404
+ }
405
+
406
+ SmallVector<int64_t> getInstDataAsInt() const {
407
+ if (DenseI32ArrayAttr inst = getInstData())
408
+ return llvm::to_vector_of<int64_t>(inst.asArrayRef());
409
+ return {};
410
+ }
411
+
412
+ SmallVector<int64_t> getLaneLayoutAsInt() const {
413
+ if (DenseI32ArrayAttr layout = getLaneLayout())
414
+ return llvm::to_vector_of<int64_t>(layout.asArrayRef());
415
+ return {};
416
+ }
417
+
418
+ SmallVector<int64_t> getLaneDataAsInt() const {
419
+ if (DenseI32ArrayAttr data = getLaneData())
420
+ return llvm::to_vector_of<int64_t>(data.asArrayRef());
421
+ return {};
389
422
}
390
423
391
424
/// Delinearizes a linear subgroup ID into its multidimensional indices
@@ -466,26 +499,67 @@ def XeGPU_SliceAttr : XeGPUAttr<"Slice", "slice", [DistributeLayoutAttr]> {
466
499
467
500
/// Returns the SgLayout of the attribute, computed by applying
468
501
/// the slice dimensions to the underlying LayoutAttr.
469
- std::optional< SmallVector<int64_t> > getSgLayoutAsInt() const {
502
+ SmallVector<int64_t> getSgLayoutAsInt() const {
470
503
SliceAttr attr = flatten();
471
504
auto parent = dyn_cast<LayoutAttr>(attr.getParent());
472
- if (auto layout = parent.getSgLayoutAsInt()) {
505
+ auto layout = parent.getSgLayoutAsInt();
506
+ if (layout.size()) {
473
507
ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
474
- return XeGPUDialect::slice(llvm:: ArrayRef<int64_t>(* layout), dims);
508
+ return XeGPUDialect::slice(ArrayRef<int64_t>(layout), dims);
475
509
}
476
- return std::nullopt ;
510
+ return {} ;
477
511
}
478
512
479
513
/// Returns the SgData of the attribute, computed by applying
480
514
/// the slice dimensions to the underlying LayoutAttr.
481
- std::optional<SmallVector<int64_t>> getSgDataAsInt() const {
515
+ SmallVector<int64_t> getSgDataAsInt() const {
516
+ SliceAttr attr = flatten();
517
+ auto parent = dyn_cast<LayoutAttr>(attr.getParent());
518
+ auto data = parent.getSgDataAsInt();
519
+ if (data.size()) {
520
+ ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
521
+ return XeGPUDialect::slice(ArrayRef<int64_t>(data), dims);
522
+ }
523
+ return {};
524
+ }
525
+
526
+ /// Returns the InstData of the attribute, computed by applying
527
+ /// the slice dimensions to the underlying LayoutAttr.
528
+ SmallVector<int64_t> getInstDataAsInt() const {
529
+ SliceAttr attr = flatten();
530
+ auto parent = dyn_cast<LayoutAttr>(attr.getParent());
531
+ auto inst = parent.getInstDataAsInt();
532
+ if (inst.size()) {
533
+ ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
534
+ return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(inst), dims);
535
+ }
536
+ return {};
537
+ }
538
+
539
+ /// Returns the LaneLayout of the attribute, computed by applying
540
+ /// the slice dimensions to the underlying LayoutAttr.
541
+ SmallVector<int64_t> getLaneLayoutAsInt() const {
542
+ SliceAttr attr = flatten();
543
+ auto parent = dyn_cast<LayoutAttr>(attr.getParent());
544
+ auto layout = parent.getLaneLayoutAsInt();
545
+ if (layout.size()) {
546
+ ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
547
+ return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(layout), dims);
548
+ }
549
+ return {};
550
+ }
551
+
552
+ /// Returns the LaneData of the attribute, computed by applying
553
+ /// the slice dimensions to the underlying LayoutAttr.
554
+ SmallVector<int64_t> getLaneDataAsInt() const {
482
555
SliceAttr attr = flatten();
483
556
auto parent = dyn_cast<LayoutAttr>(attr.getParent());
484
- if (auto data = parent.getSgDataAsInt()) {
557
+ auto data = parent.getLaneDataAsInt();
558
+ if (data.size()) {
485
559
ArrayRef<int64_t> dims = attr.getDims().asArrayRef();
486
- return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(* data), dims);
560
+ return XeGPUDialect::slice(llvm::ArrayRef<int64_t>(data), dims);
487
561
}
488
- return std::nullopt ;
562
+ return {} ;
489
563
}
490
564
491
565
SliceAttr dropSgLayoutAndData() {
0 commit comments