-
Notifications
You must be signed in to change notification settings - Fork 64
Open
Description
#include <iostream>
#include <vector>
#include <bolt/cl/iterator/counting_iterator.h>
#include <bolt/cl/iterator/transform_iterator.h>
#include <bolt/cl/functional.h>
#include <bolt/cl/device_vector.h>
#include <bolt/cl/copy.h>
BOLT_FUNCTOR(GetSquare,
struct GetSquare
{
public:
int operator()(const int& globalId) const
{
return globalId*globalId;
}
};);
int main()
{
const std::size_t n=10;
bolt::cl::control ctrl = bolt::cl::control::getDefault();
bolt::cl::device_vector<int> debug(n);
auto globalId = bolt::cl::make_counting_iterator(0);
// This is OK
// bolt::cl::transform(globalId, globalId + n, debug.begin(), GetSquare());
// This causes compilation error
auto square = bolt::cl::make_transform_iterator(globalId, GetSquare());
bolt::cl::copy(square, square + n, debug.begin());
for(int i = 0; i < n; i++)
{
std::cout << i << ": " << debug[i] << std::endl;
}
return 0;
}
This problem seems to be because bolt::cl::transform_iterator
have the method getContainer()
only with template type
template<typename Container >
Container& getContainer() const
{
return this->base().getContainer( );
}
but bolt::cl::copy
needs ITERATOR::getContainer() without any template type
V_OPENCL( kernels[whichKernel].setArg( 0, first.getContainer().getBuffer()), "Error setArg kernels[ 0 ]" );
This can be solved with C++11
auto getContainer() const -> decltype(base().getContainer())
{
return this->base().getContainer();
}
I don't have any idea in C++03 (boost::result_of
?).
Metadata
Metadata
Assignees
Labels
No labels