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

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.

主站蜘蛛池模板: 中西区| 五家渠市| 桐城市| 浦北县| 醴陵市| 富宁县| 佛坪县| 香河县| 公安县| 定西市| 沙田区| 涿州市| 左权县| 冀州市| 扎鲁特旗| 保德县| 大田县| 白水县| 高平市| 安图县| 林西县| 屏东市| 乌恰县| 拉萨市| 资源县| 诸城市| 北票市| 都兰县| 临湘市| 青浦区| 桐梓县| 嘉善县| 庐江县| 资溪县| 霍州市| 惠州市| 锦屏县| 阿尔山市| 邵阳县| 陇川县| 辽阳县|