当前位置:网站首页>cudaMemcpy study notes
cudaMemcpy study notes
2022-07-31 01:51:00 【AI Vision Network】
The host is the computer Host
Device is the gpu device.
cudaMemcpy is used to transfer data back and forth between the host (Host) and the device (Device), the usage is as follows:
Host to Device: cudaMemcpy(d_A,h_A,nBytes,cudaMemcpyHostToDevice)
Device to host: cudaMemcpy(h_A,d_A,nBytes,cudaMemcpyDeviceToHost)
Note: This function is a synchronous execution function. It will be locked before the data transfer operation is completed and will always occupy the control of the CPU process, so there is no need to add the cudaDeviceSynchronize() function.
Example:
void VectorReal_copyBuffer(realVecHandle* addr, float hostArr[], long buffer, bool tohost, int copyMode){realVecHandle * native =addr;float * host = hostArr;if ( copyMode == 0 ) {if (!tohost) {cudaMemcpy( native->data,host, native->size, cudaMemcpyHostToDevice) ;} else {cudaMemcpy( host, native->data, native->size, cudaMemcpyDeviceToHost) ;}}}//Allocate space on video memory
CUDA_SAFE_CALL(cudaMalloc((void**)&Dst_d,sizeof(float3) * totalPNum));
//Transfer data on video memory
CUDA_SAFE_CALL(cudaMemcpy(Dst_d, Srcdata0_h, sizeof(float3) * numdata0, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMemcpy(Dst_d + numpoint0, Srcdata1_d, sizeof(float3) * numdata1, cudaMemcpyDeviceToDevice));
CUDA_SAFE_CALL(cudaMemcpy(Dst_d + numpoint0 + numpoint1, Srcdata2_d, sizeof(float3) * numdata2, cudaMemcpyDeviceToDevice));
During the data transmission process, the destination address is before the source address (the address may have an offset calculation, when the data source has the same purpose for different data sources), corresponding to the latter parameter, devicetohost or hosttodevice.
Original link: https://blog.csdn.net/xiaoheibaqi/article/details/44001273
边栏推荐
- 成为比开发硬气的测试人,我都经历了什么?
- 华为od 转骰子 js
- 聚簇索引和非聚簇索引到底有什么区别
- 程序员转正述职报告/总结
- Teach you how to configure Jenkins automated email notifications
- case语句的综合结果,你究竟会了吗?【Verilog高级教程】
- "Cloud native's master, master and vulgar skills" - 2022 National New College Entrance Examination Volume I Composition
- 真正的CTO,是一个懂产品的技术人
- MySQL installation tutorial (detailed, package teaching package~)
- Shell script to loop through values in log file to sum and calculate average, max and min
猜你喜欢

VSCode插件:嵌套注释

leetcode-952:按公因数计算最大组件大小

leetcode-1161: Maximum in-layer element sum

uniapp uses 3rd party fonts

Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化

leetcode-399: division evaluation

1782. Count the number of point pairs Double pointer

Word 表格跨页,仍然显示标题

What are the project management tools like MS Project

进程间通信学习笔记
随机推荐
[WeChat applet] This article takes you to understand data binding, event binding, event parameter transfer, and data synchronization
pycharm重命名后无法运行(报错: can‘t open file......No such file or directory)
勾股数元组 od js
VSCode插件:嵌套注释
太阳能板最大面积 od js
Chi-square distribution of digital image steganography
link与@import的区别
什么是理想的大学生活?
MySQL installation tutorial (detailed, package teaching package~)
蛮力法/邻接矩阵 广度优先 有向带权图 无向带权图
程序员转正述职报告/总结
leetcode-399: division evaluation
I have been working in software testing for 3 years, how did I go from just getting started to automated testing?
两个有序数组间相加和的Topk问题
Drools基本介绍,入门案例,基本语法
rpm安装postgresql12
What have I experienced to become a tester who is harder than development?
第一学年课程期末考试
Are you still working hard on the limit of MySQL paging?
Software testing basic interface testing - getting started with Jmeter, you should pay attention to these things