2

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?

2 Answers2

4

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.

Marco A.
  • 43,032
  • 26
  • 132
  • 246
  • Huh.. Well that just renders the whole approach I was thinking of taking utterly useless. Nevertheless, even if I do linearize it, would I be able to access these vectors on the device side? How about including them in kernel calls? I know the common way of doing so is to cast it to a raw pointer and use that, but is that the only way? – user3298865 Aug 24 '14 at 21:29
  • @user3298865 This other answer will be of help: http://stackoverflow.com/a/5511249/1938163, much CUDA code deals with POD types or pointers. This makes things easier also when translating it to intermediate PTX representations (which can't deal with complex parameter objects, at most arrays and/or pointers) – Marco A. Aug 24 '14 at 21:32
  • From what you pointed out, I understand that since the pointer points to the location where the fooVector is located in memory, any changes the kernel makes are actually made to the original fooVector. My question is: Is it possible to do so with my original case, i.e. a pointer pointing to kmers? Or is linearization my only option? – user3298865 Aug 24 '14 at 21:48
  • It's something I never tried but I believe it isn't possible. If you try it out please let me know in the comments here if that worked, although I suspect it won't and since you cannot use that vector of vectors anyway you'd better off with a linearization – Marco A. Aug 25 '14 at 07:16
  • Aware of any plans for removal of this limitation? – Andreas Yankopolus Nov 02 '16 at 23:32
-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;
}