班草是什么意思| 用什么可以全身美白| 朱砂有什么作用与功效| 男命正印代表什么| 墓志铭是什么意思| 游园惊梦讲的是什么| 限购是什么意思| 铁蛋白高是什么意思| 二椅子什么意思| 本科毕业证是什么颜色| 重阳节吃什么| 3.4是什么星座| 头晕需要做什么检查| 一个永一个日念什么| 甲减吃什么食物好| 古代的天花是现代的什么病| 佬是什么意思| 中暑发烧吃什么药| 梦到黑狗是什么意思| 血线高是什么意思啊| mrna是什么| 为什么越睡越困越疲惫| 为什么脚会有酸臭味| 手不释卷的释是什么意思| 上校是什么级别| 小便很黄是什么原因| 大姨妈一个月来两次是什么原因| 左卡尼汀口服溶液主要治疗什么| 什么呼什么应| 合成革是什么材质| 吃什么最补血而且最快| 7月15是什么节日| 达菲是什么药| 什么手机电池最耐用| 血红蛋白高是什么意思| 硬卧代硬座是什么意思| 后果自负是什么意思| 区长什么级别| 乳房上长黑色的斑点是什么原因| 香奈儿是什么品牌| 脑梗有什么特效药| 鼻屎有臭味是什么原因| 中气是什么意思| 彗星为什么有尾巴| 525什么星座| 晒太阳对身体有什么好处| 汉武帝属什么生肖| 什么是偏头痛| 血小板低吃什么补的快| joeone是什么牌子| 龟头责是什么意思| 洁癖是什么意思| 气喘是什么原因| 早上八点半是什么时辰| 女人喜欢黑色代表什么| 尿酸高是什么意思| 杜甫被人们称为什么| 6月21号什么星座| 一喝水就尿多是什么原因| 腰椎钙化是什么意思| 眼疲劳用什么眼药水| 什么是心理学| 支气管扩张是什么意思| 6月17号什么星座| 心累是什么原因| 属虎的幸运色是什么颜色| 做梦遗精是什么原因| 什么是刷酸| 排卵期同房要注意什么| 高血压三级是什么意思| 2000年属什么的| 声情并茂的意思是什么| 查乳房挂什么科| 烘培是什么意思| nba季后赛什么时候开始| 梦见参加葬礼是什么意思| 儿茶酚胺是什么| 纹理是什么意思| 鹿茸是什么| 净土是什么意思| 人中发红是什么原因| 灏读什么| 嗓子疼吃什么水果好得快| 诺什么意思| 急性心肌炎有什么症状| 咳嗽不能吃什么水果| 讲述是什么意思| 属猪的跟什么属相最配| 双肺纹理增重是什么意思| 什么的钩住| 叶酸片有什么功效| 咳嗽有痰吃什么好的快| palace什么牌子| 喝山楂水有什么好处和坏处| 属牛的和什么属相最配| 石家庄以前叫什么名字| 提高免疫力吃什么维生素| 刺猬和豪猪有什么区别| 山楂和什么泡水喝减肥效果最好| 桃子和什么相克| 黄瓜为什么是绿色的| 扁桃体发炎有什么症状| 气短气喘吃什么药| 肌桥是什么意思| 吃什么英语怎么说| 疖子是什么原因引起的| 四大天王叫什么名字| 囊中之物是什么意思| 8月9号是什么星座| 高挑是什么意思| 人潮涌动是什么意思| 副词是什么| 赤小豆有什么作用| 房颤什么意思| ex是什么的缩写| 感冒发烧吃什么好| 停止长高有什么征兆| mido手表什么档次| 什么样的孙悟空| 天天吃玉米有什么好处和坏处| 栀子花叶子发黄是什么原因| 大马士革是什么意思| 粘纤是什么材质| 背痛挂什么科| 咖喱饭需要什么材料| 莫吉托是什么| 玉米是什么时候传入中国的| 欧阳修是什么居士| 吃什么东西可以变白| 智齿什么时候长| sk-ll是什么牌子| 何五行属什么| 腹痛拉稀什么原因| 桃子什么时候成熟| 一诺千金什么意思| 什么是有限公司| 白化病是什么原因引起的| 僧侣是什么意思| 属猪五行属什么| 寿司的米饭是什么米| store是什么| 破壁是什么意思| 肾结石有什么影响| 一什么话| 情结是什么意思| 小酌怡情下一句是什么| 狗狗感冒吃什么药| 尿酸高吃什么| 何如是什么意思| 嘴苦嘴臭什么原因| 河字五行属什么| 过期的牛奶有什么用| 似是而非是什么意思| 366是什么意思| 拜土地公要准备什么东西| hot什么意思| 肝硬化是什么病| 来月经量少吃什么可以增加月经量| 梦见下雪是什么征兆| 11年属什么| 肱骨头小囊变什么意思| 破执是什么意思| yy什么意思| 空调除湿和制冷有什么区别| 什么时机塞给医生红包| 为什么姓张的不用说免贵| 超敏crp高是什么原因| 指甲盖发紫是什么原因| 今年什么时间进伏| 拉不出大便吃什么药| 天荒地老是什么生肖| 狮子是什么科| 透析是什么原理| 1958年属什么| 榴莲是什么味道| 胎动突然减少是什么原因| 盐的主要成分是什么| 翊字是什么意思| 浑身麻是什么原因| 心不在焉是什么意思| 胆囊炎吃什么蔬菜好| 唇亡齿寒什么意思| mews评分是什么意思| 糖耐什么时候检查| 乙肝三抗体阳性是什么意思| 张国荣属什么生肖| 每天坚持黄瓜敷脸有什么效果| 9月14是什么星座| 什么样属于轻度地包天| bruce是什么意思| 梦见小牛犊是什么预兆| 左边太阳穴疼是什么原因| 元旦唱什么歌| 大红袍是什么茶类| 背德是什么意思| 五月十六日是什么星座| 腰扭伤吃什么药| 暗网里面有什么| 火烧是什么食物| 89年属蛇是什么命| 74是什么意思| 隐血阳性什么意思| 梦见打别人是什么意思| 梦见入室抢劫意味什么| 什么是种草| 痈肿疮疖是什么意思| 店长的工作职责是什么| 林彪什么时候死的| 物化是什么意思| 鸡心为什么不建议吃| 韧带拉伤用什么药好| 为什么清真不吃猪肉| 嵌体是什么| lee中文叫什么| 佛家思想的核心是什么| 亚甲减是什么意思| 慢性浅表性胃炎伴糜烂吃什么药| 老人头晕是什么原因引起的| 吃什么有助于排便| 几成是什么意思| 有口臭去医院挂什么科| 新生婴儿吃什么奶粉| 小暑是什么季节| 打2个喷嚏代表什么| 鹰潭有什么好玩的地方| 将军是什么生肖| 茉莉花茶有什么作用| 眼压低是什么原因| 鼻涕粘稠是什么原因| 子宫腺肌症是什么病| 职位是什么意思| 甲状腺功能亢进是什么意思| 新生儿一直哭闹是什么原因| 什么相接| 什么原因会怀上葡萄胎| 休眠是什么意思| 什么是血小板| 经常流鼻血是什么情况| 花痴什么意思| 乳房有溢液是什么原因| 什么样的血管瘤不用治| 606是什么意思| 伏特加是什么酒| 做梦怀孕了是什么意思| 月经来了不走是什么原因| 刚出生的小鱼苗吃什么| 主动脉夹层什么意思| 炙热是什么意思| 打玻尿酸有什么危害| 糜烂性胃炎可以吃什么蔬菜| 纤维蛋白原是什么意思| 柳絮是什么| r一谷氨酰转移酶高说明什么| 九什么一毛| 什么办法退烧快| sheet是什么意思| 球蛋白偏高是什么原因| 什么东西可以解酒| 飞鱼籽是什么鱼的籽| 横梁是什么| 血糖高可以吃什么主食| 失焦是什么意思| 十一月七号是什么星座| 六一送女孩子什么礼物| 百度
Models / Libraries / Frameworks

