提交 ed6ba0e1 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #1995 from nouiz/cublas_init

If we re-init a new cublas context, destroy the old one. Better error me...
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#define CNDA_END_ALLOW_THREADS #define CNDA_END_ALLOW_THREADS
#endif #endif
cublasHandle_t handle; cublasHandle_t handle = NULL;
///////////////////////// /////////////////////////
// Alloc and Free // Alloc and Free
...@@ -3549,9 +3549,33 @@ CudaNdarray_New(int nd) ...@@ -3549,9 +3549,33 @@ CudaNdarray_New(int nd)
static int static int
cublas_init() 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; return -1;
} }
// Set the default stream as the one to execute on (default) // Set the default stream as the one to execute on (default)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论