How to call a CUDA file from a C++ header file? -


i know method of calling .cu files .c files. want call .cu files c header file. possible ? if how should make settings of project ? please help.....

here's worked example:

file1.h:

int hello(); 

file2.h:

#include <stdio.h> #include "file1.h"  int myfunc(){   hello();   return 0; } 

file1.cu:

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

file2.cpp:

#include "file2.h"  int main(){   myfunc();   return 0; } 

build , test:

$ nvcc -arch=sm_20 -c file1.cu $ g++ -c file2.cpp $ g++ -o test file1.o file2.o -l/usr/local/cuda/lib64 -lcudart $ ./test hello mykernel $ 

assuming intending include file2.h cpp file, cannot call cuda kernel directly header , use in cpp file. must put wrapper around cuda kernel, , call wrapper, have indicated. because cpp file compiled host compiler, doesn't know cuda syntax (e.g. mykernel<<<1,1>>>();)

also, indicated in comments, may make more sense reserve header file file2.h needed prototypes, , put actual function definition of myfunc cpp file somewhere.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -