-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache batched functions and recursively batch. (#2222)
* don't batch the same function twice. * batch functions that are called within batched function * initial tests * support recursive functions * recursion test * formatting
- Loading branch information
Showing
4 changed files
with
174 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module { | ||
func.func private @f(%arg0: tensor<16xf32>, %arg1: tensor<16xf32>) -> tensor<16xf32> { | ||
return %arg0 : tensor<16xf32> | ||
} | ||
func.func @main(%arg0: tensor<4x16xf32>, %arg1: tensor<4x16xf32>) { | ||
%2 = enzyme.batch @f(%arg0, %arg1) {batch_shape = array<i64: 4>} : (tensor<4x16xf32>, tensor<4x16xf32>) -> tensor<4x16xf32> | ||
%3 = enzyme.batch @f(%arg0, %arg1) {batch_shape = array<i64: 4>} : (tensor<4x16xf32>, tensor<4x16xf32>) -> tensor<4x16xf32> | ||
return | ||
} | ||
} | ||
|
||
// CHECK: func.func @main(%[[arg0:.+]]: tensor<4x16xf32>, %[[arg1:.+]]: tensor<4x16xf32>) { | ||
// CHECK-NEXT: %[[v0:.+]] = call @batched_f(%[[arg0]], %[[arg1]]) : (tensor<4x16xf32>, tensor<4x16xf32>) -> tensor<4x16xf32> | ||
// CHECK-NEXT: %[[v1:.+]] = call @batched_f(%[[arg0]], %[[arg1]]) : (tensor<4x16xf32>, tensor<4x16xf32>) -> tensor<4x16xf32> | ||
// CHECK-NEXT: return | ||
// CHECK-NEXT: } | ||
// CHECK: func.func private @batched_f(%[[arg0:.+]]: tensor<4x16xf32>, %[[arg1:.+]]: tensor<4x16xf32>) -> tensor<4x16xf32> { | ||
// CHECK-NEXT: return %[[arg0]] : tensor<4x16xf32> | ||
// CHECK-NEXT: } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: %eopt -enzyme-batch %s | FileCheck %s | ||
|
||
module { | ||
func.func private @g(%arg0: tensor<16xf32>) -> tensor<16xf32> { | ||
return %arg0 : tensor<16xf32> | ||
} | ||
func.func private @f(%arg0: tensor<16xf32>, %arg1: tensor<16xf32>) -> tensor<16xf32> { | ||
%1 = func.call @g(%arg0) : (tensor<16xf32>) -> tensor<16xf32> | ||
return %1 : tensor<16xf32> | ||
} | ||
func.func @main(%arg0: tensor<4x16xf32>, %arg1: tensor<4x16xf32>) { | ||
%2 = enzyme.batch @f(%arg0, %arg1) {batch_shape = array<i64: 4>} : (tensor<4x16xf32>, tensor<4x16xf32>) -> tensor<4x16xf32> | ||
return | ||
} | ||
} | ||
|
||
// CHECK: func.func @main(%[[arg0:.+]]: tensor<4x16xf32>, %[[arg1:.+]]: tensor<4x16xf32>) { | ||
// CHECK-NEXT: %[[v0:.+]] = call @batched_f(%[[arg0]], %[[arg1]]) : (tensor<4x16xf32>, tensor<4x16xf32>) -> tensor<4x16xf32> | ||
// CHECK-NEXT: return | ||
// CHECK-NEXT: } | ||
// CHECK: func.func private @batched_f(%[[arg0:.+]]: tensor<4x16xf32>, %[[arg1:.+]]: tensor<4x16xf32>) -> tensor<4x16xf32> { | ||
// CHECK-NEXT: %[[v0:.+]] = call @batched_g(%[[arg0]]) : (tensor<4x16xf32>) -> tensor<4x16xf32> | ||
// CHECK-NEXT: return %[[v0]] : tensor<4x16xf32> | ||
// CHECK-NEXT: } | ||
// CHECK: func.func private @batched_g(%[[arg0:.+]]: tensor<4x16xf32>) -> tensor<4x16xf32> { | ||
// CHECK-NEXT: return %[[arg0]] : tensor<4x16xf32> | ||
// CHECK-NEXT: } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: %eopt -enzyme-batch %s | FileCheck %s | ||
|
||
module { | ||
func.func private @f(%arg0: tensor<16xf32>, %arg1: tensor<16xf32>) -> tensor<16xf32> { | ||
%0 = func.call @f(%arg0, %arg1) : (tensor<16xf32>, tensor<16xf32>) -> tensor<16xf32> | ||
return %0 : tensor<16xf32> | ||
} | ||
func.func @main(%arg0: tensor<4x16xf32>, %arg1: tensor<4x16xf32>) { | ||
%0 = enzyme.batch @f(%arg0, %arg1) {batch_shape = array<i64: 4>} : (tensor<4x16xf32>, tensor<4x16xf32>) -> tensor<4x16xf32> | ||
return | ||
} | ||
} | ||
|
||
// CHECK: func.func @main(%[[arg0:.+]]: tensor<4x16xf32>, %[[arg1:.+]]: tensor<4x16xf32>) { | ||
// CHECK-NEXT: %[[v0:.+]] = call @batched_f(%[[arg0]], %[[arg1]]) : (tensor<4x16xf32>, tensor<4x16xf32>) -> tensor<4x16xf32> | ||
// CHECK-NEXT: return | ||
// CHECK-NEXT: } | ||
// CHECK: func.func private @batched_f(%[[arg0:.+]]: tensor<4x16xf32>, %[[arg1:.+]]: tensor<4x16xf32>) -> tensor<4x16xf32> { | ||
// CHECK-NEXT: %[[v0:.+]] = call @batched_f(%[[arg0]], %[[arg1]]) : (tensor<4x16xf32>, tensor<4x16xf32>) -> tensor<4x16xf32> | ||
// CHECK-NEXT: return %[[v0]] : tensor<4x16xf32> | ||
// CHECK-NEXT: } |