原由:在做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
后面就编译通过了。