GPU Parallel Computing

GPU Parallel Computing

 GPU                                                                                                         

  GPU英文全称Graphic Processing Unit,中文翻译为“图形处理器”。GPU是相对于CPU的一个概念,由于在现代的计算机中(特别是家用系统,游戏的发烧友)图形的处理变得越来越重要,需要一个专门的图形的核心处理器。

  GPU有非常多的厂商都生产,和CPU一样,生产的厂商比较多,但大家熟悉的却只有3个,以至于大家以为GPU只有AMD、NVIDIA、Intel3个生产厂商。

nVidia GPU AMD GPU Intel MIC协处理器 nVidia Tegra 4 AMD ARM服务器

CUDA C/C++

CUDA fortran

OpenCL MIC OpenMP CUDA  

GPU 并行计算                                                                                              

  • 可以同CPU或主机进行协同处理
  • 拥有自己的内存
  • 可以同时开启1000个线程
  • 单精度:4.58TFlops 双精度 1.31TFlops

  GPU编程方面主要有一下方法:

GPU Parallel Computing


 

   采用GPU进行计算时与CPU主要进行以下交互:

  • CPU与GPU之间的数据交换
  • 在GPU上进行数据交换

GPU Parallel Computing


 

GPU编程–CUDA                                                                                       

CUDA C/C++: download CUDA drivers & compilers & samples (All In One Package ) free from:

    http://developer.nvidia.com/cuda/cuda-downloads

选择适合的版本~~~~我的下载的是5.0 notebook版本

具体安装方法:可参考这里http://blog.csdn.net/diyoosjtu/article/details/8454253

安装后,打开VS->新建,就会发现一个nVidia,里面有一个CUDA

  主要过程:

  • Hello World
    •   Basic syntax, compile & run
  • GPU memory management
    •   Malloc/free
    •   memcpy
  • Writing parallel kernels
    •    Threads & block
    •      Memory hierachy
复制代码
//hello_world.c:
#include <stdio.h>

void hello_world_kernel(){
    printf(“Hello World\n”);
}
int main(){    hello_world_kernel();}
Compile
& Run: gcc hello_world.c ./a.out
复制代码

CUDA:

复制代码
//hello_world.cu:
#include <stdio.h>
__global__ void hello_world_kernel(){
    printf(“Hello World\n”);
}

int main(){    hello_world_kernel<<<1,1>>>();}

Compile & Run:
nvcc hello_world.cu
./a.out
复制代码


 

GPU计算的主要过程:

  1. Allocate CPU memory for n integers
  2. Allocate GPU memory for n integers
  3. Initialize GPU memory to 0s
  4. Copy from CPU to GPU
  5. call the __global__function, compute   

    Keyword for CUDA kernel

  6. Copy from GPU to CPU
  7. Print the values
  8. free

主要函数:

复制代码
//Host (CPU) manages device (GPU) memory:
cudaMalloc (void ** pointer, size_t nbytes)
cudaMemset (void * pointer, int value, size_t count)
cudaFree (void* pointer)

int nbytes = 1024*sizeof(int);
int * d_a = 0;
cudaMalloc( (void**)&d_a,  nbytes );
cudaMemset( d_a, 0, nbytes);
cudaFree(d_a);

cudaMemcpy( void *dst,   void *src,   size_t nbytes, enum cudaMemcpyKind direction);
//returns after the copy is complete
/*blocks CPU thread until all bytes have been copied
doesn’t start copying until previous CUDA calls complete
enum cudaMemcpyKind
  cudaMemcpyHostToDevice
  cudaMemcpyDeviceToHost
  cudaMemcpyDeviceToDevice*/
复制代码

其中,<<<grid,block>>>

  • 2-level hierarchy: blocks and grid
    •   Block = a group of up to 1024 threads
    •   Grid = all blocks for a given kernel launch
    •   E.g. total 72 threads
      •      blockDim=12, gridDim=6
  • A block can:
    •   Synchronize their execution
    •   Communicate via shared memory
  • Size of grid and blocks are specified during kernel launch

例子:

GPU Parallel Computing
View Code

Thread index computation : 

  idx = blockIdx.x*blockDim.x + threadIdx.x:


 

应用                                                                                                         

High performance math routines for your applications:

  • cuFFT – Fast Fourier Transforms Library
  • cuBLAS – Complete BLAS Library
  • cuSPARSE – Sparse Matrix Library
  • cuRAND – Random Number Generation (RNG) Library
  • NPP – Performance Primitives for Image & Video Processing
  • Thrust – Templated C++ Parallel Algorithms & Data Structures
  • math.h – C99 floating-point Library
 
 

 

知识共享许可协议
本文 由 cococo点点 创作,采用 知识共享 署名-非商业性使用-相同方式共享 3.0 中国大陆 许可协议进行许可。欢迎转载,请注明出处:
转载自:cococo点点 http://www.cnblogs.com/coder2012

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/109010.html原文链接:https://javaforall.net

(0)
上一篇 2021年9月15日 上午8:00
下一篇 2021年9月15日 上午9:00


相关推荐

  • Android退出APP 并杀掉相关的所有进程

    Android退出APP 并杀掉相关的所有进程代码如下:ActivityManagermActivityManager=(ActivityManager)AppApplication.getInstance().getSystemService(Context.ACTIVITY_SERVICE);List<ActivityManager.RunningAppProcessInfo>m…

    2022年7月17日
    22
  • Python 一篇学会多线程「建议收藏」

    Python 一篇学会多线程「建议收藏」多线程一篇就懂了

    2022年7月3日
    32
  • RS232标准9针串口引脚定义

    RS232标准9针串口引脚定义无论是 RS 232C RS 422 还是 RS 485 串口接口的外形 尺寸都是相同的 部件间可以通用互换 但其引脚的定义却各不相同 因此要了解串口做线 首先要知道串口各引脚的定义 观察一个标准的串口 会发现串口无论是 9 针的标准串口物理外形 如图 3 4 所示 还是 25 针串口物理外形 如图 3 6 所示 如果横着看 都显示两排引脚 除了两排引脚这一特征之外 还有就是无论是公头 还是母头 两个引

    2026年3月18日
    2
  • LVS 算法

    LVS 算法LVS 之二 负载均衡调度算法 2013 年 10 月 06 日 nbsp nbsp 服务器集群技术 nbsp 共 2074 字 nbsp LVS 之二 负载均衡调度算法已关闭评论 nbsp 被围观 11 026 次浏览 前面的文章介绍了 LVS 的三种模式 NAT TUN DR 那这三种模式下 如果进行负载均衡调度计算呢这就涉及到新的知识点 负载均衡调度算法目前 LVS 主要有三种请求转发方式和 10 种调度算法 根据请求转发方式的不同 所构架集群的网络拓扑

    2026年3月26日
    2
  • NB-IoT:指定频点操作「建议收藏」

    NB-IoT:指定频点操作「建议收藏」NBIOT指定频点后需要关闭射频开关,然后再清频点再开射频开关,最后附着网络。实际使用中最好不要锁定频点,否则很容易造成连接不上。AT+NEARFCN=0,2508,123——这里取值均为例子AT+CFUN=0AT+NCSEARFCNAT+CFUN=1AT+CGATT=1先设置频点,然后再清除频点,然后在CGATT…

    2022年10月6日
    5
  • 使用 vsphere-automation-sdk-python 自动创建虚拟机

    使用 vsphere-automation-sdk-python 自动创建虚拟机

    2021年7月9日
    286

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号