Reputation: 23
I was using this vector of vector approach in CUDA since I am still used to Matlab and Python style programming environment. I was able to extract data from host side in the device vectors but now I am not sure how to access that data, for example, for printing. I tried using iterators but it I get error saying device_reference has no member "begin" or "end".
(Using VS 2010 with CUDA Toolkit 5.0)
thrust::device_vector<thrust::device_vector<int>> kmers;
//Do some stuff here to fill kmers
//
//
thrust::device_vector<thrust::device_vector<int>>::iterator ii;
thrust::device_vector<int>::iterator i;
for (ii = kmers.begin();ii!=kmers.end();++ii)
{
for (i = (*ii).begin(); i != (*ii).end(); i++){
std::cout << (*i) << "\n";
}
}
Any advice? Edit: I understand that thrust containers currently cannot be directly passed on to CUDA kernels. Are there any other libraries/containers which would allow me to do so?
Upvotes: 2
Views: 2051
Reputation: 1
Use this as an example code.
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
using namespace std;
void spausdintiRez(thrust::host_vector<int> rezultatai) {
std::cout << rezultatai[0] << std::endl;
}
void sudetis(thrust::device_vector<int> d,thrust::device_vector<int> &rez)
{
for (int i = 0; i < 10; i++)
{
for(int j=0; j<10;j++)
{
rez[0]+=d[i+j];
}
}
}
int main()
{
thrust::host_vector<int> duom(100);
thrust::host_vector<int> rezultatai;
thrust::device_vector<int> d;
thrust::device_vector<int> rez(1);
for(int i=0;i<100;i++)
duom[i]=i;
d = duom;
sudetis(d, rez);
rezultatai = rez;
spausdintiRez(rezultatai);
return 0;
}
Upvotes: -1
Reputation: 43662
AFAIK there were limitations in the CUDA back-end that prevented vectors of vectors from being usable.
Not sure if this was addressed in CUDA 6.0 but it surely wasn't in CUDA 5.0
You'll have to linearize your vector.
Upvotes: 4