当前位置:网站首页>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
边栏推荐
猜你喜欢
【Map与Set】之LeetCode&牛客练习
最高月薪20K?平均薪资近万...在华为子公司工作是什么体验?
What are the project management tools like MS Project
Google官方控件ShapeableImageView使用
Fiddler captures packets to simulate weak network environment testing
软件测试基础接口测试-入门Jmeter,你要注意这些事
【微信小程序】一文带你了解数据绑定、事件绑定以及事件传参、数据同步
1782. Count the number of point pairs Double pointer
Unity界面总体介绍
成为比开发硬气的测试人,我都经历了什么?
随机推荐
leetcode-952: Calculate max component size by common factor
Multiplication, DFS order
STP选举(步骤+案列)详解
Set the browser scrollbar style
vlan间路由+静态路由+NAT(PAT+静态NAT)综合实验
keep-alive缓存组件
MySQL installation tutorial (detailed, package teaching package~)
How to expose Prometheus metrics in go programs
两个有序数组间相加和的Topk问题
934. The Shortest Bridge
link与@import的区别
SQLserver查询最近三个月的数据,语句该怎么写sqlserver
leetcode-1161: Maximum in-layer element sum
pycharm cannot run after renaming (error: can't open file...No such file or directory)
勾股数元组 od js
如何在 go 程序中暴露 Prometheus 指标
Path and the largest
MySQL (6)
Overview of prometheus monitoring
Software Testing Defect Reporting - Definition, Composition, Defect Lifecycle, Defect Tracking Post-Production Process, Defect Tracking Process, Purpose of Defect Tracking, Defect Management Tools