当前位置: 首页 > news >正文

CUDA code=700(cudaErrorIllegalAddress) 报错与排查方法

CUDA code=700(cudaErrorIllegalAddress) 报错与排查方法

最近笔者在调试自己写的 CUDA 代码时, 遇到了 code=700(cudaErrorIllegalAddress) 的报错, 在此记录一下排查和解决方法.

报错

报错是由 CUDA API 函数执行时产生的, 由 checkCudaErrors() 函数检测出(CUDA 常用错误检测实现, 如下所示).

template <typename T>
void check(T result, char const *const func, const char *const file,int const line) {if (result) {fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line,static_cast<unsigned int>(result), cudaGetErrorName(result), func);exit(EXIT_FAILURE);}
}
#define checkCudaErrors(val) check((val), #val, __FILE__, __LINE__)

代码运行时报错如下所示, 显示是执行 cudaMemGetInfo() 函数时错误.

huanghy@node8:~/CL/src/cuda/build$ ./example 
[sample_cuda] start
[sample_kernel] grid_size:1, block_size:512, shm_size:6144
[sample_kernel] finished
CUDA error at /home/huanghy/CL/src/cuda/sample.cu:53 code=700(cudaErrorIllegalAddress) "cudaMemGetInfo(&freeMem, &totalMem)" 

原因

简单查阅资料可知, code=700(cudaErrorIllegalAddress) 的报错原因是 “an illegal memory access was encountered”, 即"遇到了一个非法的内存访问".

大多数情况下, 该问题产生都与数组越界访问的情况有关, 但值得一提的是, 往往报错的地方并不是问题实际存在的地方, 而由之前的 kernel 代码中的错误访问导致的.
比如, 此处报错是在 API 函数cudaMemGetInfo() 执行时, 也有可能是在自己定义的 kernel 函数执行时, 但可能一直排查当前报错的 kernel 不能解决问题的.

排查

一个很好的排查上述问题, 也是对自己的 CUDA 代码进行内存访问检查的方法是使用 CUDA 的 compute-sanitizer 工具.
该工具功能很多, 其中一个功能就是进行内存检测.

使用如下指令进行内存检查:

compute-sanitizer --launch-timeout=0 --tool=memcheck ./example > opt.txt 2>&1

其中, ./example 为检测的可执行文件. 由于输出可能比较多, 所以这里重定向到文件中. --launch-timeout=0 是将等待 kernel 加载的时间设置为无限, 以避免 compute-sanitizer 出现终止的情况, 如下所示.

========= COMPUTE-SANITIZER
========= Error: No attachable process found. compute-sanitizer timed-out.
========= Default timeout can be adjusted with --launch-timeout. Awaiting target completion.

最终 compute-sanitizer 会输出检测到的内存访问错误, 如下所示:

