cuda cudaError_t cudaerr = cudaDeviceSynchronize()运行报错“misaligned address”解决办法

最近用cuda去做加速计算,发现当计算数据量较大时,报错“misaligned address”,如下:

出现这种情况可能是因为指针没有与处理器所需的边界对齐造成的。

From the CUDA Programming Guide, section 5.3.2:

Global memory instructions support reading or writing words of size equal to 1, 2, 4, 8, or 16 bytes. Any access (via a variable or a pointer) to data residing in global memory compiles to a single global memory instruction if and only if the size of the data type is 1, 2, 4, 8, or 16 bytes and the data is naturally aligned (i.e., its address is a multiple of that size).

This is what the debugger is trying to tell you: Basically, you shouldn't dereference a pointer pointing to a 32-bit value from an address not aligned at a 32-bit boundary.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用中提到的错误"RuntimeError: CUDA error: misaligned address"是由于CUDA内核错误引起的。该错误可能会在其他API调用时异步报告,导致下面的堆栈跟踪可能是不正确的。为了调试,可以考虑在CUDA_LAUNCH_BLOCKING=1的情况下运行程序。 引用中提到的解决方法是通过设置CUDA_LAUNCH_BLOCKING=1来进行调试,以便在错误发生时阻塞程序并获得准确的堆栈跟踪。这样可以更容易地定位错误并解决问题。 引用中提到的错误"RuntimeError: CUDA out of memory"是由于GPU显存不足引起的。为了解决这个问题,可以尝试以下方法: 1. 将batch_size改小,以减小每次运算所需的显存占用量。 2. 当需要取torch变量的标量值时,使用item()属性而不是保留整个变量。 3. 在测试阶段,可以尝试添加代码以释放不必要的显存资源。 引用中提到的警告"UserWarning: NVIDIA GeForce RTX 3090 with CUDA capability sm_86 is not compatible with the current PyTorch installation"表示当前的PyTorch版本不支持您的显卡。如果想要使用NVIDIA GeForce RTX 3090 GPU进行PyTorch开发,请参考提供的链接,按照指引进行安装和配置。 综上所述,"RuntimeError: CUDA error: misaligned address"是由CUDA内核错误引起的,可以使用CUDA_LAUNCH_BLOCKING=1进行调试。而"RuntimeError: CUDA out of memory"则是由于GPU显存不足引起的,可以通过减小batch_size、使用item()属性和释放不必要的显存资源来解决问题。同时,如果要使用NVIDIA GeForce RTX 3090 GPU进行PyTorch开发,请确保PyTorch版本与显卡兼容。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [CUDA Error: no kernel image is available for execution on device](https://blog.csdn.net/qq_34845880/article/details/126460123)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [pytorch模型提示超出内存RuntimeError: CUDA out of memory.](https://download.csdn.net/download/weixin_38552305/14884908)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值