Skip to content

Commit

Permalink
Support batching scalar types (#2175)
Browse files Browse the repository at this point in the history
* support batching scalar types

* formatting
  • Loading branch information
jumerckx authored Nov 27, 2024
1 parent 0a8fdc7 commit 32a2118
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion enzyme/Enzyme/MLIR/Passes/EnzymeBatchPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ namespace {

static mlir::TensorType applyBatchSizes(mlir::Type Ty,
llvm::ArrayRef<int64_t> batchSizes) {
auto T = cast<TensorType>(Ty);
auto T = dyn_cast<TensorType>(Ty);
if (!T) {
return RankedTensorType::get(batchSizes, Ty);
}

SmallVector<int64_t> shape(batchSizes.begin(), batchSizes.end());
shape.append(T.getShape().begin(), T.getShape().end());
auto T2 = T.clone(shape);
Expand Down
21 changes: 21 additions & 0 deletions enzyme/test/MLIR/Batch/batched_scalar.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %eopt --enzyme-batch %s | FileCheck %s

module {
func.func @square(%x : f64) -> f64 {
%y = math.sin %x : f64
return %y : f64
}
func.func @dsq(%x : tensor<10x2xf64>) -> tensor<10x2xf64> {
%r = enzyme.batch @square(%x) { batch_shape=array<i64: 10, 2> } : (tensor<10x2xf64>) -> (tensor<10x2xf64>)
return %r : tensor<10x2xf64>
}
}

// CHECK: func.func @dsq(%arg0: tensor<10x2xf64>) -> tensor<10x2xf64> {
// CHECK-NEXT: %0 = call @batched_square(%arg0) : (tensor<10x2xf64>) -> tensor<10x2xf64>
// CHECK-NEXT: return %0 : tensor<10x2xf64>
// CHECK-NEXT: }
// CHECK: func.func private @batched_square(%arg0: tensor<10x2xf64>) -> tensor<10x2xf64> {
// CHECK-NEXT: %0 = math.sin %arg0 : tensor<10x2xf64>
// CHECK-NEXT: return %0 : tensor<10x2xf64>
// CHECK-NEXT: }

0 comments on commit 32a2118

Please sign in to comment.