========= COMPUTE-SANITIZER
[sample_cuda] start
[sample_kernel] grid_size:1, block_size:512, shm_size:6144
========= Invalid __global__ write of size 4 bytes
=========     at 0x1190 in sample_kernel(int *, at::GenericPackedTensorAccessor<int, (unsigned long)1, at::RestrictPtrTraits, int>, at::GenericPackedTensorAccessor<int, (unsigned long)1, at::RestrictPtrTraits, int>, at::GenericPackedTensorAccessor<int, (unsigned long)1, at::RestrictPtrTraits, int>, at::GenericPackedTensorAccessor<int, (unsigned long)1, at::RestrictPtrTraits, int>, curandStateXORWOW *, unsigned int, int, unsigned int)
=========     by thread (32,0,0) in block (0,0,0)
=========     Address 0x7f40c00275a4 is out of bounds
=========     and is 23,461 bytes after the nearest allocation at 0x7f40c001fc00 of size 7,680 bytes
=========     Saved host backtrace up to driver entry point at kernel launch time
=========     Host Frame: [0x305c18]
=========                in /usr/lib/x86_64-linux-gnu/libcuda.so.1
=========     Host Frame: [0x1488c]
=========                in /usr/local/cuda-11.8/lib64/libcudart.so.11.0
=========     Host Frame:cudaLaunchKernel [0x6c318]
=========                in /usr/local/cuda-11.8/lib64/libcudart.so.11.0
=========     Host Frame:cudaError cudaLaunchKernel<char>(char const*, dim3, dim3, void**, unsigned long, CUstream_st*) [0x1f2f7]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:__device_stub__Z23sample_kernelPiN2at27GenericPackedTensorAccessorIiLm1ENS0_17RestrictPtrTraitsEiEES3_S3_S3_P17curandStateXORWOWjij(int*, at::GenericPackedTensorAccessor<int, 1ul, at::RestrictPtrTraits, int>&, at::GenericPackedTensorAccessor<int, 1ul, at::RestrictPtrTraits, int>&, at::GenericPackedTensorAccessor<int, 1ul, at::RestrictPtrTraits, int>&, at::GenericPackedTensorAccessor<int, 1ul, at::RestrictPtrTraits, int>&, curandStateXORWOW*, unsigned int, int, unsigned int) [0x1aec2]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:sample_kernel(int*, at::GenericPackedTensorAccessor<int, 1ul, at::RestrictPtrTraits, int>, at::GenericPackedTensorAccessor<int, 1ul, at::RestrictPtrTraits, int>, at::GenericPackedTensorAccessor<int, 1ul, at::RestrictPtrTraits, int>, at::GenericPackedTensorAccessor<int, 1ul, at::RestrictPtrTraits, int>, curandStateXORWOW*, unsigned int, int, unsigned int) [0x1af3a]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:sample_cuda(std::vector<at::Tensor, std::allocator<at::Tensor> >&, std::vector<CSR, std::allocator<CSR> >&, at::Tensor&, CSR const&, unsigned int, unsigned int, unsigned int, unsigned long long) [0x1a57d]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:sample(std::vector<at::Tensor, std::allocator<at::Tensor> >&, std::vector<CSR, std::allocator<CSR> >&, at::Tensor&, CSR const&, unsigned int, unsigned int, unsigned int, unsigned long long) [0x18900]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:main [0x87d0]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:__libc_start_main [0x21c87]
=========                in /lib/x86_64-linux-gnu/libc.so.6
=========     Host Frame:_start [0x804a]
=========                in /home/huanghy/CL/src/cuda/build/./example
========= 
=========  下面有很多重复单不同 threadIdx 和 blockIdx 的报错, 在此省略
========= 
[sample_kernel] finished
========= Program hit cudaErrorLaunchFailure (error 719) due to "unspecified launch failure" on CUDA API call to cudaMemGetInfo.
=========     Saved host backtrace up to driver entry point at error
=========     Host Frame: [0x4545f6]
=========                in /usr/lib/x86_64-linux-gnu/libcuda.so.1
=========     Host Frame:cudaMemGetInfo [0x533ab]
=========                in /usr/local/cuda-11.8/lib64/libcudart.so.11.0
=========     Host Frame:print_device_mem() [0x19796]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:sample_cuda(std::vector<at::Tensor, std::allocator<at::Tensor> >&, std::vector<CSR, std::allocator<CSR> >&, at::Tensor&, CSR const&, unsigned int, unsigned int, unsigned int, unsigned long long) [0x1a5bb]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:sample(std::vector<at::Tensor, std::allocator<at::Tensor> >&, std::vector<CSR, std::allocator<CSR> >&, at::Tensor&, CSR const&, unsigned int, unsigned int, unsigned int, unsigned long long) [0x18900]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:main [0x87d0]
=========                in /home/huanghy/CL/src/cuda/build/./example
=========     Host Frame:__libc_start_main [0x21c87]
=========                in /lib/x86_64-linux-gnu/libc.so.6
=========     Host Frame:_start [0x804a]
=========                in /home/huanghy/CL/src/cuda/build/./example
========= 
CUDA error at /home/huanghy/CL/src/cuda/sample.cu:53 code=719(cudaErrorLaunchFailure) "cudaMemGetInfo(&freeMem, &totalMem)" 
========= Target application returned an error
========= ERROR SUMMARY: 34 errors