浙江有什么旅游景点

百度 不光人被遣返,连手机都被没收了,为一个表情包付出的代价,未免太过惨痛。

This is the fourth post in the CUDA Refresher series, which has the goal of refreshing key concepts in CUDA, tools, and optimization for beginning or intermediate developers.

The CUDA programming model provides an abstraction of GPU architecture that acts as a bridge between an application and its possible implementation on GPU hardware. This post outlines the main concepts of the CUDA programming model by outlining how they are exposed in general-purpose programming languages like C/C++.

Let me introduce two keywords widely used in CUDA programming model: host and device.

The host is the CPU available in the system. The system memory associated with the CPU is called host memory. The GPU is called a device and GPU memory likewise called device memory.

To execute any CUDA program, there are three main steps:

  • Copy the input data from host memory to device memory, also known as host-to-device transfer.
  • Load the GPU program and execute, caching data on-chip for performance.
  • Copy the results from device memory to host memory, also called device-to-host transfer.

CUDA kernel and thread hierarchy

Figure 1 shows that the CUDA kernel is a function that gets executed on GPU. The parallel portion of your applications is executed K times in parallel by K different CUDA threads, as opposed to only one time like regular C/C++ functions. 

Figure 1. The kernel is a function executed on  the GPU.

Every CUDA kernel starts with a __global__ declaration specifier. Programmers provide a unique global ID to each thread by using built-in variables.

