Hello everyone!
I am trying to call several kernels from a c-File. I am actually working with other librariers which are not working properly with cu-Files, so I have to use a c-File.
c-File linkTest.c:
#include<stdio.h> #include<stdlib.h> #include</home/cs071011/cvode_single/examples/myexamples/kernelProt.h> void main() { float *hV, *dV, c = 2.0f; int i; const int N = 100000; size_t size = N * sizeof(float); myCudaMalloc(dV, size); hV = (float *) malloc(size); for(i = 0; i < N; i++) { hV[i] = 2.0f; } myCpyHost(dV, hV, size); myKernelFunc(dV, c, N); myCpyDevice(hV, dV, size); myCudaFree(dV); free(hV); } Header file kernelProt.h with function prototypes:
#include<stdio.h> void myKernelFunc(float *memGpu, float c, const int N); void myCpyHost(float *memGpu, float *memCpu, size_t size); void myCpyDevice(float *memCpu, float *memGpu, size_t size); void myCudaMalloc(float *memGpu, size_t size); void myCudaFree(float *memGpu); cu-File kernelFile.cu including the kernels:
#include<stdio.h> #include<cuda.h> void myCpyHost(float *memGpu, float *memCpu, size_t size) { cudaMemcpy(memGpu, memCpu, size, cudaMemcpyHostToDevice); } void myCpyDevice(float *memCpu, float *memGpu, size_t size) { cudaMemcpy(memCpu, memGpu, size, cudaMemcpyDeviceToHost); } void myCudaMalloc(float *memGpu, size_t size) { cudaMalloc((void **) &memGpu, size); } void myCudaFree(float *memGpu) { cudaFree(memGpu); } __global__ void myKernel(float *dx, float c, const int N) { int tid = threadIdx.x + blockDim.x * blockIdx.x; if(tid < N) { dx[tid] *= c; } } void myKernelFunc(float *memGpu, float c, const int N) { const int NUM_THREADS = 256; const int NUM_BLOCKS = (N + NUM_THREADS - 1) / NUM_THREADS; myKernel<<<NUM_BLOCKS, NUM_THREADS>>>(memGpu, c, N); } I am using a Makefile, which looks like this:
SHELL = /bin/bash prefix = /home/cs071011/cvode_single mpi = /home/cs071011/mpich2-install exec_prefix = ${prefix} includedir = ${prefix}/include includedir2 = ${mpi}/include libdir = ${exec_prefix}/lib # Additional libraries needed by the project CPP = cc -E CPPFLAGS = CC = cc CFLAGS = -g -pg -O2 LDFLAGS = LIBS = -L/home/cs071011/cuda-inst/cuda/lib /home/cs071011/cuda-inst/cuda/include/kernelFile.o -l cublas -l cudart -lm INCLUDES = -I${includedir} -I${includedir2} LIBRARIES = -lsundials_cvode -lsundials_nvecserial ${LIBS} LIBRARIES_BL = EXAMPLES = linkTest OBJECTS = ${EXAMPLES:=.o} NVECTORPATH = /home/cs071011/cvode-2.6.0/src/nvec_ser CVODEPATH = /home/cs071011/cvode-2.6.0 # ----------------------------------------------------------------------------------------- .SUFFIXES : .o .c .c.o : ${CC} ${CPPFLAGS} ${CFLAGS} ${INCLUDES} -c $< # ----------------------------------------------------------------------------------------- all: ${OBJECTS} @for i in ${EXAMPLES}; do \ echo "${CC} -o a.out $${i}.o ${CFLAGS} ${LDFLAGS} -L${libdir} ${LIBRARIES} ${LIBRARIES_BL}"; \ ${CC} -o a.out $${i}.o ${CFLAGS} ${LDFLAGS} -L${libdir} ${LIBRARIES} ${LIBRARIES_BL}; \ done clean: rm -f ${OBJECTS} rm -f ${EXAMPLES} # ----------------------------------------------------------------------------------------- I have added the path of the object (/home/cs071011/cuda-inst/cuda/include/kernelFile.o) to the LIBS thing, but there might be still a linking problem.
Shell output, when error occurs:
cs071011@simlab17ubuntu:~/cvode_single/examples/myexamples$ make
cc -o a.out linkTest.o -g -pg -O2 -L/home/cs071011/cvode_single/lib -lsundials_cvode -lsundials_nvecserial -L/home/cs071011/cuda-inst/cuda/lib /home/cs071011/cuda-inst/cuda/include/kernelFile.o -l cublas -l cudart -lm
linkTest.o: In function `main’:
/home/cs071011/cvode_single/examples/myexamples/linkTest.c:14: undefined reference to `myCudaMalloc’
/home/cs071011/cvode_single/examples/myexamples/linkTest.c:22: undefined reference to `myCpyHost’
/home/cs071011/cvode_single/examples/myexamples/linkTest.c:24: undefined reference to `myKernelFunc’
/home/cs071011/cvode_single/examples/myexamples/linkTest.c:26: undefined reference to `myCpyDevice’
/home/cs071011/cvode_single/examples/myexamples/linkTest.c:28: undefined reference to `myCudaFree’
collect2: ld gab 1 als Ende-Status zurück
make: *** [all] Fehler 1
Can somebody help me out?
Regards.
AL.