Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler]add lccl op side-effect. #163

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions compiler/include/byteir/Dialect/Lccl/LcclOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define BYTEIR_DIALECT_LCCL_LCCL_OPS

include "byteir/Dialect/Lccl/LcclBase.td"
include "mlir/Interfaces/SideEffectInterfaces.td"

//===----------------------------------------------------------------------===//
// Lccl Dialect operations.
Expand Down Expand Up @@ -59,8 +60,8 @@ def Lccl_BroadcastOp : Lccl_ReplicaGroupsOp<"broadcast"> {
}];

let arguments = (ins
AnyMemRef:$src,
Optional<AnyMemRef>:$dynamic_replica_groups,
Arg<AnyMemRef, "", [MemWrite, MemRead]>:$src,
Arg<Optional<AnyMemRef>, "", [MemRead]>:$dynamic_replica_groups,
BoolAttr:$synchronous,
OptionalAttr<IndexListArrayAttr>:$replica_groups,
OptionalAttr<I64Attr>:$unique_id
Expand All @@ -76,8 +77,8 @@ def Lccl_SendOp : Lccl_Op<"send"> {
}];

let arguments = (ins
AnyMemRef:$src,
Optional<I64>:$dynamic_target_index,
Arg<AnyMemRef, "", [MemRead]>:$src,
Optional<I64> :$dynamic_target_index,
BoolAttr:$synchronous,
OptionalAttr<I64Attr>:$target_index
);
Expand All @@ -92,8 +93,8 @@ def Lccl_RecvOp : Lccl_Op<"recv"> {
}];

let arguments = (ins
AnyMemRef:$src,
Optional<I64>:$dynamic_source_index,
Arg<AnyMemRef, "", [MemWrite]>:$src,
Optional<I64> :$dynamic_source_index,
BoolAttr:$synchronous,
OptionalAttr<I64Attr>:$source_index
);
Expand All @@ -115,9 +116,9 @@ def Lccl_AllReduceOp : Lccl_ReplicaGroupsOp<"all_reduce"> {
}];

let arguments = (ins
AnyMemRef:$src,
AnyMemRef:$target,
Optional<AnyMemRef>:$dynamic_replica_groups,
Arg<AnyMemRef, "", [MemRead]>:$src,
Arg<AnyMemRef, "", [MemWrite]>:$target,
Arg<Optional<AnyMemRef>, "", [MemRead]>:$dynamic_replica_groups,
BoolAttr:$synchronous,
StrAttr:$reduction,
OptionalAttr<IndexListArrayAttr>:$replica_groups,
Expand All @@ -139,9 +140,9 @@ def Lccl_AllGatherOp : Lccl_ReplicaGroupsOp<"all_gather"> {
}];

let arguments = (ins
AnyMemRef:$src,
AnyMemRef:$target,
Optional<AnyMemRef>:$dynamic_replica_groups,
Arg<AnyMemRef, "", [MemRead]>:$src,
Arg<AnyMemRef, "", [MemWrite]>:$target,
Arg<Optional<AnyMemRef>, "", [MemRead]>:$dynamic_replica_groups,
BoolAttr:$synchronous,
I64Attr:$axis,
OptionalAttr<IndexListArrayAttr>:$replica_groups,
Expand All @@ -162,9 +163,9 @@ def Lccl_ReduceScatterOp : Lccl_ReplicaGroupsOp<"reduce_scatter"> {
}];

