Skip to content

Commit 148f25f

Browse files
authored
add docs to describe our opt debug helper (#16)
1 parent 2cdbe27 commit 148f25f

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/Debugging.md

+24-7
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,33 @@ is harder to minimize, please consider using [icemelter](https://github.com/lang
1515
If after a compilation failure you are greeted by a large amount of LLVM-IR code,
1616
then our Enzyme backend likely failed to compile your code.
1717
These cases are harder to debug, so your help is highly appreciated.
18+
Please also keep in mind, that release builds are usually much more likely to work at the moment.
1819

1920
The final goal here is to reproduce your bug in the Enzyme [compiler explorer](https://enzyme.mit.edu/explorer/),
2021
in order to create a bug report in the [Enzyme core](https://github.com/EnzymeAD/Enzyme/issues) repository.
2122

22-
Few lines of Rust code will expand into much larger LLVM-IR.
23-
It is therefore important to reduce a Rust reproducer as
24-
far as possible, before trying to minimize the generated LLVM-IR.
25-
While manual minimization can not always be avoided, here are
26-
some tools, that might help. Once you have a minimal Rust example (strongly preferable without using other crates),
27-
then please create an issue.
23+
We have an environment variable called `ENZYME_OPT` to help with this. It will print the whole LLVM-IR module,
24+
along with dummy functions called `enzyme_opt_dbg_helper_<i>`. A potential workflow on Linux could look like:
2825

26+
`cargo clean && ENZYME_OPT=1 cargo +enzyme build &> out.ll`
27+
This also captures a few warnings and info messages above and below your module.
28+
Open out.ll and remove every line above `; ModuleID = <SomeHash>` and every line below the last DILocation,
29+
e.g. below `!43760 = !DILocation(line: 297, column: 5, scope: !43746)`. The actual numbers will depend on your code.
30+
31+
`llvm-extract -S --func=f --recursive --rfunc="enzyme_opt_helper_*" out.ll -o mwe.ll`
32+
Please also adjust the name passed with the `--func` flag if your function isn't called `f`. Either look up the correct
33+
llvm-ir name for your function in out.ll, or use the `#[no_mangle]` attribute on the function which you differentiate, in which case
34+
you can pass the original Rust function name to this flag.
35+
36+
Afterwards, you should be able to copy and paste your mwe example into our [compiler explorer](https://enzyme.mit.edu/explorer/) and
37+
hopefully reproduce the same Enzyme error, which you got when you tried to compile your original Rust code.
38+
Please select `LLVM IR` as a language and `opt 17` as your compiler and replace the LLVM-IR example with your final mwe.ll content.
39+
40+
You will quickly note that even small Rust function can generate large llvm-ir reproducer. Please try to get your llvm-ir function below
41+
100 lines, by reducing the Rust function to be differentiated as far as possible. This will significantly speed up the bug fixing process.
42+
Please also try to post both, the compiler-explorer link with your llvm-ir reproducer, as well as a self-contained Rust reproducer.
43+
44+
There are a few solutions to help you with minimizing the Rust reproducer.
2945
This is probably the most simple automated approach:
3046
[cargo-minimize](https://github.com/Nilstrieb/cargo-minimize)
3147

@@ -41,7 +57,7 @@ Potentially also
4157
To support you while debugging, we have added support for various environment variables,
4258
which allow changing the behaviour of Enzyme, without recompiling rustc.
4359
If you change your environment variables, you may need to run `cargo clean` to see the new behaviour.
44-
We currently support:
60+
We currently support the following debug variables:
4561
```bash
4662
export ENZYME_PRINT_TA=1
4763
export ENZYME_PRINT_AA=1
@@ -51,6 +67,7 @@ export ENZYME_PRINT_MOD_BEFORE=1
5167
export ENZYME_PRINT_MOD_AFTER_ENZYME=1
5268
export ENZYME_PRINT_MOD_AFTER_OPTS=1
5369
export ENZYME_LOOSE_TYPES=1
70+
export ENZYME_OPT=1
5471
```
5572

5673
For performance experiments and benchmarking we also support

0 commit comments

Comments
 (0)