Hi everyone,
I am a new guy to CUDA,I met some problems that I cann’t solve .I want to make a probject in one function so it is convient to use.
I try to duplicate the “eigenvalues” project to realize a “+1” function.
1.main.cu
#include <stdlib.h>
#include <stdio.h>
#include <cutil.h>
#include “test.cuh”
int
main( int argc, char** argv)
{
float a[10]={1,1,1,1,1,2,2,2,2,2};
int i;
printf("before deal with CUDA:\n");
for (i=0;i<10;i++)
{
printf("%f\t",a[i]);
}
addline(a);
printf("\nafter deal with CUDA\n");
for (i=0;i<10;i++)
{
printf("%f\t",a[i]);
}
return 1;
}
2.test.cuh
void addline(float * a);
3.test.cu
#include <test_kernel.cu>
void addline(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));
}
4.test_kernel.cu
#include <stdlib.h>
#include <stdio.h>
#include <cutil.h>
#include <cuda_runtime.h>
global void addkernel(float *a,float *device)
{
device[threadIdx.y]=device[threadIdx.y]+1;
}
The information complier gives :
1>.\test_kernel.cu(9) : error C2065: ‘threadIdx’ : undeclared identifier
1>.\test_kernel.cu(9) : error C2228: left of ‘.y’ must have class/struct/union
1> type is ‘‘unknown-type’’
1>.\test_kernel.cu(9) : error C2228: left of ‘.y’ must have class/struct/union
1> type is ‘‘unknown-type’’
1>test.cu
1>test_kernel.cu(9) : error C2065: ‘threadIdx’ : undeclared identifier
1>test_kernel.cu(9) : error C2228: left of ‘.y’ must have class/struct/union
1> type is ‘‘unknown-type’’
1>test_kernel.cu(9) : error C2228: left of ‘.y’ must have class/struct/union
1> type is ‘‘unknown-type’’
1>.\test.cu(12) : error C2059: syntax error : ‘<’
Hope for someone’s help,thank you very much!!!