- Hands-On GPU Programming with Python and CUDA
- Dr. Brian Tuomanen
- 258字
- 2021-06-10 19:25:40
Basic pointwise arithmetic operations with gpuarray
In the last example, we saw that we can use the (overloaded) Python multiplication operator (* ) to multiply each element in a gpuarray object by a scalar value (here it was 2); note that a pointwise operation is intrinsically parallelizable, and so when we use this operation on a gpuarray object PyCUDA is able to offload each multiplication operation onto a single thread, rather than computing each multiplication in serial, one after the other (in fairness, some versions of NumPy can use the advanced SSE instructions found in modern x86 chips for these computations, so in some cases the performance will be comparable to a GPU). To be clear: these pointwise operations performed on the GPU are in parallel since the computation of one element is not dependent on the computation of any other element.
To get a feel for how the operators work, I would suggest that the reader load up IPython and create a few gpuarray objects on the GPU, and then play around with these operations for a few minutes to see that these operators do work similarly to arrays in NumPy. Here is some inspiration:

Now, we can see that gpuarray objects act predictably and are in accordance with how NumPy arrays act. (Notice that we will have to pull the output off the GPU with the get function!) Let's now do some comparison between CPU and GPU computation time to see if and when there is any advantage to doing these operations on the GPU.
- 操作系統(tǒng)實用教程(Linux版)
- Linux運維之道(第3版)
- Linux設(shè)備驅(qū)動開發(fā)詳解:基于最新的Linux4.0內(nèi)核
- Haskell Financial Data Modeling and Predictive Analytics
- Extending Puppet
- 精解Windows8
- Windows Phone應(yīng)用程序開發(fā)
- 無蘋果不生活 The New iPad隨身寶典
- 計算機應(yīng)用基礎(chǔ)(Windows 7+Office 2016)
- Hands-On GPU Programming with Python and CUDA
- μC/OS-III內(nèi)核實現(xiàn)與應(yīng)用開發(fā)實戰(zhàn)指南:基于STM32
- Linux應(yīng)用大全 基礎(chǔ)與管理
- Linux操作系統(tǒng)案例教程(第2版)
- Linux系統(tǒng)安全:縱深防御、安全掃描與入侵檢測
- Azure Resource Manager Templates Quick Start Guide