0

大家早上好

我想在学习推力时测试 p2p 内存访问。但是有一点不对劲。

测试代码如下:

#include <iostream>
#include <thrust/device_vector.h>
#include <thrust/transform.h>
#include <thrust/functional.h>
using namespace std;

void test(thrust::device_vector<int> &Vec)
{
    try{
    thrust::negate<int> op;
    thrust::transform(Vec.begin(),Vec.end(),Vec.begin(),op);
    }catch(thrust::system::system_error &e)
    {
            cerr<<"Something wrong: "<<e.what()<<endl;
    }
}
int main()
{
    cudaSetDevice(0);
    thrust::device_vector<int> Vec(5);
    for(int i=0;i<5;i++)
    {
            Vec[i]=i;
            cout<<i<<" ";
    }
    cout<<endl;

    int TID=1;
    cudaSetDevice(TID);
    cudaDeviceEnablePeerAccess(0,0);
    test(Vec);
    for(int i=0;i<5;i++)
            cout<<Vec[i]<<" ";
    cout<<endl;
    return 0;  
} 

我执行这段代码,它给了我错误信息。

terminate called after throwing an instance of 'thrust::system::system_error'
  what():  invalid device pointer
Aborted

它怎么了?

4

1 回答 1

1

我认为这取决于您的设备是否支持统一寻址,否则您必须先从 GPUdirect 调用 cudaPeerRegister 才能从其他 GPU 访问内存。

您可以使用第二台设备上的 cudaDeviceCanAccessPeer() 进行检查。您也可以调用 cudaGetDeviceProperties() 并检查统一地址字段。

PS。我刚刚在具有 4 个 Tesla S2050 GPU 的机器上检查了您的代码,对我来说 cudaDeviceCanAccessPeer() 返回 0,因此直接访问不起作用..

于 2012-08-21T10:43:07.073 回答