yuenshome / yuenshome.github.io

https://yuenshome.github.io
MIT License
83 stars 15 forks source link

gpu gemm optimize #40

Open ysh329 opened 5 years ago

ysh329 commented 5 years ago

从零開始学习OpenCL开发(一)架构 - yxwkaifa - 博客园 https://www.cnblogs.com/yxwkf/p/4552029.html ysh329/OpenCL-101: Learn OpenCL step by step. https://github.com/ysh329/OpenCL-101

ysh329 commented 5 years ago

CUDA和OpenCL的区别

参考:CUDA和OpenCL有什么区别_百度知道

从很多方面来看,CUDA和OpenCL的关系都和DirectX与OpenGL的关系很相像。如同DirectX和OpenGL一样:

虽然两者抱着相同的目标:通用并行计算。但是CUDA仅仅能够在NVIDIA的GPU硬件上运行,而OpenCL的目标是面向任何一种Massively Parallel Processor,期望能够对不同种类的硬件给出一个相同的编程模型。由于这一根本区别,二者在很多方面都存在不同:

  1. 开发者友好程度。CUDA在这方面显然受更多开发者青睐。原因在于其统一的开发套件(CUDA Toolkit, NVIDIA GPU Computing SDK以及NSight等等)、非常丰富的库(cuFFT, cuBLAS, cuSPARSE, cuRAND, NPP, Thrust)以及NVCC(NVIDIA的CUDA编译器)所具备的PTX(一种SSA中间表示,为不同的NVIDIA GPU设备提供一套统一的静态ISA)代码生成、离线编译等更成熟的编译器特性。相比之下,使用OpenCL进行开发,只有AMD对OpenCL的驱动相对成熟。
  2. 跨平台性和通用性。这一点上OpenCL占有很大优势(这也是很多National Laboratory使用OpenCL进行科学计算的最主要原因)。OpenCL支持包括ATI,NVIDIA,Intel,ARM在内的多类处理器,并能支持运行在CPU的并行代码,同时还独有Task-Parallel Execution Mode,能够更好的支持Heterogeneous Computing。这一点是仅仅支持数据级并行并仅能在NVIDIA众核处理器上运行的CUDA无法做到的。
  3. 市场占有率。作为一个开放标准,缺少背后公司的推动,OpenCL显然没有占据通用并行计算的主流市场。NVIDIA则凭借CUDA在科学计算、生物、金融等领域的推广牢牢把握着主流市场。再次想到OpenGL和DirectX的对比,不难发现公司推广的高效和非盈利机构/标准委员会的低效(抑或谨慎,想想C++0x)。

很多开发者都认为,由于目前独立显卡市场的萎缩、新一代处理器架构(AMD的Graphics Core Next (GCN)、Intel的Sandy Bridge以及Ivy Bridge)以及新的SIMD编程模型(Intel的ISPC等)的出现,未来的通用并行计算市场会有很多不确定因素,CUDA和OpenCL都不是终点,我期待未来会有更好的并行编程模型的出现(当然也包括CUDA和OpenCL,如果它们能够持续发展下去)。

ysh329 commented 5 years ago

从零開始学习OpenCL开发(一)架构 - yxwkaifa - 博客园

1. 架构

1.1 异构计算、GPGPU与OpenCL

GPU的芯片结构擅长大规模的并行计算(PC级的GPU可能就是CPU的上万倍),CPU则擅长逻辑控制,因此不仅仅局限与图像渲染,人们希望将这样的计算能力扩展到很多其它领域,所以这也被称为GPGPU(即通用处计算处理的GPU)。

image

怎样将很多其它的计算代码搬到GPU上,让CPU负责逻辑控制,让GPU做类似渲染的计算密集型任务,这样一个CPU(控制单元)+几个GPU(或几个CPU)的架构就是所谓的异构编程(heterogeneous)

下图是NVidia GPU Femi100的结构,它有着大量的并行计算单元(绿色)。

image

OpenCl没有一个特定的SDK,Khronos Group仅仅是指定标准(你能够理解为他们定义头文件),而具体实现由不同參与公司来做:

  1. NVDIA将OpenCL做了实现后集成到CUDA SDK中;
  2. AMD实现后放在AMD APP (Accelerated Paral Processing)SDK中;
  3. Intel也做了实现。

主流CPU和GPU都在OpenCL规范下支持OpenCL架构,尽管不同公司做了不同的SDK。原则上用标准OpenCl头中定义的那些接口,使用NVIDIA的SDK编的程序能够跑在AMD的显卡上。

1.2 GPU上写代码的历史

OpenCL是通过在GPU上写代码来加速,只是把CPU、GPU等统一封装了更高的一层,对开发人员也更友好。

早期显卡是不存在的,图形处理是放在CPU上,后发现主板上可以放一个单独芯片来加速图形绘制(图像处理单元),直到NVIDIA把它做强做大,并改名为GPU(图像处理器),后来GPU就以比CPU高几倍的速度增长性能。

早期GPU不能编程,处理数据的方式叫做固定管线,即把数据依照固定的通路走完,这样的方式叫可编程管线。因为也作为计算处理器,后又出了可编程GPU,可却是用GPU汇编来写程序,用GPU绘制效果的技能仅仅掌握在少数图形工程师身上。

因为难掌握GPU汇编,像C一样的高级编程语言诞生,以方便写GPU。其中言代表有NVidia和微软创作的CG,微软的HLSL,openGL的GLSL等,如今也被称为高级着色语言(Shading Language),这些shader已被广泛应用于各种游戏中。

