提交 18903386 authored 作者: Frederic's avatar Frederic

If we re-init a new cublas context, destroy the old one. Better error message.

上级 92ad39a1
......@@ -3549,9 +3549,33 @@ CudaNdarray_New(int nd)
static int
cublas_init()
{
if (CUBLAS_STATUS_SUCCESS != cublasCreate(&handle))
cublasStatus_t err;
if (handle != NULL)
{
err = cublasDestroy(handle);
if (CUBLAS_STATUS_SUCCESS != err)
{
PyErr_SetString(PyExc_RuntimeError,
"cublas_init tried to destroy the old cublas"
" context, cublasDestroy() returned an error.");
return -1;
}
handle = NULL;
}
err = cublasCreate(&handle);
if (CUBLAS_STATUS_SUCCESS != err)
{
PyErr_SetString(PyExc_RuntimeError, "error initializing device");
if(CUBLAS_STATUS_NOT_INITIALIZED == err)
PyErr_SetString(PyExc_RuntimeError,
"cublasCreate() returned this error "
"'the CUDA Runtime initialization failed'");
else if(CUBLAS_STATUS_ALLOC_FAILED == err)
PyErr_SetString(PyExc_RuntimeError,
"cublasCreate() returned this error "
"'the resources could not be allocated'");
else
PyErr_SetString(PyExc_RuntimeError,
"unknow error during returned by cublasCreate()");
return -1;
}
// Set the default stream as the one to execute on (default)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论