|
| 1 | +// RUN: sdy_opt %s -split-input-file -sdy-insert-explicit-reshards='enable-full-version=true avoid-reshards-on-calls=true' | FileCheck %s |
| 2 | + |
| 3 | +sdy.mesh @mesh = <["x"=2, "y"=2, "z"=4]> |
| 4 | + |
| 5 | +// CHECK-LABEL: func @call |
| 6 | +func.func @call(%arg0: tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"x"}]>}) -> (tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"z"}]>}) { |
| 7 | + // CHECK-NEXT: %[[CALL:.*]] = call @foo(%arg0) |
| 8 | + // CHECK-NEXT: %[[NEGATE:.*]] = stablehlo.negate %[[CALL]] |
| 9 | + // CHECK-NEXT: return %[[NEGATE]] |
| 10 | + %0 = call @foo(%arg0) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"z"}]>]>} : (tensor<210xf32>) -> (tensor<210xf32>) |
| 11 | + %1 = stablehlo.negate %0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"z"}]>]>} : tensor<210xf32> |
| 12 | + return %1 : tensor<210xf32> |
| 13 | +} |
| 14 | + |
| 15 | +// CHECK-LABEL: func private @foo |
| 16 | +func.func private @foo(%arg0: tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"y"}]>}) -> (tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"z"}]>}) { |
| 17 | + // CHECK-NEXT: %[[ABS:.*]] = stablehlo.abs %arg0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} |
| 18 | + // CHECK-NEXT: %[[RESHARD:.*]] = sdy.reshard %[[ABS]] <@mesh, [{"z"}]> |
| 19 | + // CHECK-NEXT: return %[[RESHARD]] |
| 20 | + %0 = stablehlo.abs %arg0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : tensor<210xf32> |
| 21 | + return %0 : tensor<210xf32> |
| 22 | +} |
| 23 | + |
| 24 | +// ----- |
| 25 | +sdy.mesh @mesh = <["x"=4, "y"=2]> |
| 26 | + |
| 27 | +// CHECK-LABEL: func @call_empty_block |
| 28 | +func.func @call_empty_block(%arg0: tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"x"}]>}) -> (tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"y"}]>}) { |
| 29 | + // CHECK-NEXT: %[[CALL:.*]] = call @foo(%arg0) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} |
| 30 | + // CHECK-NEXT: %[[NEGATE:.*]] = stablehlo.negate %0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} |
| 31 | + %0 = call @foo(%arg0) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : (tensor<210xf32>) -> (tensor<210xf32>) |
| 32 | + %1 = stablehlo.negate %0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : tensor<210xf32> |
| 33 | + return %1 : tensor<210xf32> |
| 34 | +} |
| 35 | + |
| 36 | +// CHECK-LABEL: func private @foo |
| 37 | +func.func private @foo(%arg0: tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"x"}]>}) -> (tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"y"}]>}) { |
| 38 | + // CHECK-NEXT: %[[RESHARD:.*]] = sdy.reshard %arg0 <@mesh, [{"y"}]> |
| 39 | + // CHECK-NEXT: return %[[RESHARD]] |
| 40 | + return %arg0 : tensor<210xf32> |
| 41 | +} |
| 42 | + |
| 43 | +// ----- |
| 44 | +sdy.mesh @mesh = <["a"=2, "b"=2, "c"=2]> |
| 45 | + |
| 46 | +// CHECK-LABEL: func @call_with_shardings |
| 47 | +func.func @call_with_shardings(%arg0: tensor<8x2xi32>, %arg1: tensor<4x2xi32>) -> tensor<12x2xi32> { |
| 48 | + // CHECK-NEXT: %[[CALL:.*]]:2 = call @foo(%arg0, %arg1) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"a"}, {}]>, <@mesh, [{}, {}]>]>} |
| 49 | + // CHECK-NEXT: %[[RESHARD1:.*]] = sdy.reshard %[[CALL]]#0 <@mesh, [{}, {"a"}]> |
| 50 | + // CHECK-NEXT: %[[RESHARD2:.*]] = sdy.reshard %[[CALL]]#1 <@mesh, [{}, {"a"}]> |
| 51 | + // CHECK-NEXT: %[[CONCAT:.*]] = stablehlo.concatenate %[[RESHARD1]], %[[RESHARD2]], dim = 0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{}, {"a"}]>]>} |
| 52 | + // CHECK-NEXT: %[[RESHARD3:.*]] = sdy.reshard %[[CONCAT]] <@mesh, [{}, {}]> |
| 53 | + %0:2 = call @foo(%arg0, %arg1) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"a"}, {}]>, <@mesh, [{}, {}]>]>} : (tensor<8x2xi32>, tensor<4x2xi32>) -> (tensor<8x2xi32>, tensor<4x2xi32>) |
| 54 | + %1 = stablehlo.concatenate %0#0, %0#1, dim = 0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{}, {"a"}]>]>} : (tensor<8x2xi32>, tensor<4x2xi32>) -> tensor<12x2xi32> |
| 55 | + return %1 : tensor<12x2xi32> |
| 56 | +} |
| 57 | + |
| 58 | +// CHECK-LABEL: func private @foo |
| 59 | +func.func private @foo(%arg0: tensor<8x2xi32> {sdy.sharding = #sdy.sharding<@mesh, [{"a"}, {}]>}, %arg1: tensor<4x2xi32> {sdy.sharding = #sdy.sharding<@mesh, [{}, {}]>}) |
| 60 | + -> (tensor<8x2xi32> {sdy.sharding = #sdy.sharding<@mesh, [{"a"}, {}]>}, tensor<4x2xi32> {sdy.sharding = #sdy.sharding<@mesh, [{}, {}]>}) { |
| 61 | + // CHECK-NEXT: %[[ABS:.*]] = stablehlo.abs %arg0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"a"}, {}]>]>} |
| 62 | + // CHECK-NEXT: %[[RESHARD0:.*]] = sdy.reshard %[[ABS]] <@mesh, [{}, {"a"}]> |
| 63 | + // CHECK-NEXT: %[[RESHARD1:.*]] = sdy.reshard %[[RESHARD0]] <@mesh, [{"a"}, {}]> |
| 64 | + // CHECK-NEXT: return %[[RESHARD1]], %arg1 |
| 65 | + %0 = stablehlo.abs %arg0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{}, {"a"}]>]>} : tensor<8x2xi32> |
| 66 | + return %0, %arg1 : tensor<8x2xi32>, tensor<4x2xi32> |
| 67 | +} |
| 68 | + |
| 69 | +// ----- |
| 70 | +sdy.mesh @mesh = <["x"=2, "y"=2, "z"=4]> |
| 71 | + |
| 72 | +// CHECK-LABEL: func @one_argument_to_multiple_calls( |
| 73 | +func.func @one_argument_to_multiple_calls(%arg0: tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"x"}]>}) -> (tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"z"}]>}) { |
| 74 | + // CHECK-NEXT: %[[CALL0:.*]] = call @foo(%arg0) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} |
| 75 | + // CHECK-NEXT: %[[CALL1:.*]] = call @bar(%arg0) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"z"}]>]>} |
| 76 | + // CHECK-NEXT: %[[RESHARD:.*]] = sdy.reshard %[[CALL0]] <@mesh, [{"z"}]> |
| 77 | + // CHECK-NEXT: %[[ADD:.*]] = stablehlo.add %[[RESHARD]], %[[CALL1]] {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"z"}]>]>} |
| 78 | + // CHECK-NEXT: return %[[ADD]] |
| 79 | + %0 = call @foo(%arg0) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : (tensor<210xf32>) -> (tensor<210xf32>) |
| 80 | + %1 = call @bar(%arg0) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"z"}]>]>} : (tensor<210xf32>) -> (tensor<210xf32>) |
| 81 | + %3 = stablehlo.add %0, %1 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"z"}]>]>} : tensor<210xf32> |
| 82 | + return %3 : tensor<210xf32> |
| 83 | +} |
| 84 | + |
| 85 | +// CHECK-LABEL: func private @foo |
| 86 | +func.func private @foo(%arg0: tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"y"}]>}) -> (tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"y"}]>}) { |
| 87 | + // CHECK-NEXT: %[[ABS:.*]] = stablehlo.abs %arg0 |
| 88 | + // CHECK-NEXT: return %[[ABS]] |
| 89 | + %0 = stablehlo.abs %arg0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : tensor<210xf32> |
| 90 | + return %0 : tensor<210xf32> |
| 91 | +} |
| 92 | + |
| 93 | +// CHECK-LABEL: func private @bar |
| 94 | +func.func private @bar(%arg0: tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"z"}]>}) -> (tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"z"}]>}) { |
| 95 | + // CHECK-NEXT: %[[ABS:.*]] = stablehlo.abs %arg0 |
| 96 | + // CHECK-NEXT: return %[[ABS]] |
| 97 | + %0 = stablehlo.abs %arg0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"z"}]>]>} : tensor<210xf32> |
| 98 | + return %0 : tensor<210xf32> |
| 99 | +} |
| 100 | + |
| 101 | +// ----- |
| 102 | +sdy.mesh @mesh = <["x"=2, "y"=2, "z"=4]> |
| 103 | + |
| 104 | + |
| 105 | +// CHECK-LABEL: func @different_arguments_to_multiple_calls_with_same_input_output_shardings |
| 106 | +func.func @different_arguments_to_multiple_calls_with_same_input_output_shardings(%arg0: tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"x"}]>}) -> (tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"y"}]>}) { |
| 107 | + // CHECK-NEXT: %[[CALL0:.*]] = call @foo(%arg0) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} |
| 108 | + // CHECK-NEXT: %[[NEGATE:.*]] = stablehlo.negate %arg0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"x"}]>]>} |
| 109 | + // CHECK-NEXT: %[[RESHARD:.*]] = sdy.reshard %[[NEGATE]] <@mesh, [{"y"}]> |
| 110 | + // CHECK-NEXT: %[[CALL1:.*]] = call @foo(%[[RESHARD]]) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} |
| 111 | + // CHECK-NEXT: %[[ADD:.*]] = stablehlo.add %[[CALL0]], %[[CALL1]] {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} |
| 112 | + // CHECK-NEXT: return %[[ADD]] |
| 113 | + %0 = call @foo(%arg0) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : (tensor<210xf32>) -> (tensor<210xf32>) |
| 114 | + %1 = stablehlo.negate %arg0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : tensor<210xf32> |
| 115 | + %2 = call @foo(%1) {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : (tensor<210xf32>) -> (tensor<210xf32>) |
| 116 | + %4 = stablehlo.add %0, %2 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : tensor<210xf32> |
| 117 | + return %4 : tensor<210xf32> |
| 118 | +} |
| 119 | + |
| 120 | +// CHECK-LABEL: func private @foo |
| 121 | +func.func private @foo(%arg0: tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"y"}]>}) -> (tensor<210xf32> {sdy.sharding = #sdy.sharding<@mesh, [{"y"}]>}) { |
| 122 | + // CHECK-NEXT: %[[ABS:.*]] = stablehlo.abs %arg0 |
| 123 | + // CHECK-NEXT: return %[[ABS]] |
| 124 | + %3 = stablehlo.abs %arg0 {sdy.sharding = #sdy.sharding_per_value<[<@mesh, [{"y"}]>]>} : tensor<210xf32> |
| 125 | + return %3 : tensor<210xf32> |
| 126 | +} |
0 commit comments