我想像下面一样一起使用boost::compute and boost::range
,但是如果我取消对#include <boost/range/combine.hpp>
行的注释,我会收到一条错误消息,指出boost::compute::zip_iterator
和boost::iterators::zip_iterator
含糊不清。有没有办法解决这个问题,以便我可以在同一cpp文件中一起使用boost::compute
和boost::range
?我在Windows vs2015 64位上使用。提升1.67.0。
更新:我发现如果尝试包含boost/iterator/zip_iterator.hpp
而不是boost/range/combine.hpp
,则会发生相同的错误,因此它不是特定于Boost Range库的。
代码:
#include <vector>
#include <iostream>
#include <algorithm>
//#include <boost/range/combine.hpp>
#include <boost/compute/lambda.hpp>
#include <boost/compute/functional/math.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/algorithm/transform.hpp>
namespace compute = boost::compute;
using compute::float4_;
using compute::lambda::_1;
using compute::lambda::_2;
using compute::lambda::distance;
int main()
{
// get default device and setup context
compute::device device = compute::system::default_device();
compute::context context(device);
compute::command_queue queue(context, device);
// generate random data on the host
std::vector<float4_> a(10000);
std::vector<float4_> b(10000);
std::vector<float> r(10000);
std::generate((float*)a.data(), (float*)(a.data() + a.size()), rand);
std::generate((float*)b.data(), (float*)(b.data() + b.size()), rand);
// create a vector on the device
compute::vector<float4_> _a(a.size(), context);
compute::vector<float4_> _b(b.size(), context);
compute::vector<float> _r(r.size(), context);
// transfer data from the host to the device
compute::copy(a.begin(), a.end(), _a.begin(), queue);
compute::copy(b.begin(), b.end(), _b.begin(), queue);
boost::compute::transform(
_a.begin(), _a.end(),
_b.begin(),
_r.begin(),
distance(_1, _2),
queue
);
// copy values back to the host
compute::copy(_r.begin(), _r.end(), r.begin(), queue);
for (int i = 0; i < a.size(); ++i)
{
float4_ va = a[i];
float4_ vb = b[i];
float vr = r[i];
float e = std::sqrt(std::pow(va[0] - vb[0], 2) +
std::pow(va[1] - vb[1], 2) +
std::pow(va[2] - vb[2], 2) +
std::pow(va[3] - vb[3], 2));
std::cout << std::setprecision(12);
if (std::abs(e - vr) > 1e-2)
std::cout << e << " != " << vr << "\n";
}
return 0;
}
错误:
1> ------开始构建:项目:演示,配置:调试x64 ------ 1> demo.cpp 1>此标头是实现细节,并提供给 向后兼容。 1> C:\ local \ boost_1_67_0 \ boost / compute / algorithm / transform.hpp(67): 错误C2668:'boost :: compute :: make_zip_iterator':模棱两可的调用 重载功能1> C:\ local \ boost_1_67_0 \ boost / compute / iterator / zip_iterator.hpp(276): 注意:可能是 'boost :: compute :: zip_iterator,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type >> boost :: compute :: make_zip_iterator,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost: :tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type >>(IteratorTuple)' 1>与1> [1>
T = boost :: compute :: float4_,1>
IteratorTuple = boost :: tuples :: tuple,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type, boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type> 1>] 1> C:\ local \ boost_1_67_0 \ boost / iterator / zip_iterator.hpp(357):注意:或
'boost :: iterators :: zip_iterator,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type >> boost :: iterators :: make_zip_iterator,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost: :tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type >>(IteratorTuple)' [使用与参数相关的查找发现] 1>与1> [ 1> T = boost :: compute :: float4_,1>
IteratorTuple = boost :: tuples :: tuple,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type, boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type> 1>] 1> C:\ local \ boost_1_67_0 \ boost / compute / algorithm / transform.hpp(67):注意: 在尝试匹配参数列表时 '(boost :: tuples :: tuple,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type, boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type>)' 1>与1> [1>
T = boost :: compute :: float4_ 1>] 1> C:\ workspaces \ compute_test \ src \ demo.cpp(45):注意:请参阅参考 函数模板实例化'OutputIterator boost :: compute :: transform,boost :: compute :: buffer_iterator,boost :: compute :: buffer_iterator,boost :: compute :: lambda :: expression>(InputIterator1,InputIterator1,InputIterator2,OutputIterator,BinaryOperator,boost :: compute :: command_queue &)'正在被1>编译为1> [1>
OutputIterator = boost :: compute :: buffer_iterator,1>
T = boost :: compute :: float4_,1>
Expr = boost :: proto :: exprns _ :: basic_expr,0 >>,const boost :: compute :: lambda :: expression>,0 >> &,const boost :: compute :: lambda :: expression>,0 >> &>,3>,1>
InputIterator1 = boost :: compute :: buffer_iterator, 1>
InputIterator2 = boost :: compute :: buffer_iterator, 1>
BinaryOperator = boost :: compute :: lambda :: expression,0 >>,const boost :: compute :: lambda :: expression>,0 >> &,const boost :: compute :: lambda :: expression>,0 >> &>,3 >> 1>] 1> C:\ local \ boost_1_67_0 \ boost / compute / algorithm / transform.hpp(68): 错误C2668:'boost :: compute :: make_zip_iterator':模棱两可的调用 重载功能1> C:\ local \ boost_1_67_0 \ boost / compute / iterator / zip_iterator.hpp(276): 注意:可能是 'boost :: compute :: zip_iterator,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type >> boost :: compute :: make_zip_iterator,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost: :tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type >>(IteratorTuple)' 1>与1> [1>
T = boost :: compute :: float4_,1>
IteratorTuple = boost :: tuples :: tuple,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type, boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type> 1>] 1> C:\ local \ boost_1_67_0 \ boost / iterator / zip_iterator.hpp(357):注意:或
'boost :: iterators :: zip_iterator,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type >> boost :: iterators :: make_zip_iterator,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost: :tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type >>(IteratorTuple)' [使用与参数相关的查找发现] 1>与1> [ 1> T = boost :: compute :: float4_,1>
IteratorTuple = boost :: tuples :: tuple,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type, boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type> 1>] 1> C:\ local \ boost_1_67_0 \ boost / compute / algorithm / transform.hpp(68):注意: 在尝试匹配参数列表时 '(boost :: tuples :: tuple,boost :: compute :: buffer_iterator,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type, boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type,boost :: tuples :: null_type>)' 1>与1> [1>
T = boost :: compute :: float4_ 1>] 1> C:\ local \ boost_1_67_0 \ boost / compute / algorithm / transform.hpp(72): 错误C2672:“转换”:找不到匹配的重载函数 1> C:\ local \ boost_1_67_0 \ boost / compute / algorithm / transform.hpp(72): 错误C2780:'OutputIterator boost :: compute :: transform(InputIterator1,InputIterator1,InputIterator2,OutputIterator,BinaryOperator,boost :: compute :: command_queue &)':需要6个参数-提供4个参数1> C:\ local \ boost_1_67_0 \ boost / compute / algorithm / transform.hpp(55):注意: 参见'boost :: compute :: transform'的声明 ========== Build:0成功,1个失败,2个最新,跳过0个==========
答案 0 :(得分:1)
短期修正是修改boost/compute/algorithm/transform.hpp
。将两个呼叫都从make_zip_iterator
更改为::boost::compute::make_zip_iterator
。这样就可以避免调用依赖于参数的查找。
更新:此问题已在#790
中修复