EnzymeAD / EnzymeAD/Enzyme-JAX

Explicitly track all possible index access in stablehlo.while

Open
#1,681 0 comments 0 reactions 1 assignee Claimed by @avik-pal View on GitHub
Dominant language
MLIR
Stars
133
Forks
53
Avg merge
1d 10h
Merged PRs (30d)
193

Description

https://github.com/EnzymeAD/Enzyme-JAX/pull/1668 generalizes indexing to `scale * i + offset`. However this wont work for IR like

```mlir
module {
func.func @main(%arg0: tensor<10xf64>) -> tensor<10xf64> {
%c = stablehlo.constant dense<1> : tensor
%c_0 = stablehlo.constant dense<0> : tensor
%c_1 = stablehlo.constant dense<10> : tensor
%c_2 = stablehlo.constant dense<3> : tensor
%cst = stablehlo.constant dense<0.000000e+00> : tensor<10xf64>
%c_3 = stablehlo.constant dense<2> : tensor
%0 = stablehlo.dynamic_slice %arg0, %c_3, sizes = [10] : (tensor<10xf64>, tensor) -> tensor<10xf64>
%1 = stablehlo.slice %0 [0:10:3] : (tensor<10xf64>) -> tensor<4xf64>
%2 = stablehlo.cosine %1 : tensor<4xf64>
%3 = stablehlo.dynamic_slice %arg0, %c_3, sizes = [10] : (tensor<10xf64>, tensor) -> tensor<10xf64>
%4 = stablehlo.slice %3 [0:10:3] : (tensor<10xf64>) -> tensor<4xf64>
%5 = stablehlo.sine %4 : tensor<4xf64>
%6:2 = stablehlo.while(%iterArg = %c_0, %iterArg_4 = %cst) : tensor, tensor<10xf64>
cond {
%7 = stablehlo.compare LT, %iterArg, %c_1 : (tensor, tensor) -> tensor
stablehlo.return %7 : tensor
} do {
%7 = stablehlo.add %c_2, %iterArg : tensor
%8 = stablehlo.convert %7 : (tensor) -> tensor
%9 = stablehlo.subtract %8, %c : tensor
%10 = stablehlo.divide %iterArg, %c_2 : tensor
%11 = stablehlo.dynamic_slice %5, %10, sizes = [1] : (tensor<4xf64>, tensor) -> tensor<1xf64>
%12 = stablehlo.dynamic_slice %2, %10, sizes = [1] : (tensor<4xf64>, tensor) -> tensor<1xf64>
%13 = stablehlo.subtract %12, %11 : tensor<1xf64>
%14 = stablehlo.dynamic_update_slice %iterArg_4, %13, %9 : (tensor<10xf64>, tensor<1xf64>, tensor) -> tensor<10xf64>
stablehlo.return %7, %14 : tensor, tensor<10xf64>
}
return %6#1 : tensor<10xf64>
}
}
}
```

If we instead track the full range of possible indices we can hoist even this loop

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.