提交 affc6d9e authored 作者: Frederic Bastien's avatar Frederic Bastien

Assert that the size of int is the same on cpu and gpu.

上级 158b1edc
...@@ -1886,12 +1886,13 @@ static PyTypeObject CudaNdarrayType = ...@@ -1886,12 +1886,13 @@ static PyTypeObject CudaNdarrayType =
static __global__ void get_gpu_ptr_size(int* dst) static __global__ void get_gpu_ptr_size(int* dst)
{ {
dst[0] = sizeof(float*); dst[0] = sizeof(float*);
dst[1] = sizeof(int);
} }
PyObject * PyObject *
CudaNdarray_ptr_int_size(PyObject* _unused, PyObject* args) CudaNdarray_ptr_int_size(PyObject* _unused, PyObject* args)
{ {
int *gpu_data = (int*)device_malloc(sizeof(int)); int *gpu_data = (int*)device_malloc(sizeof(int)*2);
if(gpu_data == NULL){ if(gpu_data == NULL){
return PyErr_Format(PyExc_MemoryError, return PyErr_Format(PyExc_MemoryError,
"CudaNdarray_ptr_int_size: Can't allocate memory on the gpu."); "CudaNdarray_ptr_int_size: Can't allocate memory on the gpu.");
...@@ -1903,14 +1904,17 @@ CudaNdarray_ptr_int_size(PyObject* _unused, PyObject* args) ...@@ -1903,14 +1904,17 @@ CudaNdarray_ptr_int_size(PyObject* _unused, PyObject* args)
return PyErr_Format(PyExc_RuntimeError, return PyErr_Format(PyExc_RuntimeError,
"CudaNdarray_ptr_int_size: error when calling the gpu code."); "CudaNdarray_ptr_int_size: error when calling the gpu code.");
} }
int gpu_ptr_size = -1;
cublasGetVector(1, sizeof(int), gpu_data, 1, &gpu_ptr_size, 1); // Transfer the result to cpu
int gpu_sizes[] = {-1,-1};
cublasGetVector(2, sizeof(int), gpu_data, 1, gpu_sizes, 1);
device_free(gpu_data); device_free(gpu_data);
if (CUBLAS_STATUS_SUCCESS != cublasGetError()){ if (CUBLAS_STATUS_SUCCESS != cublasGetError()){
PyErr_SetString(PyExc_RuntimeError, "error copying data to from memory"); PyErr_SetString(PyExc_RuntimeError, "error copying data to from memory");
return NULL; return NULL;
} }
return Py_BuildValue("iii", gpu_ptr_size, sizeof(float*), sizeof(int)); return Py_BuildValue("iiii", gpu_sizes[0], sizeof(float*), sizeof(int), gpu_sizes[1]);
} }
// Initialize the gpu. // Initialize the gpu.
......
...@@ -852,6 +852,10 @@ def local_gpu_join(node): ...@@ -852,6 +852,10 @@ def local_gpu_join(node):
# 70.0, 'fast_run', 'inplace') # 70.0, 'fast_run', 'inplace')
def get_device_type_sizes(): def get_device_type_sizes():
"""
:return:(gpu ptr size, cpu ptr size, int sizes(gpu and cpu))
:return type: tuple
"""
if hasattr(get_device_type_sizes, 'rval'): if hasattr(get_device_type_sizes, 'rval'):
return get_device_type_sizes.rval return get_device_type_sizes.rval
gpu_ptr_size = 8 gpu_ptr_size = 8
...@@ -859,9 +863,10 @@ def get_device_type_sizes(): ...@@ -859,9 +863,10 @@ def get_device_type_sizes():
int_size = 8 int_size = 8
try: try:
#RETURN (gpu ptr size, cpu ptr size, int sizes)
t = cuda_ndarray.cuda_ndarray.ptr_int_size() t = cuda_ndarray.cuda_ndarray.ptr_int_size()
gpu_ptr_size, cpu_ptr_size, int_size = t gpu_ptr_size, cpu_ptr_size, int_size, gpu_int_size = t
assert int_size == gpu_int_size
del gpu_int_size
del t del t
except Exception, e: except Exception, e:
_logger.warning(("OPTIMIZATION WARNING: " _logger.warning(("OPTIMIZATION WARNING: "
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论