Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e6432acb
提交
e6432acb
authored
6月 09, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactorized CudaNdarray_Zeros to be able to call CudaNdarray_ZEROS from c code.
上级
c7e85af0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
43 行增加
和
42 行删除
+43
-42
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+43
-42
没有找到文件。
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
e6432acb
...
@@ -267,6 +267,48 @@ PyObject * CudaNdarray_CreateArrayObj(CudaNdarray * self)
...
@@ -267,6 +267,48 @@ PyObject * CudaNdarray_CreateArrayObj(CudaNdarray * self)
}
}
PyObject* CudaNdarray_ZEROS(int n, int * dims)
{
int total_elements = 1;
for(int i=0;i<n;i++)
total_elements*=dims[i];
// total_elements now contains the size of the array, in reals
int total_size = total_elements * sizeof(real);
CudaNdarray* rval = (CudaNdarray*)CudaNdarray_new_null();
if (!rval)
{
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_Zeros: call to new_null failed");
return NULL;
}
if (CudaNdarray_alloc_contiguous(rval, n, dims))
{
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_Zeros: allocation failed.");
Py_DECREF(rval);
return NULL;
}
// Fill with zeros
//fprintf(stdout, "Sizeof: %d\n", total_size);
if (cudaSuccess != cudaMemset(rval->devdata, 0, total_size))
{
PyErr_Format(PyExc_MemoryError, "Error memsetting %d bytes of device memory.", total_size);
Py_DECREF(rval);
return NULL;
}
if (cnda_copy_structure_to_device(rval))
{
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_Zeros: syncing structure to device failed");
Py_DECREF(rval);
return NULL;
}
return (PyObject*) rval;
}
// declared as a static method (hence "dummy" is not used)
// declared as a static method (hence "dummy" is not used)
// Based on _Copy and _dimshuffle
// Based on _Copy and _dimshuffle
PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
...
@@ -295,9 +337,6 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
...
@@ -295,9 +337,6 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
return NULL;
return NULL;
}
}
// strides are in number of floats, not bytes
int total_elements = 1;
// start from the end to compute strides
// start from the end to compute strides
for (int i = shplen-1; i >= 0; --i)
for (int i = shplen-1; i >= 0; --i)
{
{
...
@@ -306,7 +345,6 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
...
@@ -306,7 +345,6 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
{
{
// shouldn't happen since we checked length before...
// shouldn't happen since we checked length before...
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_Zeros: Index out of bound in sequence");
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_Zeros: Index out of bound in sequence");
free(newdims);
return NULL;
return NULL;
}
}
...
@@ -316,50 +354,13 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
...
@@ -316,50 +354,13 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
if (shp_el <= 0)
if (shp_el <= 0)
{
{
PyErr_SetString(PyExc_ValueError, "CudaNdarray_Zeros: shape must not contain 0 (or negative value) for size of a dimension");
PyErr_SetString(PyExc_ValueError, "CudaNdarray_Zeros: shape must not contain 0 (or negative value) for size of a dimension");
free(newdims);
return NULL;
return NULL;
}
}
newdims[i] = shp_el;
newdims[i] = shp_el;
total_elements *= newdims[i];
}
}
// total_elements now contains the size of the array, in reals
PyObject* rval = CudaNdarray_ZEROS(shplen,newdims);
int total_size = total_elements * sizeof(real);
CudaNdarray* rval = (CudaNdarray*)CudaNdarray_new_null();
if (!rval)
{
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_Zeros: call to new_null failed");
free(newdims);
return NULL;
}
if (CudaNdarray_alloc_contiguous(rval, shplen, newdims))
{
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_Zeros: allocation failed.");
free(newdims);
Py_DECREF(rval);
return NULL;
}
// Fill with zeros
//fprintf(stdout, "Sizeof: %d\n", total_size);
if (cudaSuccess != cudaMemset(rval->devdata, 0, total_size))
{
PyErr_Format(PyExc_MemoryError, "Error memsetting %d bytes of device memory.", total_size);
free(newdims);
Py_DECREF(rval);
return NULL;
}
if (cnda_copy_structure_to_device(rval))
{
PyErr_SetString(PyExc_RuntimeError, "CudaNdarray_Zeros: syncing structure to device failed");
free(newdims);
Py_DECREF(rval);
return NULL;
}
free(newdims);
free(newdims);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论