What are the real C++ language constructs supported by CUDA device code?

前端 未结 2 1723
伪装坚强ぢ
伪装坚强ぢ 2020-12-16 02:08

Appendix D of the 3.2 version of the CUDA documentation refers to C++ support in CUDA device code.
It is clearly mentioned that CUDA supports \"Classes for devices of co

相关标签:
2条回答
  • 2020-12-16 02:50

    Oficially, CUDA has no support for classes on devices prior to 2.0.

    Practically, from my experience, you can use all C++ features on all devices as long as the functionality can be resolved at compile-time. Devices prior to 2.0 do not support function calls (all functions are inlined) and no program jumps to a variable address (only jumps at constant address).

    This means, you can use the following C++ constructs:

    • Visibility (public/protected/private)
    • non-virtual inheritance
    • whole template programming and metaprogramming (until you stuble on nvcc bugs; there are quite a few of them as of version 3.2)
    • constructors (except when object is declared in __ shared __ memory)
    • namespaces

    You cannot use the following:

    • new & delete operators (I believe devices >=2.0 can do that)
    • virtual methods (requires jumps at variable address)
    • function recursion (requires function calls)
    • exceptions

    Actually, all examples in chapter D.6 of the CUDA Programming Guide can compile for devices <2.0

    0 讨论(0)
  • 2020-12-16 02:59

    Some C++ class functionality will work, however the Programming Guide is basically saying that it's not fully supported and therefore not all C++ class functionality will work. If you can do what you're looking to do then you should go ahead!

    0 讨论(0)
提交回复
热议问题