|
Boost Users : |
From: David Frischknecht (fishnet37222_at_[hidden])
Date: 2024-08-22 03:25:06
I wrote this simple program to learn how to use Boost::Compute. The program failed to build on Windows, but builds without any errors on Linux. If I modify the program to only operate on one vector, it works fine. On Windows I'm using vcpkg to pull in both Boost::Compute as well as the OpenCL SDK and I'm using Visual Studio 2022 to build the project.
#define CL_TARGET_OPENCL_VERSION 300
#include <random>
#include <vector>
#include <boost/compute/core.hpp>
#include <boost/compute/lambda.hpp>
#include <boost/compute/algorithm/transform.hpp>
#include <boost/compute/container/vector.hpp>
std::mt19937 rng{ std::random_device()() };
std::uniform_int_distribution<> dist(1);
namespace compute = boost::compute;
using namespace boost::compute::lambda;
int GetRandomNumber()
{
return dist(rng);
}
int main(int argc, char* argv[])
{
const auto device = compute::system::default_device();
const compute::context context(device);
compute::command_queue commandQueue(context, device);
std::vector<int> hostVector1(10000);
std::vector<int> hostVector2(10000);
std::vector<int> hostResultVector(10000);
std::ranges::generate(hostVector1, GetRandomNumber);
std::ranges::generate(hostVector2, GetRandomNumber);
compute::vector<int> deviceVector1(hostVector1.size(), context);
compute::vector<int> deviceVector2(hostVector2.size(), context);
compute::vector<int> deviceResultVector(hostResultVector.size(), context);
compute::copy(hostVector1.begin(), hostVector1.end(), deviceVector1.begin(), commandQueue);
compute::copy(hostVector2.begin(), hostVector2.end(), deviceVector2.begin(), commandQueue);
transform(deviceVector1.begin(), deviceVector1.end(), deviceVector2.begin(), deviceResultVector.begin(), _1 + _2, commandQueue);
compute::copy(deviceResultVector.begin(), deviceResultVector.end(), hostResultVector.begin(), commandQueue);
return 0;
}
Here is the build output:
Build started at 11:13 PM...
1>------ Build started: Project: BoostComputeTest, Configuration: Debug x64 ------
1>Main.cpp
1>C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\iterator\transform_iterator.hpp(177,53): error C2039: 'get_buffer': is not a member of 'boost::compute::zip_iterator<boost::tuples::tuple<boost::compute::buffer_iterator<T>,boost::compute::buffer_iterator<T>,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>C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\iterator\transform_iterator.hpp(177,53): error C2039: with
1>C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\iterator\transform_iterator.hpp(177,53): error C2039: [
1>C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\iterator\transform_iterator.hpp(177,53): error C2039: T=int
1>C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\iterator\transform_iterator.hpp(177,53): error C2039: ]
1>(compiling source file 'Main.cpp')
1> C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\iterator\zip_iterator.hpp(172,7):
1> see declaration of 'boost::compute::zip_iterator<boost::tuples::tuple<boost::compute::buffer_iterator<T>,boost::compute::buffer_iterator<T>,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> with
1> [
1> T=int
1> ]
1> C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\iterator\transform_iterator.hpp(177,53):
1> the template instantiation context (the oldest one first) is
1> C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\Main.cpp(40,2):
1> see reference to function template instantiation 'OutputIterator boost::compute::transform<boost::compute::buffer_iterator<T>,boost::compute::buffer_iterator<T>,boost::compute::buffer_iterator<T>,boost::compute::lambda::expression<Expr>>(InputIterator1,InputIterator1,InputIterator2,OutputIterator,BinaryOperator,boost::compute::command_queue &)' being compiled
1> with
1> [
1> OutputIterator=boost::compute::buffer_iterator<int>,
1> T=int,
1> Expr=boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::plus,boost::proto::argsns_::list2<const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<0>>,0>> &,const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<1>>,0>> &>,2>,
1> InputIterator1=boost::compute::buffer_iterator<int>,
1> InputIterator2=boost::compute::buffer_iterator<int>,
1> BinaryOperator=boost::compute::lambda::expression<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::plus,boost::proto::argsns_::list2<const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<0>>,0>> &,const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<1>>,0>> &>,2>>
1> ]
1> C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\algorithm\transform.hpp(75,12):
1> see reference to function template instantiation 'OutputIterator boost::compute::transform<boost::compute::zip_iterator<boost::tuples::tuple<boost::compute::buffer_iterator<T>,boost::compute::buffer_iterator<T>,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>>,OutputIterator,boost::compute::detail::unpacked<BinaryOperator>>(InputIterator,InputIterator,OutputIterator,UnaryOperator,boost::compute::command_queue &)' being compiled
1> with
1> [
1> OutputIterator=boost::compute::buffer_iterator<int>,
1> T=int,
1> BinaryOperator=boost::compute::lambda::expression<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::plus,boost::proto::argsns_::list2<const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<0>>,0>> &,const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<1>>,0>> &>,2>>,
1> InputIterator=boost::compute::zip_iterator<boost::tuples::tuple<boost::compute::buffer_iterator<int>,boost::compute::buffer_iterator<int>,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> UnaryOperator=boost::compute::detail::unpacked<boost::compute::lambda::expression<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::plus,boost::proto::argsns_::list2<const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<0>>,0>> &,const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<1>>,0>> &>,2>>>
1> ]
1> C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\algorithm\transform.hpp(48,34):
1> see reference to class template instantiation 'boost::compute::transform_iterator<InputIterator,UnaryOperator>' being compiled
1> with
1> [
1> InputIterator=boost::compute::zip_iterator<boost::tuples::tuple<boost::compute::buffer_iterator<int>,boost::compute::buffer_iterator<int>,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> UnaryOperator=boost::compute::detail::unpacked<boost::compute::lambda::expression<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::plus,boost::proto::argsns_::list2<const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<0>>,0>> &,const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<1>>,0>> &>,2>>>
1> ]
1> C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\iterator\transform_iterator.hpp(175,15):
1> while compiling class template member function 'int boost::compute::transform_iterator<InputIterator,UnaryOperator>::dereference(void) const'
1> with
1> [
1> InputIterator=boost::compute::zip_iterator<boost::tuples::tuple<boost::compute::buffer_iterator<int>,boost::compute::buffer_iterator<int>,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> UnaryOperator=boost::compute::detail::unpacked<boost::compute::lambda::expression<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::plus,boost::proto::argsns_::list2<const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<0>>,0>> &,const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<1>>,0>> &>,2>>>
1> ]
1> C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\iterator\iterator_facade.hpp(631,11):
1> see the first reference to 'boost::compute::transform_iterator<InputIterator,UnaryOperator>::dereference' in 'boost::iterators::iterator_core_access::dereference'
1> with
1> [
1> InputIterator=boost::compute::zip_iterator<boost::tuples::tuple<boost::compute::buffer_iterator<int>,boost::compute::buffer_iterator<int>,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> UnaryOperator=boost::compute::detail::unpacked<boost::compute::lambda::expression<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::plus,boost::proto::argsns_::list2<const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<0>>,0>> &,const boost::compute::lambda::expression<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::compute::lambda::placeholder<1>>,0>> &>,2>>>
1> ]
1>C:\Users\Dave\source\repos\BoostComputeTest\BoostComputeTest\vcpkg_installed\x64-windows\x64-windows\include\boost\compute\iterator\transform_iterator.hpp(177,32): error C2530: 'context': references must be initialized
1>(compiling source file 'Main.cpp')
1>Done building project "BoostComputeTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 11:13 PM and took 03.315 seconds ==========
Is there something I'm missing from my project configuration on Windows?
Thanks,
Dave F.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net