社区
CUDA
帖子详情
怎么解决这个错error C2065:'blockIdx':undeclared identifier
hhsherrill
2009-10-26 02:38:02
我之前用MFC做了一个程序,现在想把其中一部分计算放到GPU上去做,我把cuda函数和kernel函数放在一个cu文件中,cuda函数调用kernel函数,然后工程中某个类的成员函数调用这个cuda函数,但是编译时一直有这个错error C2065:'blockIdx':undeclared identifier
网上各种配置版本我都试过了,这个错一直都在,跪求解决方法,已经困扰我很久了
...全文
905
16
打赏
收藏
怎么解决这个错error C2065:'blockIdx':undeclared identifier
我之前用MFC做了一个程序,现在想把其中一部分计算放到GPU上去做,我把cuda函数和kernel函数放在一个cu文件中,cuda函数调用kernel函数,然后工程中某个类的成员函数调用这个cuda函数,但是编译时一直有这个错error C2065:'blockIdx':undeclared identifier 网上各种配置版本我都试过了,这个错一直都在,跪求解决方法,已经困扰我很久了
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
16 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
Double_Lan_2975
2012-08-20
打赏
举报
回复
路径没配置对哦
fengye553
2012-02-20
打赏
举报
回复
1.确认编译器
2..cu不能在.cpp中包含
wanggangkahn
2010-04-26
打赏
举报
回复
有谁能说一下这个问题是怎么解决的吗?非常感谢~~~
hhsherrill
2009-11-16
打赏
举报
回复
[Quote=引用 9 楼 l7331014 的回复:]
还有编译器要用nvcc.
[/Quote]
我是把主机端代码和设备端代码写在一个.cu文件中的,我感觉是没用nvcc编译,难道一定要分开写吗
该设置我都设置了,为什么不是用nvcc编译的呢
hhsherrill
2009-11-11
打赏
举报
回复
已经加了这三个了:
cuda.h
cutil.h
cuda_runtime.h
无心人_过过小日子
2009-11-11
打赏
举报
回复
.cu中cuda的头文件include了吗?
hhsherrill
2009-11-11
打赏
举报
回复
[Quote=引用 9 楼 l7331014 的回复:]
还有编译器要用nvcc.
[/Quote]
是kernel函数要在一个独立的.cu文件中吗?我把kernel函数和调用它的那个函数放在一个.cu文件中了,这样不行吗?
编译器用nvcc怎么设置,是不是就是命令行那块?
无心人_过过小日子
2009-11-02
打赏
举报
回复
还有编译器要用nvcc.
无心人_过过小日子
2009-11-02
打赏
举报
回复
[Quote=引用 6 楼 hhsherrill 的回复:]
我讲错了不是在编译时 是在生成时
代码有点长
__global__ static void rayKernel(BYTE *datad,RGBA *colord,RGB *imgd,Vector raydir,int cy,Vector screen_ld,Vector X,Vector Y,double step,int line,int point,int sample,int byte)
{
int i=blockIdx.x*blockDim.x+threadIdx.x;
int j=blockIdx.y*blockDim.y+threadIdx.y;
int offset=i*cy+j;
(*(imgd+offset)).red=0;
(*(imgd+offset)).green=0;
(*(imgd+offset)).blue=0;
float opacity=0.0f;
//中间计算过程就省略了
(*(imgd+offset)).red=r;
(*(imgd+offset)).green=g;
(*(imgd+offset)).blue=b;
}
extern "C" void
rayCUDA(int line,int point,int sample,int byte,BYTE *data,RGB *img,RGBA color[],Vector raydir,int cx,int cy,Vector X,Vector Y,double step)
{
int nGPU = 0;
if (!InitCUDA(&nGPU))
{
return ;
}
BYTE *datad;
RGBA *colord;
RGB *imgd;
double lengthScreen;
lengthScreen=sqrt(double(line*line+point*point+sample*sample));
double dist=lengthScreen;
Vector datacenter;
datacenter.x=(line-1)/2;
datacenter.y=(point-1)/2;
datacenter.z=(sample-1)/2;
Vector screencenter;
screencenter=VecAdd(datacenter,VecMult(dist,raydir));
Vector screen_ld;
screen_ld=VecSub(screencenter,VecAdd(VecMult(cx/2,X),VecMult(cy/2,Y)));
int sized=line*point*sample*byte;
int sizei=cx*cy*sizeof(RGB);
cudaMalloc(&datad,sized);
cudaMemcpy(datad,data,sized,cudaMemcpyHostToDevice);
cudaMalloc(&colord,256*sizeof(RGBA));
cudaMemcpy(colord,(RGBA*)color,256*sizeof(RGBA),cudaMemcpyHostToDevice);
cudaMalloc(&imgd,sizei);
dim3 dimBlock(16,16);
dim3 dimGrid((cx+15)/16,(cy+15)/16);
rayKernel < < <dimGrid,dimBlock>>>(datad,colord,imgd,raydir,cy,screen_ld,X,Y,step,line,point,sample,byte);
cudaMemcpy(img,imgd,sizei,cudaMemcpyDeviceToHost);
cudaFree(datad);
cudaFree(colord);
cudaFree(imgd);
}
类成员函数就只是调用了一下这个rayCUDA函数
我才接触CUDA 不知道是不是这样写的
[/Quote]
要在一个独立的.cu文件中.
lood339
2009-11-02
打赏
举报
回复
你是否在.c 或.cpp中用了#include " xxx.cu"
这样是不对的,会把.cu中的代码包含在cpp中,然后用cpp的编译器编译.cu文件,这样就出现了语法错误
hhsherrill
2009-10-26
打赏
举报
回复
我讲错了不是在编译时 是在生成时
代码有点长
__global__ static void rayKernel(BYTE *datad,RGBA *colord,RGB *imgd,Vector raydir,int cy,Vector screen_ld,Vector X,Vector Y,double step,int line,int point,int sample,int byte)
{
int i=blockIdx.x*blockDim.x+threadIdx.x;
int j=blockIdx.y*blockDim.y+threadIdx.y;
int offset=i*cy+j;
(*(imgd+offset)).red=0;
(*(imgd+offset)).green=0;
(*(imgd+offset)).blue=0;
float opacity=0.0f;
//中间计算过程就省略了
(*(imgd+offset)).red=r;
(*(imgd+offset)).green=g;
(*(imgd+offset)).blue=b;
}
extern "C" void
rayCUDA(int line,int point,int sample,int byte,BYTE *data,RGB *img,RGBA color[],Vector raydir,int cx,int cy,Vector X,Vector Y,double step)
{
int nGPU = 0;
if (!InitCUDA(&nGPU))
{
return ;
}
BYTE *datad;
RGBA *colord;
RGB *imgd;
double lengthScreen;
lengthScreen=sqrt(double(line*line+point*point+sample*sample));
double dist=lengthScreen;
Vector datacenter;
datacenter.x=(line-1)/2;
datacenter.y=(point-1)/2;
datacenter.z=(sample-1)/2;
Vector screencenter;
screencenter=VecAdd(datacenter,VecMult(dist,raydir));
Vector screen_ld;
screen_ld=VecSub(screencenter,VecAdd(VecMult(cx/2,X),VecMult(cy/2,Y)));
int sized=line*point*sample*byte;
int sizei=cx*cy*sizeof(RGB);
cudaMalloc(&datad,sized);
cudaMemcpy(datad,data,sized,cudaMemcpyHostToDevice);
cudaMalloc(&colord,256*sizeof(RGBA));
cudaMemcpy(colord,(RGBA*)color,256*sizeof(RGBA),cudaMemcpyHostToDevice);
cudaMalloc(&imgd,sizei);
dim3 dimBlock(16,16);
dim3 dimGrid((cx+15)/16,(cy+15)/16);
rayKernel<<<dimGrid,dimBlock>>>(datad,colord,imgd,raydir,cy,screen_ld,X,Y,step,line,point,sample,byte);
cudaMemcpy(img,imgd,sizei,cudaMemcpyDeviceToHost);
cudaFree(datad);
cudaFree(colord);
cudaFree(imgd);
}
类成员函数就只是调用了一下这个rayCUDA函数
我才接触CUDA 不知道是不是这样写的
tossense
2009-10-26
打赏
举报
回复
贴代码?
hhsherrill
2009-10-26
打赏
举报
回复
我觉得正确了啊
C:\CUDA\include
C:Documents and Settings\....\SDK\..\common\inc
tossense
2009-10-26
打赏
举报
回复
include 路径确定设置正确了?
hhsherrill
2009-10-26
打赏
举报
回复
[Quote=引用 1 楼 tossense 的回复:]
我个人猜测是cu文件的编译规则调用了c++的,没用cuda build rule
在工程,右键里选择custom build rules,然后导入cuda.rules文件,为cu文件添加规则
cuda.rules在sdk目录\C\common文件夹下
[/Quote]
这个也加了
tossense
2009-10-26
打赏
举报
回复
我个人猜测是cu文件的编译规则调用了c++的,没用cuda build rule
在工程,右键里选择custom build rules,然后导入cuda.rules文件,为cu文件添加规则
cuda.rules在sdk目录\C\common文件夹下
CUDAThreadIndexing
#CUDA 线程索引这是关于在 CUDA C GPU 并行计算中确定线程索引的快速参考。 该存储库将经常更新,以包括与 GPU 的网格和块中出现的不同维度相关的不同形式的线程索引的注释、信息和视觉表示。 ``` int index = ...
跟我一起来学cuda---
解决
error
C2065
: “
block
Idx
”: 未声明的标识符
error
C2065
: “
block
Idx
”: 未声明的标识符???如何
解决
。
CMakeLists.txt 中
解决
error
:
identifier
“__ldg“ is undefined
CMakeLists.txt 中
解决
error
:
identifier
"__ldg" is undefined
cuda出现“
error
:未识别的
block
Idx
”
解决
方案
一、确认编译器规则是否为NVcc,检查方法:在
解决
方案下面找到该文件,然后右击选择属性--常规--右面窗口的“项类型”为CUDA C/C++才可以。 二、如果编译器规则正确,检查文件头文件中是否包含:"device_launch_...
c语言 2059 语法
错
误,关于CUDA C 项目中“
error
C2059: 语法
错
误:“<” ”问题的
解决
方法...
该问题的关键在于理解CUDA项目中C\C++文件需要由c++编译器进行编译,而CUDAC的源文件需要由CUDA的编译器nvcc.exe进行编译。发生该语法
错
误的原因是cu文件被C++编译器所编译,C++编译器无法识别“<<为什么cu...
CUDA
581
社区成员
2,919
社区内容
发帖
与我相关
我的任务
CUDA
CUDA™是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。 它包含了CUDA指令集架构(ISA)以及GPU内部的并行计算引擎。
复制链接
扫一扫
分享
社区描述
CUDA™是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。 它包含了CUDA指令集架构(ISA)以及GPU内部的并行计算引擎。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章