Figure 2. CUDA kernels are subdivided into blocks.
Figure 2. CUDA kernels are subdivided into blocks.

A group of threads is called a CUDA block. CUDA blocks are grouped into a grid. A kernel is executed as a grid of blocks of threads (Figure 2).

Each CUDA block is executed by one streaming multiprocessor (SM) and cannot be migrated to other SMs in GPU (except during preemption, debugging, or CUDA dynamic parallelism). One SM can run several concurrent CUDA blocks depending on the resources needed by CUDA blocks. Each kernel is executed on one device and CUDA supports running multiple kernels on a device at one time. Figure 3 shows the kernel execution and mapping on hardware resources available in GPU.

Figure 3. Kernel execution on GPU.

CUDA defines built-in 3D variables for threads and blocks. Threads are indexed using the built-in 3D variable threadIdx. Three-dimensional indexing provides a natural way to index elements in vectors, matrix, and volume and makes CUDA programming easier. Similarly, blocks are also indexed using the in-built 3D variable called blockIdx.

Here are a few noticeable points:

  • CUDA architecture limits the numbers of threads per block (1024 threads per block limit).
  • The dimension of the thread block is accessible within the kernel through the built-in blockDim variable.
  • All threads within a block can be synchronized using an intrinsic function __syncthreads. With __syncthreads, all threads in the block must wait before anyone can proceed.
  • The number of threads per block and the number of blocks per grid specified in the <<<…>>> syntax can be of type int or dim3. These triple angle brackets mark a call from host code to device code. It is also called a kernel launch.

The CUDA program for adding two matrices below shows multi-dimensional blockIdx and threadIdx and other variables like blockDim. In the example below, a 2D block is chosen for ease of indexing and each block has 256 threads with 16 each in x and y-direction. The total number of blocks are computed using the data size divided by the size of each block.

// Kernel - Adding two matrices MatA and MatB
__global__ void MatAdd(float MatA[N][N], float MatB[N][N],
float MatC[N][N])
{
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    int j = blockIdx.y * blockDim.y + threadIdx.y;
    if (i < N && j < N)
        MatC[i][j] = MatA[i][j] + MatB[i][j];
}
 
int main()
{
    ...
    // Matrix addition kernel launch from host code
    dim3 threadsPerBlock(16, 16);
    dim3 numBlocks((N + threadsPerBlock.x -1) / threadsPerBlock.x, (N+threadsPerBlock.y -1) / threadsPerBlock.y);
    MatAdd<<<numBlocks, threadsPerBlock>>>(MatA, MatB, MatC);
    ...
}

Memory hierarchy

CUDA-capable GPUs have a memory hierarchy as depicted in Figure 4.

