前言
This book shows how, by harnessing the power of your computer’s graphics process unit (GPU), you can write high-performance software for a wide rangeof applications.Although originally designed to render computer graphics ona monitor (and still used for this purpose), GPUs are increasingly being calledupon for equally demanding programs in science, engineering, and finance,among other domains.We refer collectively to GPU programs that address problems in nongraphics domains as general-purpose. Happily, although you need to have some experience working in C or C++ to benefit from this book,you need not have any knowledge of computer graphics. None whatsoever! GPU programming simply offers you an opportunity to build-and to build mightily-on your existing programming skills.
To program NVlDlA GPUs to perform general-purpose computing tasks, you will want to know what CUDA is. NVlDlA GPUs are built on what’s known as the CUDA Architecture. You can think of the CUDA Architecture as the scheme by which NVlDlA has built GPUs that can perform both traditional graphics-rendering tasks and general-purpose tasks. To program CUDA GPUs, we will be using a language known as CUDA C. As you will see very early in this book.
CUDA C is essentially C with a handful of extensions to allow programming of massively parallel machines like NVIDIA GPUs.
We’ve geared CUDA by Example toward experienced C or C++ programmers who have enough familiarity with C such that they are comfortable reading and writing code in C. This book builds on your experience with C and intends to serve as an example-driven, “quick-start" guide to using NVIDlA’s CUDA C program-
ming language. By no means do you need to have done large-scale software architecture, to have written a C compiler or an operating system kernel, or to know all the ins and outs of the ANSlC standards. However, we do not spend time reviewing C syntax or common C library routines such as malloc() or memcpy ( ) , so we will assume that you are already reasonably familiar with these topics.
You will encounter some techniques that can be considered general parallel programming paradigms, although this book does not aim to teach general parallel programming techniques. Also, while we will look at nearly every part of the CUDA APl, this book does not serve as an extensive APl reference nor will it go into gory detail about every tool that you can use to help develop your CUDA C software. Consequently, we highly recommend that this book be used in conjunction with NVlDlA’s freely available documentation, in particular the NVIDIA CUDA Programming Guide and the NVIDlA CUDA Best Practices Guide. But don’t stress out about collecting all these documents because we’ll walk you through every-thing you need to do.
Without further ado, the world of programming NVlDlA GPUs with CUDA C awaits!
emmmm,这是这本书的前言,大家应该能看明白吧,我看网上推荐这本书,去网上搜了一下就下单了,然后收到发现是一本原版的,也挺好,可以收藏😂,还写着美刀的定价呢
等我看明白了,再用汉语写出来分享给大家
一、WHY CUDA? WHY NOW?
这一章说了一下为什么有了GPU:CPU从单核,为了让它能力更强把单核的时钟频率做到了很高。之后发现,可以不只用一个核,可以多个核一起用,这样就不用每个核的频率都很高。这样还会更省电。
随着时代发展,2D-3D的推进,需要更多的图形处理算力,再加上大型游戏的崛起,就让GPU发展起来了。
前言中也提到现在的GPU(graphics process unit) 不仅负责图形处理,还负责(general-purpose computations)通用计算 – 我们可以通过参数的传递欺骗GPU,让它以为这是在对图像计算。
二、CUDA
2.1 What Is the CUDA Architecture?
Unlike previous generations that partitioned computing resources into vertex and pixel shaders, the CUDA Architecture included a unified shader pipeline,allowing each and every arithmetic logic unit (ALU) on the chip to be marshaled by a program intending to perform general-purpose computations.Because NVIDlA intended this new family of graphics processors to be used for qeneral-
purpose computing, these ALUs were built to comply with lEEE requirements for single-precision floating-point arithmetic and were designed to use an instruction set tailored for general computation rather than specifically for graphics.
Furthermore, the execution units on the GPU were allowed arbitrary read and write access to memory as well as access to a software-managed cache known as shared memory. All of these features of the CUDA Architecture were added in order to create a GPU that would excel at computation in addition to performing well at traditional graphics tasks.
这也不太好翻译,大家意会一下…
Ⅰ.CUDA 架构包含一个统一的着色器流水线,这个流水线使通用计算程序把芯片上每个算术逻辑单元(ALU)组织起来。
Ⅱ.GPU可以读写软件的共享内存
Ⅲ.CUDA架构添加的所有功能都是为了使GPU不仅能执行传统的图形计算,还能高效的执行通用计算。
重要的就这三点吧,我就胡乱给大家翻一下…
2.2 Using the CUDA Architecture
这里说了一下没有CUDA之前,大家都要了解OpenGL或者Direct才能写GPU程序。
NVIDIA专门开发的CUDA C语言后,我们不再需要了解OpenGL或者DirectX图形编程结构,也不需要将通用计算问题伪装为图形计算问题。
Applications of CUDA
介绍了用CUDA实现的系统应用:医学影像,流体力学,环境科学
这都需要大量的算力作为支撑。
这下进入正文…
电脑是英伟达的显卡才可以,这点要注意,不是可不行,如果不是,可以转向入门到放弃🙄
使用CUDA开发应用程序需要配置以下先决条件:
支持CUDA的GPU
NVIDIA显卡驱动程序
标准C编译器
CUDA开发工具包
大家别着急,不是需要下载四个东西
https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exe_local
这个网址下载 CUDA开发工具包,选择电脑的版本,我下载的network的,这个就30M,然后安装了40多分钟。
然后C编译器的话就下载 Visual Studio
然后点击创建项目,这里就会有了
创建完毕后,软件会自动生成一段基于GPU编程的代码,运行之后如果能正常出结果,说明你的CUDA安装与系统环境配置没有问题了:
出现问题MSB3721的话,大家看一下这两篇文章
https://blog.csdn.net/weixin_45566134/article/details/127266422
https://blog.csdn.net/u012374012/article/details/132038568
我就是把那个环境变量改了,然后重启,就能用了。在网上搜了大半天才解决,最难的就是环境配置了…
总结
大家先把环境配置好,我们就踏上征程!
祝大家:
元旦安康,平安喜乐!