<div dir="ltr">Regarding debug information, yeah it's not necessarily the best mechanism (obviously that would be direct Rust compiler integration), but I believe it should be sufficient at least for now. Presumably, we can always run a pass that removes debug info after Enzyme if the extra information becomes a concern.<br><br>I think your understanding of the project components is mostly correct. The one thing that I might add (and of course there's a lot here, not all of which needs completion during GSOC) is potential registration of custom derivatives for various rust internal routines/allocation mechanisms, and possibly marking explicitly the activity analysis markers of routines such as print to be inactive. The second bit is to clarify that Enzyme, by virtue of being an LLVM pass natively has support for LLVM Metadata. The specific issue here is parsing the specific layout of Rust types in the metadata into something more easily digestible to LLVM/Enzyme type analysis.<br><br>Manuel Drehwald (trying to find email and will add to cc) has recently been looking into exporting the Enzyme C API as a crate to be called from Rust. Once that exists, we can extend the Rust compiler or perhaps create a special Rust-specific optimization pass that calls the Enzyme API with the Type metadata parsing to perform end-to-end tests.<br><br>If you're looking to dive right in, I'd probably suggest pushing either the metadata parsing or Rust plugin (or custom codegen pass) as next steps.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 31, 2021 at 7:21 AM Chuyang Chen <<a href="mailto:chuyangchen@foxmail.com" target="_blank">chuyangchen@foxmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="ZH-CN"><div><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">The metadata parser in the <a href="https://github.com/tiberiusferreira/oxide-enzyme/issues/1#issuecomment-735634144" target="_blank">github discussion</a> seems to work on debuginfo. It means that each time we want Enzyme to work, we should add a “-g” option to the compiling command “rustc”. I’m a bit in doubt whether this will be OK though it doesn’t make much difference. But will there be some cases, like running on a device whose memory is limited, where adding debuginfo do have some negative effect? Anyway, this may be the most fitting way.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">Now, AIUI, there are 4 things need to be done in the project:<u></u><u></u></span></p><p style="margin-left:18pt"><u></u><span lang="EN-US" style="font-size:10.5pt;font-family:等线"><span>1.<span style="font:7pt "Times New Roman"">      </span></span></span><u></u><span lang="EN-US" style="font-size:10.5pt;font-family:等线">writing a parser parsing LLVM metadata and passing it to Enzyme<u></u><u></u></span></p><p style="margin-left:18pt"><u></u><span lang="EN-US" style="font-size:10.5pt;font-family:等线"><span>2.<span style="font:7pt "Times New Roman"">      </span></span></span><u></u><span lang="EN-US" style="font-size:10.5pt;font-family:等线">adjusting Enzyme to leverage the metadata<u></u><u></u></span></p><p style="margin-left:18pt"><u></u><span lang="EN-US" style="font-size:10.5pt;font-family:等线"><span>3.<span style="font:7pt "Times New Roman"">      </span></span></span><u></u><span lang="EN-US" style="font-size:10.5pt;font-family:等线">writing a Rust crate to provide APIs to Rust user<u></u><u></u></span></p><p style="margin-left:18pt"><u></u><span lang="EN-US" style="font-size:10.5pt;font-family:等线"><span>4.<span style="font:7pt "Times New Roman"">      </span></span></span><u></u><span lang="EN-US" style="font-size:10.5pt;font-family:等线">writing a Rust compiler patch to allow importing LLVM plugins to the Rust compiler<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线">Is that right?<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10.5pt;font-family:等线"><u></u> <u></u></span></p><p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> William Moses <<a href="mailto:wmoses@mit.edu" target="_blank">wmoses@mit.edu</a>> <br><b>Sent:</b> Wednesday, March 31, 2021 10:51 AM<br><b>To:</b> Chuyang Chen <<a href="mailto:chuyangchen@foxmail.com" target="_blank">chuyangchen@foxmail.com</a>><br><b>Cc:</b> Billy Moses <<a href="mailto:wmoses@mit.edu" target="_blank">wmoses@mit.edu</a>>; llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>; Enzyme AD <<a href="mailto:enzyme-dev@googlegroups.com" target="_blank">enzyme-dev@googlegroups.com</a>><br><b>Subject:</b> Re: FW: [GSoC 2021] Some ideas & questions about the Enzyme GSoC project<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><div><p class="MsoNormal"><span lang="EN-US">There's certainly utility to be gained by hooking into the rust compiler. At minimum this allows us to effectively integrate high level functions for calling into Enzyme as an API without going through FFI.<br><br>As you say, one of the biggest issues here is essentially parsing Rust types. This actually may not require a modification to rustc as I believe this is available in LLVM as LLVM metadata (see <a href="https://github.com/tiberiusferreira/oxide-enzyme/issues/1#issuecomment-735634144" target="_blank">https://github.com/tiberiusferreira/oxide-enzyme/issues/1#issuecomment-735634144</a> for an earlier discussion on this topic specifically).<br><br>It turns out that one doesn't need to piggyback off LLD if rustc itself can call the custom LLVM pass which runs Enzyme. This could be done by say loading a plugin to rust, or otherwise calling the API. Of course in general enabling better integration of LLVM internals/pass plugins into rust directly is potentially desirable. I recently proposed a patch to rustc that would allow importing LLVM plugins that may be worth a look (see <a href="https://github.com/rust-lang/compiler-team/issues/419" target="_blank">https://github.com/rust-lang/compiler-team/issues/419</a> <a href="https://github.com/rust-lang/rust/pull/82734" target="_blank">https://github.com/rust-lang/rust/pull/82734</a>). That said such support isn't a blocker, as much as we need to start parsing this metadata. In theory we can even fork the "nice interface" and "parsing metadata" into two concurrent projects/pieces.<u></u><u></u></span></p></div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><div><div><p class="MsoNormal"><span lang="EN-US">On Tue, Mar 30, 2021 at 12:04 PM Chuyang Chen <<a href="mailto:chuyangchen@foxmail.com" target="_blank">chuyangchen@foxmail.com</a>> wrote:<u></u><u></u></span></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span lang="EN-US">A thing I forgot to mention is that a Rust feature named </span>“<span lang="EN-US">compiler plugin</span>”<span lang="EN-US"> do satisfy the requirement of </span>“<span lang="EN-US">emitting extra debuginfo to the generated IR code</span>”<span lang="EN-US">, but it</span>’<span lang="EN-US">s unstable and won</span>’<span lang="EN-US">t be stabilized in the foreseeable future. Moreover, as to </span>“<span lang="EN-US">using lld as its linker and add the Enzyme pass to lld</span>”<span lang="EN-US">, compiler plugins help nothing.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><div><div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm"><p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> Chuyang Chen <<a href="mailto:chuyangchen@foxmail.com" target="_blank">chuyangchen@foxmail.com</a>> <br><b>Sent:</b> Tuesday, March 30, 2021 11:44 PM<br><b>To:</b> <a href="mailto:wmoses@mit.edu" target="_blank">wmoses@mit.edu</a><br><b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>; 'Enzyme AD' <<a href="mailto:enzyme-dev@googlegroups.com" target="_blank">enzyme-dev@googlegroups.com</a>><br><b>Subject:</b> [GSoC 2021] Some ideas & questions about the Enzyme GSoC project</span><span lang="EN-US"><u></u><u></u></span></p></div></div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">Hello, I</span>’<span lang="EN-US">m working on the GSoC project </span>“<span lang="EN-US">Integrate Enzyme into Rust to provide high-performance differentiation in Rust</span>”<span lang="EN-US">. I have skimmed over the codebase and now I have some preliminary ideas about the project.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">As you have said, the project can be divided to two main parts:<u></u><u></u></span></p><p style="margin-left:18pt"><span lang="EN-US">1.</span><span lang="EN-US" style="font-size:7pt;font-family:"Times New Roman",serif">      </span><span lang="EN-US">passing and parsing Rust type metadata into LLVM / Enzyme type analysis, and<u></u><u></u></span></p><p style="margin-left:18pt"><span lang="EN-US">2.</span><span lang="EN-US" style="font-size:7pt;font-family:"Times New Roman",serif">      </span><span lang="EN-US">integrating the Enzyme API/pass into rust.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">Integrating Enzyme API to rust is trivial by using proc_macros in Rust. However, passing Rust type metadata to LLVM and integrating the Enzyme pass into rust is difficult if we don</span>’<span lang="EN-US">t modify the Rust compiler. The Rust compiler seems to lack ability to emit metadata to LLVM, and if we want to add the Enzyme pass without modifying the compiler, the only way is, I think, using a command like<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"><img border="0" width="860" height="25" style="width: 8.9583in; height: 0.2604in;" id="gmail-m_-7236394230511152334gmail-m_-3420938107842278483gmail-m_-6253693781121381657图片_x0020_1" src="cid:17890ac9df8692e331" alt="cid:image003.png@01D725BE.92A91F10"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">which is not user-friendly. I sought hard for a nonintrusive way to implement them but got nothing, so it seems that the only option is modifying the Rust compiler to let it<u></u><u></u></span></p><p style="margin-left:18pt"><span lang="EN-US">1.</span><span lang="EN-US" style="font-size:7pt;font-family:"Times New Roman",serif">      </span><span lang="EN-US">emit extra debuginfo to the generated IR code, and<u></u><u></u></span></p><p style="margin-left:18pt"><span lang="EN-US">2.</span><span lang="EN-US" style="font-size:7pt;font-family:"Times New Roman",serif">      </span><span lang="EN-US">use lld as its linker and add the Enzyme pass to lld<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">with a specific option, say </span>“<span lang="EN-US">--enzyme</span>”<span lang="EN-US"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">However, <i>is it appropriate to modify the compiler to just port a plugin to it, though the modification won</i></span><i>’<span lang="EN-US">t be big or impact the rest of the compiler?</span></i><span lang="EN-US"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US">PS: Another question is about differentiating closures in Rust, but that can be postponed to the following discussions.<u></u><u></u></span></p><div style="border-top:none;border-right:none;border-left:none;border-bottom:1pt solid windowtext;padding:0cm 0cm 1pt"><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div><p class="MsoNormal" align="right" style="text-align:right;word-break:break-all"><span lang="EN-US">Chuyang Chen<u></u><u></u></span></p><p class="MsoNormal" align="right" style="text-align:right;word-break:break-all"><span lang="EN-US">MSc Student<u></u><u></u></span></p><p class="MsoNormal" align="right" style="text-align:right;word-break:break-all"><span lang="EN-US">At Department of Computer Science and Technology, Nanjing University<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div></div></blockquote></div></div></div></blockquote></div>