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:
#include <stdio.h>
#include <cuda_runtime.h>
__global__ void cube(float * d_out, float * d_in){
int index=threadIdx.x;
float f=d_in[index];
d_out[index]=f*f*f;
}
extern "C"
int cuda_main()
{
const int ARRAY_SIZE = 96;
const int ARRAY_BYTES = ARRAY_SIZE * sizeof(float);
// generate the input array on the host
float h_in[ARRAY_SIZE];
for (int i = 0; i < ARRAY_SIZE; i++) {
h_in[i] = float(i);
}
float h_out[ARRAY_SIZE];
// declare GPU memory pointers
float * d_in;
float * d_out;
// allocate GPU memory
cudaMalloc((void**) &d_in, ARRAY_BYTES);
cudaMalloc((void**) &d_out, ARRAY_BYTES);
// transfer the array to the GPU
cudaMemcpy(d_in, h_in, ARRAY_BYTES, cudaMemcpyHostToDevice);
// launch the kernel
cube<<<1, ARRAY_SIZE>>>(d_out, d_in);
// copy back the result array to the CPU
cudaMemcpy(h_out, d_out, ARRAY_BYTES, cudaMemcpyDeviceToHost);
// print out the resulting array
for (int i =0; i < ARRAY_SIZE; i++) {
printf("%f", h_out[i]);
printf(((i % 4) != 3) ? "\t" : "\n");
}
cudaFree(d_in);
cudaFree(d_out);
return 0;
}
int main(int argc, char *argv[])
{
cuda_main();
return 0;
}
#include <stdio.h>
#include <cuda_runtime.h>
__global__ void cube(float * d_out, float * d_in){
int index=threadIdx.x;
float f=d_in[index];
d_out[index]=f*f*f;
}
extern "C"
int cuda_main()
{
const int ARRAY_SIZE = 96;
const int ARRAY_BYTES = ARRAY_SIZE * sizeof(float);
// generate the input array on the host
float h_in[ARRAY_SIZE];
for (int i = 0; i < ARRAY_SIZE; i++) {
h_in[i] = float(i);
}
float h_out[ARRAY_SIZE];
// declare GPU memory pointers
float * d_in;
float * d_out;
// allocate GPU memory
cudaMalloc((void**) &d_in, ARRAY_BYTES);
cudaMalloc((void**) &d_out, ARRAY_BYTES);
// transfer the array to the GPU
cudaMemcpy(d_in, h_in, ARRAY_BYTES, cudaMemcpyHostToDevice);
// launch the kernel
cube<<<1, ARRAY_SIZE>>>(d_out, d_in);
// copy back the result array to the CPU
cudaMemcpy(h_out, d_out, ARRAY_BYTES, cudaMemcpyDeviceToHost);
// print out the resulting array
for (int i =0; i < ARRAY_SIZE; i++) {
printf("%f", h_out[i]);
printf(((i % 4) != 3) ? "\t" : "\n");
}
cudaFree(d_in);
cudaFree(d_out);
return 0;
}
int main(int argc, char *argv[])
{
cuda_main();
return 0;
}
To copy to clipboard, switch view to plain text mode
*.pro file:
CONFIG += console
CONFIG -= qt
TEMPLATE = app
SOURCES += cuda_main.cu
SOURCES -= cuda_main.cu
CUDA_SOURCES += cuda_main.cu
# project build directories
DESTDIR = $$system(pwd)
OBJECTS_DIR = $$DESTDIR/Obj
# C++ flags
QMAKE_CXXFLAGS_RELEASE = -O3
# Path to cuda toolkit install
CUDA_DIR = /usr/local/cuda-5.5
# Path to header and libs files
INCLUDEPATH += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib64 # Note I'm using a 64 bits Operating system
# libs used in your code
LIBS += -lcudart \
-lcuda
# GPU architecture
CUDA_ARCH = sm_12 # I've a old device. Adjust with your compute capability
# Here are some NVCC flags I've always used by default.
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
# Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -O3 -arch=$$CUDA_ARCH -c $$NVCCFLAGS \
$$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} 2>&1 \
| sed -r \"s/\\(([0-9]+)\\)/:\\1/g\" 1>&2
cuda.dependency_type = TYPE_C
cuda.depend_command = $$CUDA_DIR/bin/nvcc -O3 -M $$CUDA_INC $$NVCCFLAGS ${QMAKE_FILE_NAME}
cuda.input = CUDA_SOURCES
cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o
# Tell Qt that we want add more stuff to the Makefile
QMAKE_EXTRA_COMPILERS += cuda
CONFIG += console
CONFIG -= qt
TEMPLATE = app
SOURCES += cuda_main.cu
SOURCES -= cuda_main.cu
CUDA_SOURCES += cuda_main.cu
# project build directories
DESTDIR = $$system(pwd)
OBJECTS_DIR = $$DESTDIR/Obj
# C++ flags
QMAKE_CXXFLAGS_RELEASE = -O3
# Path to cuda toolkit install
CUDA_DIR = /usr/local/cuda-5.5
# Path to header and libs files
INCLUDEPATH += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib64 # Note I'm using a 64 bits Operating system
# libs used in your code
LIBS += -lcudart \
-lcuda
# GPU architecture
CUDA_ARCH = sm_12 # I've a old device. Adjust with your compute capability
# Here are some NVCC flags I've always used by default.
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
# Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -O3 -arch=$$CUDA_ARCH -c $$NVCCFLAGS \
$$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} 2>&1 \
| sed -r \"s/\\(([0-9]+)\\)/:\\1/g\" 1>&2
cuda.dependency_type = TYPE_C
cuda.depend_command = $$CUDA_DIR/bin/nvcc -O3 -M $$CUDA_INC $$NVCCFLAGS ${QMAKE_FILE_NAME}
cuda.input = CUDA_SOURCES
cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o
# Tell Qt that we want add more stuff to the Makefile
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:
linux-vdso.so.1 => (0x00007fffb9dff000)
libcudart.so.5.5 => /usr/local/cuda-5.5/lib64/libcudart.so.5.5 (0x00007fbfd3eca000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbfd3ae3000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fbfd38de000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fbfd35de000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fbfd33c1000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fbfd31b8000)
/lib64/ld-linux-x86-64.so.2 (0x00007fbfd4119000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fbfd2ebc000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fbfd2ca6000)
linux-vdso.so.1 => (0x00007fffb9dff000)
libcudart.so.5.5 => /usr/local/cuda-5.5/lib64/libcudart.so.5.5 (0x00007fbfd3eca000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbfd3ae3000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fbfd38de000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fbfd35de000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fbfd33c1000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fbfd31b8000)
/lib64/ld-linux-x86-64.so.2 (0x00007fbfd4119000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fbfd2ebc000)
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?
Bookmarks