有没有为共享内存数组设置默认值的方法? [英] 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屋!
查看全文