简体   繁体   English

推力装置矢量 推力装置矢量<int>

[英]Thrust device vector of thrust device vector<int>

I was using this vector of vector approach in CUDA since I am still used to Matlab and Python style programming environment.我在 CUDA 中使用了这种向量方法,因为我仍然习惯于 Matlab 和 Python 风格的编程环境。 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".我尝试使用迭代器,但出现错误,提示 device_reference 没有成员“开始”或“结束”。

(Using VS 2010 with CUDA Toolkit 5.0) (使用 VS 2010 和 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.编辑:我知道推力容器目前不能直接传递给 CUDA 内核。 Are there any other libraries/containers which would allow me to do so?有没有其他图书馆/容器可以让我这样做?

AFAIK there were limitations in the CUDA back-end that prevented vectors of vectors from being usable. AFAIK CUDA 后端存在一些限制,阻止了向量的使用。

Not sure if this was addressed in CUDA 6.0 but it surely wasn't in CUDA 5.0不确定这是否在 CUDA 6.0 中解决,但肯定不在CUDA 5.0 中

You'll have to linearize your vector.你必须线性化你的向量。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM