提交 4d04a47e authored 作者: Frederic's avatar Frederic

Add precheck and more detailed error message.

上级 3bea10b7
......@@ -3855,6 +3855,22 @@ int CudaNdarray_gemm(float alpha, const CudaNdarray * A, const CudaNdarray * B,
return -1;
}
#if PRECHECK_ERROR
cublasStatus prevErr = cublasGetError();
if (CUBLAS_STATUS_SUCCESS != prevErr)
{
//I don't know why, but I need to remove the cuda error too.
//Otherwise, the clean up before raising the Python error cause error too!
//So we don't see this python error.
fprintf(stderr,
"CudaNdarray_sgemm: Prev cublas error %s",
cublasGetErrorString(prevErr));
PyErr_Format(PyExc_RuntimeError,
"CudaNdarray_sgemm: Prev cublas error %s",
cublasGetErrorString(prevErr));
return -1;
}
#endif
// We must allow dimensions to be zeros.
if ((CudaNdarray_HOST_DIMS(A)[1] != CudaNdarray_HOST_DIMS(B)[0])
|| (CudaNdarray_HOST_DIMS(A)[0] != CudaNdarray_HOST_DIMS(C)[0])
......@@ -4012,8 +4028,14 @@ int CudaNdarray_gemm(float alpha, const CudaNdarray * A, const CudaNdarray * B,
if (CUBLAS_STATUS_SUCCESS != err)
{
PyErr_Format(PyExc_RuntimeError,
"cublasSgemm failed (%i)",
err);
"cublasSgemm failed (%i) %s\n"
" unit=%h N=%d, c.dims=[%d %d], a.dim=[%d %d], alpha=%f, beta=%f, a=%f, b=%f, c=%f"
" sa_0=%d, sa_1=%d, sb_0=%d, sb_1=%d, sc_0=%d, sc_1=%d",
err, cublasGetErrorString(err),
unit, N, CudaNdarray_HOST_DIMS(C)[0], CudaNdarray_HOST_DIMS(C)[1],
CudaNdarray_HOST_DIMS(A)[0], CudaNdarray_HOST_DIMS(A)[1],
alpha, beta, a, b, c, sa_0, sa_1, sb_0, sb_1, sc_0, sc_1);
return -1;
}
return 0;
......
......@@ -530,6 +530,25 @@ DllExport int CudaNdarray_inplace_elemwise(PyObject* py_self, PyObject * py_othe
DllExport int CudaNdarray_prep_output(CudaNdarray ** arr, int nd,
const int * dims);
DllExport const char* cublasGetErrorString(cublasStatus err){
if(CUBLAS_STATUS_SUCCESS == err)
return "success";
else if(CUBLAS_STATUS_NOT_INITIALIZED == err)
return "the library was not initialized";
else if(CUBLAS_STATUS_ALLOC_FAILED == err)
return "the resource allocation failed";
else if(CUBLAS_STATUS_INVALID_VALUE == err)
return "the parameters n<0 or incx,incy=0";
else if(CUBLAS_STATUS_MAPPING_ERROR == err)
return "an access to GPU memory space failed";
else if(CUBLAS_STATUS_EXECUTION_FAILED == err)
return "the function failed to launch on the GPU";
else if(CUBLAS_STATUS_INTERNAL_ERROR == err)
return "an internal operation failed";
else
return "unknow code";
}
#endif
/*
Local Variables:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论