Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Add Cuda libs to QT
Forum Updated to NodeBB v4.3 + New Features

Add Cuda libs to QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 2.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • kkingstounK Offline
    kkingstounK Offline
    kkingstoun
    wrote on last edited by kkingstoun
    #1

    Hello,

    I found in web many examples how to link NVIDIA CUDA to QtProject (Mingw or MSVC 64 bit), but none work correctly for me. Maybe someone know how to do this?

    Kking

    My last: .pro file looks like that:

    QT       += core
    QT       -= gui
    
    TARGET = QtCuda
    CONFIG   += console
    CONFIG   -= app_bundle
    
    TEMPLATE = app
    
    SOURCES += main.cpp \
               cuda_code.cu
    
    # project build directories
    DESTDIR     = $$PWD
    OBJECTS_DIR = $$DESTDIR/obj
    
    # C++ flags
    QMAKE_CXXFLAGS_RELEASE =-O3
    
    # Cuda sources
    CUDA_SOURCES += cuda_code.cu
    
    # Path to cuda toolkit installb C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\lib\x64
    CUDA_DIR      = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5"
    
    # Path to header and libs files
    INCLUDEPATH  += $$CUDA_DIR/include
    QMAKE_LIBDIR += $$CUDA_DIR/lib/x64
    
    SYSTEM_TYPE = 64            # '32' or '64', depending on your system
    
    # libs used in your code
    LIBS += -lcuda -lcudart
    
    # GPU architecture
    CUDA_ARCH     = sm_50
    
    # Here are some NVCC flags I've always used by default.
    NVCCFLAGS     = --use_fast_math
    
    
    # Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
    CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
    
    
    # MSVCRT link option (static or dynamic, it must be the same with your Qt SDK link option)
    MSVCRT_LINK_FLAG_DEBUG = "/MDd"
    MSVCRT_LINK_FLAG_RELEASE = "/MD"
    
    
    # Tell Qt that we want add more stuff to the Makefile
    QMAKE_EXTRA_COMPILERS += cuda
    
    # Configuration of the Cuda compiler
    CONFIG(debug, debug|release) {
        # Debug mode
        cuda_d.input = CUDA_SOURCES
        cuda_d.output = $$OBJECTS_DIR/${QMAKE_FILE_BASE}.obj
        cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$LIBS --machine $$SYSTEM_TYPE \
                         -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME} -Xcompiler $$MSVCRT_LINK_FLAG_DEBUG
        cuda_d.dependency_type = TYPE_C
        QMAKE_EXTRA_COMPILERS += cuda_d
    }
    else {
        # Release mode
        cuda.input = CUDA_SOURCES
        cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}.obj
        cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS --machine $$SYSTEM_TYPE \
                        -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME} -Xcompiler $$MSVCRT_LINK_FLAG_RELEASE
        cuda.dependency_type = TYPE_C
        QMAKE_EXTRA_COMPILERS += cuda
    }
    
    And errors: 
    [Image](https://snag.gy/MdxNzs.jpg)
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      IIRC, the cuda-z project has working implementation of Cuda + Qt. You should find there some inspiration.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved