user1404093
user1404093

Reputation: 1

CUDA arrays and c++ vectors

I'm new at CUDA and have the following question? My kernel is supposed to calculate a type:

vector <double *> *my_vector = new vector <double *>();

Before I tried to change the original c++ code to cuda it would calculate an array[6] in a loop and then push it back to my_vector.

for{
          //calculations


        double *array = new double[6];
        array[0] = data;
        array[1] = data;
        array[2] = data;
        array[3] = data;
        array[4] = data;
        array[5] = data;

        my_vector->push_back(array);
}

I know that using thrust could help but I prefer if I didn't use it. I thought of using a 2D array at my kernel and copying the data back to my host code and then copying that to my_vector with the std::vector. What I've tried so far has failed.

If anyone has some experience on this and has any idea it would be much help.

Upvotes: 0

Views: 1979

Answers (1)

geek
geek

Reputation: 1839

Look at the Thrust template library that provide useful templates for host and device code usage. The thrust::device_vector can be used like std::vector analogy, although not inside device code.

Upvotes: 1

Related Questions