0

我目前正在使用 GPU 的 boost.compute 库编写一个经过调整的点积内核。我只想使用一个内核调用,使用 transform_reduce。我的目标是计算 (x+y)(xy) 的点积,其中 x,y 是等长向量。

'''

namespace compute = boost::compute;

BOOST_COMPUTE_FUNCTION(double, pppm, (double x, double y),
{
    return (x+y)*(x-y);
});

void dotproduct(int N, compute::context context, compute::command_queue queue){
    Timer timer; 
    std::vector<double> timings;

    std::vector<double> host_x(N, 1.0), host_y(N, 2.0);

    // create a vector on the device
    compute::vector<double> dev_x(host_x.size(), context);
    compute::vector<double> dev_y(host_y.size(), context);

    // transfer data from the host to the device
    compute::copy(host_x.begin(), host_x.end(), dev_x.begin(), queue);
    compute::copy(host_y.begin(), host_y.end(), dev_y.begin(), queue);

    double result = 0.0;
    compute::transform_reduce(dev_x.begin(), dev_x.end(), dev_y.begin(), &result, pppm, compute::plus<double>(), queue);
    std::cout << result << std::endl; 


}'''

然而我得到一个奇怪的错误:

/usr/include/boost/compute/algorithm/transform.hpp:69:5:错误:静态断言失败:is_device_iterator::value 69 | BOOST_STATIC_ASSERT(is_device_iterator::value);

有人可以告诉我这里有什么问题吗?

4

0 回答 0