在输出中, compute-sanitizer 会指明在具体的哪个 kernel 函数中发生了越界访问, 并指明相关的 threadIdx 和 blockIdx 以及内存地址.

以上述输出为例, 可以看到是在 sample_kernel() 函数中 threadIdx 为 (32,0,0) blockIdx (0,0,0) 处出现了 Address 0x7f40c00275a4 is out of bounds 的越界访问问题.

虽然地址信息很难让我们确定具体越界访问的位置, 但是通过该工具的输出, 可以确定到具体的 kernel 函数, 对于问题排查已经有了很大帮助.

参考

  • cuda - Unspecified launch failure on Memcpy - Stack Overflow
  • Compute-sanitizer not quite a drop-in replacement of cuda-memcheck - CUDA Developer Tools / Compute Sanitizer - NVIDIA Developer Forums

相关文章:

CUDA code=700(cudaErrorIllegalAddress) 报错与排查方法

CUDA code700(cudaErrorIllegalAddress) 报错与排查方法 最近笔者在调试自己写的 CUDA 代码时, 遇到了 code700(cudaErrorIllegalAddress) 的报错, 在此记录一下排查和解决方法. 报错 报错是由 CUDA API 函数执行时产生的, 由 checkCudaErrors() 函数检测出(CUDA 常用错误检…...

项目管理过程组

项目管理有2条主线&#xff0c;一条是技术&#xff0c;一条是管理。项目过程由项目团队实施。一般术语以下两大类之一&#xff1a;一类是项目管理过程。另一类是面向产品的过程。在大多数情况下&#xff0c;大多数项目都有共同的项目管理过程。它们通过有目的的实施而互相联系起…...

python每日一练(5)

&#x1f308;write in front&#x1f308; &#x1f9f8;大家好&#xff0c;我是Aileen&#x1f9f8;.希望你看完之后&#xff0c;能对你有所帮助&#xff0c;不足请指正&#xff01;共同学习交流. &#x1f194;本文由Aileen_0v0&#x1f9f8; 原创 CSDN首发&#x1f412; 如…...

经典循环命题:百钱百鸡

翁五钱一只&#xff0c;母三钱&#xff0c;小鸡三只一钱&#xff1b;百钱百鸡百鸡花百钱。 (本笔记适合能熟练应用for循环、会使if条件分支语句、能格式化字符输出的 coder 翻阅) 【学习的细节是欢悦的历程】 Python 官网&#xff1a;https://www.python.org/ Free&#xff1a…...

IDEA使用模板创建webapp时,web.xml文件版本过低的一种解决方法

创建完成后的web.xml 文件&#xff0c;版本太低 <!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app><display-name>Archetype Created Web Appl…...

在Openresty中使用lua语言向请求浏览器返回请求头User-Agent里边的值

可以参考《Linux学习之Ubuntu 20.04在https://openresty.org下载源码安装Openresty 1.19.3.1&#xff0c;使用systemd管理OpenResty服务》安装Openresty。 然后把下边的内容写入到openresty配置文件/usr/local/openresty/nginx/conf/nginx.conf&#xff08;根据实际情况进行选…...

Hive面试常见基础问题

以下是一些Hive面试问题和答案&#xff1a; Hive是什么&#xff1f; 答&#xff1a;Hive是一个开源的数据仓库工具&#xff0c;用于处理和分析大规模结构化数据。它能够创建、修改和查询表结构&#xff0c;支持多种数据类型和查询操作&#xff0c;同时提供数据汇总和数据查询的…...

设计模式 - 观察者模式

目录 一. 前言 二. 实现 三. 优缺点 一. 前言 观察者模式属于行为型模式。在程序设计中&#xff0c;观察者模式通常由两个对象组成&#xff1a;观察者和被观察者。当被观察者状态发生改变时&#xff0c;它会通知所有的观察者对象&#xff0c;使他们能够及时做出响应&#xf…...

【自动驾驶】PETR/PETRv2/StreamPETR论文分析

1.PETR PETR网络结构如下&#xff0c;主要包括image-backbone, 3D Coordinates Generator, 3D Position Encoder, transformer Decoder 1.1 Images Backbone 采用resnet 或者 vovNet,下面的x表示concatenate 1.2 3D Coordinates Generator 坐标生成跟lss类似&#xff0c;假…...

GPT实战系列-Baichuan2本地化部署实战方案

目录 一、百川2(Baichuan 2)模型介绍 二、资源需求 模型文件类型 推理的GPU资源要求 模型获取途径 国外: Huggingface 国内:ModelScope 三、部署安装 配置环境 安装过程...

用netty实现简易rpc

文章目录 rpc介绍&#xff1a;rpc调用流程:代码&#xff1a; rpc介绍&#xff1a; RPC是远程过程调用&#xff08;Remote Procedure Call&#xff09;的缩写形式。SAP系统RPC调用的原理其实很简单&#xff0c;有一些类似于三层构架的C/S系统&#xff0c;第三方的客户程序通过接…...

【计算机网络】第三章课后习题答案

习题目录&#xff1a; 【3-01】数据链路&#xff08;即逻辑链路&#xff09;与链路&#xff08;即物理链路&#xff09;有何区别&#xff1f;"链路接通了"与"数据链路接通了"的区别何在&#xff1f; 【3-02】数据链路层中的链路控制包括哪些功能&#xf…...

cesium 地图蒙版遮罩效果

示例代码 <!DOCTYPE html> <html lang"en"><head><!-- Use correct character set. --><meta charset"utf-8" /><!-- Tell IE to use the latest, best version. --><meta http-equiv"X-UA-Compatible"…...

根据前序遍历结果构造二叉搜索树

根据前序遍历结果构造二叉搜索树-力扣 1008 题 题目说明&#xff1a; 1.preorder 长度>1 2.preorder 没有重复值 直接插入 解题思路&#xff1a; 数组索引[0]的位置为根节点&#xff0c;与根节点开始比较&#xff0c;比根节点小的就往左边插&#xff0c;比根节点大的就往右…...

微信小程序指定某个元素强制重新渲染

之前写过 vue强制让某个元素重新渲染 利用了vue中的 v-if会控制元素是否挂载 以及 $nextTick 等待响应式更改生效再执行的特性 小程序也都有类似的方法 我们可以这样 wxml <view wx:if"{{min true}}">你好</view>用 wx:if 作用和v-if是一样的 js th…...

国际教材概念基础

各种区别 缩写 A-LEVEL&#xff08;大学预科&#xff09;&#xff1a;General Certificate of Education Advanced Level AP&#xff1a;Advanced Placement&#xff08;美国地区&#xff1a;美高AP&#xff09; GCSE&#xff1a;General Certificate of Secondary Educati…...

2023全国大学生软件测试大赛开发者测试练习题满分答案(PairingHeap2023)

2023全国大学生软件测试大赛开发者测试练习题满分答案&#xff08;PairingHeap2023&#xff09; 题目详情题解代码&#xff08;直接全部复制到test类中即可&#xff09; 提示&#xff1a;该题只需要分支覆盖得分即可&#xff0c;不需要变异得分 题目详情 题解代码&#xff08;…...

介绍一下tokens

“Tokens” 是一个计算机科学和自然语言处理领域常用的术语&#xff0c;通常用于表示文本中的最小单位。在这个上下文中&#xff0c;我将解释一下 “tokens” 的含义以及它们在不同领域中的用途&#xff1a; 自然语言处理 (NLP): 在自然语言处理中&#xff0c;“token” 是指文…...

机器学习、深度学习相关的项目集合【自行选择即可】

【基于YOLOv5的瓷砖瑕疵检测系统】 YOLOv5是一种目标检测算法&#xff0c;它是YOLO&#xff08;You Only Look Once&#xff09;系列模型的进化版本。YOLOv5是由Ultralytics开发的&#xff0c;基于一阶段目标检测的概念。其目标是在保持高准确率的同时提高目标检测的速度和效率…...

百面机器学习书刊纠错

百面机器学习书刊纠错 P243 LSTM内部结构图 2023-10-7 输入门的输出 和 candidate的输出 进行按元素乘积之后 要和 遗忘门*上一层的cell state之积进行相加。...

第19节 Node.js Express 框架

Express 是一个为Node.js设计的web开发框架&#xff0c;它基于nodejs平台。 Express 简介 Express是一个简洁而灵活的node.js Web应用框架, 提供了一系列强大特性帮助你创建各种Web应用&#xff0c;和丰富的HTTP工具。 使用Express可以快速地搭建一个完整功能的网站。 Expre…...

DeepSeek 赋能智慧能源:微电网优化调度的智能革新路径

目录 一、智慧能源微电网优化调度概述1.1 智慧能源微电网概念1.2 优化调度的重要性1.3 目前面临的挑战 二、DeepSeek 技术探秘2.1 DeepSeek 技术原理2.2 DeepSeek 独特优势2.3 DeepSeek 在 AI 领域地位 三、DeepSeek 在微电网优化调度中的应用剖析3.1 数据处理与分析3.2 预测与…...

MMaDA: Multimodal Large Diffusion Language Models

CODE &#xff1a; https://github.com/Gen-Verse/MMaDA Abstract 我们介绍了一种新型的多模态扩散基础模型MMaDA&#xff0c;它被设计用于在文本推理、多模态理解和文本到图像生成等不同领域实现卓越的性能。该方法的特点是三个关键创新:(i) MMaDA采用统一的扩散架构&#xf…...

04-初识css

一、css样式引入 1.1.内部样式 <div style"width: 100px;"></div>1.2.外部样式 1.2.1.外部样式1 <style>.aa {width: 100px;} </style> <div class"aa"></div>1.2.2.外部样式2 <!-- rel内表面引入的是style样…...

HTML前端开发:JavaScript 常用事件详解

作为前端开发的核心&#xff0c;JavaScript 事件是用户与网页交互的基础。以下是常见事件的详细说明和用法示例&#xff1a; 1. onclick - 点击事件 当元素被单击时触发&#xff08;左键点击&#xff09; button.onclick function() {alert("按钮被点击了&#xff01;&…...

数据库分批入库

今天在工作中&#xff0c;遇到一个问题&#xff0c;就是分批查询的时候&#xff0c;由于批次过大导致出现了一些问题&#xff0c;一下是问题描述和解决方案&#xff1a; 示例&#xff1a; // 假设已有数据列表 dataList 和 PreparedStatement pstmt int batchSize 1000; // …...

服务器--宝塔命令

一、宝塔面板安装命令 ⚠️ 必须使用 root 用户 或 sudo 权限执行&#xff01; sudo su - 1. CentOS 系统&#xff1a; yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh2. Ubuntu / Debian 系统…...

Java求职者面试指南:Spring、Spring Boot、MyBatis框架与计算机基础问题解析

Java求职者面试指南&#xff1a;Spring、Spring Boot、MyBatis框架与计算机基础问题解析 一、第一轮提问&#xff08;基础概念问题&#xff09; 1. 请解释Spring框架的核心容器是什么&#xff1f;它在Spring中起到什么作用&#xff1f; Spring框架的核心容器是IoC容器&#…...

PHP 8.5 即将发布:管道操作符、强力调试

前不久&#xff0c;PHP宣布了即将在 2025 年 11 月 20 日 正式发布的 PHP 8.5&#xff01;作为 PHP 语言的又一次重要迭代&#xff0c;PHP 8.5 承诺带来一系列旨在提升代码可读性、健壮性以及开发者效率的改进。而更令人兴奋的是&#xff0c;借助强大的本地开发环境 ServBay&am…...

华为OD最新机试真题-数组组成的最小数字-OD统一考试(B卷)

题目描述 给定一个整型数组,请从该数组中选择3个元素 组成最小数字并输出 (如果数组长度小于3,则选择数组中所有元素来组成最小数字)。 输入描述 行用半角逗号分割的字符串记录的整型数组,0<数组长度<= 100,0<整数的取值范围<= 10000。 输出描述 由3个元素组成…...