CUDA C++ Linking error undefined reference threadIdx.x -
hello trying parallelize lattice boltzmann solver on cuda. somehow getting error while linking object files together. objects compiles without error.
lbmsolver.o: in function >
lbmsolver::calcmoments_gpu(lbmuniformgrid2d::lbmgridnode**, int)': tmpxft_00004b33_00000000-3_lbmsolver.cudafe1.cpp:(.text+0x939): undefined >reference to
blockdim' tmpxft_00004b33_00000000-3_lbmsolver.cudafe1.cpp:(.text+0x93f): undefined >referenceblockidx' tmpxft_00004b33_00000000-3_lbmsolver.cudafe1.cpp:(.text+0x948): undefined >reference to
threadidx' tmpxft_00004b33_00000000-3_lbmsolver.cudafe1.cpp:(.text+0x953): undefined >referenceblockdim' tmpxft_00004b33_00000000-3_lbmsolver.cudafe1.cpp:(.text+0x959): undefined >reference to
blockidx' tmpxft_00004b33_00000000-3_lbmsolver.cudafe1.cpp:(.text+0x962): undefined >reference `threadidx'
here makefile:
objs = main.o lbmsolver.o lbmuniformgrid2d.o lbmboundaryconditions.o writevtk.o cc = g++ nvcc = nvcc cflags = -wall -c lflags = -wall xcompiler = -xcompiler "-wall" nvcflags = -c -g -g -ccbin=$(cc) $(xcompiler) nvlflags = -g -g -ccbin=$(cc) $(xcompiler) main : $(objs) $(nvcc) $(nvlflags) $(objs) -o main main.o : main.cu lbmsolver.h writevtk.h $(nvcc) $(nvcflags) main.cu lbmsolver.o : lbmsolver.cu lbmsolver.h lbmuniformgrid2d.h lbmboundaryconditions.h $(nvcc) $(nvcflags) lbmsolver.cu lbmboundaryconditions.o : lbmboundaryconditions.cu lbmboundaryconditions.h lbmsolver.h $(nvcc) $(nvcflags) lbmboundaryconditions.cu lbmuniformgrid2d.o : lbmuniformgrid2d.cpp lbmuniformgrid2d.h $(cc) $(cflags) lbmuniformgrid2d.cpp writevtk.o : writevtk.h writevtk.cpp $(cc) $(cflags) writevtk.cpp clean_obj: \rm *.o main
function , headerfile gives error:
#pragma once #include "lbmuniformgrid2d.h" #include <cuda.h> #ifdef __cudacc__ #define cuda_hostdev __host__ __device__ #else #define cuda_hostdev #endif class lbmsolver{ ... cuda_hostdev void calcmoments_gpu(lbmuniformgrid2d::lbmgridnode **field, int nx); __host__ __device__ void lbmsolver::calcmoments_gpu(lbmuniformgrid2d::lbmgridnode **field, int nx){ int x = blockdim.x * blockidx.x + threadidx.x; int y = blockdim.y * blockidx.y + threadidx.y; lbmuniformgrid2d::lbmgridnode *node; node = field[x+y*nx]; calc_rho_gpu(node); calc_ux_gpu(node); calc_uy_gpu(node); calc_v_gpu(node); }
you cannot define function containing device code __host__
, because device specific features not supported in host code. remove , things compile correctly.
Comments
Post a Comment