内存复制速度比较CPU<->GPU [英] Memory copy speed comparison CPU<->GPU

查看:4
本文介绍了内存复制速度比较CPU<->GPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在学习Boost::Compute OpenCL包装库。 我遇到复制过程非常慢的问题。

如果我们将CPU到CPU的复制速度调整为1,那么GPU到CPU、GPU到GPU、CPU到GPU的复制速度有多快?

我不需要精确的数字。仅仅是一个大概的想法就会有很大的帮助。例如,CPU-CPU至少比GPU-GPU快10倍。

推荐答案

没有人回答我的问题。 所以我写了一个程序来检查复印速度。

#include<vector>
#include<chrono>
#include<algorithm>
#include<iostream>
#include<boost/compute.hpp>
namespace compute = boost::compute;
using namespace std::chrono;
using namespace std;

int main()
{
    int sz = 10000000;
    std::vector<float> v1(sz, 2.3f), v2(sz);
    compute::vector<float> v3(sz), v4(sz);

    auto s = system_clock::now();
    std::copy(v1.begin(), v1.end(), v2.begin());
    auto e = system_clock::now();
    cout << "cpu2cpu cp " << (e - s).count() << endl;

    s = system_clock::now();
    compute::copy(v1.begin(), v1.end(), v3.begin());
    e = system_clock::now();
    cout << "cpu2gpu cp " << (e - s).count() << endl;

    s = system_clock::now();
    compute::copy(v3.begin(), v3.end(), v4.begin());
    e = system_clock::now();
    cout << "gpu2gpu cp " << (e - s).count() << endl;

    s = system_clock::now();
    compute::copy(v3.begin(), v3.end(), v1.begin());
    e = system_clock::now();
    cout << "gpu2cpu cp " << (e - s).count() << endl;
    return 0;
}

我预计gpu2gpu的复制速度会很快。 但恰恰相反,在我的情况下,cpu2cpu是最快的,而gpu2gpu太慢了。 (我的系统是英特尔i3和英特尔(R)高清显卡Skylake ULT GT2。) 也许并行处理是一回事,复制速度是另一回事。

cpu2cpucp 7549776
Cpu2gpucp 18707268
Gpu2gpucp 65841100
Gpu2cpucp 65803119

我希望任何人都能从此测试程序中受益。

这篇关于内存复制速度比较CPU&lt;-&gt;GPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