使用shading language的过程中,科研人员发现非图形计算的问题(如数学、物理领域的并行计算)能够伪装成图形问题利用Shading Language实如今GPU上计算,而这结果是在CPU上跑速度的N倍,因而人们想着利用GPU这样的性能去解决全部大量并行计算的问题,这也叫做通用处理的GPU(GPGPU)。

ysh329 commented 5 years ago

1.3 OpenCL架构

1.3.1 硬件层

下面是OpenCL硬件层的抽象:

image

包括以下:

Compute Device切分成非常多Processing Element(这是独立參与单数据计算的最小单元,这个不同硬件实现都不一样,如GPU可能就是当中一个Processor,而CPU可能是一个Core,我猜的。。由于这个实现对开发人员是隐藏的),当中非常多个Processing Element能够组成组为一个Computer Unit,一个Unit内的element之间能够方便的共享memory,也仅仅有一个Unit内的element能够实现同步等操作

1.3.2 内存架构

image


1.3.3 软件层

这部分讲述软件层面的组件组成,在SDK中都有具体说明,下面以四个部分来介绍:

  1. setup;
  2. 内存;
  3. gpu运行;
  4. 同步。

image

第1部分:setup相关

第2部分:内存相关

第3部分:gpu代码运行相关

第4部分:同步相关

参考

ysh329 commented 5 years ago

About Arm Mali FAQs

Resources | Frequently Asked Questions – Arm Developer https://developer.arm.com/graphics/resources/faqs#mali2

What is Mali?

Arm Mali media IP offers high performing, energy efficient media processing across a large and growing number of mobile and consumer devices, including entry-level mass market smartphones, visually stunning high-performance smartphones, Android™ OS-based tablets, SmartTVs and wearables.

What is Bifrost, Midgard and Utgard?

Bifrost, Midgard and Utgard are the different types of graphics architecture in Mali GPUs:

Bifrost

Arm’s latest architecture. Features in Mali-G7x and Mali-G5x series GPUs.

Midgard

Previous-generation architecture. Features in Mali-T8xx, Mali-T7xx and Mali-T6xx series GPUs.

Utgard

First-generation architecture. Features in Mali-4xx series GPUs.

ARM GPU架构 Utgard Utgard: mali-200,mali-300,mali-400,mali-450,mali-470 Separate shader cores SIMD ISA OpenCL ES 2.x ⦁ Midgard: mali-T600 series,mali-T700 series,mali-T800 series, Unified shader cores SIMD ISA OpenGL ES 3.x OpenCL Vulkan ⦁ Bifrost: Mali-G71, Mali-G51 Unified shader cores scaler ISA clause execution full coherency Vulkan OpenCL


ARM MALI-T860

Graphics and Multimedia Processors | Mali-T860 and Mali-T880 GPUs – Arm Developer https://developer.arm.com/products/graphics-and-multimedia/mali-gpus/mali-t860-and-mali-t880-gpus

image

About Mali-T860 GPU and Mali-T880 GPU

Key features

Key benefits

Performance

Mali-T860 (MP16)

Feature Value Description
Frequency 650MHz in 28nm HPM
Throughput 1300Mtri/s, 10.4Gpix/s in 28nm HPM

Mali-T880 (MP16)

Feature Value Description
Frequency 850MHz in 16nm (16 FinFET)
Throughput 1700Mtri/s, 13.6Gpix/s in 16nm (16 FinFET)
Features Mali-T860 Value Mali-T880 Value Description
Anti-Aliasing 4x MSAA.8x MSAA.16x MSAA. 4x MSAA.8x MSAA.16x MSAA. Hardware implemented Full Scene Multiple Sample Anti-Aliasing.
API Support OpenGL® ES 1.1, 1.2, 2.0, 3.1, 3.2.Vulkan 1.0*.OpenCL™ 1.1, 1.2.DirectX® 11 FL11_1.RenderScript™. OpenGL® ES 1.1, 1.2, 2.0, 3.0, 3.1, 3.2.Vulkan 1.0*.OpenCL™ 1.1, 1.2.DirectX® 11 FL11_1.RenderScript™. Full support for next-generation and legacy 2D/3D graphics applications.
Bus Interface AMBA®4.ACE-LITE. AMBA®4.ACE-LITE. Compatible with a wide range of bus interconnect and peripheral IP.
L2 Cache Configurable 256KB-2048KB. Configurable 256KB-2048KB. 256KB-512KB for every 4 shader cores.
Memory System Virtual Memory. Virtual Memory. Built-in Memory Management Unit (MMU) to support virtual memory.
Multi-Core Scaling 1 to 16 cores. 1 to 16 cores. Optimized for high area and energy efficiency to address the high-end mobile market and consumer device requirements.
Adaptive Scalable Texture Compression (ASTC) Low Dynamic Range (LDR) and High Dynamic Range (HDR).Supports both 2D and 3D images. Low Dynamic Range (LDR) and High Dynamic Range (HDR).Supports both 2D and 3D images. ASTC offers a number of advantages over existing texture compression schemes by improving image quality, reducing memory bandwidth and thus energy use.
Arm Frame Buffer Compression (AFBC) 4x4 pixel block size. 4x4 pixel block size. AFBC is a lossless image compression format that provides random access to pixel data to a 4x4 pixel block granularity. It is employed to reduce memory bandwidth both internally within the GPU and externally throughout the SoC.
Transaction Elimination 16x16 pixel block size. 16x16 pixel block size. Transaction Elimination spots the identical pixel blocks between two consecutive render targets and performs a partial update to the frame buffer with the changed pixel blocks only, which reduces memory bandwidth and thus energy.
Smart Composition 16x16 pixel block size. 16x16 pixel block size. Smart Composition extends the concept of Transaction Elimination to every stage of UI composition. Identical pixel blocks of input surfaces are not read, not processed for composition and not written to final frame buffer.