Cuda 代码#define 错误,预期出现“)”
在下面的代码中,如果我将 #define N 65536 置于 #if FSIZE 之上,则会出现以下错误:
#if FSIZE==1
__global__ void compute_sum1(float *a, float *b, float *c, int N)
{
#define N 65536
int majorIdx = blockIdx.x;
int subIdx = threadIdx.x;
int idx=majorIdx*32+subIdx ;
float sum=0;
int t=4*idx;
if(t<N)
{
c[t]= a[t]+b[t];
c[t+1]= a[t+1]+b[t+1];
c[t+2]= a[t+2]+b[t+2];
c[t+3]= a[t+3]+b[t+3];
}
return;
}
#elif FSIZE==2
__global__ void compute_sum2(float2 *a, float2 *b, float2 *c, int N)
#define N 65536
{
int majorIdx = blockIdx.x;
int subIdx = threadIdx.x;
int idx=majorIdx*32+subIdx ;
float sum=0;
int t=2*idx;
if(t<N)
{
c[t].x= a[t].x+b[t].x;
c[t].y= a[t].y+b[t].y;
c[t+1].x= a[t+1].x+b[t+1].x;
c[t+1].y= a[t+1].y+b[t+1].y;
}
return ;
}
float1vsfloat2.cu(10):错误:需要一个“)”
这个问题有点烦人,我真的很想知道为什么会发生。我有一种感觉,我忽略了一些非常愚蠢的事情。顺便说一句,此代码部分位于文件的顶部。前面甚至没有#include。 我将非常感谢任何可能的解释。
In the following code, if I bring the #define N 65536 above the #if FSIZE, then I get the following error:
#if FSIZE==1
__global__ void compute_sum1(float *a, float *b, float *c, int N)
{
#define N 65536
int majorIdx = blockIdx.x;
int subIdx = threadIdx.x;
int idx=majorIdx*32+subIdx ;
float sum=0;
int t=4*idx;
if(t<N)
{
c[t]= a[t]+b[t];
c[t+1]= a[t+1]+b[t+1];
c[t+2]= a[t+2]+b[t+2];
c[t+3]= a[t+3]+b[t+3];
}
return;
}
#elif FSIZE==2
__global__ void compute_sum2(float2 *a, float2 *b, float2 *c, int N)
#define N 65536
{
int majorIdx = blockIdx.x;
int subIdx = threadIdx.x;
int idx=majorIdx*32+subIdx ;
float sum=0;
int t=2*idx;
if(t<N)
{
c[t].x= a[t].x+b[t].x;
c[t].y= a[t].y+b[t].y;
c[t+1].x= a[t+1].x+b[t+1].x;
c[t+1].y= a[t+1].y+b[t+1].y;
}
return ;
}
float1vsfloat2.cu(10): error: expected a ")"
This problem is a little annoying and I would really really like to know why its happening. I have a feeling I'm overlooking something really silly. Btw, this code section is at the top of the file. Not even an #include before it.
I will really appreciate any possible explanations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
预处理器更改此行:
to
which is not valid CUDA code.
The preprocessor changes this line:
to
which isn't valid CUDA code.