rust/compiler/rustc_codegen_ssa/src
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
..
back Rollup merge of #138949 - madsmtm:rename-to-darwin, r=WaffleLapkin 2025-04-04 08:02:05 +02:00
debuginfo Flatten ifs in rustc_codegen_ssa 2025-03-17 18:56:52 +00:00
mir Auto merge of #138601 - RalfJung:wasm-abi-fcw, r=alexcrichton 2025-03-26 00:06:46 +00:00
traits Auto merge of #133984 - DaniPopes:scmp-ucmp, r=scottmcm 2025-03-24 22:53:12 +00:00
assert_module_sources.rs Move methods from Map to TyCtxt, part 4. 2025-03-12 08:55:37 +11:00
base.rs Auto merge of #138629 - Zoxc:graph-anon-hashmap, r=oli-obk 2025-03-24 15:02:09 +00:00
codegen_attrs.rs Rollup merge of #137880 - EnzymeAD:autodiff-batching, r=oli-obk 2025-04-05 13:18:13 +11:00
common.rs Test fixing raw-dylib 2024-09-24 10:10:31 -07:00
errors.rs Emit better error messages when invoking xcrun 2025-03-27 04:38:54 +01:00
lib.rs Make LevelAndSource a struct 2025-04-03 09:17:55 +00:00
meth.rs More assertions, tests, and miri coverage 2025-01-30 17:44:28 +00:00
mono_item.rs Make a fake body to store typeck results for global_asm 2025-02-22 00:12:07 +00:00
size_of_val.rs Set both nuw and nsw in slice size calculation 2025-02-13 21:26:48 -08:00
target_features.rs Simplify implied_target_features. 2025-03-05 09:20:28 +11:00