Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problems with Qt/OpenGL linked with CUDA library

Problems with Qt/OpenGL linked with CUDA library

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 3 Posters 1.9k 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.
  • M Offline
    M Offline
    MorganeJ
    wrote on last edited by
    #1

    Hi,

    I have a project where I have to create a library in CUDA and link it into my Qt/OpenGL application.
    Basically, I'm

    • loading in Qt/OpenGL an image
    • give it to the library (in a way, right now I'm giving the textureId() of my QOpenGLWidget)
    • apply a sobel filter in my CUDA code
    • return the result (in a way, I do not know what and how to link it in OpenGL)
    • display it in Qt/OpenGL

    A lot of my Qt/OpenGL code is based on the cube example: http://qt-project.org/doc/qt-4.8/opengl-cube.html
    I am getting a lot of problems when I'm trying to link it.

    How am I supposed to link the result in Qt/OpenGL ?

    I'm getting a freezed windows or the original image (when I remove the "Unmap function from my CUDA code") but I never got my image with the sobel filter on it.

    Thank you for your help,

    Morgane

    Note: I'm not familiar at all with CUDA and OpenGL so sorry if it is silly questions....

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

      Hi,

      Can you share the code you are using ? Also which version of Qt/CUDA/OpenGL are you using ?

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

        Hi,

        I'm using Qt 5.4.0, OpenGL ES 2.0 and CUDA 6.5.
        Which part do you want exactly ? I have a lot of different version as I am having some problems with it but all my Qt/OpenGL code is the same than the Cube example (just using a square instead of a cube, it's the only modification I have done).

        At the moment, I'm trying to get a pointer of the CUDA result but I have no idea how to use it in my Qt/OpenGL code and if it is the good way of doing it.

        Here the part where I am calling the CUDA library:
        @ unsigned char * resultPointer = CUDA_library_processing(m_texture->textureId(), width, height);
        @
        where m_texture is my QOpenGLTexture.

        Here the CUDA part:
        @

        unsigned char* CUDA_library_processing(int opengl_buffer, int width, int height)
        {
        struct cudaGraphicsResource * cuda_vbo_resource = 0;
        cudaGraphicsGLRegisterBuffer(&cuda_vbo_resource, opengl_buffer, cudaGraphicsRegisterFlagsNone);

        cudaGraphicsMapResources(1, &cuda_vbo_resource, 0);

        size_t num_bytes = 0;
        unsigned char * dev_pointer = 0;
        cudaGraphicsResourceGetMappedPointer((void**)dev_pointer, &num_bytes, cuda_vbo_resource);

        unsigned char * result_pointer = 0;
        cudaMalloc((void **) &result_pointer, (num_bytes));

        unsigned char * respointer = (unsigned char *) malloc(num_bytes);

        sobelfilter(width, height, dev_pointer, result_pointer);

        cudaDeviceSynchronize();

        cudaMemcpy((void**)respointer, (void**)result_pointer, num_bytes, cudaMemcpyDeviceToHost);

        cudaGraphicsUnmapResources(1, &cuda_vbo_resource, 0));

        cudaFree(result_pointer);

        return respointer;
        }@

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

          Is it a typo or are you missing a & before dev_point in cudaGraphicsResourceGetMappedPointer ?

          You seem to be also mis-typecasting respointer and result_pointer in cudaMemcpy

          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
          • A Offline
            A Offline
            agocs
            wrote on last edited by
            #5

            The CUDA section in the article http://blog.qt.io/blog/2015/03/03/qt-weekly-28-qt-and-cuda-on-the-jetson-tk1/ may give an idea how this could be achieved.

            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