官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 常宁市| 大连市| 古田县| 乐陵市| 隆安县| 延津县| 长岭县| 河北省| 玉树县| 威海市| 淄博市| 会昌县| 海门市| 宣武区| 昌都县| 陆川县| 肇东市| 当雄县| 颍上县| 南郑县| 肥西县| 花莲县| 荥阳市| 博客| 林口县| 沙雅县| 吴江市| 兴义市| 孝义市| 浦北县| 荥经县| 孟连| 闽侯县| 甘泉县| 诏安县| 闸北区| 渑池县| 尖扎县| 卓尼县| 临澧县| 汕尾市|