Is there a way of setting default value for shared memory array?

后端 未结 3 1038
悲&欢浪女
悲&欢浪女 2020-12-06 02:06

Consider the following code:

__global__ void kernel(int *something) {
extern __shared__ int shared_array[];     

// Some operations on shared_array here.

}         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 02:15

    No. Shared memory is uninitialised. You have to somehow initialise it yourself, one way or another...

    From CUDA C Programming Guide 3.2, Section B.2.4.2, paragraph 2:

    __shared__ variables cannot have an initialization as part of their declaration.

    This also discards nontrivial default constructors for shared variables.

提交回复
热议问题