^_^Hi everyone:
I want to make a project to intergrate a function like the CUDA project “MonteCarlo”.But the complier cann’t find function “addkernel”. The code I wrote in my project is:
1.test.cpp
#include <stdlib.h>
#include <stdio.h>
#include <cuda_runtime.h>
#include <cutil.h>
extern “C” void addline(float *a);
int main(int argc, const char **argv)
{
float a[10]={1,1,1,1,1,2,2,2,2,2};
addline(a);
int i;
for (i=0;i<10;i++)
{
printf("%f\t",a[i]);
}
return 1;
}
2.test.cu
#include “test_kernel.cuh”
extern “C” void addline(float *a)
{
addGPU(a);
}
3.test_kernel.cuh
#ifndef TEST_CUH
#define TEST_CUH
#include <stdlib.h>
#include <stdio.h>
#include <cutil.h>
#include <cuda_runtime.h>
static void addGPU(float *a)
{
float *device;
CUDA_SAFE_CALL(cudaMalloc((void**)&device,10*sizeof(float)));
CUDA_SAFE_CALL(cudaMemcpy(device,a,sizeof(float) *10,cudaMemcpyHostToDevice));
addkernel<<<1,10>>>(a,device);
CUDA_SAFE_CALL(cudaMemcpy(a,device,10*sizeof(float),cudaMemcpyDeviceToHost));
}
static global void addkernel(float *a,float *device)
{
device[threadIdx.x]=device[threadIdx.x]+100;
}
Hope for you help ,thank you.