【问题标题】:CUDA "Access Violation" when access “ __managed__ int ”variables by a host function当主机函数访问“__managed__ int”变量时,CUDA“访问冲突”
【发布时间】:2017-07-22 14:20:44
【问题描述】:

运行“Gipuma”项目时出现问题,需要opencv和CUDA的支持。我的显卡是 GTX 750Ti,CUDA 8.0。

通过主机函数访问“__managed__ int”变量时出现“访问冲突”。通常,“__managed__”变量可以通过设备和主机进行读写。我很困惑,我认为可能配置有问题吗?

“gipuma.cu”中声明的变量:

#ifndef SHARED_HARDCODED
__managed__ int SHARED_SIZE_W_m;
__constant__ int SHARED_SIZE_W;
__managed__ int SHARED_SIZE_H;
__managed__ int SHARED_SIZE = 0;
__managed__ int WIN_RADIUS_W;
__managed__ int WIN_RADIUS_H;
__managed__ int TILE_W;
__managed__ int TILE_H;
#endif  

和“gipuma.cu”中的宿主函数:

int runcuda(GlobalState &gs)
{
    WIN_RADIUS_W = 0;//it gets wrong here,access violation.
    printf("test is %d\n", WIN_RADIUS_W);
    printf("Run cuda\n");

    if(gs.params->color_processing)
        gipuma<float4>(gs);
    else
        gipuma<float>(gs);

    return 0;
}

和错误信息:

0x000000013FA1DCBD has an unhandled exception (in gipuma.exe): 0xC0000005: An access violation occurred when writing to location 0x0000000000000000.

【问题讨论】:

  • CUDA 不是 C,也不是真正的 C++。
  • 您需要提供minimal reproducible example。这个can happen 如果你调用内核然后你的主机函数没有干预cudaDeviceSynchronize()
  • 另外,请确保将其构建为 64 位项目。
  • 感谢您的建议,但我认为代码很好。因为它在其他计算中以相同的步骤成功运行。并且“/__managed__”变量可以在此计算中的其他项目中访问。
  • 顺便说一句,代码是从github.com/kysucix/gipuma下载的。

标签: cuda gpu nvidia


【解决方案1】:

在计算能力 6.0 之前的设备上,主机和设备可能无法同时访问 __managed__ 内存,因为 the driver needs an opportunity to programmatically copy the data between host and device

因此,正如 Robert Crovella 在他的评论中已经指出的那样,您需要在内核调用之后插入对 cudaDeviceSynchronize() 的调用,然后才能再次从主机访问 __managed__ 内存。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多