[cfe-dev] Clang and CUDA with C++11 features

Sean Silva silvas at purdue.edu
Wed Jun 13 21:35:10 PDT 2012


Try:

find $HEADER_DIR | xargs sed --i.bak -e 's/>>>/> > >/'

I don't think there are any syntactic dark corners where that will break
otherwise valid C++.

No guarantees though (that's what the -i.bak is for ;).

--Sean Silva

On Wed, Jun 13, 2012 at 8:28 PM, Peter Colberg <peter at colberg.org> wrote:

> On Wed, Jun 13, 2012 at 07:30:25PM -0700, Richard Smith wrote:
> > On Wed, Jun 13, 2012 at 6:57 PM, Peter Colberg <peter at colberg.org>
> wrote:
> > > Hi,
> > >
> > > I am experimenting with CUDA language support in Clang, and so far
> > > the kernel-call test in Clang trunk (r158426) compiles and runs, on
> > > a Tesla C2050.
> > >
> > > Now I would like to enable C++11 support in Clang to use compile-time
> > > C++11 features in GPU code, primarily variadic templates and lambda
> > > functions.
> > > …
> > > Is there a way to tell Clang to enable C++11 extensions?
> >
> > Sadly no, it appears we enable CUDA features based on whether we're
> > using -std=cuda, not whether we're using -x cuda, so even though we
> > accept -x cuda -std=c++11, that diasbles CUDA support! I expect we'd
> > accept a patch to fix that :-)
> >
> > For your own experimentation, try modifying
> > include/clang/Frontend/LangStandards.def as follows:
> >
> > --- include/clang/Frontend/LangStandards.def    (revision 158416)
> > +++ include/clang/Frontend/LangStandards.def    (working copy)
> > @@ -115,6 +115,6 @@
> >  // CUDA
> >  LANGSTANDARD(cuda, "cuda",
> >               "NVIDIA CUDA(tm)",
> > -             BCPLComment | CPlusPlus | Digraphs)
> > +             BCPLComment | CPlusPlus | CPlusPlus0x | Digraphs)
> >
> >  #undef LANGSTANDARD
>
> Thanks, Richard and Sean, indeed that works! I could compile a
> __attribute__((global)) function calling a local lambda function,
> and a variadic function with __attribute__((device)).
>
> There seems to be an issue with C++11 headers, e.g. <iostream>
>
>    clang++ -I/usr/local/cuda-4.2/cuda/include
> -L/usr/local/cuda-4.2/cuda/lib64 -lcudart -o kernel-call kernel-call.cu
>    In file included from kernel-call.cu:7:
>    In file included from
> /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/iostream:39:
>    In file included from
> /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ostream:39:
>    In file included from
> /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/ios:40:
>    In file included from
> /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/char_traits.h:40:
>    In file included from
> /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_algobase.h:65:
>    In file included from
> /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_pair.h:61:
>    In file included from
> /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/move.h:57:
>
>  /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/type_traits:441:38:
> error: expected '>'
>                              is_void<_Tp>>>::type
>                                         ^
>
>  /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/type_traits:441:38:
> error: expected a type
>
>  /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/type_traits:442:8:
> error: expected a type
>        { };
>           ^
>
>  /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/type_traits:442:8:
> error: expected class
>          name
>
>  /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/type_traits:442:8:
> error: expected
>          '{' after base class list
>
>  /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/type_traits:563:61:
> error: expected '>'
>        : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
>                                                                ^
>
>  /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/type_traits:563:61:
> error: expected a type
>
>  /home/peter/usr/rhel6-x86_64/gcc-4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/type_traits:564:8:
> error: expected a type
>        { };
>>
>
> The parser interprets the compressed C++11 template parameter syntax
> as a call to a CUDA kernel function. Is there a way to disable parsing
> of the CUDA call syntax <<< >>>? I would be using a C++ wrapper around
> cudaConfigureCall, cudaSetupArgument and cudaLaunch anyway.
>
>
> Besides, this is very impressive. C++11 on GPUs appears to be near :-).
>
> Peter
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120613/321cddb1/attachment.html>


More information about the cfe-dev mailing list