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

Merge pull request #1998 from abergeron/fix_cublas_init

[FIX] Fix the init/deinit of the cublas handle
...@@ -3090,6 +3090,11 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args) ...@@ -3090,6 +3090,11 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args)
"There is no device that supports CUDA"); "There is no device that supports CUDA");
} }
// Initialize cublas
if (handle != NULL)
if (cublas_shutdown() == -1)
return NULL;
if(card_number_provided) { if(card_number_provided) {
err = cudaSetDevice(card_nb); err = cudaSetDevice(card_nb);
if(cudaSuccess != err) { if(cudaSuccess != err) {
...@@ -3100,10 +3105,8 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args) ...@@ -3100,10 +3105,8 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args)
} }
} }
// Initialize cublas if (cublas_init() == -1)
if (handle != NULL) return NULL;
cublas_shutdown();
cublas_init();
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
...@@ -3552,19 +3555,6 @@ static int ...@@ -3552,19 +3555,6 @@ static int
cublas_init() cublas_init()
{ {
cublasStatus_t err; cublasStatus_t err;
//The following is causing problems so I comment it.
// 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); err = cublasCreate(&handle);
if (CUBLAS_STATUS_SUCCESS != err) if (CUBLAS_STATUS_SUCCESS != err)
{ {
...@@ -3594,11 +3584,16 @@ cublas_init() ...@@ -3594,11 +3584,16 @@ cublas_init()
static int static int
cublas_shutdown() cublas_shutdown()
{ {
if (CUBLAS_STATUS_SUCCESS != cublasDestroy(handle)) cublasStatus_t err;
err = cublasDestroy(handle);
if (CUBLAS_STATUS_SUCCESS != err)
{ {
PyErr_SetString(PyExc_RuntimeError, "error shutting down device"); PyErr_SetString(PyExc_RuntimeError,
"cublas_init tried to destroy the old cublas"
" context, cublasDestroy() returned an error.");
return -1; return -1;
} }
handle = NULL;
return 0; return 0;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论