当前位置:网站首页>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
边栏推荐
猜你喜欢
leetcode-399:除法求值
Tower of Hanoi problem
vlan间路由+静态路由+NAT(PAT+静态NAT)综合实验
Interprocess communication study notes
进程间通信学习笔记
Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化
What have I experienced to become a tester who is harder than development?
《云原生的本手、妙手和俗手》——2022全国新高考I卷作文
Overview of prometheus monitoring
leetcode-399: division evaluation
随机推荐
mysql 索引
Between two orderly array of additive and Topk problem
Software Testing Defect Reporting - Definition, Composition, Defect Lifecycle, Defect Tracking Post-Production Process, Defect Tracking Process, Purpose of Defect Tracking, Defect Management Tools
Fiddler抓包模拟弱网络环境测试
Chi-square distribution of digital image steganography
Tower of Hanoi problem
Programmer's debriefing report/summary
GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
【flask入门系列】Flask-SQLAlchemy的使用
kotlin中函数作为参数和函数作为返回值实例练习
Simple confession page
MySQL (6)
SQLserver查询最近三个月的数据,语句该怎么写sqlserver
Inner monologue from a female test engineer...
用户交互+格式化输出
力扣刷题之有效的正方形(每日一题7/29)
Force buckled brush the stairs (7/30)
VSCode插件:嵌套注释
Nacos
cudaMemcpy学习笔记