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
#include
#include
#include
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>'
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>'
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(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>,0>> &,const boost::compute::lambda::expression>,0>> &>,2>,
1> InputIterator1=boost::compute::buffer_iterator<int>,
1> InputIterator2=boost::compute::buffer_iterator<int>,
1> BinaryOperator=boost::compute::lambda::expression>,0>> &,const boost::compute::lambda::expression>,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>,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>,0>> &,const boost::compute::lambda::expression>,0>> &>,2>>,
1> InputIterator=boost::compute::zip_iterator>,
1> UnaryOperator=boost::compute::detail::unpacked>,0>> &,const boost::compute::lambda::expression>,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' being compiled
1> with
1> [
1> InputIterator=boost::compute::zip_iterator>,
1> UnaryOperator=boost::compute::detail::unpacked>,0>> &,const boost::compute::lambda::expression>,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::dereference(void) const'
1> with
1> [
1> InputIterator=boost::compute::zip_iterator>,
1> UnaryOperator=boost::compute::detail::unpacked>,0>> &,const boost::compute::lambda::expression>,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::dereference' in 'boost::iterators::iterator_core_access::dereference'
1> with
1> [
1> InputIterator=boost::compute::zip_iterator>,
1> UnaryOperator=boost::compute::detail::unpacked>,0>> &,const boost::compute::lambda::expression>,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.