I'm starting a new project which involves CUDA, and I would like to use Glade (v3) for the GUI.
I'm trying to implement a Glade project in a basic CUDA template project, and here is my code so far:
#include <iostream>
#include <numeric>
#include <stdlib.h>
#include <gtk/gtk.h>
static void CheckCudaErrorAux (const char *, unsigned, const char *, cudaError_t);
#define CUDA_CHECK_RETURN(value) CheckCudaErrorAux(__FILE__,__LINE__, #value, value)
/**
* CUDA kernel that computes reciprocal values for a given vector
*/
__global__ void reciprocalKernel(float *data, unsigned vectorSize) {
unsigned idx = blockIdx.x*blockDim.x+threadIdx.x;
if (idx < vectorSize)
data[idx] = 1.0/data[idx];
}
/**
* Host function that copies the data and launches the work on GPU
*/
float *gpuReciprocal(float *data, unsigned size)
{
float *rc = new float[size];
float *gpuData;
CUDA_CHECK_RETURN(cudaMalloc((void **)&gpuData, sizeof(float)*size));
CUDA_CHECK_RETURN(cudaMemcpy(gpuData, data, sizeof(float)*size, cudaMemcpyHostToDevice));
static const int BLOCK_SIZE = 256;
const int blockCount = (size+BLOCK_SIZE-1)/BLOCK_SIZE;
reciprocalKernel<<<blockCount, BLOCK_SIZE>>> (gpuData, size);
CUDA_CHECK_RETURN(cudaMemcpy(rc, gpuData, sizeof(float)*size, cudaMemcpyDeviceToHost));
CUDA_CHECK_RETURN(cudaFree(gpuData));
return rc;
}
float *cpuReciprocal(float *data, unsigned size)
{
float *rc = new float[size];
for (unsigned cnt = 0; cnt < size; ++cnt) rc[cnt] = 1.0/data[cnt];
return rc;
}
void initialize(float *data, unsigned size)
{
for (unsigned i = 0; i < size; ++i)
data[i] = .5*(i+1);
}
int main(int argc, char *argv[])
{
static const int WORK_SIZE = 65530;
float *data = new float[WORK_SIZE];
initialize (data, WORK_SIZE);
GtkBuilder *builder;
GtkWidget *window;
gtk_init(&argc, &argv);
builder = gtk_builder_new();
gtk_builder_add_from_file (builder, "GladeTest01.glade", NULL);
window = GTK_WIDGET(gtk_builder_get_object(builder, "applicationwindow1"));
gtk_builder_connect_signals(builder, NULL);
g_object_unref(builder);
gtk_widget_show(window);
gtk_main();
/*
float *recCpu = cpuReciprocal(data, WORK_SIZE);
float *recGpu = gpuReciprocal(data, WORK_SIZE);
float cpuSum = std::accumulate (recCpu, recCpu+WORK_SIZE, 0.0);
float gpuSum = std::accumulate (recGpu, recGpu+WORK_SIZE, 0.0);
/* Verify the results *//*
std::cout<<"gpuSum = "<<gpuSum<< " cpuSum = " <<cpuSum<<std::endl;
/* Free memory *//*
delete[] data;
delete[] recCpu;
delete[] recGpu;
*/
return 0;
}
// called when window is closed
void on_QuitApp()
{
gtk_main_quit();
}
At compilation, I'm unable to understand why I got these errors :
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:72: undefined reference to `gtk_init'
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:74: undefined reference to `gtk_builder_new'
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:75: undefined reference to `gtk_builder_add_from_file'
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:77: undefined reference to `gtk_widget_get_type'
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:77: undefined reference to `gtk_builder_get_object'
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:77: undefined reference to `g_type_check_instance_cast'
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:78: undefined reference to `gtk_builder_connect_signals'
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:80: undefined reference to `g_object_unref'
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:82: undefined reference to `gtk_widget_show'
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:83: undefined reference to `gtk_main'
./src/GladeTest.o: In function `on_QuitApp()':
/home/fabio/AppTests/GladeTest01/Debug/../src/GladeTest.cu:105: undefined reference to `gtk_main_quit'
collect2: error: ld returned 1 exit status
make: *** [GladeTest] Error 1
As everything seems to be defined in gtk.h and all the other includes in it... What am I missing here ?
Is somebody able to give me some directions or to tell me what I am doing wrong?
Edit : Here is the compilation commands used :
Invoking: NVCC Compiler
/usr/local/cuda-7.5/bin/nvcc -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/glib-2.0 -G -g -O3 -gencode arch=compute_52,code=sm_52 -m64 -odir "src" -M -o "src/GladeTest.d" "../src/GladeTest.cu"
/usr/local/cuda-7.5/bin/nvcc -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/glib-2.0 -G -g -O3 --compile --relocatable-device-code=false -gencode arch=compute_52,code=compute_52 -gencode arch=compute_52,code=sm_52 -m64 -x cu -o "src/GladeTest.o" "../src/GladeTest.cu"
Finished building: ../src/GladeTest.cu
Building target: GladeTest
Invoking: NVCC Linker
/usr/local/cuda-7.5/bin/nvcc --cudart static --relocatable-device-code=false -gencode arch=compute_52,code=compute_52 -gencode arch=compute_52,code=sm_52 -m64 -link -o "GladeTest" ./src/GladeTest.o
If I understood correctly the answers, all the -I options should be in the nvcc linker call and not in the nvcc compiler command ?
Edit 2 : Here is one of the many variants I tried. With the same results everytime :
Invoking: NVCC Compiler
/usr/local/cuda-7.5/bin/nvcc -I/usr/include/gtk-3.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0 -G -g -O3 -gencode arch=compute_52,code=sm_52 -m64 -odir "src" -M -o "src/GladeTest.d" "../src/GladeTest.cu"
/usr/local/cuda-7.5/bin/nvcc -I/usr/include/gtk-3.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0 -G -g -O3 --compile --relocatable-device-code=false -gencode arch=compute_52,code=compute_52 -gencode arch=compute_52,code=sm_52 -m64 -x cu -o "src/GladeTest.o" "../src/GladeTest.cu"
Finished building: ../src/GladeTest.cu
Building target: GladeTest
Invoking: NVCC Linker
/usr/local/cuda-7.5/bin/nvcc --cudart static -L/usr/include/gtk-3.0 -L/usr/include/glib-2.0 -L/usr/lib/x86_64-linux-gnu/glib-2.0/include -L/usr/include/pango-1.0 -L/usr/include/cairo -L/usr/include/gdk-pixbuf-2.0 -L/usr/include/atk-1.0 -lGL -lGLU -lglut --relocatable-device-code=false -gencode arch=compute_52,code=compute_52 -gencode arch=compute_52,code=sm_52 -m64 -link -o "GladeTest" ./src/GladeTest.o