Cuda 对等内存访问引发异常

Cuda 对等内存访问引发异常,cuda,gpu,thrust,Cuda,Gpu,Thrust,大家早上好 我想在学习时测试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> &V

大家早上好

我想在学习时测试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;  
} 

发生了什么事

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

您可以使用第二台设备上的cudaDeviceCanAccessPeer()来检查这一点。 还可以调用cudaGetDeviceProperties()并检查UnifiedAddress字段

另外,我刚刚在一台装有4个特斯拉S2050 GPU的机器上检查了你的代码
对我来说,cudaDeviceCanAccessPeer()返回0,因此直接访问不起作用。

我已经检查了它,返回了1。但是有相同的终止信息@asmhmm。。您还可以检查以前是否发生过与Cuda相关的错误吗?例如,使用如下宏包装对CUDA运行时函数的每个调用:#定义CUDA_安全_调用(call){\cudaError err=call;\if(cudaSuccess!=err){\fprintf(stderr,文件“%s”第%i行中的Cuda错误:%s。\n“,\file,line,cudaGetErrorString(err));\exit(1);}很抱歉这么晚才回复你,我用手机看你的答案。每次推力呼叫都不能与CUDA_SAFE_呼叫相冲突。我用device_malloc而不是device_vector l。不,我的意思是只需结束每次CUDA运行时呼叫,即:CUDA_SAFE_呼叫(cudaDeviceEnablePeerAccess(..)或CUDA_SAFE_呼叫(CUDASEVIVE(..);为了检查在我之前是否发生了运行时错误,所有cuda调用都可以被扭曲。
terminate called after throwing an instance of 'thrust::system::system_error'
  what():  invalid device pointer
Aborted