rust/tests/pretty
Stuart Cook c6bf3a01ef
Rollup merge of #137880 - EnzymeAD:autodiff-batching, r=oli-obk
Autodiff batching

Enzyme supports batching, which is especially known from the ML side when training neural networks.
There we would normally have a training loop, where in each iteration we would pass in some data (e.g. an image), and a target vector. Based on how close we are with our prediction we compute our loss, and then use backpropagation to compute the gradients and update our weights.
That's quite inefficient, so what you normally do is passing in a batch of 8/16/.. images and targets, and compute the gradients for those all at once, allowing better optimizations.

Enzyme supports batching in two ways, the first one (which I implemented here) just accepts a Batch size,
and then each Dual/Duplicated argument has not one, but N shadow arguments.  So instead of
```rs
for i in 0..100 {
   df(x[i], y[i], 1234);
}
```
You can now do
```rs
for i in 0..100.step_by(4) {
   df(x[i+0],x[i+1],x[i+2],x[i+3], y[i+0], y[i+1], y[i+2], y[i+3], 1234);
}
```
which will give the same results, but allows better compiler optimizations. See the testcase for details.

There is a second variant, where we can mark certain arguments and instead of having to pass in N shadow arguments, Enzyme assumes that the argument is N times longer. I.e. instead of accepting 4 slices with 12 floats each, we would accept one slice with 48 floats. I'll implement this over the next days.

I will also add more tests for both modes.

For any one preferring some more interactive explanation, here's a video of Tim's llvm dev talk, where he presents his work. https://www.youtube.com/watch?v=edvaLAL5RqU
I'll also add some other docs to the dev guide and user docs in another PR.

r? ghost

Tracking:

- https://github.com/rust-lang/rust/issues/124509
- https://github.com/rust-lang/rust/issues/135283
2025-04-05 13:18:13 +11:00
..
auxiliary Update tests to use new proc-macro header 2024-11-27 07:18:25 -08:00
postfix-match Pretty-print parenthesis around binary in postfix match 2024-04-29 11:34:22 +02:00
asm.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
asm.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
ast-stmt-expr-attr.rs Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwco" 2024-06-06 20:39:54 +00:00
async.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
attr-derive.rs Update tests to use new proc-macro header 2024-11-27 07:18:25 -08:00
attr-fn-inner.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
attr-literals.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
attr-tokens-raw-ident.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
auto-trait.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
autodiff_forward.pp add new tests for autodiff batching and update old ones 2025-04-04 14:24:46 -04:00
autodiff_forward.rs add new tests for autodiff batching and update old ones 2025-04-04 14:24:46 -04:00
autodiff_reverse.pp add new tests for autodiff batching and update old ones 2025-04-04 14:24:46 -04:00
autodiff_reverse.rs update tests 2025-03-17 16:21:45 -04:00
blank-lines.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-comment-multiple-asterisks.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-comment-trailing-whitespace.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-comment-trailing-whitespace2.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-comment-wchar.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
block-comment-wchar.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
block-disambig.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
cast-lt.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
cast-lt.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
closure-reform-pretty.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
delegation.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
delimited-token-groups.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
disamb-stmt-expr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
do1.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
doc-comments.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
dollar-crate.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
dollar-crate.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
empty-impl.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
empty-lines.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
enum-variant-vis.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
example1.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
example2.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
example2.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
expanded-and-path-remap-80832.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
expanded-and-path-remap-80832.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
fn-return.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
fn-types.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
fn-variadic.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
for-comment.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
format-args-str-escape.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
format-args-str-escape.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
gat-bounds.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
hir-fn-params.pp Fix HIR param pretty printing some more. 2025-03-14 09:45:41 +11:00
hir-fn-params.rs Add a pretty printing test for fn params. 2025-03-14 06:29:24 +11:00
hir-fn-variadic.pp Handle safety keyword for extern block inner items 2024-06-04 14:19:42 -03:00
hir-fn-variadic.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
hir-lifetimes.pp Improve hir_pretty for struct expressions. 2025-03-30 11:21:51 +02:00
hir-lifetimes.rs Add a HIR pretty-printing test focused on lifetimes. 2025-03-28 08:25:06 +11:00
hir-pretty-attr.pp Fix pretty printing of parsed attrs in hir_pretty 2025-03-10 02:04:26 +00:00
hir-pretty-attr.rs pretty print hir attributes 2025-02-24 14:31:19 +01:00
hir-pretty-loop.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
hir-pretty-loop.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
hir-struct-expr.pp Improve hir_pretty for struct expressions. 2025-03-30 11:21:51 +02:00
hir-struct-expr.rs Improve hir_pretty for struct expressions. 2025-03-30 11:21:51 +02:00
if-attr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
import-renames.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-4264.pp Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
issue-4264.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-12590-a.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-12590-b.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-12590-c.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
issue-12590-c.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-19077.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-25031.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-30731.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-31073.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
issue-31073.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-68710-field-attr-proc-mac-lost.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-73626.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-74745.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
issue-85089.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
issue-85089.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
let.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
lifetime.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
macro.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
macro_rules.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
match-block-expr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
match-naked-expr-medium.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
match-naked-expr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
nested-item-vis-defaultness.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
offset_of.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
path-type-bounds.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
pin-ergonomics.rs Implement &pin const self and &pin mut self sugars 2025-03-05 22:37:53 +08:00
postfix-yield.rs Preserve yield position during pretty printing 2025-03-14 12:21:59 -07:00
qpath-associated-type-bound.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
raw-address-of.rs stabilize raw_ref_op 2024-08-18 19:46:53 +02:00
raw-str-nonexpr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
stmt_expr_attributes.rs fix pretty test 2025-03-21 09:35:31 +01:00
struct-pattern.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
struct-tuple.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
tag-blank-lines.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
tests-are-sorted.pp expand: Leave traces when expanding cfg attributes 2025-03-26 15:30:12 +03:00
tests-are-sorted.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
top-level-doc-comments.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
trait-inner-attr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
trait-polarity.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
trait-safety.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
unary-op-disambig.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
use-tree.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
vec-comments.pp Re-bless tests/pretty 2024-02-22 16:04:05 +00:00
vec-comments.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
where-clauses.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
yeet-expr.rs [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00