xref: /aosp_15_r20/external/eigen/doc/UsingNVCC.dox (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li
2*bf2c3715SXin Linamespace Eigen {
3*bf2c3715SXin Li
4*bf2c3715SXin Li/** \page TopicCUDA Using Eigen in CUDA kernels
5*bf2c3715SXin Li
6*bf2c3715SXin LiStaring from CUDA 5.5 and Eigen 3.3, it is possible to use Eigen's matrices, vectors, and arrays for fixed size within CUDA kernels. This is especially useful when working on numerous but small problems. By default, when Eigen's headers are included within a .cu file compiled by nvcc most Eigen's functions and methods are prefixed by the \c __device__ \c __host__ keywords making them callable from both host and device code.
7*bf2c3715SXin LiThis support can be disabled by defining \c EIGEN_NO_CUDA before including any Eigen's header.
8*bf2c3715SXin LiThis might be useful to disable some warnings when a .cu file makes use of Eigen on the host side only.
9*bf2c3715SXin LiHowever, in both cases, host's SIMD vectorization has to be disabled in .cu files.
10*bf2c3715SXin LiIt is thus \b strongly \b recommended to properly move all costly host computation from your .cu files to regular .cpp files.
11*bf2c3715SXin Li
12*bf2c3715SXin LiKnown issues:
13*bf2c3715SXin Li
14*bf2c3715SXin Li - \c nvcc with MS Visual Studio does not work (patch welcome)
15*bf2c3715SXin Li
16*bf2c3715SXin Li - \c nvcc 5.5 with gcc-4.7 (or greater) has issues with the standard \c \<limits\> header file. To workaround this, you can add the following before including any other files:
17*bf2c3715SXin Li   \code
18*bf2c3715SXin Li    // workaround issue between gcc >= 4.7 and cuda 5.5
19*bf2c3715SXin Li    #if (defined __GNUC__) && (__GNUC__>4 || __GNUC_MINOR__>=7)
20*bf2c3715SXin Li      #undef _GLIBCXX_ATOMIC_BUILTINS
21*bf2c3715SXin Li      #undef _GLIBCXX_USE_INT128
22*bf2c3715SXin Li    #endif
23*bf2c3715SXin Li   \endcode
24*bf2c3715SXin Li
25*bf2c3715SXin Li - On 64bits system Eigen uses \c long \c int as the default type for indexes and sizes. On CUDA device, it would make sense to default to 32 bits \c int.
26*bf2c3715SXin Li   However, to keep host and CUDA code compatible, this cannot be done automatically by %Eigen, and the user is thus required to define \c EIGEN_DEFAULT_DENSE_INDEX_TYPE to \c int throughout his code (or only for CUDA code if there is no interaction between host and CUDA code through %Eigen's object).
27*bf2c3715SXin Li
28*bf2c3715SXin Li*/
29*bf2c3715SXin Li
30*bf2c3715SXin Li}
31