| // NOTE: Assertions have been autogenerated by utils/generate-test-checks.py | |
| // RUN: mlir-opt %s -sparsification | FileCheck %s | |
| #CSR = #sparse_tensor.encoding<{ | |
| dimLevelType = [ "dense", "compressed" ], | |
| dimOrdering = affine_map<(i,j) -> (i,j)> | |
| }> | |
| #DCSR = #sparse_tensor.encoding<{ | |
| dimLevelType = [ "compressed", "compressed" ], | |
| dimOrdering = affine_map<(i,j) -> (i,j)> | |
| }> | |
| #SparseTensor = #sparse_tensor.encoding<{ | |
| dimLevelType = [ "compressed", "compressed", "compressed" ] | |
| }> | |
| #trait_scale_inpl = { | |
| indexing_maps = [ | |
| affine_map<(i,j) -> (i,j)> // X (out) | |
| ], | |
| iterator_types = ["parallel", "parallel"], | |
| doc = "X(i,j) *= 2 or X(i,j) += X(i,j)" | |
| } | |
| // CHECK-LABEL: func @sparse_simply_dynamic1( | |
| // CHECK-SAME: %[[VAL_0:.*]]: tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> { | |
| // CHECK-DAG: %[[VAL_1:.*]] = arith.constant 2.000000e+00 : f32 | |
| // CHECK-DAG: %[[VAL_2:.*]] = arith.constant 0 : index | |
| // CHECK-DAG: %[[VAL_3:.*]] = arith.constant 1 : index | |
| // CHECK: %[[VAL_4:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_2]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_6:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_3]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_8:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> to memref<?xf32> | |
| // CHECK: %[[VAL_9:.*]] = memref.load %[[VAL_4]]{{\[}}%[[VAL_2]]] : memref<?xindex> | |
| // CHECK: %[[VAL_10:.*]] = memref.load %[[VAL_4]]{{\[}}%[[VAL_3]]] : memref<?xindex> | |
| // CHECK: scf.for %[[VAL_11:.*]] = %[[VAL_9]] to %[[VAL_10]] step %[[VAL_3]] { | |
| // CHECK: %[[VAL_12:.*]] = memref.load %[[VAL_6]]{{\[}}%[[VAL_11]]] : memref<?xindex> | |
| // CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_11]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_14:.*]] = memref.load %[[VAL_6]]{{\[}}%[[VAL_13]]] : memref<?xindex> | |
| // CHECK: scf.for %[[VAL_15:.*]] = %[[VAL_12]] to %[[VAL_14]] step %[[VAL_3]] { | |
| // CHECK: %[[VAL_16:.*]] = memref.load %[[VAL_8]]{{\[}}%[[VAL_15]]] : memref<?xf32> | |
| // CHECK: %[[VAL_17:.*]] = arith.mulf %[[VAL_16]], %[[VAL_1]] : f32 | |
| // CHECK: memref.store %[[VAL_17]], %[[VAL_8]]{{\[}}%[[VAL_15]]] : memref<?xf32> | |
| // CHECK: } | |
| // CHECK: } | |
| // CHECK: %[[VAL_18:.*]] = sparse_tensor.load %[[VAL_0]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: return %[[VAL_18]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: } | |
| func @sparse_simply_dynamic1(%argx: tensor<32x16xf32, #DCSR> {linalg.inplaceable = true}) -> tensor<32x16xf32, #DCSR> { | |
| %c = arith.constant 2.0 : f32 | |
| %0 = linalg.generic #trait_scale_inpl | |
| outs(%argx: tensor<32x16xf32, #DCSR>) { | |
| ^bb(%x: f32): | |
| %1 = arith.mulf %x, %c : f32 | |
| linalg.yield %1 : f32 | |
| } -> tensor<32x16xf32, #DCSR> | |
| return %0 : tensor<32x16xf32, #DCSR> | |
| } | |
| // CHECK-LABEL: func @sparse_simply_dynamic2( | |
| // CHECK-SAME: %[[VAL_0:.*]]: tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK-DAG: %[[VAL_1:.*]] = arith.constant 0 : index | |
| // CHECK-DAG: %[[VAL_2:.*]] = arith.constant 1 : index | |
| // CHECK: %[[VAL_3:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_1]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: %[[VAL_4:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_2]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: %[[VAL_5:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: %[[VAL_6:.*]] = memref.load %[[VAL_3]]{{\[}}%[[VAL_1]]] : memref<?xindex> | |
| // CHECK: %[[VAL_7:.*]] = memref.load %[[VAL_3]]{{\[}}%[[VAL_2]]] : memref<?xindex> | |
| // CHECK: scf.for %[[VAL_8:.*]] = %[[VAL_6]] to %[[VAL_7]] step %[[VAL_2]] { | |
| // CHECK: %[[VAL_9:.*]] = memref.load %[[VAL_4]]{{\[}}%[[VAL_8]]] : memref<?xindex> | |
| // CHECK: %[[VAL_10:.*]] = arith.addi %[[VAL_8]], %[[VAL_2]] : index | |
| // CHECK: %[[VAL_11:.*]] = memref.load %[[VAL_4]]{{\[}}%[[VAL_10]]] : memref<?xindex> | |
| // CHECK: scf.for %[[VAL_12:.*]] = %[[VAL_9]] to %[[VAL_11]] step %[[VAL_2]] { | |
| // CHECK: %[[VAL_13:.*]] = memref.load %[[VAL_5]]{{\[}}%[[VAL_12]]] : memref<?xf32> | |
| // CHECK: %[[VAL_14:.*]] = memref.load %[[VAL_5]]{{\[}}%[[VAL_12]]] : memref<?xf32> | |
| // CHECK: %[[VAL_15:.*]] = arith.addf %[[VAL_13]], %[[VAL_14]] : f32 | |
| // CHECK: memref.store %[[VAL_15]], %[[VAL_5]]{{\[}}%[[VAL_12]]] : memref<?xf32> | |
| // CHECK: } | |
| // CHECK: } | |
| // CHECK: %[[VAL_16:.*]] = sparse_tensor.load %[[VAL_0]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: return %[[VAL_16]] : tensor<32x16xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: } | |
| func @sparse_simply_dynamic2(%argx: tensor<32x16xf32, #DCSR> {linalg.inplaceable = true}) -> tensor<32x16xf32, #DCSR> { | |
| %0 = linalg.generic #trait_scale_inpl | |
| outs(%argx: tensor<32x16xf32, #DCSR>) { | |
| ^bb(%x: f32): | |
| %1 = arith.addf %x, %x : f32 | |
| linalg.yield %1 : f32 | |
| } -> tensor<32x16xf32, #DCSR> | |
| return %0 : tensor<32x16xf32, #DCSR> | |
| } | |
| #trait_scale = { | |
| indexing_maps = [ | |
| affine_map<(i,j) -> (i,j)>, // A | |
| affine_map<(i,j) -> (i,j)> // X (out) | |
| ], | |
| iterator_types = ["parallel", "parallel"], | |
| doc = "X(i,j) = A(i,j) * 2.0" | |
| } | |
| // CHECK-LABEL: func @sparse_truly_dynamic( | |
| // CHECK-SAME: %[[VAL_0:.*]]: tensor<10x20xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK-DAG: %[[VAL_1:.*]] = arith.constant 2.000000e+00 : f32 | |
| // CHECK-DAG: %[[VAL_2:.*]] = arith.constant 10 : index | |
| // CHECK-DAG: %[[VAL_3:.*]] = arith.constant 20 : index | |
| // CHECK-DAG: %[[VAL_4:.*]] = arith.constant 1 : index | |
| // CHECK-DAG: %[[VAL_5:.*]] = arith.constant 2 : index | |
| // CHECK-DAG: %[[VAL_6:.*]] = arith.constant 0 : index | |
| // CHECK: %[[VAL_7:.*]] = sparse_tensor.init{{\[}}%[[VAL_2]], %[[VAL_3]]] : tensor<10x20xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: %[[VAL_8:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_4]] : tensor<10x20xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: %[[VAL_9:.*]] = sparse_tensor.indices %[[VAL_0]], %[[VAL_4]] : tensor<10x20xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: %[[VAL_10:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<10x20xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: %[[VAL_11:.*]] = memref.alloca(%[[VAL_5]]) : memref<?xindex> | |
| // CHECK: scf.for %[[VAL_12:.*]] = %[[VAL_6]] to %[[VAL_2]] step %[[VAL_4]] { | |
| // CHECK: memref.store %[[VAL_12]], %[[VAL_11]]{{\[}}%[[VAL_6]]] : memref<?xindex> | |
| // CHECK: %[[VAL_13:.*]] = memref.load %[[VAL_8]]{{\[}}%[[VAL_12]]] : memref<?xindex> | |
| // CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_12]], %[[VAL_4]] : index | |
| // CHECK: %[[VAL_15:.*]] = memref.load %[[VAL_8]]{{\[}}%[[VAL_14]]] : memref<?xindex> | |
| // CHECK: scf.for %[[VAL_16:.*]] = %[[VAL_13]] to %[[VAL_15]] step %[[VAL_4]] { | |
| // CHECK: %[[VAL_17:.*]] = memref.load %[[VAL_9]]{{\[}}%[[VAL_16]]] : memref<?xindex> | |
| // CHECK: memref.store %[[VAL_17]], %[[VAL_11]]{{\[}}%[[VAL_4]]] : memref<?xindex> | |
| // CHECK: %[[VAL_18:.*]] = memref.load %[[VAL_10]]{{\[}}%[[VAL_16]]] : memref<?xf32> | |
| // CHECK: %[[VAL_19:.*]] = arith.mulf %[[VAL_18]], %[[VAL_1]] : f32 | |
| // CHECK: sparse_tensor.lex_insert %[[VAL_7]], %[[VAL_11]], %[[VAL_19]] : tensor<10x20xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: } | |
| // CHECK: } | |
| // CHECK: %[[VAL_20:.*]] = sparse_tensor.load %[[VAL_7]] hasInserts : tensor<10x20xf32, #sparse_tensor.encoding<{{.*}}>> | |
| // CHECK: return %[[VAL_20]] : tensor<10x20xf32, #sparse_tensor.encoding<{ | |
| // CHECK: } | |
| func @sparse_truly_dynamic(%arga: tensor<10x20xf32, #CSR>) -> tensor<10x20xf32, #DCSR> { | |
| %s = arith.constant 2.0 : f32 | |
| %d10 = arith.constant 10 : index | |
| %d20 = arith.constant 20 : index | |
| %xm = sparse_tensor.init [%d10, %d20] : tensor<10x20xf32, #DCSR> | |
| %0 = linalg.generic #trait_scale | |
| ins(%arga: tensor<10x20xf32, #CSR>) | |
| outs(%xm: tensor<10x20xf32, #DCSR>) { | |
| ^bb(%a: f32, %x: f32): | |
| %1 = arith.mulf %a, %s : f32 | |
| linalg.yield %1 : f32 | |
| } -> tensor<10x20xf32, #DCSR> | |
| return %0 : tensor<10x20xf32, #DCSR> | |
| } | |
| #trait_sumred = { | |
| indexing_maps = [ | |
| affine_map<(i,j,k) -> (i,j,k)>, // A | |
| affine_map<(i,j,k) -> (i,j,k)>, // B | |
| affine_map<(i,j,k) -> (i,j)> // X (out) | |
| ], | |
| iterator_types = ["parallel", "parallel", "reduction"], | |
| doc = "X(i,j) = SUM_k A(i,j,k) * B(i,j,k)" | |
| } | |
| // CHECK-LABEL: func @sumred( | |
| // CHECK-SAME: %[[VAL_0:.*]]: tensor<?x?x?xi32, #sparse_tensor.encoding<{ dimLevelType = [ "compressed", "compressed", "compressed" ], pointerBitWidth = 0, indexBitWidth = 0 }>>, | |
| // CHECK-SAME: %[[VAL_1:.*]]: tensor<?x?x?xi32, #sparse_tensor.encoding<{ dimLevelType = [ "compressed", "compressed", "compressed" ], pointerBitWidth = 0, indexBitWidth = 0 }>>) | |
| // CHECK-DAG: %[[VAL_2:.*]] = arith.constant 0 : index | |
| // CHECK-DAG: %[[VAL_3:.*]] = arith.constant 1 : index | |
| // CHECK-DAG: %[[VAL_4:.*]] = arith.constant 2 : index | |
| // CHECK-DAG: %[[VAL_5:.*]] = arith.constant 0 : i32 | |
| // CHECK: %[[VAL_6:.*]] = tensor.dim %[[VAL_0]], %[[VAL_2]] : tensor<?x?x?xi32, #{{.*}}>> | |
| // CHECK: %[[VAL_7:.*]] = tensor.dim %[[VAL_0]], %[[VAL_3]] : tensor<?x?x?xi32, #{{.*}}>> | |
| // CHECK: %[[VAL_8:.*]] = sparse_tensor.init{{\[}}%[[VAL_6]], %[[VAL_7]]] : tensor<?x?xi32, #{{.*}}>> | |
| // CHECK: %[[VAL_9:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_2]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_10:.*]] = sparse_tensor.indices %[[VAL_0]], %[[VAL_2]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_11:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_3]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_12:.*]] = sparse_tensor.indices %[[VAL_0]], %[[VAL_3]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_13:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_4]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_14:.*]] = sparse_tensor.indices %[[VAL_0]], %[[VAL_4]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_15:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xi32> | |
| // CHECK: %[[VAL_16:.*]] = sparse_tensor.pointers %[[VAL_1]], %[[VAL_2]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_17:.*]] = sparse_tensor.indices %[[VAL_1]], %[[VAL_2]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_18:.*]] = sparse_tensor.pointers %[[VAL_1]], %[[VAL_3]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_19:.*]] = sparse_tensor.indices %[[VAL_1]], %[[VAL_3]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_20:.*]] = sparse_tensor.pointers %[[VAL_1]], %[[VAL_4]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_21:.*]] = sparse_tensor.indices %[[VAL_1]], %[[VAL_4]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_22:.*]] = sparse_tensor.values %[[VAL_1]] : tensor<?x?x?xi32, #{{.*}}>> to memref<?xi32> | |
| // CHECK: %[[VAL_23:.*]] = memref.alloca(%[[VAL_4]]) : memref<?xindex> | |
| // CHECK: %[[VAL_24:.*]] = memref.load %[[VAL_9]]{{\[}}%[[VAL_2]]] : memref<?xindex> | |
| // CHECK: %[[VAL_25:.*]] = memref.load %[[VAL_9]]{{\[}}%[[VAL_3]]] : memref<?xindex> | |
| // CHECK: %[[VAL_26:.*]] = memref.load %[[VAL_16]]{{\[}}%[[VAL_2]]] : memref<?xindex> | |
| // CHECK: %[[VAL_27:.*]] = memref.load %[[VAL_16]]{{\[}}%[[VAL_3]]] : memref<?xindex> | |
| // CHECK: %[[VAL_28:.*]]:2 = scf.while (%[[VAL_29:.*]] = %[[VAL_24]], %[[VAL_30:.*]] = %[[VAL_26]]) : (index, index) -> (index, index) { | |
| // CHECK: %[[VAL_31:.*]] = arith.cmpi ult, %[[VAL_29]], %[[VAL_25]] : index | |
| // CHECK: %[[VAL_32:.*]] = arith.cmpi ult, %[[VAL_30]], %[[VAL_27]] : index | |
| // CHECK: %[[VAL_33:.*]] = arith.andi %[[VAL_31]], %[[VAL_32]] : i1 | |
| // CHECK: scf.condition(%[[VAL_33]]) %[[VAL_29]], %[[VAL_30]] : index, index | |
| // CHECK: } do { | |
| // CHECK: ^bb0(%[[VAL_34:.*]]: index, %[[VAL_35:.*]]: index): | |
| // CHECK: %[[VAL_36:.*]] = memref.load %[[VAL_10]]{{\[}}%[[VAL_34]]] : memref<?xindex> | |
| // CHECK: %[[VAL_37:.*]] = memref.load %[[VAL_17]]{{\[}}%[[VAL_35]]] : memref<?xindex> | |
| // CHECK: %[[VAL_38:.*]] = arith.cmpi ult, %[[VAL_37]], %[[VAL_36]] : index | |
| // CHECK: %[[VAL_39:.*]] = arith.select %[[VAL_38]], %[[VAL_37]], %[[VAL_36]] : index | |
| // CHECK: memref.store %[[VAL_39]], %[[VAL_23]]{{\[}}%[[VAL_2]]] : memref<?xindex> | |
| // CHECK: %[[VAL_40:.*]] = arith.cmpi eq, %[[VAL_36]], %[[VAL_39]] : index | |
| // CHECK: %[[VAL_41:.*]] = arith.cmpi eq, %[[VAL_37]], %[[VAL_39]] : index | |
| // CHECK: %[[VAL_42:.*]] = arith.andi %[[VAL_40]], %[[VAL_41]] : i1 | |
| // CHECK: scf.if %[[VAL_42]] { | |
| // CHECK: %[[VAL_43:.*]] = memref.load %[[VAL_11]]{{\[}}%[[VAL_34]]] : memref<?xindex> | |
| // CHECK: %[[VAL_44:.*]] = arith.addi %[[VAL_34]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_45:.*]] = memref.load %[[VAL_11]]{{\[}}%[[VAL_44]]] : memref<?xindex> | |
| // CHECK: %[[VAL_46:.*]] = memref.load %[[VAL_18]]{{\[}}%[[VAL_35]]] : memref<?xindex> | |
| // CHECK: %[[VAL_47:.*]] = arith.addi %[[VAL_35]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_48:.*]] = memref.load %[[VAL_18]]{{\[}}%[[VAL_47]]] : memref<?xindex> | |
| // CHECK: %[[VAL_49:.*]]:2 = scf.while (%[[VAL_50:.*]] = %[[VAL_43]], %[[VAL_51:.*]] = %[[VAL_46]]) : (index, index) -> (index, index) { | |
| // CHECK: %[[VAL_52:.*]] = arith.cmpi ult, %[[VAL_50]], %[[VAL_45]] : index | |
| // CHECK: %[[VAL_53:.*]] = arith.cmpi ult, %[[VAL_51]], %[[VAL_48]] : index | |
| // CHECK: %[[VAL_54:.*]] = arith.andi %[[VAL_52]], %[[VAL_53]] : i1 | |
| // CHECK: scf.condition(%[[VAL_54]]) %[[VAL_50]], %[[VAL_51]] : index, index | |
| // CHECK: } do { | |
| // CHECK: ^bb0(%[[VAL_55:.*]]: index, %[[VAL_56:.*]]: index): | |
| // CHECK: %[[VAL_57:.*]] = memref.load %[[VAL_12]]{{\[}}%[[VAL_55]]] : memref<?xindex> | |
| // CHECK: %[[VAL_58:.*]] = memref.load %[[VAL_19]]{{\[}}%[[VAL_56]]] : memref<?xindex> | |
| // CHECK: %[[VAL_59:.*]] = arith.cmpi ult, %[[VAL_58]], %[[VAL_57]] : index | |
| // CHECK: %[[VAL_60:.*]] = arith.select %[[VAL_59]], %[[VAL_58]], %[[VAL_57]] : index | |
| // CHECK: memref.store %[[VAL_60]], %[[VAL_23]]{{\[}}%[[VAL_3]]] : memref<?xindex> | |
| // CHECK: %[[VAL_61:.*]] = arith.cmpi eq, %[[VAL_57]], %[[VAL_60]] : index | |
| // CHECK: %[[VAL_62:.*]] = arith.cmpi eq, %[[VAL_58]], %[[VAL_60]] : index | |
| // CHECK: %[[VAL_63:.*]] = arith.andi %[[VAL_61]], %[[VAL_62]] : i1 | |
| // CHECK: scf.if %[[VAL_63]] { | |
| // CHECK: %[[VAL_64:.*]] = memref.load %[[VAL_13]]{{\[}}%[[VAL_55]]] : memref<?xindex> | |
| // CHECK: %[[VAL_65:.*]] = arith.addi %[[VAL_55]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_66:.*]] = memref.load %[[VAL_13]]{{\[}}%[[VAL_65]]] : memref<?xindex> | |
| // CHECK: %[[VAL_67:.*]] = memref.load %[[VAL_20]]{{\[}}%[[VAL_56]]] : memref<?xindex> | |
| // CHECK: %[[VAL_68:.*]] = arith.addi %[[VAL_56]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_69:.*]] = memref.load %[[VAL_20]]{{\[}}%[[VAL_68]]] : memref<?xindex> | |
| // CHECK: %[[VAL_70:.*]]:3 = scf.while (%[[VAL_71:.*]] = %[[VAL_64]], %[[VAL_72:.*]] = %[[VAL_67]], %[[VAL_73:.*]] = %[[VAL_5]]) : (index, index, i32) -> (index, index, i32) { | |
| // CHECK: %[[VAL_74:.*]] = arith.cmpi ult, %[[VAL_71]], %[[VAL_66]] : index | |
| // CHECK: %[[VAL_75:.*]] = arith.cmpi ult, %[[VAL_72]], %[[VAL_69]] : index | |
| // CHECK: %[[VAL_76:.*]] = arith.andi %[[VAL_74]], %[[VAL_75]] : i1 | |
| // CHECK: scf.condition(%[[VAL_76]]) %[[VAL_71]], %[[VAL_72]], %[[VAL_73]] : index, index, i32 | |
| // CHECK: } do { | |
| // CHECK: ^bb0(%[[VAL_77:.*]]: index, %[[VAL_78:.*]]: index, %[[VAL_79:.*]]: i32): | |
| // CHECK: %[[VAL_80:.*]] = memref.load %[[VAL_14]]{{\[}}%[[VAL_77]]] : memref<?xindex> | |
| // CHECK: %[[VAL_81:.*]] = memref.load %[[VAL_21]]{{\[}}%[[VAL_78]]] : memref<?xindex> | |
| // CHECK: %[[VAL_82:.*]] = arith.cmpi ult, %[[VAL_81]], %[[VAL_80]] : index | |
| // CHECK: %[[VAL_83:.*]] = arith.select %[[VAL_82]], %[[VAL_81]], %[[VAL_80]] : index | |
| // CHECK: memref.store %[[VAL_83]], %[[VAL_23]]{{\[}}%[[VAL_4]]] : memref<?xindex> | |
| // CHECK: %[[VAL_84:.*]] = arith.cmpi eq, %[[VAL_80]], %[[VAL_83]] : index | |
| // CHECK: %[[VAL_85:.*]] = arith.cmpi eq, %[[VAL_81]], %[[VAL_83]] : index | |
| // CHECK: %[[VAL_86:.*]] = arith.andi %[[VAL_84]], %[[VAL_85]] : i1 | |
| // CHECK: %[[VAL_87:.*]] = scf.if %[[VAL_86]] -> (i32) { | |
| // CHECK: %[[VAL_88:.*]] = memref.load %[[VAL_15]]{{\[}}%[[VAL_77]]] : memref<?xi32> | |
| // CHECK: %[[VAL_89:.*]] = memref.load %[[VAL_22]]{{\[}}%[[VAL_78]]] : memref<?xi32> | |
| // CHECK: %[[VAL_90:.*]] = arith.muli %[[VAL_88]], %[[VAL_89]] : i32 | |
| // CHECK: %[[VAL_91:.*]] = arith.addi %[[VAL_79]], %[[VAL_90]] : i32 | |
| // CHECK: scf.yield %[[VAL_91]] : i32 | |
| // CHECK: } else { | |
| // CHECK: scf.yield %[[VAL_79]] : i32 | |
| // CHECK: } | |
| // CHECK: %[[VAL_92:.*]] = arith.cmpi eq, %[[VAL_80]], %[[VAL_83]] : index | |
| // CHECK: %[[VAL_93:.*]] = arith.addi %[[VAL_77]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_94:.*]] = arith.select %[[VAL_92]], %[[VAL_93]], %[[VAL_77]] : index | |
| // CHECK: %[[VAL_95:.*]] = arith.cmpi eq, %[[VAL_81]], %[[VAL_83]] : index | |
| // CHECK: %[[VAL_96:.*]] = arith.addi %[[VAL_78]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_97:.*]] = arith.select %[[VAL_95]], %[[VAL_96]], %[[VAL_78]] : index | |
| // CHECK: scf.yield %[[VAL_94]], %[[VAL_97]], %[[VAL_98:.*]] : index, index, i32 | |
| // CHECK: } | |
| // CHECK: sparse_tensor.lex_insert %[[VAL_8]], %[[VAL_23]], %[[VAL_99:.*]]#2 : tensor<?x?xi32, #{{.*}}>, memref<?xindex>, i32 | |
| // CHECK: } else { | |
| // CHECK: } | |
| // CHECK: %[[VAL_100:.*]] = arith.cmpi eq, %[[VAL_57]], %[[VAL_60]] : index | |
| // CHECK: %[[VAL_101:.*]] = arith.addi %[[VAL_55]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_102:.*]] = arith.select %[[VAL_100]], %[[VAL_101]], %[[VAL_55]] : index | |
| // CHECK: %[[VAL_103:.*]] = arith.cmpi eq, %[[VAL_58]], %[[VAL_60]] : index | |
| // CHECK: %[[VAL_104:.*]] = arith.addi %[[VAL_56]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_105:.*]] = arith.select %[[VAL_103]], %[[VAL_104]], %[[VAL_56]] : index | |
| // CHECK: scf.yield %[[VAL_102]], %[[VAL_105]] : index, index | |
| // CHECK: } | |
| // CHECK: } else { | |
| // CHECK: } | |
| // CHECK: %[[VAL_106:.*]] = arith.cmpi eq, %[[VAL_36]], %[[VAL_39]] : index | |
| // CHECK: %[[VAL_107:.*]] = arith.addi %[[VAL_34]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_108:.*]] = arith.select %[[VAL_106]], %[[VAL_107]], %[[VAL_34]] : index | |
| // CHECK: %[[VAL_109:.*]] = arith.cmpi eq, %[[VAL_37]], %[[VAL_39]] : index | |
| // CHECK: %[[VAL_110:.*]] = arith.addi %[[VAL_35]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_111:.*]] = arith.select %[[VAL_109]], %[[VAL_110]], %[[VAL_35]] : index | |
| // CHECK: scf.yield %[[VAL_108]], %[[VAL_111]] : index, index | |
| // CHECK: } | |
| // CHECK: %[[VAL_112:.*]] = sparse_tensor.load %[[VAL_8]] hasInserts : tensor<?x?xi32, #{{.*}}> | |
| // CHECK: return %[[VAL_112]] : tensor<?x?xi32, #{{.*}}> | |
| // CHECK: } | |
| func @sumred(%arga: tensor<?x?x?xi32, #SparseTensor>, | |
| %argb: tensor<?x?x?xi32, #SparseTensor>) -> tensor<?x?xi32, #DCSR> { | |
| %c0 = arith.constant 0 : index | |
| %c1 = arith.constant 1 : index | |
| %d0 = tensor.dim %arga, %c0 : tensor<?x?x?xi32, #SparseTensor> | |
| %d1 = tensor.dim %arga, %c1 : tensor<?x?x?xi32, #SparseTensor> | |
| %xinit = sparse_tensor.init [%d0, %d1] : tensor<?x?xi32, #DCSR> | |
| %0 = linalg.generic #trait_sumred | |
| ins(%arga, %argb: tensor<?x?x?xi32, #SparseTensor>, | |
| tensor<?x?x?xi32, #SparseTensor>) | |
| outs(%xinit: tensor<?x?xi32, #DCSR>) { | |
| ^bb(%a: i32, %b: i32, %x: i32): | |
| %0 = arith.muli %a, %b : i32 | |
| %1 = arith.addi %x, %0 : i32 | |
| linalg.yield %1 : i32 | |
| } -> tensor<?x?xi32, #DCSR> | |
| return %0 : tensor<?x?xi32, #DCSR> | |
| } | |
| #trait_matmat = { | |
| indexing_maps = [ | |
| affine_map<(i,j,k) -> (i,k)>, // A | |
| affine_map<(i,j,k) -> (k,j)>, // B | |
| affine_map<(i,j,k) -> (i,j)> // C (out) | |
| ], | |
| iterator_types = ["parallel", "parallel", "reduction"], | |
| doc = "C(i,j) = SUM_k A(i,k) * B(k,j)" | |
| } | |
| // CHECK-LABEL: func @matmat( | |
| // CHECK-SAME: %[[VAL_0:.*]]: tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>>, | |
| // CHECK-SAME: %[[VAL_1:.*]]: tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> { | |
| // CHECK-DAG: %[[VAL_2:.*]] = arith.constant 0 : index | |
| // CHECK-DAG: %[[VAL_3:.*]] = arith.constant 1 : index | |
| // CHECK-DAG: %[[VAL_4:.*]] = arith.constant 2 : index | |
| // CHECK-DAG: %[[VAL_5:.*]] = arith.constant false | |
| // CHECK-DAG: %[[VAL_6:.*]] = arith.constant true | |
| // CHECK: %[[VAL_7:.*]] = tensor.dim %[[VAL_0]], %[[VAL_2]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> | |
| // CHECK: %[[VAL_8:.*]] = tensor.dim %[[VAL_1]], %[[VAL_3]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> | |
| // CHECK: %[[VAL_9:.*]] = sparse_tensor.init{{\[}}%[[VAL_7]], %[[VAL_8]]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> | |
| // CHECK: %[[VAL_10:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_2]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_11:.*]] = sparse_tensor.indices %[[VAL_0]], %[[VAL_2]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_12:.*]] = sparse_tensor.pointers %[[VAL_0]], %[[VAL_3]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_13:.*]] = sparse_tensor.indices %[[VAL_0]], %[[VAL_3]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_14:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xf32> | |
| // CHECK: %[[VAL_15:.*]] = sparse_tensor.pointers %[[VAL_1]], %[[VAL_2]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_16:.*]] = sparse_tensor.indices %[[VAL_1]], %[[VAL_2]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_17:.*]] = sparse_tensor.pointers %[[VAL_1]], %[[VAL_3]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_18:.*]] = sparse_tensor.indices %[[VAL_1]], %[[VAL_3]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xindex> | |
| // CHECK: %[[VAL_19:.*]] = sparse_tensor.values %[[VAL_1]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xf32> | |
| // CHECK: %[[VAL_20:.*]] = memref.alloca(%[[VAL_4]]) : memref<?xindex> | |
| // CHECK: %[[VAL_21:.*]] = memref.load %[[VAL_10]]{{\[}}%[[VAL_2]]] : memref<?xindex> | |
| // CHECK: %[[VAL_22:.*]] = memref.load %[[VAL_10]]{{\[}}%[[VAL_3]]] : memref<?xindex> | |
| // CHECK: scf.for %[[VAL_23:.*]] = %[[VAL_21]] to %[[VAL_22]] step %[[VAL_3]] { | |
| // CHECK: %[[VAL_24:.*]] = memref.load %[[VAL_11]]{{\[}}%[[VAL_23]]] : memref<?xindex> | |
| // CHECK: memref.store %[[VAL_24]], %[[VAL_20]]{{\[}}%[[VAL_2]]] : memref<?xindex> | |
| // CHECK: %[[VAL_25:.*]], %[[VAL_26:.*]], %[[VAL_27:.*]], %[[VAL_28:.*]] = sparse_tensor.expand %[[VAL_9]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> to memref<?xf32>, memref<?xi1>, memref<?xindex>, index | |
| // CHECK: %[[VAL_29:.*]] = memref.load %[[VAL_12]]{{\[}}%[[VAL_23]]] : memref<?xindex> | |
| // CHECK: %[[VAL_30:.*]] = arith.addi %[[VAL_23]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_31:.*]] = memref.load %[[VAL_12]]{{\[}}%[[VAL_30]]] : memref<?xindex> | |
| // CHECK: %[[VAL_32:.*]] = memref.load %[[VAL_15]]{{\[}}%[[VAL_2]]] : memref<?xindex> | |
| // CHECK: %[[VAL_33:.*]] = memref.load %[[VAL_15]]{{\[}}%[[VAL_3]]] : memref<?xindex> | |
| // CHECK: %[[VAL_34:.*]]:3 = scf.while (%[[VAL_35:.*]] = %[[VAL_29]], %[[VAL_36:.*]] = %[[VAL_32]], %[[VAL_37:.*]] = %[[VAL_28]]) : (index, index, index) -> (index, index, index) { | |
| // CHECK: %[[VAL_38:.*]] = arith.cmpi ult, %[[VAL_35]], %[[VAL_31]] : index | |
| // CHECK: %[[VAL_39:.*]] = arith.cmpi ult, %[[VAL_36]], %[[VAL_33]] : index | |
| // CHECK: %[[VAL_40:.*]] = arith.andi %[[VAL_38]], %[[VAL_39]] : i1 | |
| // CHECK: scf.condition(%[[VAL_40]]) %[[VAL_35]], %[[VAL_36]], %[[VAL_37]] : index, index, index | |
| // CHECK: } do { | |
| // CHECK: ^bb0(%[[VAL_41:.*]]: index, %[[VAL_42:.*]]: index, %[[VAL_43:.*]]: index): | |
| // CHECK: %[[VAL_44:.*]] = memref.load %[[VAL_13]]{{\[}}%[[VAL_41]]] : memref<?xindex> | |
| // CHECK: %[[VAL_45:.*]] = memref.load %[[VAL_16]]{{\[}}%[[VAL_42]]] : memref<?xindex> | |
| // CHECK: %[[VAL_46:.*]] = arith.cmpi ult, %[[VAL_45]], %[[VAL_44]] : index | |
| // CHECK: %[[VAL_47:.*]] = arith.select %[[VAL_46]], %[[VAL_45]], %[[VAL_44]] : index | |
| // CHECK: %[[VAL_48:.*]] = arith.cmpi eq, %[[VAL_44]], %[[VAL_47]] : index | |
| // CHECK: %[[VAL_49:.*]] = arith.cmpi eq, %[[VAL_45]], %[[VAL_47]] : index | |
| // CHECK: %[[VAL_50:.*]] = arith.andi %[[VAL_48]], %[[VAL_49]] : i1 | |
| // CHECK: %[[VAL_51:.*]] = scf.if %[[VAL_50]] -> (index) { | |
| // CHECK: %[[VAL_52:.*]] = memref.load %[[VAL_14]]{{\[}}%[[VAL_41]]] : memref<?xf32> | |
| // CHECK: %[[VAL_53:.*]] = memref.load %[[VAL_17]]{{\[}}%[[VAL_42]]] : memref<?xindex> | |
| // CHECK: %[[VAL_54:.*]] = arith.addi %[[VAL_42]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_55:.*]] = memref.load %[[VAL_17]]{{\[}}%[[VAL_54]]] : memref<?xindex> | |
| // CHECK: %[[VAL_56:.*]] = scf.for %[[VAL_57:.*]] = %[[VAL_53]] to %[[VAL_55]] step %[[VAL_3]] iter_args(%[[VAL_58:.*]] = %[[VAL_43]]) -> (index) { | |
| // CHECK: %[[VAL_59:.*]] = memref.load %[[VAL_18]]{{\[}}%[[VAL_57]]] : memref<?xindex> | |
| // CHECK: %[[VAL_60:.*]] = memref.load %[[VAL_25]]{{\[}}%[[VAL_59]]] : memref<?xf32> | |
| // CHECK: %[[VAL_61:.*]] = memref.load %[[VAL_19]]{{\[}}%[[VAL_57]]] : memref<?xf32> | |
| // CHECK: %[[VAL_62:.*]] = arith.mulf %[[VAL_52]], %[[VAL_61]] : f32 | |
| // CHECK: %[[VAL_63:.*]] = arith.addf %[[VAL_60]], %[[VAL_62]] : f32 | |
| // CHECK: %[[VAL_64:.*]] = memref.load %[[VAL_26]]{{\[}}%[[VAL_59]]] : memref<?xi1> | |
| // CHECK: %[[VAL_65:.*]] = arith.cmpi eq, %[[VAL_64]], %[[VAL_5]] : i1 | |
| // CHECK: %[[VAL_66:.*]] = scf.if %[[VAL_65]] -> (index) { | |
| // CHECK: memref.store %[[VAL_6]], %[[VAL_26]]{{\[}}%[[VAL_59]]] : memref<?xi1> | |
| // CHECK: memref.store %[[VAL_59]], %[[VAL_27]]{{\[}}%[[VAL_58]]] : memref<?xindex> | |
| // CHECK: %[[VAL_67:.*]] = arith.addi %[[VAL_58]], %[[VAL_3]] : index | |
| // CHECK: scf.yield %[[VAL_67]] : index | |
| // CHECK: } else { | |
| // CHECK: scf.yield %[[VAL_58]] : index | |
| // CHECK: } | |
| // CHECK: memref.store %[[VAL_63]], %[[VAL_25]]{{\[}}%[[VAL_59]]] : memref<?xf32> | |
| // CHECK: scf.yield %[[VAL_68:.*]] : index | |
| // CHECK: } | |
| // CHECK: scf.yield %[[VAL_69:.*]] : index | |
| // CHECK: } else { | |
| // CHECK: scf.yield %[[VAL_43]] : index | |
| // CHECK: } | |
| // CHECK: %[[VAL_70:.*]] = arith.cmpi eq, %[[VAL_44]], %[[VAL_47]] : index | |
| // CHECK: %[[VAL_71:.*]] = arith.addi %[[VAL_41]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_72:.*]] = arith.select %[[VAL_70]], %[[VAL_71]], %[[VAL_41]] : index | |
| // CHECK: %[[VAL_73:.*]] = arith.cmpi eq, %[[VAL_45]], %[[VAL_47]] : index | |
| // CHECK: %[[VAL_74:.*]] = arith.addi %[[VAL_42]], %[[VAL_3]] : index | |
| // CHECK: %[[VAL_75:.*]] = arith.select %[[VAL_73]], %[[VAL_74]], %[[VAL_42]] : index | |
| // CHECK: scf.yield %[[VAL_72]], %[[VAL_75]], %[[VAL_76:.*]] : index, index, index | |
| // CHECK: } | |
| // CHECK: sparse_tensor.compress %[[VAL_9]], %[[VAL_20]], %[[VAL_25]], %[[VAL_26]], %[[VAL_27]], %[[VAL_77:.*]]#2 : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>>, memref<?xindex>, memref<?xf32>, memref<?xi1>, memref<?xindex>, index | |
| // CHECK: } | |
| // CHECK: %[[VAL_78:.*]] = sparse_tensor.load %[[VAL_9]] hasInserts : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> | |
| // CHECK: return %[[VAL_78]] : tensor<?x?xf32, #sparse_tensor.encoding<{{{.*}}}>> | |
| // CHECK: } | |
| func @matmat(%arga: tensor<?x?xf32, #DCSR>, | |
| %argb: tensor<?x?xf32, #DCSR>) -> tensor<?x?xf32, #DCSR> { | |
| %c0 = arith.constant 0 : index | |
| %c1 = arith.constant 1 : index | |
| %d0 = tensor.dim %arga, %c0 : tensor<?x?xf32, #DCSR> | |
| %d1 = tensor.dim %argb, %c1 : tensor<?x?xf32, #DCSR> | |
| %cinit = sparse_tensor.init [%d0, %d1] : tensor<?x?xf32, #DCSR> | |
| %0 = linalg.generic #trait_matmat | |
| ins(%arga, %argb: tensor<?x?xf32, #DCSR>, | |
| tensor<?x?xf32, #DCSR>) | |
| outs(%cinit: tensor<?x?xf32, #DCSR>) { | |
| ^bb(%a: f32, %b: f32, %c: f32): | |
| %1 = arith.mulf %a, %b : f32 | |
| %2 = arith.addf %c, %1 : f32 | |
| linalg.yield %2 : f32 | |
| } -> tensor<?x?xf32, #DCSR> | |
| return %0 : tensor<?x?xf32, #DCSR> | |
| } |