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

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.

主站蜘蛛池模板: 彰化县| 平南县| 凌海市| 长子县| 昌吉市| 景东| 武胜县| 三亚市| 芷江| 营山县| 磐石市| 区。| 高密市| 密云县| 交口县| 石阡县| 曲阳县| 揭阳市| 乃东县| 平度市| 阳春市| 灯塔市| 湖南省| 新民市| 萨嘎县| 中西区| 松阳县| 安顺市| 凤城市| 师宗县| 永清县| 奈曼旗| 同德县| 宁津县| 松江区| 东平县| 阜平县| 安多县| 靖远县| 万山特区| 禹城市|