<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:等线;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@等线";
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:宋体;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin:0cm;
margin-bottom:.0001pt;
text-indent:21.0pt;
font-size:12.0pt;
font-family:宋体;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:宋体;}
p.gmail-m-6253693781121381657msolistparagraph, li.gmail-m-6253693781121381657msolistparagraph, div.gmail-m-6253693781121381657msolistparagraph
{mso-style-name:gmail-m_-6253693781121381657msolistparagraph;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:宋体;}
span.EmailStyle19
{mso-style-type:personal;
font-family:等线;
color:windowtext;}
span.EmailStyle20
{mso-style-type:personal-compose;
font-family:等线;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:等线;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:31148757;
mso-list-type:hybrid;
mso-list-template-ids:1970470698 -1872206564 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:18.0pt;
text-indent:-18.0pt;}
@list l0:level2
{mso-level-number-format:alpha-lower;
mso-level-text:"%2\)";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:42.0pt;
text-indent:-21.0pt;}
@list l0:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
margin-left:63.0pt;
text-indent:-21.0pt;}
@list l0:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:84.0pt;
text-indent:-21.0pt;}
@list l0:level5
{mso-level-number-format:alpha-lower;
mso-level-text:"%5\)";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:105.0pt;
text-indent:-21.0pt;}
@list l0:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
margin-left:126.0pt;
text-indent:-21.0pt;}
@list l0:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:147.0pt;
text-indent:-21.0pt;}
@list l0:level8
{mso-level-number-format:alpha-lower;
mso-level-text:"%8\)";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:168.0pt;
text-indent:-21.0pt;}
@list l0:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
margin-left:189.0pt;
text-indent:-21.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=ZH-CN link=blue vlink=purple><div class=WordSection1><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">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.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:等线'><o:p> </o:p></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:<o:p></o:p></span></p><p class=MsoListParagraph style='margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span lang=EN-US style='font-size:10.5pt;font-family:等线'><span style='mso-list:Ignore'>1.<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US style='font-size:10.5pt;font-family:等线'>writing a parser parsing LLVM metadata and passing it to Enzyme<o:p></o:p></span></p><p class=MsoListParagraph style='margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span lang=EN-US style='font-size:10.5pt;font-family:等线'><span style='mso-list:Ignore'>2.<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US style='font-size:10.5pt;font-family:等线'>adjusting Enzyme to leverage the metadata<o:p></o:p></span></p><p class=MsoListParagraph style='margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span lang=EN-US style='font-size:10.5pt;font-family:等线'><span style='mso-list:Ignore'>3.<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><span lang=EN-US style='font-size:10.5pt;font-family:等线'>writing a Rust crate to provide APIs to Rust user<o:p></o:p></span></p><p class=MsoListParagraph style='margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span lang=EN-US style='font-size:10.5pt;font-family:等线'><span style='mso-list:Ignore'>4.<span style='font:7.0pt "Times New Roman"'> </span></span></span><![endif]><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<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:等线'>Is that right?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:等线'><o:p> </o:p></span></p><p class=MsoNormal><b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'> William Moses <wmoses@mit.edu> <br><b>Sent:</b> Wednesday, March 31, 2021 10:51 AM<br><b>To:</b> Chuyang Chen <chuyangchen@foxmail.com><br><b>Cc:</b> Billy Moses <wmoses@mit.edu>; llvm-dev <llvm-dev@lists.llvm.org>; Enzyme AD <enzyme-dev@googlegroups.com><br><b>Subject:</b> Re: FW: [GSoC 2021] Some ideas & questions about the Enzyme GSoC project<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></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">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">https://github.com/rust-lang/compiler-team/issues/419</a> <a href="https://github.com/rust-lang/rust/pull/82734">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.<o:p></o:p></span></p></div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></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">chuyangchen@foxmail.com</a>> wrote:<o:p></o:p></span></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm'><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><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.<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US> <o:p></o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span lang=EN-US style='font-size:11.0pt;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><o:p></o:p></span></p></div></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US> <o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><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.<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US> <o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US>As you have said, the project can be divided to two main parts:<o:p></o:p></span></p><p class=gmail-m-6253693781121381657msolistparagraph style='margin-left:18.0pt'><span lang=EN-US>1.</span><span lang=EN-US style='font-size:7.0pt;font-family:"Times New Roman",serif'> </span><span lang=EN-US>passing and parsing Rust type metadata into LLVM / Enzyme type analysis, and<o:p></o:p></span></p><p class=gmail-m-6253693781121381657msolistparagraph style='margin-left:18.0pt'><span lang=EN-US>2.</span><span lang=EN-US style='font-size:7.0pt;font-family:"Times New Roman",serif'> </span><span lang=EN-US>integrating the Enzyme API/pass into rust.<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US> <o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><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<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US><img border=0 width=860 height=25 style='width:8.9583in;height:.2604in' id="gmail-m_-6253693781121381657图片_x0020_1" src="cid:image003.png@01D72660.9EF59710" alt="cid:image003.png@01D725BE.92A91F10"><o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><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<o:p></o:p></span></p><p class=gmail-m-6253693781121381657msolistparagraph style='margin-left:18.0pt'><span lang=EN-US>1.</span><span lang=EN-US style='font-size:7.0pt;font-family:"Times New Roman",serif'> </span><span lang=EN-US>emit extra debuginfo to the generated IR code, and<o:p></o:p></span></p><p class=gmail-m-6253693781121381657msolistparagraph style='margin-left:18.0pt'><span lang=EN-US>2.</span><span lang=EN-US style='font-size:7.0pt;font-family:"Times New Roman",serif'> </span><span lang=EN-US>use lld as its linker and add the Enzyme pass to lld<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US>with a specific option, say </span>“<span lang=EN-US>--enzyme</span>”<span lang=EN-US><o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US> <o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><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><o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US> <o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US>PS: Another question is about differentiating closures in Rust, but that can be postponed to the following discussions.<o:p></o:p></span></p><div style='border:none;border-bottom:solid windowtext 1.0pt;padding:0cm 0cm 1.0pt 0cm'><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US> <o:p></o:p></span></p></div><p class=MsoNormal align=right style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:right;word-break:break-all'><span lang=EN-US>Chuyang Chen<o:p></o:p></span></p><p class=MsoNormal align=right style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:right;word-break:break-all'><span lang=EN-US>MSc Student<o:p></o:p></span></p><p class=MsoNormal align=right style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:right;word-break:break-all'><span lang=EN-US>At Department of Computer Science and Technology, Nanjing University<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-US> <o:p></o:p></span></p></div></div></blockquote></div></div></body></html>