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

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.

主站蜘蛛池模板: 马龙县| 屯留县| 阜城县| 梁山县| 海丰县| 毕节市| 保靖县| 武安市| 东丽区| 兴和县| 庄河市| 奉化市| 凌海市| 定结县| 清新县| 绥化市| 芷江| 博罗县| 常熟市| 辽中县| 祥云县| 灵璧县| 额济纳旗| 乌鲁木齐县| 扎囊县| 辽宁省| 弋阳县| 佛学| 确山县| 汽车| 临清市| 英德市| 广东省| 南部县| 崇州市| 灵山县| 西充县| 石家庄市| 寿光市| 陆川县| 高青县|