0

I am wondering if there is it possible to setup multiple pointers to single data already allocated in memory? the reason i am asking this is because i was implementing lexographical sorting with gpu with the help of thrust vectors (and failed miserably in terms of time)

for example i am trying to acheive equivalent of these c++ statments

unsigned int * pword;      //setting up the array of memory for permutations of word
pword = new unsigned int [N*N];

unsigned int* * p_pword;    //pointers to permutation words
p_pword = new unsigned int* [N];

//setting up the pointers on the locations such that if N=4 then 0,4,8,12,...
int count;
for(count=0;count<N;count++)
        p_pword[count]=&pword[count*N];

I am not asking for someone to provide me with code, i just want to know is there any way i can setup pointers to single array of data. PS: i have tried the following method but not achieving any speedup at all

int * raw_ptr = thrust::raw_pointer_cast(&d_Data[0]); //doing same with multiple pointers

but i guess due to the fact that i am pointing towards device_vector it might be the problem of slow accessing

Any help in this regard is highly appreciated.

1 Answer 1

1

Well this doesn't make any sense:

int * raw_ptr = thrust::raw_pointer_cast([0]);
                                          ^ what is this??

I don't think that line would compile correctly.

But in thrust you can certainly do something like this:

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/device_ptr.h>
#include <thrust/sequence.h>

int main(){

  int N=16;
  thrust::device_vector<int> d_A(4*N);
  thrust::sequence(d_A.begin(), d_A.end());
  thrust::device_ptr<int> p_A[N];
  for (int i=0; i<N; i++)
    p_A[i] = &(d_A[4*i]);
  thrust::host_vector<int> h_A(N);
  thrust::copy(p_A[4], p_A[8], h_A.begin());
  for (int i=0; i<N; i++)
    printf("h_A[%d] = %d\n", i, h_A[i]);
  return 0;
}

Not sure what to say about speedup. Speedup in the context of the tiny little snippet of code you've posted doesn't make much sense to me.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks again Robert Crovella for reply actually i was trying to do this int * raw_ptr = thrust::raw_pointer_cast(&d_Data[0]);
Nice answer by the way (but i already did that using thrust's device_ptrs), and sorry if i was confusing in asking question i wanted to ask that is there any way i can make array of pointers save the address of single array in CUDA memory (let's say unsigned int *d_Data) i have implemented the same logic you described above in my example but i was looking for multiple pointers to single array (not device_vector)
That should work. But its creating a pointer that is not conveniently usable in thrust algorithms. You would be able to use that pointer in ordinary CUDA code, however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.