http://developer.download.nvidia.com/CUDA/training/GTC_Express_Sarah_Tariq_June2011.pdf
In the above tutorial (slide 29), they initiate 3 pointers to ints:
int *a, *b, *c;
Clearly this is of type (int *), yet they somehow make it possible for the kernel to access its indices with syntax a[index]
They also use some (to me) unknown command to initialize their values:
a = (int *)malloc(size); random_ints(a, N);
So what does this command do? First it casts the pointer *a to point to an int (but later on a magically becomes a vector). I can’t find any sources on what random_ints precisely does (and my compiler doesn’t recognize it either because it probably requires some include). I guess it makes a a vector of length N with random ints (though a is of type int).
I tried working around this by doing the same thing with vector <int> * a; etc etc but I still have trouble passing that to my kernel (it won’t add the elements no matter what I try).
I’m working in C++. Thanks in advance.
Edit: could this be pseudocode? Because the explicit C++ example does this in a different (comprehensible way)
Example
intExample
Be aware that you must free this pointer by
free(p), not bydelete [] p.Example: