[LLVMdev] PTX generation examples?
Justin Holewinski
justin.holewinski at gmail.com
Tue Dec 10 05:54:52 PST 2013
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.
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.
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.
FYI: I'm the maintainer of the NVPTX target in LLVM. Feel free to contact
me with any questions you have.
On Mon, Dec 9, 2013 at 12:19 PM, Larry Gritz <lg at larrygritz.com> wrote:
> 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.
>
> 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?
>
> -- lg
>
>
> On Dec 9, 2013, at 7:00 AM, Justin Holewinski <justin.holewinski at gmail.com>
> wrote:
>
> 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).
>
> 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.
>
> 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:
>
> InitializeAllTargets();
> InitializeAllTargetMCs();
> InitializeAllAsmPrinters();
> InitializeAllAsmParsers();
>
> std::string Err;
> const Target *Tgt = TargetRegistry::lookupTarget("nvptx64", Err);
> if (Tgt) {
> // nvptx target is available
> } else {
> // nvptx target is not available
> }
>
>
> More information about the PTX target can be found at:
> http://llvm.org/docs/NVPTXUsage.html
>
>
>
> On Fri, Dec 6, 2013 at 3:43 PM, Larry Gritz <lg at larrygritz.com> wrote:
>
>> OK, fine -- an example of MCJIT that sets up for PTX JIT would also be
>> helpful.
>>
>>
>> On Dec 6, 2013, at 12:32 PM, Eli Bendersky <eliben at google.com> wrote:
>>
>>
>> You'll have to switch to MCJIT for this purpose. Legacy JIT doesn't emit
>> PTX.
>>
>> Eli
>>
>>
>> --
>> Larry Gritz
>> lg at larrygritz.com
>>
>>
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>>
>
>
> --
>
> Thanks,
>
> Justin Holewinski
>
>
> --
> Larry Gritz
> lg at larrygritz.com
>
>
>
>
--
Thanks,
Justin Holewinski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131210/6f227931/attachment.html>
More information about the llvm-dev
mailing list