拷贝时间测试=cudamelloc+cudahostalloc
/*
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property and
* proprietary rights in and to this software and related documentation.
* Any use, reproduction, disclosure, or distribution of this software
* and related documentation without an express license agreement from
* NVIDIA Corporation is strictly prohibited.
*
* Please refer to the applicable NVIDIA end user license agreement (EULA)
* associated with this source code for terms and conditions that govern
* your use of this NVIDIA software.
*
*/ #include "../common/book.h"
#include <cuda.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#define SIZE (64*1024*1024) float cuda_malloc_test(int size, bool up) {
cudaEvent_t start, stop;
int *a, *dev_a;
float elapsedTime; HANDLE_ERROR(cudaEventCreate(&start));
HANDLE_ERROR(cudaEventCreate(&stop)); a = (int*)malloc(size * sizeof(*a));
HANDLE_NULL(a);
HANDLE_ERROR(cudaMalloc((void**)&dev_a,
size * sizeof(*dev_a))); HANDLE_ERROR(cudaEventRecord(start, ));
for (int i = ; i<; i++) {
if (up)
HANDLE_ERROR(cudaMemcpy(dev_a, a,
size * sizeof(*dev_a),
cudaMemcpyHostToDevice));
else
HANDLE_ERROR(cudaMemcpy(a, dev_a,
size * sizeof(*dev_a),
cudaMemcpyDeviceToHost));
}
HANDLE_ERROR(cudaEventRecord(stop, ));
HANDLE_ERROR(cudaEventSynchronize(stop));
HANDLE_ERROR(cudaEventElapsedTime(&elapsedTime,
start, stop)); free(a);
HANDLE_ERROR(cudaFree(dev_a));
HANDLE_ERROR(cudaEventDestroy(start));
HANDLE_ERROR(cudaEventDestroy(stop)); return elapsedTime;
} float cuda_host_alloc_test(int size, bool up) {
cudaEvent_t start, stop;
int *a, *dev_a;
float elapsedTime; HANDLE_ERROR(cudaEventCreate(&start));
HANDLE_ERROR(cudaEventCreate(&stop)); HANDLE_ERROR(cudaHostAlloc((void**)&a,
size * sizeof(*a),
cudaHostAllocDefault));
HANDLE_ERROR(cudaMalloc((void**)&dev_a,
size * sizeof(*dev_a))); HANDLE_ERROR(cudaEventRecord(start, ));
for (int i = ; i<; i++) {
if (up)
HANDLE_ERROR(cudaMemcpy(dev_a, a,
size * sizeof(*a),
cudaMemcpyHostToDevice));
else
HANDLE_ERROR(cudaMemcpy(a, dev_a,
size * sizeof(*a),
cudaMemcpyDeviceToHost));
}
HANDLE_ERROR(cudaEventRecord(stop, ));
HANDLE_ERROR(cudaEventSynchronize(stop));
HANDLE_ERROR(cudaEventElapsedTime(&elapsedTime,
start, stop)); HANDLE_ERROR(cudaFreeHost(a));
HANDLE_ERROR(cudaFree(dev_a));
HANDLE_ERROR(cudaEventDestroy(start));
HANDLE_ERROR(cudaEventDestroy(stop)); return elapsedTime;
} int main(void) {
float elapsedTime;
float MB = (float) * SIZE*sizeof(int) / / ; // try it with cudaMalloc
elapsedTime = cuda_malloc_test(SIZE, true);
printf("Time using cudaMalloc: %3.1f ms\n",
elapsedTime);
printf("\tMB/s during copy up: %3.1f\n",
MB / (elapsedTime / )); elapsedTime = cuda_malloc_test(SIZE, false);
printf("Time using cudaMalloc: %3.1f ms\n",
elapsedTime);
printf("\tMB/s during copy down: %3.1f\n",
MB / (elapsedTime / )); // now try it with cudaHostAlloc
elapsedTime = cuda_host_alloc_test(SIZE, true);
printf("Time using cudaHostAlloc: %3.1f ms\n",
elapsedTime);
printf("\tMB/s during copy up: %3.1f\n",
MB / (elapsedTime / )); elapsedTime = cuda_host_alloc_test(SIZE, false);
printf("Time using cudaHostAlloc: %3.1f ms\n",
elapsedTime);
printf("\tMB/s during copy down: %3.1f\n",
MB / (elapsedTime / ));
}
项目打包下载
拷贝时间测试=cudamelloc+cudahostalloc的更多相关文章
- 用于.NET环境的时间测试(转)
用于.NET环境的时间测试 在.NET环境中,衡量运行完整算法所花费的时间长度,需要考虑很多 需要考虑很多种情况 ,如:程序运行所处的线程以及无用单位收集(GC垃圾回收). 在程序执行过程中无用单 ...
- 使用拷贝文件测试(BufferedInputStream,FileInputStream)
package com.demo; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ja ...
- 数据结构和算法 – 番外篇.时间测试类Timing
public class Timing { //startingTime--用来存储正在测试的代码的开始时间. TimeSpan startingTime; //duration--用来存储正在测试的 ...
- Linux 目录操作和4中文件拷贝效率测试
/*1.用户输入任意目录名称,显示该目录下的文件列表信息,包括文件类型,文件权限,文件大小,文件名称2.拷贝用户输入的文件到当前目录下3.第二点功能,使用4种方式完成,并比较说明效率*/ /* str ...
- R︱Rstudio 1.0版本尝鲜(R notebook、下载链接、sparkR、代码时间测试profile)
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 2016年11月1日,RStudio 1.0版 ...
- 关于Java中的HashMap的深浅拷贝的测试与几点思考
0.前言 工作忙起来后,许久不看算法,竟然DFA敏感词算法都要看好一阵才能理解...真是和三阶魔方还原手法一样,田园将芜,非常可惜啊. 在DFA算法中,第一步是需要理解它的数据结构,在此基础上,涉及到 ...
- C#下的时间测试(用于计算方法执行时间)
public class Timing { private TimeSpan m_StartTime; private TimeSpan duringTime; public Timing() //构 ...
- USACO1.5Superprime Rid[附带关于素数算法时间测试]
题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们.农民约翰确定他卖给买方的是真正的质数肋骨,是因为从右边开始切下肋骨,每次还剩下的肋骨上的数字都组 ...
- Unity-Animator深入系列---StateMachineBehaviour初始化时间测试
回到 Animator深入系列总目录 结果和想的有点出入 测试结果: 1.SMB初始化会被调用多次,次数不可控,当Animator组件重复开关则重复初始化. 2.SMB支持构造函数 MyClass p ...
随机推荐
- Mybatis插件Plugin
Mybatis开源Plugin中最熟知的pagehelper,重点made in China 很多人开始用pagehelper时候,肯定很纳闷,以mysql为例,明明没有加limit语句,为什么打印出 ...
- 记录在APIO2019前
2019-05-07 嗯, 只报名参加了APIO. 今天是五月七号,距离前往帝都参加我的退役之战, 还有八天(5.15) 然后没什么可说的, 就是记录一下这几天吧. 今天下午去学了虚树(其实没什么的) ...
- ldap第二天-yum安装LDAP + phpLDAPadmin
1.安装LDAP服务器和客户端,migrationtools工具包 yum install -y openldap-servers openldap-clients migrationtools 2. ...
- Vue中全局导入和按需导入的区别
export {router} //按需导出 import {router} from './router' //按需导入路由模块 export default //全局导出store模块 store ...
- 关于webpack的版本导致的postcss-loader的问题
来源自问题 https://segmentfault.com/q/1010000006987956 !!!发现这解决方案还是不能用,估计是webpack又更新了一轮,请看看下下方的答案 某个版本web ...
- 4、python数据类型之列表(list)
列表列表常见操作1.索引取值 name_list = ['wang','zhou','li','hu','wu','zhao'] print(name_list[0]) print(name_list ...
- python之Selenium库的使用
一 什么是Selenium selenium 是一套完整的web应用程序测试系统,包含了测试的录制(selenium IDE),编写及运行(Selenium Remote Control)和测试的并 ...
- 74th LeetCode Weekly Contest Valid Tic-Tac-Toe State
A Tic-Tac-Toe board is given as a string array board. Return True if and only if it is possible to r ...
- 使用tortoise git将一个现有项目推送到远程仓库
一.安装文件: 1.git https://git-scm.com/downloads 2.tortoise git https://tortoisegit.org/download/ 二.将一个现有 ...
- Arduino连接pH计
关于arduino连接ph,核心的东西就是对ph传感器返回的信号值进行一系列的操作,注意因为返回的信号很弱,而且外部环境对其影响也很大,所以需要在电路设计上加入一些功能,比如信号放大.滤波等,电路设计 ...