有没有办法为共享内存数组设置默认值? [英] Is there a way of setting default value for shared memory array?
本文介绍了有没有办法为共享内存数组设置默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下代码:
__global__ void kernel(int *something) {
extern __shared__ int shared_array[];
// Some operations on shared_array here.
}
是否可以将整个 shared_array 设置为某个值 - 例如0 - 没有明确解决某个线程中的每个单元格?
Is it possible to set whole shared_array to some value - e.g. 0 - without explicitly addressing each cell in some thread?
推荐答案
没有.共享内存未初始化.您必须以某种方式自己初始化它...
No. Shared memory is uninitialised. You have to somehow initialise it yourself, one way or another...
来自 CUDA C 编程指南 3.2,B.2.4.2 节,第 2 段:
From CUDA C Programming Guide 3.2, Section B.2.4.2, paragraph 2:
__shared__
变量不能将初始化作为其声明的一部分.
__shared__
variables cannot have an initialization as part of their declaration.
这也会丢弃共享变量的重要默认构造函数.
This also discards nontrivial default constructors for shared variables.
这篇关于有没有办法为共享内存数组设置默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文