官术网_书友最值得收藏!

Local memory and registers

Local memory and register files are unique to each thread. Register files are the fastest memory available for each thread. When variables of the kernel do not fit in register files, they use local memory. This is called register spilling. Basically, local memory is a part of global memory that is unique for each thread. Access to local memory will be slow compared to register files. Though local memory is cached in L1 and L2 caches, register spilling might not affect your program adversely

A simple program to understand how to use local memory is shown as follows:

#include <stdio.h>
#define N 5

__global__ void gpu_local_memory(int d_in)
{
int t_local;
t_local = d_in * threadIdx.x;
printf("Value of Local variable in current thread is: %d \n", t_local);
}
int main(int argc, char **argv)
{
printf("Use of Local Memory on GPU:\n");
gpu_local_memory << <1, N >> >(5);
cudaDeviceSynchronize();
return 0;
}

The  t_local variable will be local to each thread and stored in a register file. When this variable is used for computation in the kernel function, the computation will be the fastest. The output of the preceding code is shown as follows:

主站蜘蛛池模板: 和平县| 衡南县| 通城县| 武乡县| 西丰县| 江阴市| 许昌县| 阿克苏市| 庆元县| 石城县| 隆林| 吉林省| 韩城市| 五莲县| 乌兰察布市| 阳原县| 家居| 名山县| 兴和县| 社会| 镇巴县| 崇阳县| 莱西市| 常山县| 威信县| 南乐县| 姜堰市| 山西省| 三门峡市| 道真| 仙游县| 巴青县| 榆林市| 沅陵县| 加查县| 屯门区| 辽阳市| 特克斯县| 慈溪市| 招远市| 黄山市|