我现在正在学习boost::compute开源OpenCL封装库。
我发现复制过程非常缓慢。
如果我们将CPU到CPU的复制速度比例设为1,那么GPU到CPU、GPU到GPU和CPU到GPU的复制速度有多快?
我不需要精确的数字,只需要一个大致的概念就可以了。例如,CPU到CPU至少比GPU到GPU快10倍。
我现在正在学习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
我希望这个测试程序能让任何人受益。
ram_location1到ram_location2和ram_location2到ram_location3
是否比ram_location1到vram_location1和vram_location1到ram_location2
更快。然而,我仍然不确定。我关心的是骁龙865。 - zeitgeist