1// RUN: mlir-linalg-ods-gen %s -gen-ods-decl=1 | FileCheck %s --check-prefix=ODS 2// RUN: mlir-linalg-ods-gen %s -gen-impl=1 | FileCheck %s --check-prefix=IMPL 3 4// ODS-LABEL: def Test1Op : LinalgStructuredBase_Op<"test1", [ 5// ODS-NEXT: AttrSizedOperandSegments 6// ODS-NEXT: DeclareOpInterfaceMethods<MemoryEffectsOpInterface>, 7// ODS-NEXT: NamedStructuredOpTrait 8// ODS-NEXT: SingleBlockImplicitTerminator<"YieldOp"> 9// 10// IMPL-LABEL: ArrayAttr Test1Op::iterator_types() { 11// IMPL: { {{.*}}Parallel{{.*}}, {{.*}}Reduction{{.*}} } 12// 13// IMPL: ArrayAttr Test1Op::indexing_maps() { 14// IMPL: AffineMap::get(2, 0, {d0, d1}, context), 15// IMPL-NEXT: AffineMap::get(2, 0, {d1}, context), 16// IMPL-NEXT: AffineMap::get(2, 0, {d0}, context) }); 17// 18// IMPL: void Test1Op::regionBuilder(Block &block) { 19// IMPL: Value [[a:.*]](args[0]), [[b:.*]](args[1]), [[c:.*]](args[2]); 20// IMPL: Value [[d:.*]] = std_mulf([[a]], [[b]]); 21// IMPL: Value [[e:.*]] = std_addf([[c]], [[d]]); 22// IMPL: (linalg_yield(ValueRange{ [[e]] })); 23// 24ods_def<Test1Op> : 25def test1(A: f32(M, K), B: f32(K)) -> (C: f32(M)) { 26 C(m) = std_addf<k>(std_mulf(A(m, k), B(k))); 27} 28 29// ODS-LABEL: def Test2Op : LinalgStructuredBase_Op<"test2", [ 30// ODS-NEXT: AttrSizedOperandSegments 31// ODS-NEXT: DeclareOpInterfaceMethods<MemoryEffectsOpInterface>, 32// ODS-NEXT: NamedStructuredOpTrait 33// ODS-NEXT: SingleBlockImplicitTerminator<"YieldOp"> 34// 35// IMPL-LABEL: ArrayAttr Test2Op::iterator_types() { 36// IMPL: { {{.*}}Parallel{{.*}}, {{.*}}Parallel{{.*}}, {{.*}}Reduction{{.*}} } 37// 38// IMPL: ArrayAttr Test2Op::indexing_maps() { 39// IMPL: AffineMap::get(3, 0, {d0, d2}, context), 40// IMPL-NEXT: AffineMap::get(3, 0, {d2, d1}, context), 41// IMPL-NEXT: AffineMap::get(3, 0, {d0, d1}, context) }); 42// 43// IMPL: Test2Op::regionBuilder(Block &block) { 44// IMPL: Value [[a:.*]](args[0]), [[b:.*]](args[1]), [[c:.*]](args[2]); 45// IMPL: Value [[d:.*]] = std_mulf([[a]], [[b]]); 46// IMPL: Value [[e:.*]] = std_addf([[c]], [[d]]); 47// IMPL: (linalg_yield(ValueRange{ [[e]] })); 48// 49ods_def<Test2Op> : 50def test2(A: f32(M, K), B: f32(K, N)) -> (C: f32(M, N)) { 51 C(m, n) = std_addf<k>(std_mulf(A(m, k), B(k, n))); 52} 53 54// ODS-LABEL: def Test3Op : LinalgStructuredBase_Op<"test3", [ 55// ODS-NEXT: AttrSizedOperandSegments 56// ODS-NEXT: DeclareOpInterfaceMethods<MemoryEffectsOpInterface>, 57// ODS-NEXT: NamedStructuredOpTrait 58// ODS-NEXT: SingleBlockImplicitTerminator<"YieldOp"> 59// 60// IMPL-LABEL: ArrayAttr Test3Op::iterator_types() { 61// IMPL: { {{.*}}Parallel{{.*}}, {{.*}}Parallel{{.*}}, {{.*}}Reduction{{.*}} } 62// 63// IMPL: ArrayAttr Test3Op::indexing_maps() { 64// IMPL: AffineMap::get(4, 0, {d0, d1, d3}, context), 65// IMPL-NEXT: AffineMap::get(4, 0, {d3, d2}, context), 66// IMPL-NEXT: AffineMap::get(4, 0, {d0, d1, d2}, context) }); 67// 68// IMPL: Test3Op::regionBuilder(Block &block) { 69// IMPL: Value [[a:.*]](args[0]), [[b:.*]](args[1]), [[c:.*]](args[2]); 70// IMPL: Value [[d:.*]] = std_mulf([[a]], [[b]]); 71// IMPL: Value [[e:.*]] = std_addf([[c]], [[d]]); 72// IMPL: (linalg_yield(ValueRange{ [[e]] })); 73// 74ods_def<Test3Op> : 75def test3(A: f32(Batch, M, K), B: f32(K, N)) -> (C: f32(Batch, M, N)) { 76 C(b, m, n) = std_addf<k>(std_mulf(A(b, m, k), B(k, n))); 77} 78