为什么我收到错误消息:"限制"不允许?

ein*_*ica 1 c++ cuda compiler-errors restrict-qualifier

我正在写一个CUDA内核并想要__restrict__我的一些参数.我收到错误消息:

"restrict" is not allowed

是否允许某些变量类型?对于某些参数组合?因为有些编译器标志?因为我一直顽皮?

简化的内核签名:

template <typename T> foo(
    const T a[],
    __restrict__ SomeType b[],
    const T c
) {
    /* etc. */
}
Run Code Online (Sandbox Code Playgroud)

Rog*_*ahl 7

您只能__restrict__在指针类型上使用.这也是唯一__restrict__有意义的背景.

  • 只是为了放大:`__ sattrict__ SomeType b []`不行.`SomeType __restrict__ b []`不行.`__restrict__ SomeType*b`不行.`SomeType*__restrict__ b`没问题.有关示例,请参阅[文档](http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#restrict). (13认同)
  • 在c99标准中给出了`restrict`的[正式定义](http://www.lysator.liu.se/c/restrict.html#formal-definition)(特别注意链接部分3.10).`restrict`是*指针限定符*.它不符合指向的对象.因此,在遇到`restrict`时,我们必须引用*指针类型*.cuda`__restrict__`限定符模仿了这种行为.因此,如果`T`不是指针类型,那么`T restrict`将不起作用,无论其后面是什么.你不能做你在C中建议的事情.这不是真正的CUDA问题. (3认同)