CUDA shared memory

原文来自CUDA C programming guide

shared memory在片上,因此比local memory与global memory快得多。

 

To achieve high bandwidth, shared memory is divided into equally-sized memory modules, called banks, which can be accessed simultaneously. Any memory read or write request made of n addresses that fall in n distinct memory banks can therefore be serviced simultaneously, yielding an overall bandwidth that is n times as high as the bandwidth of a single module.

为了达到高带宽,shared memory被划分成相同大小的内存块,叫做banks。Banks可以同步访问。n个地址的落在n个独立memory bank的任意内存读或写请求因此可以同步服务。

However, if two addresses of a memory request fall in the same memory bank, there is a bank conflict and the access has to be serialized. The hardware splits a memory request with bank conflicts into as many separate conflict-free requests as necessary, decreasing throughput by a factor equal to the number of separate memory requests. If the number of separate memory requests is n, the initial memory request is said to cause n-way bank conflicts.

然而,如果一次内存请求的两个地址落到同一个memory bank上,将会导致bank conflict并且访问将被串行化。

 

To get maximum performance, it is therefore important to understand how memory addresses map to memory banks in order to schedule the memory requests so as to minimize bank conflicts。

 

章节1 计算能力1.x的device

Shared memory has 16 banks that are organized such that successive 32-bit words are assign to successive banks, i.e. interleaved. Each bank has a bandwidth of 32 bits per two clock cycles.

 

Shared memory被组织成16个bank这样连续的32位 word被分配到连续的bank上。每两个时钟周期每条bank有32位的带宽。

 

A shared memory request for a warp is split into two memory requests, one for each half-warp, that are issued independently. As a consequence, there can be no bank conflict between a thread belonging to the first half of a warp and a thread belonging to the second half of the same warp.

一个warp的一次shared memory请求被分成两次内存请求,每个half-warp一次,并独立发射。因此,在属于前半部分warp的线程与后半部分warp的线程之间不会有bank conflict。

注:这应该是针对计算能力1.x的device

 

For devices of compute capability 1.x, the warp size is 32 threads and the number of banks is 16.

 A shared memory request for a warp is split into one request for the first half of the warp and one request for the second half of the warp. Note that no bank conflict occurs if only one memory location per bank is accessed by a half warp of threads.

对于计算能力1.x的device,warp大小为32个线程bank的数量为16。一个warp的一次shared memory请求被分成前半个warp的一次请求和后半个warp的一次请求。

 

If a non-atomic instruction executed by a warp writes to the same location in shared memory for more than one of the threads of the warp, only one thread per half-warp performs a write and which thread performs the final write is undefined.

 

A common access pattern is for each thread to access a 32-bit word from an array indexed by the thread ID tid and with some stride s: __shared__ float shared[32];

 float data = shared[BaseIndex + s * tid];

s为跨越的歩数。即跨越的bank

 


In this case, threads tid and tid+n access the same bank whenever s*n is a multiple of the number of banks (i.e. 16) or, equivalently, whenever n is a multiple of 16/d where d is the greatest common divisor of 16 and s. As a consequence, there will be no bank conflict only if half the warp size (i.e. 16) is less than or equal to 16/d., that is only if d is equal to 1, i.e. s is odd.

32位的跨越访问,即访问bank时跨越访问

tid访问的是BaseIndex+s*tid这个地址,线程tid+n访问的是BaseIndex+s*tid+s*n。因为bank的个数为16,如果两个地址相差的是16的倍数,即s*n是16的倍数即这两个线程会访问相同的bank。两者线程间隔为n,这两个线程要不属于同一个half-warp,若16/d>=half-warp的大小,n肯定>=half-warp的size,两者不会在相同的half-warp内。

 


 F .3.3.2 32-Bit Broadcast Access
Shared memory features a broadcast mechanism whereby a 32-bit word can be read and broadcast to several threads simultaneously when servicing one memory read.request. This reduces the number of bank conflicts when several threads read from an address within the same 32-bit word. More precisely, a memory read request made of several addresses is serviced in several steps over time by servicing one conflict-free subset of these addresses per step until all addresses have been serviced; at each step, the subset is built from the remaining addresses that have yet to be serviced using the following procedure:

