<div dir="auto"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">---------- Forwarded message ---------<br>De: <strong class="gmail_sendername" dir="auto">William Moses via llvm-dev</strong> <span dir="auto"><<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>></span><br>Date: mar., 30 de mar. de 2021 20:51<br>Subject: Re: [llvm-dev] FW: [GSoC 2021] Some ideas & questions about the Enzyme GSoC project<br>To: Chuyang Chen <<a href="mailto:chuyangchen@foxmail.com">chuyangchen@foxmail.com</a>><br>Cc: llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>>, Enzyme AD <<a href="mailto:enzyme-dev@googlegroups.com">enzyme-dev@googlegroups.com</a>><br></div><br><br><div dir="ltr">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" rel="noreferrer">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" rel="noreferrer">https://github.com/rust-lang/compiler-team/issues/419</a> <a href="https://github.com/rust-lang/rust/pull/82734" target="_blank" rel="noreferrer">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.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 30, 2021 at 12:04 PM Chuyang Chen <<a href="mailto:chuyangchen@foxmail.com" target="_blank" rel="noreferrer">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">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" align="left" style="text-align:left"><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" rel="noreferrer">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" rel="noreferrer">wmoses@mit.edu</a><br><b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a>; 'Enzyme AD' <<a href="mailto:enzyme-dev@googlegroups.com" target="_blank" rel="noreferrer">enzyme-dev@googlegroups.com</a>><br><b>Subject:</b> [GSoC 2021] Some ideas & questions about the Enzyme GSoC project<u></u><u></u></span></p></div></div><p class="MsoNormal" align="left" style="text-align:left"><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"><u></u><span lang="EN-US"><span>1.<span style="font:7pt "Times New Roman"">      </span></span></span><u></u><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"><u></u><span lang="EN-US"><span>2.<span style="font:7pt "Times New Roman"">      </span></span></span><u></u><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 width="860" height="25" style="width:8.9583in;height:0.2604in" id="m_-4451036639501302652gmail-m_-6253693781121381657_x56fe__x7247__x0020_1" src="cid:17886291d664cff311" alt="cid:image003.png@01D725BE.92A91F10"></span><span lang="EN-US"><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"><u></u><span lang="EN-US"><span>1.<span style="font:7pt "Times New Roman"">      </span></span></span><u></u><span lang="EN-US">emit extra debuginfo to the generated IR code, and<u></u><u></u></span></p><p style="margin-left:18pt"><u></u><span lang="EN-US"><span>2.<span style="font:7pt "Times New Roman"">      </span></span></span><u></u><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>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</div>