<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Mar 28, 2014 at 3:56 PM, Yuan Lin <span dir="ltr"><<a href="mailto:yulin@nvidia.com" target="_blank">yulin@nvidia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div lang="EN-US" link="#0563C1" vlink="#954F72"><div><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Eli, <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>

<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I am sure you are aware this is a very specific pass for translating calls to printf functions for the NVPTX backend with current existing CUDA driver implementation.</span></p>

</div></div></blockquote><div><br></div><div><br></div><div>Hi Yuan, thanks for your comments.</div><div><br></div><div>I'm note sure I fully understand. A lot in the NVPTX backend is tightly coupled with the driver, which further lowers the PTX into something. Are you suggesting it would be better to create this coupling between the front-end and the driver?</div>

<div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72">

<div><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>

<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">With your patch, the NVPTX backend won’t be able to handle the input IR that contains a user defined ‘printf’ function.</span></p>

</div></div></blockquote><div><br></div><div>The pass checks whether printf is *defined* in the module (note that this is the final, linked IR module before code generation). If yes, it doesn't do its thing, so IR containing a user-defined 'printf' will work. I can add a tests case for that upstream just to be on the safe side.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72">

<div><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> It will also cause trouble for implementation that implements ‘printf’ as an external llibrary call.</span></p></div>

</div></blockquote><div><br></div><div>Can you clarify -- is there PTX-level linking here? NVPTX gets the fully linked LLVM IR and code-gens it. At this stage I believe there are no external library calls, only PTX syscalls.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72">

<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>

<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Instead of adding this pass to the NVPTX backend, it would be better to do the translation in the compiler module (e.g. clang or other front-ends) that generates the LLVM IR for the NVPTX backend.</span></p>

</div></blockquote><div><br></div><div>So you're suggesting to expose vprintf as a formal part of the NVVM IR specification (<a href="http://docs.nvidia.com/cuda/nvvm-ir-spec/index.html">http://docs.nvidia.com/cuda/nvvm-ir-spec/index.html</a>)? Because it's not currently there.</div>

<div><br></div><div>Neither is printf, to be fair. But printf is at least documented & known at the CUDA level.</div><div><br></div><div>In other words, when you expect someone to target libNVVM for some alternative front-end language (let's say compiling Matlab or whatever other language), how can he print anything? Are you going to expose vprintf as a libNVVM API?</div>

<div><br></div><div>As long as it's not exposed in this way, it makes more sense to me to make it a NVPTX explicit pass, because conceptually only NVPTX "knows" what vprintf is (in the same way it "knows" how PTX instructions should look). And this is then a viable way for someone to develop an open-source toolchain for CUDA based on Clang and LLVM with the NVPTX backend.</div>

<div><br></div><div>Eli</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div lang="EN-US" link="#0563C1" vlink="#954F72"><div><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> <u></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>

<p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> Eli Bendersky [mailto:<a href="mailto:eliben@google.com" target="_blank">eliben@google.com</a>] <br>

<b>Sent:</b> Wednesday, March 26, 2014 9:51 AM<br><b>To:</b> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a>; Justin Holewinski; Justin Holewinski<br><b>Cc:</b> Yuan Lin; Jingyue Wu<br>

<b>Subject:</b> PATCH: implement printf call lowering in the NVPTX backend<u></u><u></u></span></p><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">Hello,<u></u><u></u></p><div><p class="MsoNormal">

<u></u> <u></u></p></div><div><p class="MsoNormal">This patch implements lowering of the printf call to the vprintf syscall in the NVPTX backend. It is implemented as a target-specific IR pass that runs before codegen. The pass builds the required data structure from the varargs to pass to the vprintf calls.<u></u><u></u></p>

</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Tests (IR to IR, and IR to PTX) included.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">

PTAL,<u></u><u></u></p></div><div><p class="MsoNormal">Eli<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div>
<div>
<hr>
</div>
<div>This email message is for the sole use of the intended recipient(s) and may 
contain confidential information.  Any unauthorized review, use, disclosure 
or distribution is prohibited.  If you are not the intended recipient, 
please contact the sender by reply email and destroy all copies of the original 
message. </div>
<div>
<hr>
</div>
</div></blockquote></div><br></div></div>