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

Justin Holewinski jholewinski at nvidia.com
Tue Jun 30 09:26:38 PDT 2015


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.
-----------------------------------------------------------------------------------




More information about the llvm-commits mailing list