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

Passing parameters by value

If you recall, in the gpuAdd program, the syntax for calling the kernel was as follows:

gpuAdd << <1,1> >>(1,4,d_c)

On the other hand, the signature of the gpuAdd function in definition was as follows:

__global__  gpuAdd(int d_a, int d_b, int *d_c) 

So, you can see that we are passing values of d_a and d_b while calling the kernel. First, parameter 1 will be copied to d_a and then parameter 4 will be copied to d_b while calling the kernal. The answer after addition will be stored at the address pointed by d_c on device memory. Instead of directly passing values 1 and 4 as inputs to the kernel, we can also write the following:

gpuAdd << <1,1> >>(a,b,d_c)

Here, a and b are integer variables that can contain any integer values. Passing parameters by values is not recommended, as it creates unnecessary confusion and complications in programs. It is better to pass parameters by reference.

主站蜘蛛池模板: 应城市| 邢台市| 互助| 怀宁县| 鄂伦春自治旗| 永济市| 始兴县| 乌恰县| 辽宁省| 山东省| 东方市| 溆浦县| 崇左市| 申扎县| 龙里县| 遵义县| 腾冲县| 皮山县| 丹东市| 海淀区| 贵港市| 靖宇县| 凤山市| 泊头市| 额尔古纳市| 临沂市| 贡山| 清徐县| 板桥市| 永昌县| 澄迈县| 政和县| 布尔津县| 都安| 汕头市| 新巴尔虎左旗| 玉田县| 南部县| 湖口县| 柯坪县| 双鸭山市|