这种方式减少了bank conflict的数量当几个线程从相同的32位word内的某一个地址(注:这个地址应该是相同的)读取的时候。
 Select one of the words pointed to by the remaining addresses as the broadcast word;
 Include in the subset:
 All addresses that are within the broadcast word,
 One address for each bank (other than the broadcasting bank) pointed to by the remaining addresses.
Which word is selected as the broadcast word and which address is picked up for each bank at each cycle are unspecified.
A common conflict-free case is when all threads of a half-warp read from an address within the same 32-bit word.

 

 

 

8-bit and 16-bit accesses typically generate bank conflicts. For example, there are bank conflicts if an array of char is accessed the following way:

__shared__ char shared[32];

 char data = shared[BaseIndex + tid];
because shared[0], shared[1], shared[2], and shared[3], for example, belong to the same bank. There are no bank conflicts however, if the same array is accessed the following way: char data = shared[BaseIndex + 4 * tid];

注:char占一个字节

 

 

 

章节2  计算能力2.x的设备

For devices of compute capability 2.x, the warp size is 32 threads and the number of banks is also 32. A shared memory request for a warp is not split as with devices of compute capability 1.x, meaning that bank conflicts can occur between threads in the first half of a warp and threads in the second half of the same warp (see Section F.4.3 of the CUDA C Programming Guide).

对于计算能力2.x的设备,warp大小为32个线程,bank数量也是32.一个warp的一次memory请求不会像计算能力1.x的设备那样分开。这意味着bank conflict会在前半个warp的线程与同一个warp的后半个线程之间发生。

注:这应该是属于同一warp的不同半边的线程访问了同一个bank

 

A bank conflict only occurs if two or more threads access any bytes within different 32-bit words belonging to the same bank. If two or more threads access any bytes within the same 32-bit word, there is no bank conflict between these threads: For read accesses, the word is broadcast to the requesting threads (unlike for devices of compute capability 1.x, multiple words can be broadcast in a single transaction); for write accesses, each byte is written by only one of the threads (which thread performs the write is undefined).

bank conflict仅在两个或更多的线程访问属于同一个bank的不同32位word中的字节。如果两个或以上的线程访问了同一个32位字内的字节。这些线程之间将没有bank conflict。对于读访问,这个word将会在所有请求的线程之间广播。对于写操作,每个字节只会被这其中之一的线程写入。(哪个线程执行这个写操作未定义)

 

This means, in particular, that unlike for devices of compute capability 1.x, there are no bank conflicts if an array of char is accessed as follows, for example:

__shared__ char shared[32];

char data = shared[BaseIndex + tid];

这个在1.x的device上有bank conflict,在2.x上没有bank conflict。因为2.x上只要访问的是同一个bank上的相同32位word中的字节,就不会有bank conflict。

 

 

The __shared__ qualifier, optionally used together with __device__, declares a variable that:
Resides in the shared memory space of a thread block,
 Has the lifetime of the block,
 Is only accessible from all the threads within the block.


When declaring a variable in shared memory as an external array such as

extern __shared__ float shared[];
the size of the array is determined at launch time (see Section B.17).

注:因为shared数组为external,因此数组大小由kernel函数加载时的参数决定

 

 All variables declared in this fashion, start at the same address in memory, so that the layout of the variables in the array must be explicitly managed through offsets.

所有以这个方式声明的变量在memory中的初始地址都是相同的,因此数组中变量的布局必须通过偏移量来明确管理。

For example, if one wants the equivalent of short array0[128]; float array1[64]; int array2[256];
in dynamically allocated shared memory, one could declare and initialize the arrays the following way:

 extern __shared__ float array[];

