c/c++:cuda编译时 error: : identifier “xxx“ is undefined 的错误

原由:在做yolov7 tensorrt部署时,编译过程中出现“error identifier ‘kIgnoreThresh’ is undefined in device code”;

const static float kIgnoreThresh = 0.1f;

在大佬的帮助下,查找CUDA文档中常量限定变量部分说明:

Let ‘V’ denote a namespace scope variable or a class static member variable that has const qualified type and does not have execution space annotations (e.g., device, constant, shared). V is considered to be a host code variable.
The value of V may be directly used in device code, if:V has been initialized with a constant expression before the point of use, andit has one of the following types:builtin floating point type except when the Microsoft compiler is used as the host compiler,builtin integral type.
Device source code cannot contain a reference to V or take the address of V.
'kIgnoreThresh’常量可以在host上使用,但是在device的源代码不能识别。
解决方法
将常量改为宏定义

//const static float kIgnoreThresh = 0.1f;
#define kIgnoreThresh 0.1f

后面就编译通过了。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值