[PATCH] D11690: [CUDA] Added stubs for new attributes used by CUDA headers.

Artem Belevich tra at google.com
Fri Jul 31 13:42:51 PDT 2015


On Fri, Jul 31, 2015 at 1:09 PM, Aaron Ballman <aaron at aaronballman.com>
wrote:

> On Fri, Jul 31, 2015 at 4:01 PM, Artem Belevich <tra at google.com> wrote:
> > tra created this revision.
> > tra added reviewers: echristo, jholewinski, eliben.
> > tra added a subscriber: cfe-commits.
> >
> > http://reviews.llvm.org/D11690
> >
> > Files:
> >   include/clang/Basic/Attr.td
> >   test/Index/attributes-cuda.cu
>
> Some background about what you are trying to accomplish would be nice.
> I notice that these are all ignored attributes; are there plans to
> support them in the future, or will they always be ignored?
>
>
The plan is to make clang a usable CUDA compiler. Eventually.
One of prerequisites for that is that we must be able to parse CUDA header
files.
CUDA header files contain things that clang currently throws warnings or
errors on.

The attributes in this patch are those that we need to get out of the way.
Alas, they are not documented anywhere by NVIDIA, so I can only guess what
exactly they use them for. At the moment I need to get them out of the way
so clang can parse the rest of the header files and deal with things we do
know what to do about.

As for the future, we may end up doing something useful at least with some
of those attributes.
Builtin surface and texture attributes will likely be needed in order to
implement support for surface and texture lookups as those seem to require
special handling.

nv_weak is likely to be needed if/when we get to the point where we can
produce real GPU code (i.e. SASS, not PTX). My understanding is that only
SASS supports linking GPU code form multiple files. Unless we do linking
multiple files, nv_weak should not make any difference. Again, I'm guessing
based purely on the attribute name.

I have no idea about the future of device_builtin and cudart_builtin.
Currently I don't see any particular use for them in clang.


> There should not be a need to set the Documentation field for anything
> inheriting from IgnoredAttr as that specifies an undocumented
> attribute by default.
>

OK. I'll clean it up.


>
> >
> > Index: test/Index/attributes-cuda.cu
> > ===================================================================
> > --- test/Index/attributes-cuda.cu
> > +++ test/Index/attributes-cuda.cu
> > @@ -7,6 +7,14 @@
> >  __attribute__((constant)) int* g_constant;
> >  __attribute__((shared)) float *g_shared;
> >  __attribute__((host)) void f_host();
> > +__attribute__((device_builtin)) void f_device_builtin();
> > +typedef __attribute__((device_builtin)) const void *t_device_builtin;
> > +enum __attribute__((device_builtin)) e_device_builtin {};
> > +__attribute__((device_builtin)) int v_device_builtin;
> > +__attribute__((cudart_builtin)) void f_cudart_builtin();
> > +__attribute__((nv_weak)) void f_nv_weak();
> > +__attribute__((device_builtin_surface_type)) unsigned long long
> surface_var;
> > +__attribute__((device_builtin_texture_type)) unsigned long long
> texture_var;
> >
> >  // CHECK:       attributes-cuda.cu:5:30: FunctionDecl=f_device:5:30
> >  // CHECK-NEXT:  attributes-cuda.cu:5:16: attribute(device)
> > @@ -18,3 +26,11 @@
> >  // CHECK-NEXT:  attributes-cuda.cu:8:16: attribute(shared)
> >  // CHECK:       attributes-cuda.cu:9:28: FunctionDecl=f_host:9:28
> >  // CHECK-NEXT:  attributes-cuda.cu:9:16: attribute(host)
> > +// CHECK:      attributes-cuda.cu:10:38:
> FunctionDecl=f_device_builtin:10:38
> > +// CHECK:      attributes-cuda.cu:11:53:
> TypedefDecl=t_device_builtin:11:53
> > +// CHECK:      attributes-cuda.cu:12:38:
> EnumDecl=e_device_builtin:12:38
> > +// CHECK:      attributes-cuda.cu:13:37: VarDecl=v_device_builtin:13:37
> > +// CHECK:      attributes-cuda.cu:14:38:
> FunctionDecl=f_cudart_builtin:14:38
> > +// CHECK:      attributes-cuda.cu:15:31: FunctionDecl=f_nv_weak:15:31
> > +// CHECK:      attributes-cuda.cu:16:65: VarDecl=surface_var:16:65
> > +// CHECK:      attributes-cuda.cu:17:65: VarDecl=texture_var:17:65
> > Index: include/clang/Basic/Attr.td
> > ===================================================================
> > --- include/clang/Basic/Attr.td
> > +++ include/clang/Basic/Attr.td
> > @@ -557,13 +557,37 @@
> >    let Documentation = [Undocumented];
> >  }
> >
> > +def CUDACudartBuiltin : IgnoredAttr {
> > +  let Spellings = [GNU<"cudart_builtin">];
> > +  let LangOpts = [CUDA];
> > +  let Documentation = [Undocumented];
> > +}
> > +
> >  def CUDADevice : InheritableAttr {
> >    let Spellings = [GNU<"device">];
> >    let Subjects = SubjectList<[Function, Var]>;
> >    let LangOpts = [CUDA];
> >    let Documentation = [Undocumented];
> >  }
> >
> > +def CUDADeviceBuiltin : IgnoredAttr {
> > +  let Spellings = [GNU<"device_builtin">];
> > +  let LangOpts = [CUDA];
> > +  let Documentation = [Undocumented];
> > +}
> > +
> > +def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
> > +  let Spellings = [GNU<"device_builtin_surface_type">];
> > +  let LangOpts = [CUDA];
> > +  let Documentation = [Undocumented];
> > +}
> > +
> > +def CUDADeviceBuiltinTextureType : IgnoredAttr {
> > +  let Spellings = [GNU<"device_builtin_texture_type">];
> > +  let LangOpts = [CUDA];
> > +  let Documentation = [Undocumented];
> > +}
> > +
> >  def CUDAGlobal : InheritableAttr {
> >    let Spellings = [GNU<"global">];
> >    let Subjects = SubjectList<[Function]>;
> > @@ -1015,6 +1039,11 @@
> >    let Documentation = [Undocumented];
> >  }
> >
> > +def NvWeak : IgnoredAttr {
> > +  let Spellings = [GCC<"nv_weak">];
> > +  let Documentation = [Undocumented];
> > +}
>
> Is this attribute supported by gcc? I did a quick test of
> [[gnu::nv_weak]] and it seemed to be an unknown attribute.
>
> That's a typo. Should've been GNU.

--Artem


> ~Aaron
>
> > +
> >  def ObjCBridge : InheritableAttr {
> >    let Spellings = [GNU<"objc_bridge">];
> >    let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
> >
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
>



-- 
--Artem Belevich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150731/7890fdd8/attachment.html>


More information about the cfe-commits mailing list