// RUN: mlir-opt %s -convert-linalg-to-std | FileCheck %s // CHECK-DAG: #[[$map0:.*]] = affine_map<(d0)[s0] -> (d0 + s0)> // CHECK-DAG: #[[$map1:.*]] = affine_map<(d0, d1, d2)[s0, s1, s2] -> (d0 * s1 + s0 + d1 * s2 + d2)> // CHECK-DAG: #[[$map2:.*]] = affine_map<(d0, d1, d2)[s0, s1, s2] -> (d0 * s1 + s0 + d2 * s2 + d1)> // CHECK-DAG: #[[$map4:.*]] = affine_map<(d0, d1, d2)[s0, s1, s2] -> (d2 * s1 + s0 + d1 * s2 + d0)> // CHECK-DAG: #[[$map6:.*]] = affine_map<(d0)[s0, s1] -> (d0 * s1 + s0)> // CHECK-DAG: #[[$map7:.*]] = affine_map<()[s0] -> (s0)> // CHECK-DAG: #[[$map8:.*]] = affine_map<(d0, d1, d2)[s0, s1, s2, s3] -> (d0 * s1 + s0 + d1 * s2 + d2 * s3)> func @dot(%arg0: memref, %arg1: memref, %arg2: memref) { linalg.dot ins(%arg0, %arg1: memref, memref) outs(%arg2: memref) return } // CHECK-LABEL: func @dot( // CHECK-SAME: %[[arg0:[a-zA-z0-9]*]]: memref, // CHECK-SAME: %[[arg1:[a-zA-z0-9]*]]: memref, // CHECK-SAME: %[[arg2:[a-zA-z0-9]*]]: memref) { // CHECK: %[[o0:.*]] = memref_cast %[[arg0]] : // CHECK-SAME: memref to memref // CHECK: %[[o1:.*]] = memref_cast %[[arg1]] : // CHECK-SAME: memref to memref // CHECK: %[[o2:.*]] = memref_cast %[[arg2]] : // CHECK-SAME: memref to memref // CHECK: call @linalg_dot_viewsxf32_viewsxf32_viewf32( // CHECK-SAME: %[[o0]], %[[o1]], %[[o2]]) : // CHECK-SAME: memref, memref, memref func @copy(%arg0: memref, %arg1: memref) { linalg.copy(%arg0, %arg1) : memref, memref return } // CHECK-LABEL: func @copy( // CHECK-SAME: %[[arg0:[a-zA-z0-9]*]]: memref, // CHECK-SAME: %[[arg1:[a-zA-z0-9]*]]: memref) { // CHECK: %[[o0:.*]] = memref_cast %[[arg0]] : // CHECK-SAME: memref to memref // CHECK: %[[o1:.*]] = memref_cast %[[arg1]] : // CHECK-SAME: memref to memref // CHECK: call @linalg_copy_viewsxsxsxf32_viewsxsxsxf32(%[[o0]], %[[o1]]) : // CHECK-SAME: memref, memref func @copy_transpose(%arg0: memref, %arg1: memref) { linalg.copy(%arg0, %arg1) {inputPermutation = affine_map<(i, j, k) -> (i, k, j)>, outputPermutation = affine_map<(i, j, k) -> (k, j, i)>} : memref, memref return } // CHECK-LABEL: func @copy_transpose( // CHECK-SAME: %[[arg0:[a-zA-z0-9]*]]: memref, // CHECK-SAME: %[[arg1:[a-zA-z0-9]*]]: memref) { // CHECK: %[[t0:.*]] = transpose %[[arg0]] // CHECK-SAME: (d0, d1, d2) -> (d0, d2, d1) : memref // CHECK: %[[t1:.*]] = transpose %[[arg1]] // CHECK-SAME: (d0, d1, d2) -> (d2, d1, d0) : memref // CHECK: %[[o0:.*]] = memref_cast %[[t0]] : // CHECK-SAME: memref to memref // CHECK: %[[o1:.*]] = memref_cast %[[t1]] : // CHECK-SAME: memref to memref // CHECK: call @linalg_copy_viewsxsxsxf32_viewsxsxsxf32(%[[o0]], %[[o1]]) : // CHECK-SAME: memref, memref #matmul_accesses = [ affine_map<(m, n, k) -> (m, k)>, affine_map<(m, n, k) -> (k, n)>, affine_map<(m, n, k) -> (m, n)> ] #matmul_trait = { iterator_types = ["parallel", "parallel", "reduction"], indexing_maps = #matmul_accesses, library_call = "external_outerproduct_matmul" } !vector_type_A = type vector<4xf32> !vector_type_B = type vector<4xf32> !vector_type_C = type vector<4x4xf32> !matrix_type_A = type memref !matrix_type_B = type memref !matrix_type_C = type memref func @matmul_vec_impl(%A: !matrix_type_A, %B: !matrix_type_B, %C: !matrix_type_C) { linalg.generic #matmul_trait ins(%A, %B : !matrix_type_A, !matrix_type_B) outs(%C : !matrix_type_C) { ^bb0(%a: !vector_type_A, %b: !vector_type_B, %c: !vector_type_C): %d = vector.outerproduct %a, %b, %c: !vector_type_A, !vector_type_B linalg.yield %d: !vector_type_C } return } // CHECK-LABEL: func @matmul_vec_impl( // CHECK: call @external_outerproduct_matmul(%{{.*}}) : #indexed_matmul_trait = { iterator_types = ["parallel", "parallel", "reduction"], indexing_maps = #matmul_accesses, library_call = "external_indexed_outerproduct_matmul" } func @matmul_vec_indexed(%A: !matrix_type_A, %B: !matrix_type_B, %C: !matrix_type_C) { linalg.indexed_generic #indexed_matmul_trait ins(%A, %B : !matrix_type_A, !matrix_type_B) outs(%C : !matrix_type_C) { ^bb0(%i: index, %j: index, %k: index, %a: !vector_type_A, %b: !vector_type_B, %c: !vector_type_C): %d = vector.outerproduct %a, %b, %c: !vector_type_A, !vector_type_B linalg.yield %d: !vector_type_C } return } // CHECK-LABEL: func @matmul_vec_indexed( // CHECK: %[[ZERO:.*]] = constant 0 : index // CHECK: call @external_indexed_outerproduct_matmul(%[[ZERO]], %[[ZERO]], %[[ZERO]], %{{.*}})