原由:在做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

后面就编译通过了。

Logo

欢迎来到由智源人工智能研究院发起的Triton中文社区,这里是一个汇聚了AI开发者、数据科学家、机器学习爱好者以及业界专家的活力平台。我们致力于成为业内领先的Triton技术交流与应用分享的殿堂,为推动人工智能技术的普及与深化应用贡献力量。

更多推荐