608
社区成员




如何解决?求大佬评论!
由于之前的版本(OpenCL 1.2)内核语言不支持全局变量,只支持全局常量(__constant,需要定义时就初始化)。如果为了支持OpenCL 1.2我想到一个办法就是,在需要调用到全局变量的地方,都把全局变量的指针带上,一直从HOST带到具体的Kernel函数中,过程中想读就读、想写就写。 只是写法比较繁琐,但是确实能解决此问题。
发现我电脑上的Intel核心显卡有此编译错误,而NVIDIA显卡没有此问题;两个支持的OpenCL版本不同。
进一步查看1.2/2.0和3.0的文档中关于__constant的表述,发现有差异。可以概括为,在3.0中支持在程序范围内(全部作用域变量)声明__global变量,而之前的版本对于程序生命周期范围内的变量,只支持__constant。
Variables in the program scope must be declared in the constant address space. Variables in the outermost scope of kernel functions can be declared in the constant address space. These variables are required to be initialized and the values used to initialize these variables must be a compile time constant. Writing to such a variable results in a compile-time error.
Implementations are not required to aggregate these declarations into the fewest number of constant arguments. This behavior is implementation defined.
程序作用域中的变量必须在常量地址空间中声明。内核函数最外层作用域中的变量可以在常量地址空间中声明。这些变量需要初始化,用于初始化这些变量的值必须是编译时常数。写入这样的变量会导致编译时错误。
实现不需要将这些声明聚合到最少数量的常量参数中。这种行为是由实现定义的。