-
Notifications
You must be signed in to change notification settings - Fork 338
Closed
Description
When templates for compute::vector<T> gpu_vec
and std::vector<U> host_vec
mismatch, compute::copy(gpu_vec.begin(),gpu_vec.end(),host_vec.begin(),queue)
returns incorrect values.
I think it would be nice to throw an error or write a warning in documentation.
The following code demonstrate the issue and was compiled under Visual Studio 2015 with the latest develop branch.
#include <boost/compute.hpp>
#include<iostream>
namespace compute = boost::compute;
// select device
compute::device select_device()
{
auto devices = compute::system::devices();
int i = 0;
for (auto & elem : devices)
{
std::cout << "device[" << i++ << "]: " << elem.name() << std::endl;
}
int device_id;
std::cout << "select device: ";
std::cin >> device_id;
return devices[device_id];
}
int main()
{
// select device
auto device = select_device();
compute::context context(device);
compute::command_queue queue(context, device);
//sample data
compute::vector<int> gpu_vec(5, context);
int start = 0;
// generate 0 to 4
compute::iota(gpu_vec.begin(), gpu_vec.end(), start, queue);
// gpu->host
// instead of std::vector<int>
std::vector<double> host_vec(5);
compute::copy(gpu_vec.begin(),gpu_vec.end(),host_vec.begin(),queue);
// check result
for (auto & elem : host_vec)
{
std::cout << elem << std::endl;
}
return 0;
}
Metadata
Metadata
Assignees
Labels
No labels