提交 f6962bc8 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Fix the init/deinit of the cublas handle.

上级 c1abbdd5
...@@ -3090,6 +3090,10 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args) ...@@ -3090,6 +3090,10 @@ 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)
cublas_shutdown();
if(card_number_provided) { if(card_number_provided) {
err = cudaSetDevice(card_nb); err = cudaSetDevice(card_nb);
if(cudaSuccess != err) { if(cudaSuccess != err) {
...@@ -3100,9 +3104,6 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args) ...@@ -3100,9 +3104,6 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args)
} }
} }
// Initialize cublas
if (handle != NULL)
cublas_shutdown();
cublas_init(); cublas_init();
Py_INCREF(Py_None); Py_INCREF(Py_None);
...@@ -3552,19 +3553,6 @@ static int ...@@ -3552,19 +3553,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 +3582,15 @@ cublas_init() ...@@ -3594,11 +3582,15 @@ cublas_init()
static int static int
cublas_shutdown() cublas_shutdown()
{ {
if (CUBLAS_STATUS_SUCCESS != cublasDestroy(handle)) 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论