提交 af5a7fe6 authored 作者: Josh Bleecher Snyder's avatar Josh Bleecher Snyder

Refactor the printing of device name and number.

Only print it for the device in use, when it is really being used. For the moment, just continue to print to sys.stderr.
上级 e3a882ce
import atexit, os, stat import atexit, os, stat, sys
from theano.compile import optdb from theano.compile import optdb
from theano import config from theano import config
from theano.gof.cmodule import get_lib_extension from theano.gof.cmodule import get_lib_extension
...@@ -178,6 +178,7 @@ def use(device, force=False, default_to_move_computation_to_gpu = True, ...@@ -178,6 +178,7 @@ def use(device, force=False, default_to_move_computation_to_gpu = True,
handle_shared_float32(True) handle_shared_float32(True)
use.device_number = device use.device_number = device
cuda_enabled = True cuda_enabled = True
print >> sys.stderr, "Using gpu device %d: %s" % (active_device_number(), active_device_name())
except (EnvironmentError, ValueError), e: except (EnvironmentError, ValueError), e:
_logger.error(("ERROR: Not using GPU." _logger.error(("ERROR: Not using GPU."
" Initialisation of device %i failed:\n%s") % (device, e)) " Initialisation of device %i failed:\n%s") % (device, e))
......
...@@ -1918,8 +1918,6 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args) ...@@ -1918,8 +1918,6 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args)
} }
if(card_number_provided) { if(card_number_provided) {
//fprintf(stderr, "DEBUG: calling cudaSetDevice %i\n", card_nb);
err = cudaSetDevice(card_nb); err = cudaSetDevice(card_nb);
if(cudaSuccess != err) { if(cudaSuccess != err) {
return PyErr_Format(PyExc_EnvironmentError, return PyErr_Format(PyExc_EnvironmentError,
...@@ -1928,12 +1926,32 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args) ...@@ -1928,12 +1926,32 @@ CudaNdarray_gpu_init(PyObject* _unused, PyObject* args)
cudaGetErrorString(cudaGetLastError())); cudaGetErrorString(cudaGetLastError()));
} }
} }
fprintf(stderr, "Using gpu device %d: %s\n", card_nb, deviceProp.name);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
PyObject *
CudaNdarray_active_device_number(PyObject* _unused, PyObject* _unused_args) {
// NB: No cuda error checking here; keeps things simple, and it's not
// really necessary.
int currentDevice;
cudaGetDevice(&currentDevice);
return PyInt_FromLong(currentDevice);
}
PyObject *
CudaNdarray_active_device_name(PyObject* _unused, PyObject* _unused_args) {
// NB: No cuda error checking here; keeps things simple, and it's not
// really necessary.
int currentDevice;
cudaGetDevice(&currentDevice);
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp, currentDevice);
return PyString_FromString(deviceProp.name);
}
PyObject * PyObject *
CudaNdarray_gpu_shutdown(PyObject* _unused, PyObject* _unused_args) { CudaNdarray_gpu_shutdown(PyObject* _unused, PyObject* _unused_args) {
cudaThreadExit(); cudaThreadExit();
...@@ -2097,6 +2115,8 @@ filter(PyObject* __unsed_self, PyObject *args) // args = (data, broadcastable, s ...@@ -2097,6 +2115,8 @@ filter(PyObject* __unsed_self, PyObject *args) // args = (data, broadcastable, s
static PyMethodDef module_methods[] = { static PyMethodDef module_methods[] = {
{"dot", CudaNdarray_Dot, METH_VARARGS, "Returns the matrix product of two CudaNdarray arguments."}, {"dot", CudaNdarray_Dot, METH_VARARGS, "Returns the matrix product of two CudaNdarray arguments."},
{"gpu_init", CudaNdarray_gpu_init, METH_VARARGS, "Select the gpu card to use; also usable to test whether CUDA is available."}, {"gpu_init", CudaNdarray_gpu_init, METH_VARARGS, "Select the gpu card to use; also usable to test whether CUDA is available."},
{"active_device_name", CudaNdarray_active_device_name, METH_VARARGS, "Get the name of the active device."},
{"active_device_number", CudaNdarray_active_device_number, METH_VARARGS, "Get the number of the active device."},
{"gpu_shutdown", CudaNdarray_gpu_shutdown, METH_VARARGS, "Shut down the gpu."}, {"gpu_shutdown", CudaNdarray_gpu_shutdown, METH_VARARGS, "Shut down the gpu."},
{"ptr_int_size", CudaNdarray_ptr_int_size, METH_VARARGS, "Return a tuple with the size of gpu pointer, cpu pointer and int in bytes."}, {"ptr_int_size", CudaNdarray_ptr_int_size, METH_VARARGS, "Return a tuple with the size of gpu pointer, cpu pointer and int in bytes."},
{"filter", filter, METH_VARARGS, "filter(obj, broadcastable, strict, storage) returns a CudaNdarray initialized to obj if it matches the constraints of broadcastable. strict=True prevents any numeric casting. If storage is a CudaNdarray it may be overwritten and used as the return value."}, {"filter", filter, METH_VARARGS, "filter(obj, broadcastable, strict, storage) returns a CudaNdarray initialized to obj if it matches the constraints of broadcastable. strict=True prevents any numeric casting. If storage is a CudaNdarray it may be overwritten and used as the return value."},
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论