|
| 1 | +// RUN: enzymexlamlir-opt %s --pass-pipeline='builtin.module(enzyme-hlo-opt{passses=65536},enzyme-hlo-opt)' | FileCheck %s |
| 2 | + |
| 3 | +func.func @main1(%arg0: tensor<5x2xf32>, %arg1: tensor<4x3x2xf32>) -> tensor<5x2xf32> { |
| 4 | + %c = stablehlo.constant dense<[[[0, 1, 2, 3], [3, 1, 0, 2], [2, 4, 4, 2]]]> : tensor<1x3x4xi64> |
| 5 | + %0 = stablehlo.transpose %arg0, dims = [1, 0] : (tensor<5x2xf32>) -> tensor<2x5xf32> |
| 6 | + %1 = stablehlo.transpose %arg1, dims = [2, 1, 0] : (tensor<4x3x2xf32>) -> tensor<2x3x4xf32> |
| 7 | + %2 = "stablehlo.scatter"(%0, %c, %1) <{scatter_dimension_numbers = #stablehlo.scatter<update_window_dims = [0], inserted_window_dims = [1], scatter_dims_to_operand_dims = [1]>}> ({ |
| 8 | + ^bb0(%arg2: tensor<f32>, %arg3: tensor<f32>): |
| 9 | + %4 = stablehlo.multiply %arg2, %arg3 : tensor<f32> |
| 10 | + stablehlo.return %4 : tensor<f32> |
| 11 | + }) : (tensor<2x5xf32>, tensor<1x3x4xi64>, tensor<2x3x4xf32>) -> tensor<2x5xf32> |
| 12 | + %3 = stablehlo.transpose %2, dims = [1, 0] : (tensor<2x5xf32>) -> tensor<5x2xf32> |
| 13 | + return %3 : tensor<5x2xf32> |
| 14 | +} |
| 15 | + |
| 16 | +// CHECK: func.func @main1(%arg0: tensor<5x2xf32>, %arg1: tensor<4x3x2xf32>) -> tensor<5x2xf32> { |
| 17 | +// CHECK-NEXT{LITERAL}: %c = stablehlo.constant dense<[[[0, 1, 2, 3], [3, 1, 0, 2], [2, 4, 4, 2]]]> : tensor<1x3x4xi64> |
| 18 | +// CHECK-NEXT: %0 = stablehlo.transpose %arg1, dims = [2, 1, 0] : (tensor<4x3x2xf32>) -> tensor<2x3x4xf32> |
| 19 | +// CHECK-NEXT: %1 = "stablehlo.scatter"(%arg0, %c, %0) <{scatter_dimension_numbers = #stablehlo.scatter<update_window_dims = [0], inserted_window_dims = [1], scatter_dims_to_operand_dims = [0]>}> ({ |
| 20 | +// CHECK-NEXT: ^bb0(%arg2: tensor<f32>, %arg3: tensor<f32>): |
| 21 | +// CHECK-NEXT: %2 = stablehlo.multiply %arg2, %arg3 : tensor<f32> |
| 22 | +// CHECK-NEXT: stablehlo.return %2 : tensor<f32> |
| 23 | +// CHECK-NEXT: }) : (tensor<5x2xf32>, tensor<1x3x4xi64>, tensor<2x3x4xf32>) -> tensor<5x2xf32> |
| 24 | +// CHECK-NEXT: return %1 : tensor<5x2xf32> |
| 25 | +// CHECK-NEXT: } |
| 26 | + |
| 27 | +func.func @main2(%arg0: tensor<5x2xf32>, %arg1: tensor<4x3x2xf32>) -> tensor<5x2xf32> { |
| 28 | + %c = stablehlo.constant dense<[[[0, 1, 2, 3], [3, 1, 0, 2], [2, 4, 4, 2]]]> : tensor<1x3x4xi64> |
| 29 | + %0 = stablehlo.transpose %arg0, dims = [1, 0] : (tensor<5x2xf32>) -> tensor<2x5xf32> |
| 30 | + %1 = stablehlo.transpose %arg1, dims = [2, 1, 0] : (tensor<4x3x2xf32>) -> tensor<2x3x4xf32> |
| 31 | + %2 = "stablehlo.scatter"(%0, %c, %1) <{scatter_dimension_numbers = #stablehlo.scatter<update_window_dims = [0], inserted_window_dims = [1], scatter_dims_to_operand_dims = [1]>}> ({ |
| 32 | + ^bb0(%arg2: tensor<f32>, %arg3: tensor<f32>): |
| 33 | + %4 = stablehlo.add %arg2, %arg3 : tensor<f32> |
| 34 | + stablehlo.return %4 : tensor<f32> |
| 35 | + }) : (tensor<2x5xf32>, tensor<1x3x4xi64>, tensor<2x3x4xf32>) -> tensor<2x5xf32> |
| 36 | + %3 = stablehlo.transpose %2, dims = [1, 0] : (tensor<2x5xf32>) -> tensor<5x2xf32> |
| 37 | + return %3 : tensor<5x2xf32> |
| 38 | +} |
| 39 | + |
| 40 | +// CHECK: func.func @main2(%arg0: tensor<5x2xf32>, %arg1: tensor<4x3x2xf32>) -> tensor<5x2xf32> { |
| 41 | +// CHECK-NEXT{LITERAL}: %c = stablehlo.constant dense<[[[0, 1, 2, 3], [3, 1, 0, 2], [2, 4, 4, 2]]]> : tensor<1x3x4xi64> |
| 42 | +// CHECK-NEXT: %0 = stablehlo.transpose %arg1, dims = [2, 1, 0] : (tensor<4x3x2xf32>) -> tensor<2x3x4xf32> |
| 43 | +// CHECK-NEXT: %1 = "stablehlo.scatter"(%arg0, %c, %0) <{scatter_dimension_numbers = #stablehlo.scatter<update_window_dims = [0], inserted_window_dims = [1], scatter_dims_to_operand_dims = [0]>}> ({ |
| 44 | +// CHECK-NEXT: ^bb0(%arg2: tensor<f32>, %arg3: tensor<f32>): |
| 45 | +// CHECK-NEXT: %2 = stablehlo.add %arg2, %arg3 : tensor<f32> |
| 46 | +// CHECK-NEXT: stablehlo.return %2 : tensor<f32> |
| 47 | +// CHECK-NEXT: }) : (tensor<5x2xf32>, tensor<1x3x4xi64>, tensor<2x3x4xf32>) -> tensor<5x2xf32> |
| 48 | +// CHECK-NEXT: return %1 : tensor<5x2xf32> |
| 49 | +// CHECK-NEXT: } |
| 50 | + |
| 51 | +func.func @main3(%arg0: tensor<32x32xf32>, %arg1: tensor<32xf32>) -> tensor<32x32xf32> { |
| 52 | + %c = stablehlo.constant dense<[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19], [20, 20], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25], [26, 26], [27, 27], [28, 28], [29, 29], [30, 30], [31, 31]]> : tensor<32x2xi64> |
| 53 | + %cst = stablehlo.constant dense<0.000000e+00> : tensor<32x32xf32> |
| 54 | + %0 = "stablehlo.scatter"(%cst, %c, %arg1) <{scatter_dimension_numbers = #stablehlo.scatter<inserted_window_dims = [0, 1], scatter_dims_to_operand_dims = [0, 1], index_vector_dim = 1>, unique_indices = true}> ({ |
| 55 | + ^bb0(%arg2: tensor<f32>, %arg3: tensor<f32>): |
| 56 | + stablehlo.return %arg3 : tensor<f32> |
| 57 | + }) {enzymexla.symmetric_matrix = [#enzymexla<guaranteed NOTGUARANTEED>]} : (tensor<32x32xf32>, tensor<32x2xi64>, tensor<32xf32>) -> tensor<32x32xf32> |
| 58 | + %1 = stablehlo.transpose %0, dims = [1, 0] : (tensor<32x32xf32>) -> tensor<32x32xf32> |
| 59 | + %2 = stablehlo.add %arg0, %1 {enzymexla.symmetric_matrix = [#enzymexla<guaranteed NOTGUARANTEED>]} : tensor<32x32xf32> |
| 60 | + return %2 : tensor<32x32xf32> |
| 61 | +} |
| 62 | + |
| 63 | +// CHECK: func.func @main3(%arg0: tensor<32x32xf32>, %arg1: tensor<32xf32>) -> tensor<32x32xf32> { |
| 64 | +// CHECK-NEXT{LITERAL}: %c = stablehlo.constant dense<[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [11, 11], [12, 12], [13, 13], [14, 14], [15, 15], [16, 16], [17, 17], [18, 18], [19, 19], [20, 20], [21, 21], [22, 22], [23, 23], [24, 24], [25, 25], [26, 26], [27, 27], [28, 28], [29, 29], [30, 30], [31, 31]]> : tensor<32x2xi64> |
| 65 | +// CHECK-NEXT: %cst = stablehlo.constant dense<0.000000e+00> : tensor<32x32xf32> |
| 66 | +// CHECK-NEXT: %0 = "stablehlo.scatter"(%cst, %c, %arg1) <{scatter_dimension_numbers = #stablehlo.scatter<inserted_window_dims = [0, 1], scatter_dims_to_operand_dims = [1, 0], index_vector_dim = 1>, unique_indices = true}> ({ |
| 67 | +// CHECK-NEXT: ^bb0(%arg2: tensor<f32>, %arg3: tensor<f32>): |
| 68 | +// CHECK-NEXT: stablehlo.return %arg3 : tensor<f32> |
| 69 | +// CHECK-NEXT: }) : (tensor<32x32xf32>, tensor<32x2xi64>, tensor<32xf32>) -> tensor<32x32xf32> |
| 70 | +// CHECK-NEXT: %1 = stablehlo.add %arg0, %0 {enzymexla.symmetric_matrix = [#enzymexla<guaranteed NOTGUARANTEED>]} : tensor<32x32xf32> |
| 71 | +// CHECK-NEXT: return %1 : tensor<32x32xf32> |
| 72 | +// CHECK-NEXT: } |
| 73 | + |
| 74 | +func.func @main4(%arg0: tensor<3x4x4xf64>) -> tensor<3x4x4xf64> { |
| 75 | + %cst = stablehlo.constant dense<2.000000e+00> : tensor<f64> |
| 76 | + %cst_0 = stablehlo.constant dense<2.000000e+00> : tensor<3x4x3xf64> |
| 77 | + %c = stablehlo.constant dense<[[0], [2], [1]]> : tensor<3x1xi64> |
| 78 | + %0 = stablehlo.transpose %arg0, dims = [2, 1, 0] : (tensor<3x4x4xf64>) -> tensor<4x4x3xf64> |
| 79 | + %1 = "stablehlo.scatter"(%0, %c, %cst_0) <{indices_are_sorted = false, scatter_dimension_numbers = #stablehlo.scatter<update_window_dims = [1, 2], inserted_window_dims = [0], scatter_dims_to_operand_dims = [0], index_vector_dim = 1>, unique_indices = true}> ({ |
| 80 | + ^bb0(%arg1: tensor<f64>, %arg2: tensor<f64>): |
| 81 | + stablehlo.return %cst : tensor<f64> |
| 82 | + }) : (tensor<4x4x3xf64>, tensor<3x1xi64>, tensor<3x4x3xf64>) -> tensor<4x4x3xf64> |
| 83 | + %2 = stablehlo.transpose %1, dims = [2, 1, 0] : (tensor<4x4x3xf64>) -> tensor<3x4x4xf64> |
| 84 | + return %2 : tensor<3x4x4xf64> |
| 85 | +} |
| 86 | + |
| 87 | +// CHECK: func.func @main4(%arg0: tensor<3x4x4xf64>) -> tensor<3x4x4xf64> { |
| 88 | +// CHECK-NEXT: %cst = stablehlo.constant dense<2.000000e+00> : tensor<f64> |
| 89 | +// CHECK-NEXT: %cst_0 = stablehlo.constant dense<2.000000e+00> : tensor<3x4x3xf64> |
| 90 | +// CHECK-NEXT{LITERAL}: %c = stablehlo.constant dense<[[0], [2], [1]]> : tensor<3x1xi64> |
| 91 | +// CHECK-NEXT: %0 = "stablehlo.scatter"(%arg0, %c, %cst_0) <{indices_are_sorted = false, scatter_dimension_numbers = #stablehlo.scatter<update_window_dims = [1, 2], inserted_window_dims = [0], scatter_dims_to_operand_dims = [2], index_vector_dim = 1>, unique_indices = true}> ({ |
| 92 | +// CHECK-NEXT: ^bb0(%arg1: tensor<f64>, %arg2: tensor<f64>): |
| 93 | +// CHECK-NEXT: stablehlo.return %cst : tensor<f64> |
| 94 | +// CHECK-NEXT: }) : (tensor<3x4x4xf64>, tensor<3x1xi64>, tensor<3x4x3xf64>) -> tensor<3x4x4xf64> |
| 95 | +// CHECK-NEXT: return %0 : tensor<3x4x4xf64> |
| 96 | +// CHECK-NEXT: } |
0 commit comments