在 GPU 和 CPU 中运行矩阵乘法时,我得到了相同的结果。
这是我的代码:。
viennacl::ocl::set_context_platform_index(1, 1);
viennacl::ocl::set_context_platform_index(0, 0);
viennacl::ocl::switch_context(0);
std::cout << "--- Computing matrix-matrix product using viennacl in GPU ---" << std::endl;
timer.start();
vcl_C = viennacl::linalg::prod(vcl_A, vcl_B);
exec_time = timer.get();
std::cout << " - Execution time: " << exec_time << std::endl;
std::cout << "result on GPU: "<<viennacl::ocl::current_device().name() << std::endl;
//same operation on CPU
std::cout << "coming here" << std::endl;
viennacl::ocl::switch_context(1);
std::cout << "--- Computing matrix-matrix product using viennacl in CPU ---" << std::endl;
timer.start();
vcl_C = viennacl::linalg::prod(vcl_A, vcl_B);
exec_time = timer.get();
std::cout << " - Execution time: " << exec_time << std::endl;
std::cout << "result on CPU: " << viennacl::ocl::current_device().name() << std::endl << std::endl;
这是我的结果:
--- Computing matrix-matrix product using viennacl in GPU ---
- Execution time: 24.4675
result on GPU: GeForce GTX 1080
coming here
--- Computing matrix-matrix product using viennacl in CPU ---
- Execution time: 24.4654
result on CPU: Intel(R) Xeon(R) CPU E3-1225 v5 @ 3.30GHz
请帮我解决这个问题。提前致谢