Important: Please read the Qt Code of Conduct -

[Solved]add CUDA

  • Hello,
    I want use CUDA in QT,
    but I don't know ,how to add CUDA lib in makefile。

    thank you

  • Add to your .pro file:

    INCLUDEPATH += /path/to/dir/with/cuda/includes
    LIBS += -L/path/to/dir/with/cuda/libs -lcudalib

    qmake does all the other magic for you.

  • thank you ,
    what's the settings for like since it requires nvcc ?

    or how to combine other .o file in Qt?

  • Sorry, I have no clue how CUDA and the libs work. What's nvcc? Another tool that must be called on some file?

  • [quote author="devroyc" date="1293824069"]thank you ,
    what's the settings for like since it requires nvcc ?

    or how to combine other .o file in Qt?[/quote]

    With some clever QMAKE_EXTRA_COMPILERS black magic. See

  • Note that there is also a labs project on OpenCL. Perhaps you could leverage that instead? It seems to me that OpenCl has more future than Cuda, due to its more open nature and brand independency.

  • Psst. Don't tell that to Nvidia ;).

    Some people may prefer coding in CUDA or may require something that (at this time) only CUDA provides. It has some nicer tools (for debugging and so on) and it also has more library support (plug-ins).

  • Two comments:

    1. Regarding using Cuda from Qt. That was a major concern of the project
      I am consulting on, and it turns out to be straightforward. The Cuda code
      that I have written is designed to be used from a Qt application. It (the Cuda
      portion) is compiled in its own project directory using nvcc where appropriate
      and .o files are created. These are packaged using ar into a lib<whatever>.a
      archive. Then, in a different directory (for what that is worth) I have my Qt
      application, which uses qmake and a <whatever>.pro file, and it adds the
      location of the lib<whatever>.a, a -l<whatever> to the library switches, and a
      reference to the location and name of the cuda run time libraries. It all seems
      to compile and run just fine.

    2. Regarding the comment on OpenCL vs Cuda. Although OpenCL may be the
      future, it may not be as well. Cuda is far more mature and is used, my guess,
      for 95% of all serious GPU development. There are good reasons why OpenCL
      might actually be a little nicer for development, but at an inherently slower speed.
      It all depends on how practical your needs are. If you need to write something
      that works today, and is more mature, and dont mind using Nvidia (and I like Nvidia),
      then Cuda is the way to go. Ultimately, in the long run, well we will have to see.
      They are very similar, but not identical, but its not too bad. If you learn one, the
      other will be straightforward.


Log in to reply