How to do error checking in CUDA(如何在CUDA里做错误检查)
https://codeyarns.com/2011/03/02/how-to-do-error-checking-in-cuda/
Error checks in CUDA code can help catch CUDA errors at their source. There are 2 sources of errors in CUDA source code:
- Errors from CUDA API calls. For example, a call to
cudaMalloc()might fail. - Errors from CUDA kernel calls. For example, there might be invalid memory access inside a kernel
在CUDA代码里,错误检查可以帮助找到CUDA代码里的错误,有两种从代码里产生的错误
- CUDA API调用错误。如,一个cudaMalloc()调用可能会失败。
- CUDA kernel调用错误。如,可能会在某个kernel的实现了访问了非法的内存。
All CUDA API calls return a cudaError value, so these calls are easy to check:
所有CUDA API调用都会返回一个cudaError值,所以这种调用非常容易检查。
if ( cudaSuccess != cudaMalloc( &fooPtr, fooSize ) )
printf( "Error!\n" );
CUDA kernel invocations do not return any value. Error from a CUDA kernel call can be checked after its execution by calling cudaGetLastError():
CUDA kernel不返回任何值。从CUDA kernel调用产生的错误可以在该调用完毕后,从cudaGetLastError()中检查到。
fooKernel<<< x, y >>>(); // Kernel call
if ( cudaSuccess != cudaGetLastError() )
printf( "Error!\n" );
These two types of checks can be elegantly wrapped up in two simple error-checking functions like this:
这两种检查可以非常优雅地封装在两个错误检查函数中,如下,
// Define this to turn on error checking
#define CUDA_ERROR_CHECK #define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ )
#define CudaCheckError() __cudaCheckError( __FILE__, __LINE__ ) inline void __cudaSafeCall( cudaError err, const char *file, const int line )
{
#ifdef CUDA_ERROR_CHECK
if ( cudaSuccess != err )
{
fprintf( stderr, "cudaSafeCall() failed at %s:%i : %s\n",
file, line, cudaGetErrorString( err ) );
exit( - );
}
#endif return;
} inline void __cudaCheckError( const char *file, const int line )
{
#ifdef CUDA_ERROR_CHECK
cudaError err = cudaGetLastError();
if ( cudaSuccess != err )
{
fprintf( stderr, "cudaCheckError() failed at %s:%i : %s\n",
file, line, cudaGetErrorString( err ) );
exit( - );
} // More careful checking. However, this will affect performance.
// Comment away if needed.
err = cudaDeviceSynchronize();
if( cudaSuccess != err )
{
fprintf( stderr, "cudaCheckError() with sync failed at %s:%i : %s\n",
file, line, cudaGetErrorString( err ) );
exit( - );
}
#endif return;
}
Using these error checking functions is easy:
使用这两个错误检查函数非常简单:
CudaSafeCall( cudaMalloc( &fooPtr, fooSize ) ); fooKernel<<< x, y >>>(); // Kernel call
CudaCheckError();
These functions are actually derived from similar functions which used to be available in the cutil.h in old CUDA SDKs.
这两个函数实际上也是从简单的旧CUDA SDK里导出的
How to do error checking in CUDA(如何在CUDA里做错误检查)的更多相关文章
- ECC(Error Checking and Correction)校验和纠错
ECC的全称是 Error Checking and Correction or Error correction Coding,是一种用于差错检测和修正的算法.上一节的BBM中我们提到过,NAND闪 ...
- docker build提示error checking context:can't stat xxx
现象描述 使用docker build一个镜像的时候,提示下面的错误: ➜ docker build -t image_name -f xxx.dockerfile . error checking ...
- HTTP 错误 500.21 - Internal Server Error 处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
HTTP 错误 500.21 - Internal Server Error 处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipe ...
- MySQL ERROR 1005: Can't create table (errno: 150)的错误解决办法
在mysql 中建立引用约束的时候会出现MySQL ERROR 1005: Can't create table (errno: 150)的错误信息结果是不能建立 引用约束. 出现问题的大致情况 1. ...
- HTTP 错误 500.21 - Internal Server Error处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
HTTP 错误 500.21 - Internal Server Error处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipel ...
- 解决:安装SQL Server 2008 Native Client遇到错误(在Navicat premium新建sqlserver连接时 需要):An error occurred during ...HRESULT: 0x80070422(注意尾部的错误号)
解决:安装SQL Server 2008 Native Client遇到错误(在Navicat premium新建sqlserver连接时 需要):An error occurred during . ...
- HTTP 错误 500.21 - Internal Server Error 处理程序“BlockViewHandler”在其模块列表中有一个错误模块“ManagedPipelineHandler
HTTP 错误 500.21 - Internal Server Error 处理程序“BlockViewHandler”在其模块列表中有一个错误模块“ManagedPipelineHandler ...
- ubuntu14.04 安装 CUDA 7.5 / CUDA 8.0
原文转自:http://blog.csdn.net/masa_fish/article/details/51882183 CUDA7.5和CUDA8.0的安装过程是一毛一样的.所以如果安装CUDA8. ...
- 【MySQL】ERROR 1005: Can't create table (errno: 150)的错误解决办法
在mysql 中建立引用约束的时候会出现MySQL ERROR 1005: Can't create table (errno: 150)的错误信息结果是不能建立 引用约束. 出现问题的大致情况 1. ...
随机推荐
- Widgets学习
ListView ListView RecyclerView RecyclerView ExpandableListView 关闭箭头 elvMsg.setGroupIndicator(null); ...
- 添砖加瓦:简述ELK部署
1.准备工作 ELK下载:https://www.elastic.co/downloads/ jdk version:1.8.0_162 2.环境搭建 ElasticSearch: (1)不能使用ro ...
- 开始使用Github
Gather ye rosebuds while ye may 我自己也是刚开始使用github没几天,写得不好我就写自己常用的吧 2015年9月20日下午3:19更新知乎上这个答案写得好多了
- HBase源码系列之HFile
本文讨论0.98版本的hbase里v2版本.其实对于HFile能有一个大体的较深入理解是在我去查看"到底是不是一条记录不能垮block"的时候突然意识到的. 首先说一个对HFile ...
- 《Java 8实战》读书笔记系列——第三部分:高效Java 8编程(四):使用新的日期时间API
https://www.lilu.org.cn/https://www.lilu.org.cn/ 第十二章:新的日期时间API 在Java 8之前,我们常用的日期时间API是java.util.Dat ...
- LeetCode 225题用队列实现栈(Implement Stack using Queues) Java语言求解
链接 https://leetcode-cn.com/problems/implement-stack-using-queues/ 思路 首先演示push()操作:将元素依次进入队1,进入时用top元 ...
- Docker+Cmd+Cli+Git之前端工程化纪要(一)整体目标
之前一版的工程化核心产物就是一个IDE,即利用python+node将webpack等技术将FE的开发.编译.部署上线等环境集成在sublime中,产出了一个核心工具.但随着长期的使用与技术栈的优化升 ...
- this软拷贝详解
<script> if( !Function.prototype.softBind ){ Function.prototype.softBind = function( obj ){ va ...
- TCP/IP协议族的四个层次
OSI7层模型的小结 : 在7层模型中,每一层都提供一个特殊的网络功能.从网络功能的角度看:下面4层(物理层.数据链路层.网络层和传输层)主要提供数据传输和交换功能,即以节点到节点之间的通信为主:第4 ...
- 【CSS3】自定义设置可编辑元素闪烁光标的颜色
前言 因为业务需求, 要求我们的input框内的文本与悬浮的光标颜色不同, 这样的问题肯定在书本上很难找到解决办法, 需要通过平时的基础积累和经验. 解决方案 使用 ::first-line 伪元素 ...