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

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:

主站蜘蛛池模板: 彰化市| 杭锦后旗| 桂东县| 安陆市| 林甸县| 九龙城区| 体育| 麻城市| 新绛县| 图木舒克市| 怀化市| 固镇县| 佛坪县| 淳安县| 昌图县| 镇康县| 昌都县| 安西县| 宣威市| 绥棱县| 平顶山市| 澳门| 天水市| 溧阳市| 万载县| 保靖县| 锦屏县| 司法| 平遥县| 苗栗市| 白水县| 乐平市| 丰县| 唐山市| 连城县| 横峰县| 将乐县| 蕉岭县| 苍梧县| 三穗县| 布尔津县|