我现在正在学习 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 却很慢。
(我的系统是 Intel I3 和 Intel(R) HD Graphics Skylake ULT GT2。)
也许并行处理是一回事,复制速度是另一回事。
cpu2cpu cp 7549776
cpu2gpu cp 18707268
GPU2GPU CP 65841100
gpu2cpu cp 65803119
我希望任何人都能从这个测试程序中受益。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)