[PATCH] [NVPTX] noop when kernel pointers are already global

Jingyue Wu jingyue at google.com
Tue Jun 30 16:42:28 PDT 2015


Justin,

I am confused. I didn't find any link that says "CUDA interface expects
kernel parameters to be in the generic address space". Instead, I found PTX
ISA
<http://docs.nvidia.com/cuda/parallel-thread-execution/#kernel-function-parameters>
says
"... kernel function parameters ... may hold address to objects in
constant, global, local, or shared state spaces". PTX can even attach .ptr
metadata to pointer parameters to indicate which address space. When the
.ptr annotation is missing, PTX assumes the pointer parameter is generic.

Am I missing something?

Jingyue

On Tue, Jun 30, 2015 at 9:26 AM, Justin Holewinski <jholewinski at nvidia.com>
wrote:

> Hi Tobias,
>
> One thing to keep in mind is that the CUDA interface expects kernel
> parameters to be in the generic address space.  If you write kernels that
> pass arguments as global memory pointers, you are technically violating the
> contract between host and device.  Now, this just so happens to work since
> the global->generic and generic->global pointer conversions are no-ops, but
> as far as I know this is not actually guaranteed and may not be true in the
> future.
>
> > On Jun 26, 2015, at 6:36 PM, Jingyue Wu <jingyue at google.com> wrote:
> >
> > REPOSITORY
> >  rL LLVM
> >
> > http://reviews.llvm.org/D10779
> >
> > Files:
> >  llvm/trunk/lib/Target/NVPTX/NVPTXLowerKernelArgs.cpp
> >  llvm/trunk/test/CodeGen/NVPTX/lower-kernel-ptr-arg.ll
> >
> > Index: llvm/trunk/lib/Target/NVPTX/NVPTXLowerKernelArgs.cpp
> > ===================================================================
> > --- llvm/trunk/lib/Target/NVPTX/NVPTXLowerKernelArgs.cpp
> > +++ llvm/trunk/lib/Target/NVPTX/NVPTXLowerKernelArgs.cpp
> > @@ -132,6 +132,10 @@
> >   assert(!Arg->hasByValAttr() &&
> >          "byval params should be handled by handleByValParam");
> >
> > +  // Do nothing if the argument already points to the global address
> space.
> > +  if (Arg->getType()->getPointerAddressSpace() == ADDRESS_SPACE_GLOBAL)
> > +    return;
> > +
> >   Instruction *FirstInst = Arg->getParent()->getEntryBlock().begin();
> >   Instruction *ArgInGlobal = new AddrSpaceCastInst(
> >       Arg, PointerType::get(Arg->getType()->getPointerElementType(),
> > Index: llvm/trunk/test/CodeGen/NVPTX/lower-kernel-ptr-arg.ll
> > ===================================================================
> > --- llvm/trunk/test/CodeGen/NVPTX/lower-kernel-ptr-arg.ll
> > +++ llvm/trunk/test/CodeGen/NVPTX/lower-kernel-ptr-arg.ll
> > @@ -16,5 +16,16 @@
> >   ret void
> > }
> >
> > -!nvvm.annotations = !{!0}
> > +define void @kernel2(float addrspace(1)* %input, float addrspace(1)*
> %output) {
> > +; CHECK-LABEL: .visible .entry kernel2(
> > +; CHECK-NOT: cvta.to.global.u64
> > +  %1 = load float, float addrspace(1)* %input, align 4
> > +; CHECK: ld.global.f32
> > +  store float %1, float addrspace(1)* %output, align 4
> > +; CHECK: st.global.f32
> > +  ret void
> > +}
> > +
> > +!nvvm.annotations = !{!0, !1}
> > !0 = !{void (float*, float*)* @kernel, !"kernel", i32 1}
> > +!1 = !{void (float addrspace(1)*, float addrspace(1)*)* @kernel2,
> !"kernel", i32 1}
> >
> > EMAIL PREFERENCES
> >  http://reviews.llvm.org/settings/panel/emailpreferences/
> > <D10779.28605.patch>
>
>
> -----------------------------------------------------------------------------------
> 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.
>
> -----------------------------------------------------------------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150630/cce91bbc/attachment.html>


More information about the llvm-commits mailing list