当前位置:网站首页>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
边栏推荐
猜你喜欢

Kyushu cloud as cloud computing standardization excellent member unit

leetcode-399:除法求值

Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"

Crypto Life, a day in the life of a Web3 project partner

MySQL stored procedure

软件测试要达到一个什么水平才能找到一份9K的工作?

两个有序数组间相加和的Topk问题
![CV-Model [3]: MobileNet v2](/img/c7/1155a1f610110724c67a3b7557ef28.jpg)
CV-Model [3]: MobileNet v2
![[Map and Set] LeetCode & Niu Ke exercise](/img/66/d812a6ad854cb0993c796760042150.png)
[Map and Set] LeetCode & Niu Ke exercise

曼城推出可检测情绪的智能围巾,把球迷给整迷惑了
随机推荐
uniapp使用第三方字体
基于FPGA的售货机
keep-alive cache component
Shell script to loop through values in log file to sum and calculate average, max and min
pc端判断当前使用浏览器类型
MySQL (6)
加密生活,Web3 项目合伙人的一天
C语言小程序 -- 常见经典练习题
VSCode插件:嵌套注释
手把手教你配置Jenkins自动化邮件通知
MySQL的存储过程
【微信小程序】一文带你了解数据绑定、事件绑定以及事件传参、数据同步
《MySQL数据库进阶实战》读后感(SQL 小虚竹)
软件测试报告有哪些内容?
Drools WorkBench的简介与使用
leetcode-128:最长连续序列
Likou Daily Question - Day 46 - 704. Binary Search
蛮力法/邻接矩阵 广度优先 有向带权图 无向带权图
12 pictures take you to fully understand service current limit, circuit breaker, downgrade, and avalanche
观察者(observer)模式(一)