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. Cuda + qt qml app is compiled but not running
QtWS25 Last Chance

Cuda + qt qml app is compiled but not running

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 402 Views
  • 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.
  • Y Offline
    Y Offline
    YoniSp
    wrote on last edited by YoniSp
    #1

    Hi,

    After successfully compilation of cuda+qt project by using cmake I encounter the following runtime error during the excecution of first cuda command:

    "main.cpp @ 114. Error code: 2 Error string: out of memory"

    In addition wo verify that there is no Cuda issue I created another app without QT which operates ok on the same system

    I tested the code on 2 systems with same results:

    Systems configuration:
    Fedora 32 with Cuda 11.1 gcc 10.0.1 and qt 5.12
    RockyLinux 8.5with Cuda 11.2 / cuda 11.5 gcc 8.5 and qt 5.15.2

    My cmake code is :

    Main cmake:

    
    cmake_minimum_required(VERSION 3.19)
    
     project(Project1 CXX CUDA)
     add_definitions("-DUSE_GPU=ON")
     set(CUDA_ENABLE "ON")
     message(STATUS "CUDA is on")
    
    
    option(VIEWER_EN "Enable disable flag of nltTb signal viewer application" OFF)
    
    if(VIEWER_EN)
    find_package(Qt5 COMPONENTS Core  Quick Widgets Charts REQUIRED)
    endif()
    
    
    
    include(common.cmake)
    
    message(STATUS "CMAKE_CUDA_ARCHITECTURES: ${CMAKE_CUDA_ARCHITECTURES}$")
    
    message(STATUS "Creates paths to projects")
    set(UTILS ${CMAKE_SOURCE_DIR}/utils)
    set(INFRA ${CMAKE_SOURCE_DIR}/infra)
    set(ALGORITHMS ${CMAKE_SOURCE_DIR}/algorithms)
    message( "UTILS path  ${UTILS}")
    message( "INFRA path  ${INFRA}")
    message( "ALGORITHMS path  ${ALGORITHMS}")
    
    FIND_PACKAGE(Protobuf REQUIRED)
    find_package(Threads REQUIRED)
    message(STATUS "Using protobuf ${Protobuf_VERSION}")
    
    
    INCLUDE_DIRECTORIES(
      ${CUDA_INCLUDE_DIRS}
      ${GTEST_INCLUDE_DIRS}
    
      infra/
     utils/
      pipeline_modules/pipeline
      pipeline_modules/viewer
    )
    
    ADD_SUBDIRECTORY(utils)
    ADD_SUBDIRECTORY(algorithms)
    ADD_SUBDIRECTORY(infra)
    
    
    if(VIEWER_EN)
        message("VIEWER_EN active")
    ADD_SUBDIRECTORY(apps/viewer)
    endif()
    
    

    common cmake

    
    
    message("cmake processor ${CMAKE_SYSTEM_PROCESSOR}")
    
     set(CMAKE_CUDA_STANDARD 17)
     set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
     set(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
     
    IF (DBG MATCHES "ON")
     set(CMAKE_BUILD_TYPE Debug) # Release | Debug
    ELSEIF(DBG MATCHES "OFF")
     set(CMAKE_BUILD_TYPE Release) # Release | Debug
    ENDIF (DBG MATCHES "ON")
    set(CMAKE_VERBOSE_MAKEFILE OFF)
    
    
    if (CUDA_ENABLE MATCHES "ON")
     IF (CMAKE_BUILD_TYPE MATCHES Debug)
      set(CMAKE_CUDA_FLAGS "--expt-extended-lambda")# --default-stream per-thread -G")
      if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
       message("Current platform is AARCH64")
        set(CMAKE_CUDA_ARCHITECTURES 61 72 75)
      else()
        set(CMAKE_CUDA_ARCHITECTURES 61  75)
      endif()
      message("CUDA debug")
      ELSE()
      set(CMAKE_CUDA_FLAGS "--expt-extended-lambda")# --default-stream per-thread ")
      if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
       message("Current platform is AARCH64")
       set(CMAKE_CUDA_ARCHITECTURES 61 72 75)
      else()
       set(CMAKE_CUDA_ARCHITECTURES 61  75)
      endif()
     ENDIF()
    
     IF( DEFINED STOP_ON_CUDA_ERROR)
      add_definitions("-DSTOP_ON_CUDA_ERROR")
     ENDIF ()
    
    
     find_package(CUDAToolkit REQUIRED cusparse cublas ddd)
     # Check for cuda
     message("CUDA INCLUDE: ${CUDAToolkit_INCLUDE_DIRS}")
     INCLUDE_DIRECTORIES(${CUDAToolkit_INCLUDE_DIRS})
    
     LINK_DIRECTORIES(${CUDAToolkit_LIBRARY_DIR})
    
    
    else ()
     message(STATUS "No CUDA support")
     set(CUDA_LIBS)
    endif ()
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
    
    # Retrieve information about current git branch into environment var
    find_package(Git)
    if (Git_FOUND)
     message("Git found: ${GIT_EXECUTABLE}")
    
     message(STATUS "Resolving GIT Version")
    
     # the commit's SHA1, and whether the building workspace was dirty or not
     execute_process(COMMAND
       "${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh --always #--abbrev=8
       WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
       OUTPUT_VARIABLE GIT_SHA1
       ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
    
    
     execute_process(COMMAND
       "${GIT_EXECUTABLE}" describe --tag #--abbrev=8
       WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
       OUTPUT_VARIABLE GIT_TAG
       ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
    
     # the date of the commit
     execute_process(COMMAND
       "${GIT_EXECUTABLE}" log -1 --format=%ad --date=local
       WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
       OUTPUT_VARIABLE GIT_DATE
       ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
    
     # the subject of the commit
     execute_process(COMMAND
       "${GIT_EXECUTABLE}" log -1 --format=%s
       WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
       OUTPUT_VARIABLE GIT_COMMIT_SUBJECT
       ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
    
     string(REPLACE "#"
       "" GIT_COMMIT_SUBJECT
       "${GIT_COMMIT_SUBJECT}")
     message(STATUS "GIT_COMMIT_SUBJECT=" ${GIT_COMMIT_SUBJECT})
     message(STATUS "GIT_SHA1=" ${GIT_SHA1})
     message(STATUS "GIT_DATE=" ${GIT_DATE})
     message(STATUS "GIT_TAG=" ${GIT_TAG})
    
     add_definitions("-DGIT_COMMIT_SUBJECT=aa")
     add_definitions("-DGIT_SHA1=\"${GIT_SHA1}\"")
     add_definitions("-DGIT_DATE=\"${GIT_DATE}\"")
     add_definitions("-DGIT_TAG=\"${GIT_TAG}\"")
    else ()
     message(SEND_ERROR "Could not find git package")
    endif ()
    
    
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wno-c++17-extensions ")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++17-extensions -Wall -pedantic ")
    
    set(SANITIZE "ADDRESS_LEAK")
    #set(SANITIZE  "THREADS")
    #set(SANITIZE  "LEAK")
    IF (CMAKE_BUILD_TYPE MATCHES Debug)
     IF (SANITIZE MATCHES "ADDRESS_LEAK")
      message("Sanitize address...")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -fno-omit-frame-pointer")
     ELSEIF (SANITIZE MATCHES "ADDRESS")
      message("Sanitize address...")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address  -fno-omit-frame-pointer")
     ELSEIF (SANITIZE MATCHES "THREADS")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread  -fno-omit-frame-pointer")
     ELSEIF (SANITIZE MATCHES "LEAK")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak  -fno-omit-frame-pointer")
     ENDIF ()
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    ENDIF ()
    message("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
    
    #set(BOOST_ROOT /usr/local/)
    #set(BOOST_INCLUDEDIR /usr/local/include/)
    #set(BOOST_LIBRARYDIR /usr/local/lib64/)
    #set(Boost_NO_SYSTEM_PATHS TRUE)
    
    FIND_PACKAGE(Boost 1.72.0 COMPONENTS thread system filesystem date_time timer chrono regex REQUIRED)
    INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
    LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
    # OpenCV library
    FIND_PACKAGE(OpenCV 4.1 REQUIRED)
    INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
    LINK_DIRECTORIES(${OpenCV_LIBS})
    message(STATUS "OpenCV include=" ${OpenCV_INCLUDE_DIRS})
    message(STATUS "OpenCV libs=" ${OpenCV_LIBS})
    message(STATUS "CMAKE_DL_LIBS=" ${CMAKE_DL_LIBS})
    set(Boost_USE_MULTITHREADED ON)
    set(Boost_USE_STATIC_LIBS ON)
    set(Boost_USE_STATIC_RUNTIME ON)
    
    find_package(GTest REQUIRED)
    
    find_package(Eigen3 3.3 REQUIRED NO_MODULE)
    
    

    app cmake :

    add_executable(viewer_app
      main.cpp
    )
    
    #set_target_properties(viewer_app
    #                      PROPERTIES -cudart=static)
    
     target_link_libraries(viewer_app
       
       utils_remoteConsole utils_network utils_general algs_optimization
       ${Boost_LIBRARIES} ${OpenCV_LIBS}
    
       Qt5::Charts Qt5::Quick  Qt5::Core
       ${CUDA_cufft_LIBRARY} ${CUDA_cublas_LIBRARY} ${CUDA_cusparse_LIBRARY} ${CUDA_rt_LIBRARY} ${CUDA_cudart_LIBRARY}  ${CUDA_rt_LIBRARY} ${CUDA_cudadevrt_LIBRARY}
        ${CUDA_CUDA_LIBRARY} ${CUDA_rt_LIBRARY}
        muparser z pthread)
    
    

    What I amd doing wrong and how can I fix the issue

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Without any code, it's pretty hard to be able to tell you what is going on.

      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
      • Y Offline
        Y Offline
        YoniSp
        wrote on last edited by YoniSp
        #3

        Hi the cde has error from first line as I comented below

        #include <QtWidgets/QApplication>
        #include <QtQuick/QQuickView>
        #include <QtCore/QDir>
        #include <QtQml/QQmlEngine>
        #include <QtQml/QQmlContext>
        #include <memory>
        #include "SigViewerPipe.h"
        #include "SigViewerWorker.h"
        #include "paramFile.h"
        #include "datasource.h"
        #include "FeMgm.h"
        #include "RemoteConsoleServer.h"
        #include <cuda.h>
        #include <cuda_runtime.h>
        #include<cuda_profiler_api.h>
        
        #ifndef CUDA_KERNEL_LAUNCH
        #ifndef NDEBUG
        #define CUDA_KERNEL_LAUNCH(KERNEL) (KERNEL); \
        cudaDeviceSynchronize() ;                                            \
        camero_utils::general::__checkCudaErrors ( cudaPeekAtLastError() , __FILE__, __LINE__);
        #else
        #define CUDA_KERNEL_LAUNCH(KERNEL) (KERNEL); \
        camero_utils::general::__checkCudaErrors ( cudaPeekAtLastError() , __FILE__, __LINE__);
        #endif
        #endif
        
        inline void __checkCudaErrors(cudaError err, const char *file, const int line)
        {
          if (cudaSuccess != err) {
            std::stringstream ss;
            ss << "Cuda Error in " << file << " @ " << line <<". Error code: " << err << " Error string: " << cudaGetErrorString(err);
            std::cerr << ss.str() << "\n";
        #ifndef   STOP_ON_CUDA_ERROR
            throw InternalError(ss.str());
        #else
            cudaProfilerStop();
            cudaDeviceReset();
            std::cerr<<"__checkCudaErrors::Stop on cuda error"<<std::endl;
            std::cerr<<ss.str();
            exit(2222);
        #endif
          }
        }
        
        int run(int argc, char *argv[])
        {
          // init param file
          ParamFile param(argc, argv);
          camero_utils::remote_console::RemoteConsoleServer remoteConsole(param);
          FeMgm::initFeMgm(param);
          SigViewerPipe pipe(&param, nullptr);
          // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used.
          QApplication app(argc, argv);
          
          // init viewer
          QQuickView viewer;
          
          // The following are needed to make examples run without having to install the module
          // in desktop environments.
        #ifdef Q_OS_WIN
          QString extraImportPath(QStringLiteral("%1/../../../../%2"));
        #else
          QString extraImportPath(QStringLiteral("%1/../../../%2"));
        #endif
          viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(),
                                                             QString::fromLatin1("qml")));
          QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close);
          
        
          // create data source and register it for qml
          auto dataSource = std::make_unique<DataSourceHandle>(param, &viewer);
          viewer.rootContext()->setContextProperty("dataSource", dataSource.get());
        
          pipe.getSigViewer()->setDataSource(std::move(dataSource));
          remoteConsole.addToParserMap("NltbPipe", pipe);
          
          auto &feMgm = FeMgm::getFeMgm();
          feMgm.initAllFeBoards();
          feMgm.feScanAll();
          // start pipe
          pipe.start();
          pipe.pipeRestartListen();
          remoteConsole.start();
          pipe.restartPipeAndReset();
        
          // window configuration
          viewer.setTitle(QStringLiteral("viewer"));
          viewer.setSource(QUrl("qrc:/main.qml"));
          viewer.setResizeMode(QQuickView::SizeRootObjectToView);
          viewer.show();
          
          // run qt app
          return app.exec();
          
        }
        
        int main(int argc, char **argv)
        {
        
           size_t free,total;
            checkCudaErrors( cudaDeviceReset()); //There is cuda error from this line of code
           checkCudaErrors(cudaMemGetInfo ( &free, &total ));
           std::cout<<"total free"<<total<<" "<<free<<std::endl;
          checkCudaErrors(cudaSetDevice(1));
        
        
          return run(argc, argv);
        }
        
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What if you create the QApplication object before ParamFile ?

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

          Y 1 Reply Last reply
          0
          • SGaistS SGaist

            What if you create the QApplication object before ParamFile ?

            Y Offline
            Y Offline
            YoniSp
            wrote on last edited by
            #5

            @SGaist
            I did not try that but the I get the first error from the second line from start of main function before calling to run function

            int main(int argc, char **argv)
            {
            
               size_t free,total;
                checkCudaErrors( cudaDeviceReset()); //There is cuda error from this line of code
               checkCudaErrors(cudaMemGetInfo ( &free, &total ));
               std::cout<<"total free"<<total<<" "<<free<<std::endl;
              checkCudaErrors(cudaSetDevice(1));
            
            
              return run(argc, argv);
            }
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Are you sure you do not have an issue with your card/card driver ?

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

              Y 1 Reply Last reply
              0
              • SGaistS SGaist

                Are you sure you do not have an issue with your card/card driver ?

                Y Offline
                Y Offline
                YoniSp
                wrote on last edited by
                #7

                @SGaist
                Yes
                we tested the code over 2 different computers which ran the same app whiteout gui but with cuda properly

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Which card model do you have ?
                  Version of the driver ?

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

                  Y 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Which card model do you have ?
                    Version of the driver ?

                    Y Offline
                    Y Offline
                    YoniSp
                    wrote on last edited by
                    #9

                    @SGaist
                    Hi,
                    We are using rtx2080ti with cuda 11.5 with driver version 495.29.05

                    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