compilation - Compiling and Linking pure C and CUDA code [warning: implicit declaration of function] -


i trying compile , link .c , .cu files , getting warning

 warning: implicit declaration of function 

i have function in .cu file need call .c file. .c file compiled using gcc , .cu file compiled using nvcc compiler. since header file .cu file contains built in cuda data types cannot include in .c file. still able compile , link files want rid of warning not able to. basic structure of code is:

gpu.cu     void fooinsidecuda();  cpu.c     fooinsidecuda(); //calling function in gpu.cu 

any or suggestion appreciated.

this link: https://devtalk.nvidia.com/default/topic/388072/calling-cuda-functions-from-a-c-file/

answers question:,. basically:

in .c file

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <cuda.h>  extern void kernel_wrapper(int *a, int *b);  int main(int argc, char *argv[]) {     int = 2;     int b = 3;      kernel_wrapper(&a, &b);     return 0; } 

and in .cu file;

__global__ void kernel(int *a, int *b) {     int tx = threadidx.x;      switch( tx )     {     case 0:      *a = *a + 10;      break;     case 1:      *b = *b + 3;      break;     default:      break;     }  }  void kernel_wrapper(int *a, int *b) {     int *d_1, *d_2;      dim3 threads( 2, 1 );     dim3 blocks( 1, 1 );      cudamalloc( (void **)&d_1, sizeof(int) );     cudamalloc( (void **)&d_2, sizeof(int) );      cudamemcpy( d_1, a, sizeof(int), cudamemcpyhosttodevice );     cudamemcpy( d_2, b, sizeof(int), cudamemcpyhosttodevice );      kernel<<< blocks, threads >>>( a, b );      cudamemcpy( a, d_1, sizeof(int), cudamemcpydevicetohost );     cudamemcpy( b, d_2, sizeof(int), cudamemcpydevicetohost );      cudafree(d_1);     cudafree(d_2); } 

then .h file similar this:

#ifndef __b__ #define __b__  #include "cuda.h" #include "cuda_runtime.h"  extern "c" void kernel_wrapper(int *a, int *b); #endif 

also note .cu compiler uses c++ conventions

so need following in .cu file:

extern "c" void a(void) {     ....... } 

so 'c' conventions used


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -