-
Notifications
You must be signed in to change notification settings - Fork 13.6k
TypeTree support in autodiff #144197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
TypeTree support in autodiff #144197
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Currently, I have implemented only for |
r? @ZuseZ4 |
Some changes occurred in compiler/rustc_ast/src/expand/autodiff_attrs.rs cc @ZuseZ4 Some changes occurred in compiler/rustc_codegen_llvm/src/builder/autodiff.rs cc @ZuseZ4 Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_monomorphize/src/partitioning/autodiff.rs cc @ZuseZ4 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
CI is failing, fixing them! |
Some changes occurred in src/tools/enzyme cc @ZuseZ4 |
This comment has been minimized.
This comment has been minimized.
d3f78d7
to
94aa8bc
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #143684) made this pull request unmergeable. Please resolve the merge conflicts. |
83aa06f
to
a28f311
Compare
This comment has been minimized.
This comment has been minimized.
use run_make_support::{llvm_filecheck, rfs, rustc}; | ||
|
||
fn main() { | ||
// First, compile to LLVM IR to check for enzyme_type attributes | ||
let _ir_output = rustc() | ||
.input("memcpy.rs") | ||
.arg("-Zautodiff=Enable") | ||
.arg("-Zautodiff=NoPostopt") | ||
.opt_level("3") | ||
.arg("-Clto=fat") | ||
.arg("--emit=llvm-ir") | ||
.arg("-o") | ||
.arg("main.ll") | ||
.run(); | ||
|
||
// Then compile with TypeTree analysis output for the existing checks | ||
let output = rustc() | ||
.input("memcpy.rs") | ||
.arg("-Zautodiff=Enable,PrintTAFn=test_memcpy") | ||
.arg("-Zautodiff=NoPostopt") | ||
.opt_level("3") | ||
.arg("-Clto=fat") | ||
.arg("-g") | ||
.run(); | ||
|
||
let stdout = output.stdout_utf8(); | ||
let stderr = output.stderr_utf8(); | ||
let ir_content = rfs::read_to_string("main.ll"); | ||
|
||
rfs::write("memcpy.stdout", &stdout); | ||
rfs::write("memcpy.stderr", &stderr); | ||
rfs::write("main.ir", &ir_content); | ||
|
||
llvm_filecheck().patterns("memcpy.check").stdin_buf(stdout).run(); | ||
|
||
llvm_filecheck().patterns("memcpy-ir.check").stdin_buf(ir_content).run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jieyouxu can you review this run make test, i am creating two check files to test IR and type analysis from enzyme, is this correct way or i should be combining them in one file with one single check?
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
Signed-off-by: Karan Janthe <[email protected]>
110292b
to
cffae78
Compare
☔ The latest upstream changes (presumably #145300) made this pull request unmergeable. Please resolve the merge conflicts. |
TypeTrees for Autodiff
What are TypeTrees?
Memory layout descriptors for Enzyme. Tell Enzyme exactly how types are structured in memory so it can compute derivatives efficiently.
Structure
Example:
fn compute(x: &f32, data: &[f32]) -> f32
Input 0:
x: &f32
Input 1:
data: &[f32]
Output:
f32
Why Needed?
What Enzyme Does With This Information:
Without TypeTrees (current state):
With TypeTrees (our goal):
TypeTrees - Offset and -1 Explained
Type Structure
Offset Values
Regular Offset (0, 4, 8, etc.)
Specific byte position within a structure
TypeTree for
&Point
:Offset -1 (Special: "Everywhere")
Means "this pattern repeats for ALL elements"
Example 1: Array
[f32; 100]
Instead of listing 100 separate Types with offsets 0,4,8,12...396
Example 2: Slice
&[i32]
Example 3: Mixed Structure