// RUN: mlir-opt \ // RUN: --pass-pipeline="builtin.module(func.func(shard-partition))" \ // RUN: %s | FileCheck %s shard.grid @grid(shape = 4) // CHECK-LABEL: func @test_alloc_tensor_op // CHECK-SAME: tensor func.func @test_alloc_tensor_op(%t: tensor, %sz: index) { %sharding = shard.sharding @grid split_axes = [[], [0]] : !shard.sharding %sharded = shard.shard %t to %sharding : tensor // CHECK: bufferization.alloc_tensor(%{{.*}}) : tensor %0 = bufferization.alloc_tensor(%sz) : tensor %sharded0 = shard.shard %0 to %sharding : tensor %sharded1 = shard.shard %sharded to %sharding annotate_for_users : tensor // CHECK: bufferization.alloc_tensor() copy(%{{.*}}) {escape = true} : tensor %4 = bufferization.alloc_tensor() copy(%sharded1) {escape = true} : tensor %sharded4 = shard.shard %4 to %sharding : tensor return } // CHECK-LABEL: func @test_dealloc_tensor_op // CHECK-SAME: tensor<1xi32> func.func @test_dealloc_tensor_op(%arg0: tensor<4xi32>) { %sharding = shard.sharding @grid split_axes = [[0]] : !shard.sharding %sharded = shard.shard %arg0 to %sharding : tensor<4xi32> %sharded1 = shard.shard %sharded to %sharding annotate_for_users : tensor<4xi32> // CHECK: bufferization.dealloc_tensor {{.*}} : tensor<1xi32> bufferization.dealloc_tensor %sharded1 : tensor<4xi32> return } // CHECK-LABEL: func @test_materialize_in_destination_op // CHECK-SAME: tensor<2xf32>) -> tensor<2xf32> func.func @test_materialize_in_destination_op( %arg0: tensor, %arg1: tensor, %arg2: tensor<8xf32>) -> tensor<8xf32> { %sharding = shard.sharding @grid split_axes = [[0]] : !shard.sharding %sharded0 = shard.shard %arg0 to %sharding : tensor %sharded1 = shard.shard %arg1 to %sharding : tensor %sharded2 = shard.shard %arg2 to %sharding : tensor<8xf32> %sharded0_in = shard.shard %sharded0 to %sharding annotate_for_users : tensor %sharded1_in = shard.shard %sharded1 to %sharding annotate_for_users : tensor // CHECK: bufferization.materialize_in_destination {{.*}} : (tensor, tensor) -> tensor %0 = bufferization.materialize_in_destination %sharded0_in in %sharded1_in : (tensor, tensor) -> tensor %sharded_res0 = shard.shard %0 to %sharding : tensor // CHECK: bufferization.materialize_in_destination {{.*}} : (tensor, tensor<2xf32>) -> tensor<2xf32> %sharded0_in2 = shard.shard %sharded0 to %sharding annotate_for_users : tensor %sharded2_in1 = shard.shard %sharded2 to %sharding annotate_for_users : tensor<8xf32> %1 = bufferization.materialize_in_destination %sharded0_in2 in %sharded2_in1 : (tensor, tensor<8xf32>) -> tensor<8xf32> %sharded_res1 = shard.shard %1 to %sharding : tensor<8xf32> %sharded_res1_in = shard.shard %sharded_res1 to %sharding annotate_for_users : tensor<8xf32> // CHECK tensor<2xf32> return %sharded_res1_in : tensor<8xf32> }