let arguments = (ins
AnyMemRef:$src,
AnyMemRef:$target,
Optional<AnyMemRef>:$dynamic_replica_groups,
Arg<AnyMemRef, "", [MemRead]>:$src,
Arg<AnyMemRef, "", [MemWrite]>:$target,
Arg<Optional<AnyMemRef>, "", [MemRead]>:$dynamic_replica_groups,
BoolAttr:$synchronous,
StrAttr:$reduction,
I64Attr:$axis,
Expand Down
32 changes: 16 additions & 16 deletions compiler/test/Dialect/Ccl/ccl_bufferize.mlir
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: byteir-opt %s -byteir-one-shot-bufferize -split-input-file | FileCheck %s

func.func @broadcast(%arg0: tensor<2x3x8xf32>) -> tensor<2x3x8xf32> {
%0 = "ccl.broadcast"(%arg0) {replica_groups = [[2, 3]], synchronous = true} : (tensor<2x3x8xf32>) -> tensor<2x3x8xf32>
%0 = ccl.broadcast %arg0 {replica_groups = [[2, 3]], synchronous = true} : (tensor<2x3x8xf32>) -> tensor<2x3x8xf32>
return %0 : tensor<2x3x8xf32>
}

Expand All @@ -14,7 +14,7 @@ func.func @broadcast(%arg0: tensor<2x3x8xf32>) -> tensor<2x3x8xf32> {
// -----

func.func @broadcast_dynamic(%arg0: tensor<2x3x8xf32>, %arg1: tensor<1x4xindex>) -> tensor<2x3x8xf32> {
%0 = "ccl.broadcast"(%arg0, %arg1) {synchronous = true} : (tensor<2x3x8xf32>, tensor<1x4xindex>) -> tensor<2x3x8xf32>
%0 = ccl.broadcast %arg0, %arg1 {synchronous = true} : (tensor<2x3x8xf32>, tensor<1x4xindex>) -> tensor<2x3x8xf32>
return %0 : tensor<2x3x8xf32>
}
// CHECK-LABEL: func.func @broadcast_dynamic(
Expand All @@ -27,7 +27,7 @@ func.func @broadcast_dynamic(%arg0: tensor<2x3x8xf32>, %arg1: tensor<1x4xindex>)
// -----

func.func @send(%arg0: tensor<3xf32>) -> tensor<3xf32> {
%0 = "ccl.send"(%arg0){ synchronous = true, target_index = 0 : i64 }: (tensor<3xf32>) -> tensor<3xf32>
%0 = ccl.send %arg0 { synchronous = true, target_index = 0 : i64 }: (tensor<3xf32>) -> tensor<3xf32>
return %0 : tensor<3xf32>
}
// CHECK-LABEL: func.func @send(
Expand All @@ -40,7 +40,7 @@ func.func @send(%arg0: tensor<3xf32>) -> tensor<3xf32> {

func.func @send_dynamic(%arg0: tensor<3xf32>) -> tensor<3xf32> {
%target_index = arith.constant 0 : i64
%0 = "ccl.send"(%arg0, %target_index) { synchronous = true } : (tensor<3xf32>, i64) -> tensor<3xf32>
%0 = ccl.send %arg0, %target_index { synchronous = true } : (tensor<3xf32>, i64) -> tensor<3xf32>
return %0 : tensor<3xf32>
}
// CHECK-LABEL: func.func @send_dynamic(
Expand All @@ -53,7 +53,7 @@ func.func @send_dynamic(%arg0: tensor<3xf32>) -> tensor<3xf32> {
// -----

func.func @recv(%arg0: tensor<3xf32>) -> tensor<3xf32> {
%0 = "ccl.recv"(%arg0){ synchronous = true, source_index = 0 : i64 } : (tensor<3xf32>) -> tensor<3xf32>
%0 = ccl.recv %arg0 { synchronous = true, source_index = 0 : i64 } : (tensor<3xf32>) -> tensor<3xf32>
return %0 : tensor<3xf32>
}
// CHECK-LABEL: func.func @recv(
Expand All @@ -66,7 +66,7 @@ func.func @recv(%arg0: tensor<3xf32>) -> tensor<3xf32> {

func.func @recv_dynamic(%arg0: tensor<3xf32>) -> tensor<3xf32> {
%target_index = arith.constant 0 : i64
%0 = "ccl.recv"(%arg0, %target_index) { synchronous = true } : (tensor<3xf32>, i64) -> tensor<3xf32>
%0 = ccl.recv %arg0, %target_index { synchronous = true } : (tensor<3xf32>, i64) -> tensor<3xf32>
return %0 : tensor<3xf32>
}

Expand All @@ -80,7 +80,7 @@ func.func @recv_dynamic(%arg0: tensor<3xf32>) -> tensor<3xf32> {
// -----

func.func @all_gather_0(%arg0: tensor<4x4xf32>) -> tensor<8x4xf32> {
%0 = "ccl.all_gather"(%arg0) { replica_groups = [[0, 1] ,[2, 3]], axis = 0 : i64 , synchronous = true }: (tensor<4x4xf32>) -> tensor<8x4xf32>
%0 = ccl.all_gather %arg0 { replica_groups = [[0, 1] ,[2, 3]], axis = 0 : i64 , synchronous = true }: (tensor<4x4xf32>) -> tensor<8x4xf32>
return %0 : tensor<8x4xf32>
}
// CHECK-LABEL: func.func @all_gather_0(
Expand All @@ -93,7 +93,7 @@ func.func @all_gather_0(%arg0: tensor<4x4xf32>) -> tensor<8x4xf32> {
// -----

func.func @all_gather_1(%arg0: tensor<4x4xf32>) -> tensor<4x8xf32> {
%0 = "ccl.all_gather"(%arg0) { replica_groups = [[0, 1] ,[2, 3]], axis = 1 : i64 , synchronous = true }: (tensor<4x4xf32>) -> tensor<4x8xf32>
%0 = ccl.all_gather %arg0 { replica_groups = [[0, 1] ,[2, 3]], axis = 1 : i64 , synchronous = true }: (tensor<4x4xf32>) -> tensor<4x8xf32>
return %0 : tensor<4x8xf32>
}
// CHECK-LABEL: func.func @all_gather_1(
Expand All @@ -106,7 +106,7 @@ func.func @all_gather_1(%arg0: tensor<4x4xf32>) -> tensor<4x8xf32> {
// -----

func.func @all_gather_dynamic_0(%arg0: tensor<4x4xf32>, %arg1: tensor<2x2xindex>) -> tensor<8x4xf32> {
%0 = "ccl.all_gather"(%arg0, %arg1) {axis=0 : i64, synchronous=true}: (tensor<4x4xf32>, tensor<2x2xindex>) -> tensor<8x4xf32>
%0 = ccl.all_gather %arg0, %arg1 {axis=0 : i64, synchronous=true}: (tensor<4x4xf32>, tensor<2x2xindex>) -> tensor<8x4xf32>
return %0 : tensor<8x4xf32>
}
// CHECK-LABEL: func.func @all_gather_dynamic_0(
Expand All @@ -120,7 +120,7 @@ func.func @all_gather_dynamic_0(%arg0: tensor<4x4xf32>, %arg1: tensor<2x2xindex>
// -----

func.func @all_gather_dynamic_1(%arg0: tensor<4x4xf32>, %arg1: tensor<2x2xindex>) -> tensor<4x8xf32> {
%0 = "ccl.all_gather"(%arg0, %arg1) {axis=1 : i64, synchronous=true}: (tensor<4x4xf32>, tensor<2x2xindex>) -> tensor<4x8xf32>
%0 = ccl.all_gather %arg0, %arg1 {axis=1 : i64, synchronous=true}: (tensor<4x4xf32>, tensor<2x2xindex>) -> tensor<4x8xf32>
return %0 : tensor<4x8xf32>
}
// CHECK-LABEL: func.func @all_gather_dynamic_1(
Expand All @@ -134,7 +134,7 @@ func.func @all_gather_dynamic_1(%arg0: tensor<4x4xf32>, %arg1: tensor<2x2xindex>
// -----

func.func @all_reduce(%arg0: tensor<4xf32>) -> tensor<4xf32> {
%0 = "ccl.all_reduce"(%arg0) {reduction = "sum", synchronous=true, replica_groups = [[0, 1] ,[2, 3]]}: (tensor<4xf32>) -> tensor<4xf32>
%0 = ccl.all_reduce %arg0 {reduction = "sum", synchronous=true, replica_groups = [[0, 1] ,[2, 3]]}: (tensor<4xf32>) -> tensor<4xf32>
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func.func @all_reduce(
Expand All @@ -147,7 +147,7 @@ func.func @all_reduce(%arg0: tensor<4xf32>) -> tensor<4xf32> {
// -----

func.func @all_reduce_dynamic(%arg0: tensor<4xf32>, %arg1:tensor<1x4xi64>) -> tensor<4xf32> {
%0 = "ccl.all_reduce"(%arg0, %arg1) {reduction = "sum", synchronous=true}: (tensor<4xf32>, tensor<1x4xi64>) -> tensor<4xf32>
%0 = ccl.all_reduce %arg0, %arg1 {reduction = "sum", synchronous=true}: (tensor<4xf32>, tensor<1x4xi64>) -> tensor<4xf32>
return %0 : tensor<4xf32>
}
// CHECK-LABEL: func.func @all_reduce_dynamic(
Expand All @@ -161,7 +161,7 @@ func.func @all_reduce_dynamic(%arg0: tensor<4xf32>, %arg1:tensor<1x4xi64>) -> te
// -----

func.func @reduce_scatter_0(%arg0: tensor<4x4xf32>) -> tensor<1x4xf32> {
%0 = "ccl.reduce_scatter"(%arg0) { reduction="sum", replica_groups = [[0, 1, 2, 3]], axis = 0 : i64 , synchronous=true } : (tensor<4x4xf32>) -> tensor<1x4xf32>
%0 = ccl.reduce_scatter %arg0 { reduction="sum", replica_groups = [[0, 1, 2, 3]], axis = 0 : i64 , synchronous=true } : (tensor<4x4xf32>) -> tensor<1x4xf32>
return %0 : tensor<1x4xf32>
}

Expand All @@ -175,7 +175,7 @@ func.func @reduce_scatter_0(%arg0: tensor<4x4xf32>) -> tensor<1x4xf32> {
// -----

func.func @reduce_scatter_1(%arg0: tensor<4x4xf32>) -> tensor<4x1xf32> {
%0 = "ccl.reduce_scatter"(%arg0) { reduction="sum", replica_groups = [[0, 1, 2, 3]], axis = 1 : i64 , synchronous=true } : (tensor<4x4xf32>) -> tensor<4x1xf32>
%0 = ccl.reduce_scatter %arg0 { reduction="sum", replica_groups = [[0, 1, 2, 3]], axis = 1 : i64 , synchronous=true } : (tensor<4x4xf32>) -> tensor<4x1xf32>
return %0 : tensor<4x1xf32>
}

Expand All @@ -189,7 +189,7 @@ func.func @reduce_scatter_1(%arg0: tensor<4x4xf32>) -> tensor<4x1xf32> {
// -----

func.func @reduce_scatter_dynamic_0(%arg0: tensor<4x4xf32>, %arg1: tensor<2x2xindex>) -> tensor<2x4xf32> {
%0 = "ccl.reduce_scatter"(%arg0, %arg1) { axis = 0 : i64, synchronous = true, reduction = "sum" }: (tensor<4x4xf32>, tensor<2x2xindex>) -> tensor<2x4xf32>
%0 = ccl.reduce_scatter %arg0, %arg1 { axis = 0 : i64, synchronous = true, reduction = "sum" }: (tensor<4x4xf32>, tensor<2x2xindex>) -> tensor<2x4xf32>
return %0 : tensor<2x4xf32>
}
// CHECK-LABEL: func.func @reduce_scatter_dynamic_0(
Expand All @@ -203,7 +203,7 @@ func.func @reduce_scatter_dynamic_0(%arg0: tensor<4x4xf32>, %arg1: tensor<2x2xin
// -----

func.func @reduce_scatter_dynamic_1(%arg0: tensor<4x4xf32>, %arg1: tensor<2x2xindex>) -> tensor<4x2xf32> {
%0 = "ccl.reduce_scatter"(%arg0, %arg1) { axis=1 : i64, synchronous=true, reduction= "sum" } : (tensor<4x4xf32>, tensor<2x2xindex>) -> tensor<4x2xf32>
%0 = ccl.reduce_scatter %arg0, %arg1 { axis=1 : i64, synchronous=true, reduction= "sum" } : (tensor<4x4xf32>, tensor<2x2xindex>) -> tensor<4x2xf32>
return %0 : tensor<4x2xf32>
}
// CHECK-LABEL: func.func @reduce_scatter_dynamic_1(
Expand Down
Loading