- Hands-On GPU:Accelerated Computer Vision with OpenCV and CUDA
- Bhaumik Vaidya
- 158字
- 2021-08-13 15:48:21
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.
- HTML5+CSS3王者歸來
- Visual C++程序設計學習筆記
- Android應用程序開發與典型案例
- JavaScript語言精髓與編程實踐(第3版)
- C語言程序設計(第2版)
- Offer來了:Java面試核心知識點精講(原理篇)
- JavaScript+jQuery開發實戰
- 碼上行動:零基礎學會Python編程(ChatGPT版)
- jQuery從入門到精通 (軟件開發視頻大講堂)
- Scratch 3游戲與人工智能編程完全自學教程
- 手把手教你學C語言
- Learning FuelPHP for Effective PHP Development
- 深入分布式緩存:從原理到實踐
- Microsoft Azure Storage Essentials
- 愛上micro:bit