Can I call CUDA runtime function from C++ code not compiled by nvcc? -
is there way can call cuda runtime function calls such as
cudamemcpy(...);
in .cpp file, compiled regular c++ compiler?
edit: there example here it's not longer found, of example copied below.
the caller c (but c++)
#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; }
the callee (cuda)
__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); }
Comments
Post a Comment