Linking CUDA files to an existing c++ project using Cmake -




i've been trying port part of existing c++ project cuda. found this great example on how include simple cuda kernel existing header file, key separate gpu code cpu, , further on include function definitions.

i've been trying accomplish similar, yet can't seem make example work cmake tool, build tool of project. cmake looks in lines of:

include_directories($cmake_current_source_dir)  find_package(cuda quiet)  if(cuda_found)    set( codebase      basic.cpp     kernel.hpp   )    include_directories(${cuda_include_dirs})   message(status "cuda detected")   set(cuda_propagate_host_flags on)   set(cuda_separable_compilation off)   list( append cuda_nvcc_flags -gencode=arch=compute_30,code=compute_30,ccbin=g++-4.8 )   list( append cuda_nvcc_flags -gencode=arch=compute_52,code=sm_52 )    #collect cuda files   file(glob kernels *.cu)    #build static library   cuda_add_library(kernel_lib ${kernels} static)   set(libs ${kernel_lib} ${codebase})   add_library(codebase_static static ${libs})  endif() 

my basic.cpp, basic.hpp, kernel.hpp , kernel.cu file (found *.cu) following:

basic.cpp

#include "kernel.hpp" #include <stdio.h>  int main(){   gpu_hello();   return 0; } 

kernel.hpp

int gpu_hello(); 

and kernel.cu

#include <stdio.h> #include "kernel.hpp"  __global__ void mykernel(){   printf("hello mykernel\n"); }  int gpu_hello(){    mykernel<<<1,1>>>();   cudadevicesynchronize();   return 0;  } 

when try call gpu_hello() basic.cpp, emits the: undefined reference 'gpu_hello()' error.

is there trick it? need wrap gpu_hello() function 1 in basic.hpp?

thank explanation, realize beginner question, yet me understand problem more thoroughly.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -