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

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.

主站蜘蛛池模板: 淮安市| 安吉县| 怀宁县| 龙里县| 神池县| 高尔夫| 旬阳县| 贵溪市| 兰西县| 满洲里市| 九龙城区| 衡阳县| 探索| 饶阳县| 柳河县| 鹤壁市| 沾益县| 长沙县| 西丰县| 昌图县| 洮南市| 舞阳县| 上栗县| 镇宁| 台前县| 乐昌市| 崇仁县| 扬州市| 河北区| 舞钢市| 永康市| 宜君县| 景泰县| 齐河县| 南昌市| 施甸县| 永新县| 南开区| 剑阁县| 佳木斯市| 美姑县|