【问题标题】:Memory copy speed comparison CPU<->GPU内存拷贝速度对比 CPU<->GPU
【发布时间】:2018-05-18 20:03:18
【问题描述】:

我现在正在学习 boost::compute openCL 包装库。 我的复制过程非常缓慢。

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

我不需要精确的数字。只是一个一般的想法将是一个很大的帮助。例如,CPU-CPU 至少比 GPU-GPU 快 10 倍。

【问题讨论】:

  • 完全取决于您的硬件设置和软件技术,但如果做得好应该在 40% 到 90% 的 PCIe 带宽内,前提是您的传输足够大(以及许多其他因素,包括您的GPU 位于 16 通道插槽中)。如果我没记错的话,我看到大约 5-6 GB/s。

标签: opencl gpu memcpy boost-compute


【解决方案1】:

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

#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 太慢了。 (我的系统是 Intel I3 和 Intel(R) HD Graphics Skylake ULT GT2。) 也许并行处理是一回事,复制速度是另一回事。

cpu2cpu cp 7549776
cpu2gpu cp 18707268
gpu2gpu cp 65841100
gpu2cpu cp 65803119

我希望任何人都可以从这个测试程序中受益。

【讨论】:

  • 如果我没记错的话,Intel HD Graphics Skylake 没有显存,而是与 CPU 共享内存。比较不同系统上的结果会很有趣。
  • stackoverflow 需要改进。
猜你喜欢
  • 2019-04-18
  • 2015-12-27
  • 2012-04-19
  • 1970-01-01
  • 2015-09-23
  • 1970-01-01
  • 2012-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多