__device__ void func() // __device__ or __global__ function

 {  short* array0 = (short*)array;

   float* array1 = (float*)&array0[128];

   int* array2 = (int*)&array1[64];

}

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目目目 录录录 目录 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · i 第一章 导论 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 1 1.1 从图形处理到通用并行计算 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 1 1.2 CUDATM :一种通用并行计算架构 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 3 1.3 一种可扩展的编程模型· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 3 1.4 文档结构 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 4 第二章 编程模型 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 7 2.1 内核· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 7 2.2 线程层次 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 8 2.3 存储器层次 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 11 2.4 异构编程 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 11 2.5 计算能力 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 11 第三章 编程接口 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 15 3.1 用nvcc编译 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 15 3.1.1 编译流程 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 16 3.1.1.1 离线编译 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 16 3.1.1.2 即时编译 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 16 3.1.2 二进制兼容性· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 17 3.1.3 PTX兼容性· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 17 3.1.4 应用兼容性 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 18 3.1.5 C/C++兼容性· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 19 3.1.6 64位兼容性 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 19 3.2 CUDA C运行时· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 19 ii CUDA编程指南5.0中文版 3.2.1 初始化 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 20 3.2.2 设备存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 20 3.2.3 共享存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 24 3.2.4 分页锁定主机存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 32 3.2.4.1 可分享存储器(portable memory) · · · · · · · · · · · · · · · · 34 3.2.4.2 写结合存储器· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 34 3.2.4.3 被映射存储器· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 34 3.2.5 异步并发执行· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 35 3.2.5.1 主机和设备间异步执行· · · · · · · · · · · · · · · · · · · · · · · · · · 35 3.2.5.2 数据传输和内核执行重叠 · · · · · · · · · · · · · · · · · · · · · · · 36 3.2.5.3 并发内核执行· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 36 3.2.5.4 并发数据传输· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 36 3.2.5.5 流 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 37 3.2.5.6 事件· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 41 3.2.5.7 同步调用 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 42 3.2.6 多设备系统 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 42 3.2.6.1 枚举设备 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 42 3.2.6.2 设备指定 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 42 3.2.6.3 流和事件行为· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 43 3.2.6.4 p2p存储器访问 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 44 3.2.6.5 p2p存储器复制 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 45 3.2.6.6 统一虚拟地址空间 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 45 3.2.6.7 错误检查 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 46 3.2.7 调用栈 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 47 3.2.8 纹理和表面存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 47 3.2.8.1 纹理存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 47 3.2.8.2 表面存储器(surface) · · · · · · · · · · · · · · · · · · · · · · · · · · · · 60 3.2.8.3 CUDA 数组 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 65 目录 iii 3.2.8.4 读写一致性 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 66 3.2.9 图形学互操作性 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 66 3.2.9.1 OpenGL互操作性 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 67 3.2.9.2 Direct3D互操作性 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 70 3.2.9.3 SLI(速力)互操作性· · · · · · · · · · · · · · · · · · · · · · · · · · · 82 3.3 版本和兼容性· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 82 3.4 计算模式 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 83 3.5 模式切换 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 84 3.6 Windows上的Tesla计算集群模式 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 85 第四章 硬件实现 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 87 4.1 SIMT 架构 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 87 4.2 硬件多线程 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 88 第五章 性能指南 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 91 5.1 总体性能优化策略 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 91 5.2 最大化利用率· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 91 5.2.1 应用层次 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 91 5.2.2 设备层次 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 92 5.2.3 多处理器层次· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 92 5.3 最大化存储器吞吐量 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 94 5.3.1 主机和设备的数据传输· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 95 5.3.2 设备存储器访问 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 96 5.3.2.1 全局存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 96 5.3.2.2 本地存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 98 5.3.2.3 共享存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 99 5.3.2.4 常量存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 100 5.3.2.5 纹理和表面存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 100 5.4 最大化指令吞吐量 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 100 iv CUDA编程指南5.0中文版 5.4.1 算术指令 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 101 5.4.2 控制流指令 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 104 5.4.3 同步指令 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 105 附录 A 支持CUDA的GPU · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 107 附录 B C语言扩展 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 109 B.1 函数类型限定符 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 109 B.1.1 device · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 109 B.1.2 global · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 109 B.1.3 host · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 109 B.1.4 noinline 和 forceinline · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 110 B.2 变量类型限定符 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 110 B.2.1 device · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 111 B.2.2 constant · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 111 B.2.3 shared · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 112 B.2.4 restrict · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 113 B.3 内置变量类型· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 115 B.3.1 char1、uchar1、char2、uchar2、char3、uchar3、char4、 uchar4、short1、ushort1、short2、ushort2、short3、ushort3、 short4、ushort4、int1、uint1、int2、uint2、int3、uint3、 int4、uint4、long1、ulong1、long2、ulong2、long3、ulong3、 long4、ulong4、float1、float2、float3、float4、double2 · · · 115 B.3.2 dim3类型 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 115 B.4 内置变量 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 115 B.4.1 gridDim · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 115 B.4.2 blockIdx · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 115 B.4.3 blockDim · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 117 B.4.4 threadIdx · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 117 B.4.5 warpSize · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 117 目录 v B.5 存储器栅栏函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 117 B.6 同步函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 119 B.7 数学函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 120 B.8 纹理函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 120 B.8.1 纹理对象函数· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 120 B.8.1.1 tex1Dfetch() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 120 B.8.1.2 tex1D()· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 121 B.8.1.3 tex2D()· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 121 B.8.1.4 tex3D()· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 121 B.8.1.5 tex1DLayered() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 121 B.8.1.6 tex2DLayered() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 122 B.8.1.7 texCubemap() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 122 B.8.1.8 texCubemapLayered()· · · · · · · · · · · · · · · · · · · · · · · · · · · 122 B.8.1.9 tex2Dgather() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 123 B.8.2 纹理参考函数· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 123 B.8.2.1 tex1Dfetch() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 123 B.8.2.2 tex1D()· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 124 B.8.2.3 tex2D()· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 124 B.8.2.4 tex3D()· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 125 B.8.2.5 tex1DLayered() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 125 B.8.2.6 tex2DLayered() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 125 B.8.2.7 texCubemap() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 125 B.8.2.8 texCubemapLayered()· · · · · · · · · · · · · · · · · · · · · · · · · · · 126 B.8.2.9 tex2Dgather() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 126 B.9 表面函数(surface)· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 126 B.9.1 表面对象函数· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 127 B.9.1.1 surf1Dread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 127 B.9.1.2 surf1Dwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 127 vi CUDA编程指南5.0中文版 B.9.1.3 surf2Dread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 127 B.9.1.4 surf2Dwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 128 B.9.1.5 surf3Dread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 128 B.9.1.6 surf3Dwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 128 B.9.1.7 surf1DLayeredread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · 129 B.9.1.8 surf1DLayeredwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · 129 B.9.1.9 surf2DLayeredread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · 129 B.9.1.10 surf2DLayeredwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · 130 B.9.1.11 surfCubemapread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 130 B.9.1.12 surfCubemapwrite()· · · · · · · · · · · · · · · · · · · · · · · · · · · · · 131 B.9.1.13 surfCubemapLayeredread() · · · · · · · · · · · · · · · · · · · · · · 131 B.9.1.14 surfCubemapLayeredwrite() · · · · · · · · · · · · · · · · · · · · · 131 B.9.2 表面引用API · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 132 B.9.2.1 surf1Dread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 132 B.9.2.2 surf1Dwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 132 B.9.2.3 surf2Dread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 132 B.9.2.4 surf2Dwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 133 B.9.2.5 surf3Dread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 133 B.9.2.6 surf3Dwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 133 B.9.2.7 surf1DLayeredread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · 134 B.9.2.8 surf1DLayeredwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · 134 B.9.2.9 surf2DLayeredread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · 135 B.9.2.10 surf2DLayeredwrite() · · · · · · · · · · · · · · · · · · · · · · · · · · · 135 B.9.2.11 surfCubemapread() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 135 B.9.2.12 surfCubemapwrite()· · · · · · · · · · · · · · · · · · · · · · · · · · · · · 136 B.9.2.13 surfCubemapLayeredread() · · · · · · · · · · · · · · · · · · · · · · 136 B.9.2.14 surfCubemapLayeredwrite() · · · · · · · · · · · · · · · · · · · · · 137 B.10 时间函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 137 目录 vii B.11 原子函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 137 B.11.1 数学函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 138 B.11.1.1 atomicAdd() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 138 B.11.1.2 atomicSub() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 139 B.11.1.3 atomicExch() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 139 B.11.1.4 atomicMin() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 140 B.11.1.5 atomicMax()· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 140 B.11.1.6 atomicInc() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 140 B.11.1.7 atomicDec() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 141 B.11.1.8 atomicCAS() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 141 B.11.2 位逻辑函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 141 B.11.2.1 atomicAnd() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 141 B.11.2.2 atomicOr() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 142 B.11.2.3 atomicXor() · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 142 B.12 束表决(warp vote)函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 142 B.13 束洗牌函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 143 B.13.1 概览 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 143 B.13.2 在束内广播一个值 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 144 B.13.3 计算8个线程的前缀和· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 145 B.13.4 束内求和 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 146 B.14 取样计数器函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 146 B.15 断言 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 147 B.16 格式化输出 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 148 B.16.1 格式化符号 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 149 B.16.2 限制 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 149 B.16.3 相关的主机端API · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 150 B.16.4 例程 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 151 B.17 动态全局存储器分配 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 152 viii CUDA编程指南5.0中文版 B.17.1 堆存储器分配 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 153 B.17.2 与设备存储器API的互操作 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 154 B.17.3 例程 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 154 B.17.3.1 每个线程的分配 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 154 B.17.3.2 每个线程块的分配 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 155 B.17.3.3 在内核启动之间持久的分配 · · · · · · · · · · · · · · · · · · · · · 156 B.18 执行配置 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 159 B.19 启动绑定 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 160 B.20 #pragma unroll · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 162 B.21 SIMD 视频指令 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 163 附录 C 数学函数· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 165 C.1 标准函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 165 C.1.1 单精度浮点函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 165 C.1.2 双精度浮点函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 168 C.2 内置函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 171 C.2.1 单精度浮点函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 172 C.2.2 双精度浮点函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 172 附录 D C++语言支持· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 175 D.1 代码例子 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 175 D.1.1 数据类 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 175 D.1.2 派生类 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 176 D.1.3 类模板 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 177 D.1.4 函数模板 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 178 D.1.5 函子类 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 178 D.2 限制· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 180 D.2.1 预处理符号 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 180 D.2.2 限定符 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 180 目录 ix D.2.2.1 设备存储器限定符 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 180 D.2.2.2 Volatile限定符 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 182 D.2.3 指针· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 182 D.2.4 运算符 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 183 D.2.4.1 赋值运算符 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 183 D.2.4.2 地址运算符 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 183 D.2.5 函数· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 183 D.2.5.1 编译器生成的函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 183 D.2.5.2 函数参数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 184 D.2.5.3 函数内静态变量 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 184 D.2.5.4 函数指针 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 184 D.2.5.5 函数递归 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 185 D.2.6 类 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 185 D.2.6.1 数据成员 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 185 D.2.6.2 函数成员 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 185 D.2.6.3 虚函数 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 185 D.2.6.4 虚基类 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 185 D.2.6.5 Windows相关 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 185 D.2.7 模板· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 186 附录 E 纹理获取· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 187 E.1 最近点取样 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 187 E.2 线性滤波 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 187 E.3 查找表 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 189 附录 F 计算能力 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 191 F.1 特性和技术规范 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 191 F.2 浮点标准 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 195 F.3 计算能力1.x · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 198 x CUDA编程指南5.0中文版 F.3.1 架构· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 198 F.3.2 全局存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 199 F.3.2.1 计算能力1.0和1.1的设备 · · · · · · · · · · · · · · · · · · · · · · · · 199 F.3.2.2 计算能力1.2和1.3的设备 · · · · · · · · · · · · · · · · · · · · · · · · 199 F.3.3 共享存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 201 F.3.3.1 32位步长访问· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 201 F.3.3.2 32位广播访问· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 202 F.3.3.3 8位和16位访问 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 205 F.3.3.4 大于32位访问· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 205 F.4 计算能力2.x · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 206 F.4.1 架构· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 206 F.4.2 全局存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 208 F.4.3 共享存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 209 F.4.3.1 32位步长访问· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 209 F.4.3.2 大于32位访问· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 210 F.4.4 常量存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 211 F.5 计算能力3.x · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 211 F.5.1 架构· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 211 F.5.2 全局存储器访问 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 212 F.5.3 共享存储器 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 213 F.5.3.1 64位模式 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 213 F.5.3.2 32位模式 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 213 附录 G 驱动API · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 215 G.1 上下文 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 218 G.2 模块· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 219 G.3 内核执行 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 220 G.4 运行时API和驱动API的互操作性 · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 222 G.5 注意· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 223 表表表 格格格 5.1 原生算术指令吞吐量/每时钟每流多处
### 回答1: CUDA共享内存是一种特殊的内存类型,它可以在同一个线程块内的线程之间共享数据。这种内存类型的访问速度非常快,因为它是在GPU芯片上的SRAM中实现的。使用共享内存可以有效地减少全局内存的访问,从而提高CUDA程序的性能。共享内存的大小是有限制的,通常为每个线程块的总共享内存大小的一半。因此,在使用共享内存时需要仔细考虑内存的使用情况,以避免内存溢出和性能下降。 ### 回答2: CUDA shared memory是一种专门用于加速GPU并行计算的高速缓存区域。它位于GPU的多个处理核心之间共享,并在同一个线程块中的线程之间交流数据。相比于全局内存,shared memory具有更低的访问延迟和更高的带宽。 shared memory可以通过声明__shared__关键字来定义,并通过静态分配的方式进行初始化。每个线程块都具有自己独立的shared memory空间,其大小在编译时确定,但最大限制为48KB。 shared memory的主要优点是其高带宽和低延迟。由于其位于多个处理核心之间共享,可以实现线程之间的快速数据交换。通过将计算中频繁使用的数据存储在shared memory中,可以减少从全局内存中读取数据所需的时间。这对于那些具有访存限制的算法,如矩阵乘法和图像处理等,非常有用。 使用shared memory还可以避免线程间的数据冗余读取,从而提高整体的并行计算效率。当多个线程需要访问相同的数据时,可以将这些数据存储在shared memory中,以便线程之间进行共享,从而减少了重复的全局内存访问。 但shared memory也有一些限制和需要注意的地方。首先,shared memory的大小是有限的,需要根据具体的算法和硬件限制进行适当调整。其次,由于其共享的特性,需要确保线程之间的数据同步。最后,使用shared memory时需要注意避免bank conflict,即多个线程同时访问同一个shared memory bank造成的资源竞争,从而导致性能下降。 综上所述,CUDA shared memory在GPU并行计算中具有重要的作用。通过使用shared memory,可以有效减少全局内存访问、提高数据交换速度和并行计算效率,从而加速GPU上的并行计算任务。 ### 回答3: CUDA共享内存(shared memory)是指在CUDA程序中使用的一种特殊的内存空间。它是GPU上的一块高速、低延迟的内存,被用来在同一个线程块(thread block)中的线程之间进行数据共享。 与全局内存相比,共享内存的访问速度更快,读写延迟更低。这是因为共享内存位于SM(Streaming Multiprocessor)内部,可以直接被SM访问,而全局内存则需要通过PCIe总线与主机内存进行通信。 使用共享内存可以提高应用程序性能的原因之一是避免了全局内存的频繁访问。当多个线程需要读写同一个数据时,如果每个线程都从全局内存中读取/写入,会导致内存带宽饱和,限制了整体性能。而将这些数据缓存在共享内存中,可以减少对全局内存的访问次数,提高内存带宽的利用率。 除此之外,共享内存的另一个重要特性是可以用作线程间的通信机制。在同一个线程块中的线程可以通过共享内存交换数据,而无需利用全局内存作为中介。这使得线程之间的协作变得更加高效和灵活。 然而,共享内存也有一些限制。首先,共享内存的大小是有限的,通常为每个SM的一定容量(如16KB或48KB)。其次,共享内存的生命周期与线程块相同,每个线程块结束后,共享内存中的数据将被销毁。 在编写CUDA程序时,可以使用__shared__关键字来声明共享内存。同时需要注意,合理地使用共享内存,并避免冲突和竞争条件,才能充分发挥共享内存的优势,提高CUDA程序的性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值