<div dir="ltr"><div class="gmail_extra">The NVPTX target in upstream LLVM is basically the same NVPTX target from libNVVM, ported to upstream LLVM with a couple of proprietary features removed.<br><br></div><div class="gmail_extra">
One thing to consider is that libNVVM is based on LLVM 3.0 and only IR-compatible up to LLVM 3.2.  So if you use the LLVM 3.3, 3.4, or trunk libraries to generate IR, it will not be compatible with libNVVM due to differences in the IR and bitcode formats.  Even dumping the IR to text first will not work because of the new attributes syntax.<br>
<br></div><div class="gmail_extra">With libNVVM, you get the same compiler middle-end and back-end as the shipped nvcc compiler, but you're limited to LLVM 3.0-3.2.  With upstream LLVM, the target handles new IR features and can take advantage of improvements to the LLVM core optimizers.  If you're already invested in LLVM 3.3+, I would recommend sticking with it and using the upstream NVPTX target.  The libdevice math library that ships with the CUDA toolkit is fully compatible with upstream LLVM, not just libNVVM.<br>
<br></div><div class="gmail_extra">FYI: I'm the maintainer of the NVPTX target in LLVM.  Feel free to contact me with any questions you have.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 9, 2013 at 12:19 PM, Larry Gritz <span dir="ltr"><<a href="mailto:lg@larrygritz.com" target="_blank">lg@larrygritz.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Ah, that's helpful.  I knew that I'd need to end up with PTX as text, not a true binary, but I would have figured that it would come out of MCJIT. Thanks for helping to steer me away from the wrong trail.<div>
<br></div><div>OK, one more question: Can anybody clarify the pros and cons of generating the PTX through the standard LLVM distro, versus using the "libnvvm" that comes with the Cuda SDK?</div><div><br></div><div>
<span style="white-space:pre-wrap">     </span>-- lg</div><div><br></div><div><div><div class="h5"><br><div><div>On Dec 9, 2013, at 7:00 AM, Justin Holewinski <<a href="mailto:justin.holewinski@gmail.com" target="_blank">justin.holewinski@gmail.com</a>> wrote:</div>
<br><blockquote type="cite"><div dir="ltr"><div><div><div><div><div><div><div><div>There is no MCJIT support for PTX at the moment (mainly because PTX does not have a binary format, and is not machine code per se).<br><br>
</div>To generate PTX at run-time, you just set up a standard codegen pass manager like you would like an off-line compiler.  The output will be a string buffer that contains the PTX, which you can load into the CUDA runtime.<br>

<br></div>As for determining if PTX support is compiled into the LLVM binary you are using, you could register all targets and then check if you can create a Target for the "nvptx" or "nvptx64" triple:<br>

<span style="font-family:courier new,monospace"><br>  InitializeAllTargets();<br>  InitializeAllTargetMCs();<br>  InitializeAllAsmPrinters();<br>  InitializeAllAsmParsers();<br><br></span></div><div><span style="font-family:courier new,monospace">  std::string Err;<br>

</span></div><span style="font-family:courier new,monospace">  const Target *Tgt = TargetRegistry::lookupTarget("nvptx64", Err);<br></span></div><span style="font-family:courier new,monospace">  if (Tgt) {<br></span></div>

<span style="font-family:courier new,monospace">    // nvptx target is available<br></span></div><span style="font-family:courier new,monospace">  } else {<br></span></div><span style="font-family:courier new,monospace">    // nvptx target is not available<br>

  }</span><br><br><br></div><div>More information about the PTX target can be found at: <a href="http://llvm.org/docs/NVPTXUsage.html" target="_blank">http://llvm.org/docs/NVPTXUsage.html</a><br><br></div></div><div class="gmail_extra">
<br>
<br><div class="gmail_quote">On Fri, Dec 6, 2013 at 3:43 PM, Larry Gritz <span dir="ltr"><<a href="mailto:lg@larrygritz.com" target="_blank">lg@larrygritz.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div style="word-wrap:break-word">OK, fine -- an example of MCJIT that sets up for PTX JIT would also be helpful.<div><br></div><div><div><br><div><div>On Dec 6, 2013, at 12:32 PM, Eli Bendersky <<a href="mailto:eliben@google.com" target="_blank">eliben@google.com</a>> wrote:</div>

<br><blockquote type="cite"><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><div>You'll have to switch to MCJIT for this purpose. Legacy JIT doesn't emit PTX.</div><div><br></div><div>Eli </div>



</div></div></div>
</blockquote></div><br></div><div>
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;white-space:normal;font-family:Helvetica;word-spacing:0px">--<br>

Larry Gritz<br><a href="mailto:lg@larrygritz.com" target="_blank">lg@larrygritz.com</a><br><br><br></span>

</div>
<br></div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div>
</div>
</blockquote></div><br></div></div><div>
<span style="border-collapse:separate;border-spacing:0px">--<br>Larry Gritz<br><a href="mailto:lg@larrygritz.com" target="_blank">lg@larrygritz.com</a><br><br><br></span>

</div>
<br></div></div></blockquote></div><br><br clear="all"><br>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div>
</div></div>