设备内存上的多个指针,用于cuda中的单个分配数组

时间:2013-04-08 05:59:40

标签: cuda thrust

我想知道是否有可能设置多个指针已分配到内存中的单个数据?我问这个的原因是因为我在推力矢量的帮助下用gpu实现词法排序(并且在时间方面失败了)

例如,我试图获得相当于这些c ++的声明

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];

我不是要求有人向我提供代码,我只想知道是否有任何方法可以设置指向单个数据数组的指针。 PS:我尝试过以下方法,但根本没有实现任何加速

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

但我想由于我指向device_vector这可能是访问速度慢的问题

对此方面的任何帮助表示高度赞赏。

1 个答案:

答案 0 :(得分:1)

这没有任何意义:

int * raw_ptr = thrust::raw_pointer_cast([0]);
                                          ^ what is 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;
}

不确定如何说说加速。在你发布的一小段代码的背景下加速对我来说没有多大意义。

相关问题