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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • springBoot+mybatis报错Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required

    springBoot+mybatis报错Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required报错为:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IllegalArgumentException:Property’sqlSessionFactory’or’sqlSessionTemplate’arerequired日志很长,报错在末尾2018-07-1213:56:41.760 I…

    2022年5月6日
    190
  • 字符指针 赋值

    字符指针 赋值字符串赋值给字符指针(char*a=“hello”)的正确理解方式 对于语句 char*a=”hello”;       对于这个声明方式,会造成的误解是:声明了一个字符指针(它会指向一个位置),将“字符串”赋值给指针表达式”*a”所指向的地址。但正解是:声明了一个字符指针后,并用字符串常量的第一个字符的地址赋值给指针变量a。       即正确顺序是:1.分配

    2022年7月11日
    16
  • h3c bios密码_日本服务器ip端口密码

    h3c bios密码_日本服务器ip端口密码版本Ladon>=7.1139端口NetBIOSFileandPrintSharing通过这个端口进入的连接试图获得NetBIOS/SMB服务。这个协议被用于Windows”文件和打印机共享”和SAMBA。IPC$通信Windows系统中的netuseipc整个通信过程,先445−>137−>139验证,当你开启防火墙禁用445,发现系统命令就无法连接IPC了,根本没机会走到139,所以使用系统自带命令连接的ipc整个通信过程,先445->137->

    2022年10月9日
    2
  • MySQL与php时间戳与日期格式的相互转换[通俗易懂]

    MySQL与php时间戳与日期格式的相互转换[通俗易懂]文章来自:源码在线https://www.shengli.me/php/336.html  

    2022年6月21日
    31
  • java restcontroller_java中的RestController

    java restcontroller_java中的RestController从Spring4开始,Spring以Servlet3为进行开发,如果用SpringMVC测试框架的话需要指定Servlet3兼容的jar包(因为其Mock的对象都是基于Servlet3的)。另外为了方便Rest开发,通过新的@RestController指定在控制器上,这样就不需要在每个@RequestMapping方法上加@ResponseBody了。而且添加了一个AsyncRestTemp…

    2022年6月16日
    66
  • 深入理解机器学习中的:目标函数,损失函数和代价函数「建议收藏」

    深入理解机器学习中的:目标函数,损失函数和代价函数「建议收藏」参考知乎回答整理:https://www.zhihu.com/question/52398145主要参考:https://www.zhihu.com/question/52398145/answer/209358209基本概念:损失函数:计算的是一个样本的误差代价函数:是整个训练集上所有样本误差的平均目标函数:代价函数+正则化项实际应用:损失函数和代价函数是同一个东

    2022年5月8日
    37

发表回复

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

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