我用cudaMemcpy()一次将1GB的数据准确复制到设备上.这需要5.9秒.反过来需要5.1s.这是正常的吗?
在复制之前,函数本身是否有这么多开销?理论上,PCIe总线的吞吐量至少应为4GB/s.
没有内存传输重叠,因为特斯拉C870不支持它.任何提示?
编辑2:我的测试程序+更新的时间; 我希望阅读不是太多!
该cutCreateTimer()功能不会编译我:"错误:标识符'cutCreateTimer’不确定" -这可能与安装在计算机上的旧版本的CUDA(2.0)
__host__ void time_int(int print){
static struct timeval t1; /* var for previous time stamp */
static struct timeval t2; /* var of current time stamp */
double time;
if(gettimeofday(&t2, 0) == -1) return;
if(print != 0){
time = (double) (t2.tv_sec - t1.tv_sec) + ((double) (t2.tv_usec - t1.tv_usec)) / 1000000.0;
printf(...);
}
t1 = t2;
}
main:
time(0);
void *x;
cudaMallocHost(&x,1073741824);
void *y;
cudaMalloc(&y, 1073741824);
time(1);
cudaMemcpy(y,x,1073741824, cudaMemcpyHostToDevice);
time(1);
cudaMemcpy(x,y,1073741824, …Run Code Online (Sandbox Code Playgroud) 我在循环中使用以下代码将大约6000个文本文件读入内存:
void readDocs(const char *dir, char **array){
DIR *dp = opendir(dir);;
struct dirent *ep;
struct stat st;
static uint count = 0;
if (dp != NULL){
while (ep = readdir(dp)){ // crawl through directory
char name[strlen(dir) + strlen(ep->d_name) + 2];
sprintf(name, "%s/%s", dir, ep->d_name);
if(ep->d_type == DT_REG){ // regular file
stat(name, &st);
array[count] = (char*) malloc(st.st_size);
int f;
if((f = open(name, O_RDONLY)) < 0) perror("open: ");
read(f, array[count], st.st_size));
if(close(f) < 0) perror("close: ");
++count;
}
else if(ep->d_type == DT_DIR …Run Code Online (Sandbox Code Playgroud) 为了估计程序在一次内核启动时可以处理多少数据,我尝试获取一些内存信息cudaMemGetInfo().但是,编译器告诉我这个:
错误:标识符"cudaMemGetInfo"未定义
其他函数如cudaGetDeviceProperties();工作正常.我是否必须安装某个CUDA版本?该库的描述不包含版本等相关信息.
编辑:尽可能小的代码.cudaSetDevice()而不会产生编译器错误cudaMemGetInfo()呢
#include <cuda.h>
#include <cuda_runtime_api.h>
int main(){
unsigned int f, t;
cudaSetDevice(0);
cudaMemGetInfo(&f, &t);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编辑2:
我在Linux上使用"Cuda编译工具,版本2.0,V0.2.1221"(nvcc).
因为我试图安装cuda驱动程序版本cudaDriverGetVersion()时发生了同样的错误(当我使用驱动程序函数时同样的事情cuDriverGetVersion()).
系统似乎不会让我知道任何有关自身的细节......
在OpenCV库中有一个
typedef const _InputArray& InputArray;
Run Code Online (Sandbox Code Playgroud)
在我们的代码中,我们有以下函数定义:
void wimshow(const String& winName, InputArray &img) {
Run Code Online (Sandbox Code Playgroud)
编译时会发生以下错误:
error: cannot declare reference to 'cv::InputArray {aka const class cv::_InputArray&}'
void wimshow(const String& winName, InputArray &img) {
奇怪的是,只有在Cray环境中使用GCC 4.8.1才会出现此错误.在具有GCC 4.8.1的普通Linux环境中进行编译可以正常工作.
乍一看,我会说对引用类型的引用无论如何都不是很有意义,但我很好奇什么可能导致不同的编译器行为!?