Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
17460952
提交
17460952
authored
4月 12, 2010
作者:
fsavard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplified zeros in cudandarray
上级
9b441ceb
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
6 行增加
和
23 行删除
+6
-23
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+6
-23
没有找到文件。
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
17460952
...
@@ -268,9 +268,7 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
...
@@ -268,9 +268,7 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
return NULL;
return NULL;
}
}
//fprintf(stdout, "Pattern length: %d\n", shplen);
int* newdims = (int *)malloc(sizeof(int) * shplen);
int* newdims = (int *)malloc(sizeof(int) * 2 * shplen);
if (!newdims)
if (!newdims)
{
{
...
@@ -279,10 +277,8 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
...
@@ -279,10 +277,8 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
return NULL;
return NULL;
}
}
int* newstrides = newdims + shplen;
// strides are in number of floats, not bytes
// strides are in number of floats, not bytes
int
cur_stride
= 1;
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)
...
@@ -305,25 +301,13 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
...
@@ -305,25 +301,13 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
return NULL;
return NULL;
}
}
// based on alloc_contiguous, we set
// stride=0 if the dim == 1
if (shp_el == 1)
{
// broadcast
newdims[i] = 1;
newstrides[i] = 0;
}
else
{
newdims[i] = shp_el;
newdims[i] = shp_el;
newstrides[i] = cur_stride;
}
cur_stride
*= newdims[i];
total_elements
*= newdims[i];
}
}
//
cur_stride
now contains the size of the array, in reals
//
total_elements
now contains the size of the array, in reals
int total_size =
cur_stride
* sizeof(real);
int total_size =
total_elements
* sizeof(real);
CudaNdarray* rval = (CudaNdarray*)CudaNdarray_new_null();
CudaNdarray* rval = (CudaNdarray*)CudaNdarray_new_null();
if (!rval)
if (!rval)
...
@@ -345,8 +329,7 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
...
@@ -345,8 +329,7 @@ PyObject* CudaNdarray_Zeros(PyObject* dummy, PyObject* shape)
//fprintf(stdout, "Sizeof: %d\n", total_size);
//fprintf(stdout, "Sizeof: %d\n", total_size);
if (cudaSuccess != cudaMemset(rval->devdata, 0, total_size))
if (cudaSuccess != cudaMemset(rval->devdata, 0, total_size))
{
{
fprintf(stderr, "Error memsetting %d bytes of device memory.\n", cur_stride);
PyErr_Format(PyExc_MemoryError, "Error memsetting %d bytes of device memory.", total_size);
PyErr_Format(PyExc_MemoryError, "Error memsetting %d bytes of device memory.", cur_stride);
free(newdims);
free(newdims);
Py_DECREF(rval);
Py_DECREF(rval);
return NULL;
return NULL;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论