[LLVMdev] PTX builtin functions.

Justin Holewinski justin.holewinski at gmail.com
Wed Nov 16 06:17:59 PST 2011


On Wed, Nov 16, 2011 at 9:16 AM, Justin Holewinski <
justin.holewinski at gmail.com> wrote:

> On Wed, Nov 16, 2011 at 8:05 AM, Alberto Magni <alberto.magni86 at gmail.com>wrote:
>
>> Dear Justin,
>>
>> I am trying to add the support for some OpenCL builtin functions to
>> the PTX backend.
>> The attached file represent the first stub of a patch for the fmax
>> builtin function.
>>
>
> First off, thanks for helping to improve the PTX back-end!
>
> There are really two main issues here.  First, OpenCL built-in functions
> do not belong in the PTX back-end.  These will be implemented in the libclc
> library (http://www.pcc.me.uk/~peter/libclc).  The back-end will only
> implement PTX intrinsics, which may be used by the OpenCL built-in
> functions in libclc.  However, this particular function (max) corresponds
> to a PTX instruction, so it makes sense to implement it as an intrinsic in
> the back-end.
>
> Second, intrinsic functions require a bit more work.  You're off to a
> great start, but intrinsics are implemented a bit differently.  It looks
> like LLVM does not have a max intrinsic, so we'll need to create one.  Have
> a look at include/llvm/IntrinsicsPTX.td.  This file defines the
> PTX-specific intrinsics.  You can add an intrinsic for max here, and then
> implement a pattern-match in the PTXInstrInfo.td file.  There is no need to
> create a new SDNode type for intrinsics, unless they require some special
> handling in the C++ code, which I do not see being the case here.
>

Sorry, there's a typo here.  The intrinsic pattern matching goes in
PTXInstrinsicInstrInfo.td.


>
> When you define a new intrinsic, use the following template as a name:
> int_ptx_max.  This will define the LLVM intrinsic as @llvm.ptx.max().
>  Please follow the same convention when naming the __builtin_* function.
>
>
>
>>
>> The test case I am trying is the following:
>>
>> define ptx_device float @f(float %x, float %y) {
>> entry:
>>  %z = call float @fmax(float %x, float %y)
>>  ret float %z
>> }
>>
>> declare float @fmax(float, float)
>>
>> But at the moment llc crashes saying that "calls are not supported",
>> this does not
>> happens with llvm builtins like llvm.sqrt.f32
>>
>
> Which version of LLVM are you using?  Calls to PTX device functions have
> been implemented for a little while now, so I'm surprised to see that
> error.  Perhaps it's because the fmax function is not defined as ptx_device.
>
>
>>
>> Can you please give me a hint on what I am missing, or some general
>> advice on how
>> to add builtin functions.
>>
>> Thank you in advance,
>>
>> Alberto.
>>
>> _______________________________________________
>> 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
>
>


-- 

Thanks,

Justin Holewinski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111116/8cabfef0/attachment.html>


More information about the llvm-dev mailing list