Figure 4. Memory hierarchy in GPUs.

The following memories are exposed by the GPU architecture:

  • Registers—These are private to each thread, which means that registers assigned to a thread are not visible to other threads. The compiler makes decisions about register utilization.
  • L1/Shared memory (SMEM)—Every SM has a fast, on-chip scratchpad memory that can be used as L1 cache and shared memory. All threads in a CUDA block can share shared memory, and all CUDA blocks running on a given SM can share the physical memory resource provided by the SM..
  • Read-only memory—Each SM has an instruction cache, constant memory,  texture memory and RO cache, which is read-only to kernel code.
  • L2 cache—The L2 cache is shared across all SMs, so every thread in every CUDA block can access this memory. The NVIDIA A100 GPU has increased the L2 cache size to 40 MB as compared to 6 MB in V100 GPUs.
  • Global memory—This is the framebuffer size of the GPU and DRAM sitting in the GPU.

The NVIDIA CUDA compiler does a good job in optimizing memory resources but an expert CUDA developer can choose to use this memory hierarchy efficiently to optimize the CUDA programs as needed.

Compute capability

The compute capability of a GPU determines its general specifications and available features supported by the GPU hardware. This version number can be  used by applications at runtime to determine which hardware features or instructions are available on the present GPU.

Every GPU comes with a version number denoted as X.Y where X comprises a major revision number and Y a minor revision number. The minor revision number corresponds to an incremental improvement to the architecture, possibly including new features.

For more information about the compute capability of any CUDA-enabled device, see the CUDA sample code deviceQuery. This sample enumerates the properties of the CUDA devices present in the system

Summary

The CUDA programming model provides a heterogeneous environment where the host code is running the C/C++ program on the CPU and the kernel runs on a physically separate GPU device. The CUDA programming model also assumes that both the host and the device maintain their own separate memory spaces, referred to as host memory and device memory, respectively. CUDA code also provides for data transfer between host and device memory, over the PCIe bus.

CUDA also exposes many built-in variables and provides the flexibility of multi-dimensional indexing to ease programming. CUDA also manages different memories including registers, shared memory and L1 cache, L2 cache, and global memory. Advanced developers can use some of these memories efficiently to optimize the CUDA program.

Discuss (2)

Tags

空调综合征有什么症状 双鱼座和什么星座最配 貂蝉属什么生肖 羊水是什么颜色的 发光免疫是检查什么的
咪咪头疼是什么原因 梦见大老鼠是什么意思 骨骼惊奇什么意思 聿读什么 7月生日是什么星座
内分泌失调吃什么食物好 什么可以驱蛇 肝郁是什么意思 pbr是什么意思 线束是什么意思
吴刚和嫦娥什么关系 空腹c肽偏高说明什么 根管治疗后要注意什么 没有痔疮大便出血是什么原因 lcu是什么意思
含蓄是什么意思hcv8jop2ns8r.cn 小姑子是什么关系hcv9jop2ns4r.cn 生理期腰疼是什么原因hcv8jop0ns4r.cn 场记是做什么的hcv8jop8ns2r.cn 睾丸疼是什么原因hcv8jop7ns2r.cn
朱砂有什么用hcv8jop1ns9r.cn 戍是什么意思hcv7jop5ns0r.cn 易胖体质是什么原因造成的hcv8jop6ns6r.cn 人活着意义是什么hcv8jop9ns0r.cn 子宫复旧是什么意思hcv8jop8ns3r.cn
生殖疱疹吃什么药不复发hcv8jop2ns6r.cn 整天放屁是什么原因hcv8jop3ns5r.cn 散光看东西是什么样的hcv7jop6ns7r.cn 宫颈潴留囊肿是什么意思hcv9jop3ns9r.cn 什么是阴虚hcv9jop3ns0r.cn
手术室为什么在三楼hcv8jop1ns0r.cn 彩超能检查什么hcv7jop5ns1r.cn 尿频尿急吃什么药最好520myf.com 搬家有什么讲究和忌讳hcv7jop9ns5r.cn 八月十六号是什么星座hcv7jop6ns1r.cn
百度