我想在CUDA代码中实例化一个类,该类与同一块中的其他线程共享一些成员。
但是,当尝试编译以下代码时,我会收到错误提示:
但是,当尝试编译以下代码时,我会收到错误提示:
attribute "shared" does not apply here
(nvcc版本4.2)。
class SharedSomething {
public:
__shared__ int i; // this is not allowed
};
__global__ void run() {
SharedSomething something;
}
这背后的原理是什么?有没有方法可以实现期望的行为(在一个块内共享类的成员)?