06-10-2018 07:31 AM
#ifndef __MY_CUDA_PARTS_H__
#define __MY_CUDA_PARTS_H__
#define MY_DEBUG 1
#if MY_DEBUG
#include "GL/CAPI_GLE.h"
#else
#endif
#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>
int my_fcn(void);
__global__ void my_cuda_fcn(int a, int b, int * c);
#endif
#include "my_cuda_parts.h"
int my_fcn(void)
{
int c;
int *dev_c;
cudaMalloc((void **)&dev_c, sizeof(int));
my_cuda_fcn << <1, 1 >> > (2, 7, dev_c);
cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
std::printf("2 + 7 = %d\n", c);
cudaFree(dev_c);
return c;
}
__global__ void my_cuda_fcn(int a, int b, int * c)
{
*c = a + b;
}
#include "my_cuda_parts.h"
and put at the top of the WinMain function:int c = my_fcn();
std::printf("What is %d\n", c);