I have a 2D vector, and I want to implement transform functor to each element of the 2D vector(every element is a postfix expression which is to be evaluated via different threads)
how is it possible using Cuda thrust? I have written a test code which evaluates sum of each vector but its giving error. Is this the correct approach ?
struct sum_v
{
__host__ __device__ float operator()(thrust::device_vector<float> v)
{
float sum=reduce(v.begin(),v.end());
return sum;
}
};
int main(void)
{
thrust::host_vector<float> h1_vec(3);
thrust::device_vector<float> vectors[3];
vectors[0] = thrust::device_vector<float>(3);
vectors[1] = thrust::device_vector<float>(3);
vectors[2] = thrust::device_vector<float>(3);
thrust::sequence(vectors[0].begin(), vectors[0].end());
thrust::sequence(vectors[1].begin(), vectors[1].end());
thrust::sequence(vectors[2].begin(), vectors[2].end());
thrust::device_vector<float> d1_vec(3);
thrust::transform(vectors.begin(), vectors.end(),d1_vec.begin(),sum_v());
thrust::copy(d1_vec.begin(), d1_vec.end(), h1_vec.begin());
return 0;
}