Results 1 to 5 of 5

Thread: QtCreator + CUDA-5.5

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2012
    Location
    Warsaw,Poland
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QtCreator + CUDA-5.5

    Hello everyone!

    I'm facing now the problem with integrating CUDA-5.5 with QtCreator on Ubuntu 12.04. Steps I followed:
    1. I installed CUDA-5.5 with samples, then builded them and run correctly.
    2. I added to .bashrc file:
    export PATH=$PATH:/usr/local/cuda-5.5/bin
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-5.5/lib64
    3. I made a program, which looks like follows:
    cuda_main.cu:
    Qt Code:
    1. #include <stdio.h>
    2. #include <cuda_runtime.h>
    3.  
    4. __global__ void cube(float * d_out, float * d_in){
    5. int index=threadIdx.x;
    6. float f=d_in[index];
    7. d_out[index]=f*f*f;
    8. }
    9.  
    10. extern "C"
    11. int cuda_main()
    12. {
    13. const int ARRAY_SIZE = 96;
    14. const int ARRAY_BYTES = ARRAY_SIZE * sizeof(float);
    15.  
    16. // generate the input array on the host
    17. float h_in[ARRAY_SIZE];
    18. for (int i = 0; i < ARRAY_SIZE; i++) {
    19. h_in[i] = float(i);
    20. }
    21. float h_out[ARRAY_SIZE];
    22.  
    23. // declare GPU memory pointers
    24. float * d_in;
    25. float * d_out;
    26.  
    27. // allocate GPU memory
    28. cudaMalloc((void**) &d_in, ARRAY_BYTES);
    29. cudaMalloc((void**) &d_out, ARRAY_BYTES);
    30.  
    31. // transfer the array to the GPU
    32. cudaMemcpy(d_in, h_in, ARRAY_BYTES, cudaMemcpyHostToDevice);
    33.  
    34. // launch the kernel
    35. cube<<<1, ARRAY_SIZE>>>(d_out, d_in);
    36.  
    37. // copy back the result array to the CPU
    38. cudaMemcpy(h_out, d_out, ARRAY_BYTES, cudaMemcpyDeviceToHost);
    39.  
    40. // print out the resulting array
    41. for (int i =0; i < ARRAY_SIZE; i++) {
    42. printf("%f", h_out[i]);
    43. printf(((i % 4) != 3) ? "\t" : "\n");
    44. }
    45.  
    46. cudaFree(d_in);
    47. cudaFree(d_out);
    48.  
    49. return 0;
    50. }
    51.  
    52. int main(int argc, char *argv[])
    53. {
    54. cuda_main();
    55. return 0;
    56. }
    To copy to clipboard, switch view to plain text mode 

    *.pro file:
    Qt Code:
    1. CONFIG += console
    2. CONFIG -= qt
    3. TEMPLATE = app
    4. SOURCES += cuda_main.cu
    5. SOURCES -= cuda_main.cu
    6. CUDA_SOURCES += cuda_main.cu
    7.  
    8. # project build directories
    9. DESTDIR = $$system(pwd)
    10. OBJECTS_DIR = $$DESTDIR/Obj
    11.  
    12. # C++ flags
    13. QMAKE_CXXFLAGS_RELEASE = -O3
    14.  
    15. # Path to cuda toolkit install
    16. CUDA_DIR = /usr/local/cuda-5.5
    17.  
    18. # Path to header and libs files
    19. INCLUDEPATH += $$CUDA_DIR/include
    20. QMAKE_LIBDIR += $$CUDA_DIR/lib64 # Note I'm using a 64 bits Operating system
    21.  
    22. # libs used in your code
    23. LIBS += -lcudart \
    24. -lcuda
    25.  
    26. # GPU architecture
    27. CUDA_ARCH = sm_12 # I've a old device. Adjust with your compute capability
    28.  
    29. # Here are some NVCC flags I've always used by default.
    30. NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
    31.  
    32. # Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
    33. CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
    34. cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -O3 -arch=$$CUDA_ARCH -c $$NVCCFLAGS \
    35. $$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} 2>&1 \
    36. | sed -r \"s/\\(([0-9]+)\\)/:\\1/g\" 1>&2
    37.  
    38. cuda.dependency_type = TYPE_C
    39. cuda.depend_command = $$CUDA_DIR/bin/nvcc -O3 -M $$CUDA_INC $$NVCCFLAGS ${QMAKE_FILE_NAME}
    40. cuda.input = CUDA_SOURCES
    41. cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o
    42.  
    43. # Tell Qt that we want add more stuff to the Makefile
    44. QMAKE_EXTRA_COMPILERS += cuda
    To copy to clipboard, switch view to plain text mode 

    4. Application builded correctly, but when I tried to run it from terminal i got message:
    ./CUDATry: error while loading shared libraries: libcudart.so.5.5: cannot open shared object file: No such file or directory
    That's what ldd ./CUDATry return:
    Qt Code:
    1. linux-vdso.so.1 => (0x00007fffb9dff000)
    2. libcudart.so.5.5 => /usr/local/cuda-5.5/lib64/libcudart.so.5.5 (0x00007fbfd3eca000)
    3. libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbfd3ae3000)
    4. libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fbfd38de000)
    5. libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fbfd35de000)
    6. libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fbfd33c1000)
    7. librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fbfd31b8000)
    8. /lib64/ld-linux-x86-64.so.2 (0x00007fbfd4119000)
    9. libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fbfd2ebc000)
    10. libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fbfd2ca6000)
    To copy to clipboard, switch view to plain text mode 
    So it looks like libcudart.so.5.5 was included properly... I dont know what to do, what do you think about it?

  2. #2
    Join Date
    Jul 2013
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5

    Default Re: QtCreator + CUDA-5.5

    A wild guess:
    Try this:
    export LD_LIBRARY_PATH=/usr/local/cuda-5.5/lib64
    ./CUDATry

    If that works, you may have to add the library path by creating/editing: /etc/ld.so.conf.d/cuda.conf
    And then run ldconfig once to update.

  3. #3
    Join Date
    Oct 2012
    Location
    Warsaw,Poland
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtCreator + CUDA-5.5

    I forgot to show my .bashrc file:
    Qt Code:
    1. ######################JAVA############################
    2. export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
    3. ######################################################
    4.  
    5.  
    6. ##########Zmienne Srodowiskowe CUDA###################
    7. export PATH=$PATH:/usr/local/cuda-5.5/bin
    8. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-5.5/lib64:/usr/local/cuda-5.5/lib
    9. ######################################################
    10.  
    11.  
    12. ##########Zmienne Srodowiskowe ROS####################
    13. source /opt/ros/groovy/setup.bash
    14. source ~/Programowanie/ROS/Groovy/catkin_workspace/devel/setup.bash
    15. export ROS_PACKAGE_PATH=/opt/ros/groovy/share:/opt/ros/groovy/stacks:~/Programowanie/ROS/Groovy/catkin_workspace/src
    16. export ROS_MASTER_URI=http://monster:11311
    17. ######################################################
    To copy to clipboard, switch view to plain text mode 

    It should be enought, right?

  4. #4
    Join Date
    Oct 2012
    Location
    Warsaw,Poland
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtCreator + CUDA-5.5

    Don't anybody have a single clue?

  5. #5
    Join Date
    Oct 2012
    Location
    Warsaw,Poland
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtCreator + CUDA-5.5

    Ok, problem fixed. It turns out, LD_LIBRARY_PATH in isn't the best idea. After removing it from .bashrc and adding new line in file /etc/ld.so.conf:
    Qt Code:
    1. /usr/local/cuda-5.5/lib64
    To copy to clipboard, switch view to plain text mode 
    and run:
    Qt Code:
    1. sudo ldconfig
    To copy to clipboard, switch view to plain text mode 
    everything works fine. I hope it will help someone.

Similar Threads

  1. QtConcurrent and CUDA or GPGPU
    By olidem in forum Qt Programming
    Replies: 8
    Last Post: 27th February 2013, 22:07
  2. Qt Creator Qt and CUDA VIsual Profiler
    By pQB in forum Qt Tools
    Replies: 0
    Last Post: 12th May 2011, 11:46
  3. QGLWidget + OpenGL + CUDA
    By sic(6)SaNdMaN in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 01:20
  4. NVIDIA CUDA + Qt
    By redscorp in forum Qt Programming
    Replies: 3
    Last Post: 24th October 2010, 17:35
  5. cuda gdb
    By Wu in forum Newbie
    Replies: 2
    Last Post: 8th January 2010, 11:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.