当前位置:网站首页>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
边栏推荐
- pycharm重命名后无法运行(报错: can‘t open file......No such file or directory)
- [1154]如何将字符串转换为datetime
- MySQL (6)
- Nacos
- 充电效果模拟
- C language applet -- common classic practice questions
- 1782. Count the number of point pairs Double pointer
- rpm安装postgresql12
- Likou Daily Question - Day 46 - 704. Binary Search
- Jetpack Compose学习(8)——State及remeber
猜你喜欢

STP选举(步骤+案列)详解

Software testing basic interface testing - getting started with Jmeter, you should pay attention to these things

MySQL installation tutorial (detailed, package teaching package~)

力扣刷题之爬楼梯(7/30)

case语句的综合结果,你究竟会了吗?【Verilog高级教程】

力扣刷题之有效的正方形(每日一题7/29)

内网渗透——提权

JPEG Steganalysis of Digital Image Steganography

系统需求多变如何设计

pycharm重命名后无法运行(报错: can‘t open file......No such file or directory)
随机推荐
第一学年课程期末考试
12张图带你彻底搞懂服务限流、熔断、降级、雪崩
leetcode-1161:最大层内元素和
ROS Action communication
What does a software test report contain?
Arbitrum 专访 | L2 Summer, 脱颖而出的 Arbitrum 为开发者带来了什么?
VSCode Plugin: Nested Comments
multiplayer-hlap 包有问题,无法升级的解决方案
Fiddler captures packets to simulate weak network environment testing
Force buckled brush the stairs (7/30)
Crypto Life, a day in the life of a Web3 project partner
Overview of prometheus monitoring
leetcode-1161: Maximum in-layer element sum
keep-alive缓存组件
内网渗透——提权
CV-Model【3】:MobileNet v2
Maximum monthly salary of 20K?The average salary is nearly 10,000... What is the experience of working in a Huawei subsidiary?
系统需求多变如何设计
pycharm cannot run after renaming (error: can't open file...No such file or directory)
Software Testing Defect Reporting - Definition, Composition, Defect Lifecycle, Defect Tracking Post-Production Process, Defect Tracking Process, Purpose of Defect Tracking, Defect Management Tools