Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
561b084b
提交
561b084b
authored
11月 26, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1012 from goodfeli/cuda_alloc
Ready to merge: Cuda allocation code
上级
9eb9db60
4557c310
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
49 行增加
和
7 行删除
+49
-7
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+27
-0
cuda_ndarray.cuh
theano/sandbox/cuda/cuda_ndarray.cuh
+22
-7
没有找到文件。
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
561b084b
...
...
@@ -4666,6 +4666,33 @@ int fprint_CudaNdarray(FILE * fd, const CudaNdarray *self)
return
0
;
}
int
CudaNdarray_prep_output
(
CudaNdarray
**
arr
,
int
nd
,
const
int
*
dims
)
{
bool
allocated
=
false
;
if
(
*
arr
==
NULL
)
{
// This allocates the metadata but not the data
*
arr
=
(
CudaNdarray
*
)
CudaNdarray_new_nd
(
nd
);
if
(
*
arr
==
NULL
)
return
-
1
;
allocated
=
true
;
}
if
(
CudaNdarray_alloc_contiguous
(
*
arr
,
nd
,
dims
))
{
if
(
allocated
)
{
Py_DECREF
(
*
arr
);
*
arr
=
NULL
;
}
return
-
1
;
}
return
0
;
}
/*
Local Variables:
mode:c++
...
...
theano/sandbox/cuda/cuda_ndarray.cuh
浏览文件 @
561b084b
...
...
@@ -149,11 +149,11 @@ DllExport int
CudaNdarray_Equal
(
CudaNdarray
*
cnda1
,
CudaNdarray
*
cnda2
);
/****
* Set the
idx'th dimension
to value d.
* Set the
dimension[idx]
to value d.
*
* Updates the log2dim shadow array.
*
* Does not sync structure to
host
.
* Does not sync structure to
device
.
*/
DllExport
inline
void
__attribute__
((
always_inline
))
CudaNdarray_set_dim
(
CudaNdarray
*
self
,
int
idx
,
int
d
)
...
...
@@ -229,7 +229,8 @@ DllExport PyObject * CudaNdarray_new_nd(const int nd);
/**
* [Re]allocate a CudaNdarray with access to 'nd' dimensions.
*
* Note: This does not allocate storage for data.
* Note: This does not allocate storage for data, or free
* pre-existing storage.
*/
DllExport
inline
int
__attribute__
((
always_inline
))
CudaNdarray_set_nd
(
CudaNdarray
*
self
,
const
int
nd
)
...
...
@@ -276,6 +277,7 @@ CudaNdarray_set_nd(CudaNdarray * self, const int nd)
* CudaNdarray_alloc_contiguous
*
* Allocate storage space for a tensor of rank 'nd' and given dimensions.
* (No-op if self already has a contiguous tensor of the right dimensions)
*
* Note: CudaNdarray_alloc_contiguous is templated to work for both int dimensions and npy_intp dimensions
*/
...
...
@@ -286,13 +288,13 @@ static int CudaNdarray_alloc_contiguous(CudaNdarray *self, const int nd, const i
// return 0 on success
int
size
=
1
;
//set up the strides for contiguous tensor
assert
(
nd
>=
0
);
// Here we modify the host structure to have the desired shape and
// strides. This does not cause the storage to be freed or reallocated.
if
(
CudaNdarray_set_nd
(
self
,
nd
))
{
return
-
1
;
}
//TODO: check if by any chance our current dims are correct,
// and strides already contiguous
// in that case we can return right here.
for
(
int
i
=
nd
-
1
;
i
>=
0
;
--
i
)
{
CudaNdarray_set_stride
(
self
,
i
,
(
dim
[
i
]
==
1
)
?
0
:
size
);
...
...
@@ -300,7 +302,11 @@ static int CudaNdarray_alloc_contiguous(CudaNdarray *self, const int nd, const i
size
=
size
*
dim
[
i
];
}
if
((
self
->
data_allocated
==
size
)
&&
CudaNdarray_is_c_contiguous
(
self
))
// If the allocated buffer is already of the right size, we don't need to
// do anything else.
// Note: self->data_allocated is 0 for a view, so views will fail this
// check and be turned into independent arrays below.
if
(
self
->
data_allocated
==
size
)
{
return
0
;
}
...
...
@@ -468,6 +474,15 @@ PyObject * CudaNdarray_View(const CudaNdarray * self);
PyObject
*
CudaNdarray_inplace_add
(
PyObject
*
py_self
,
PyObject
*
py_other
);
// Ensures that *arr is a pointer to a contiguous ndarray of the specified
// dimensions.
// *arr may initially be NULL, a pointer to an ndarray of the wrong size,
// or a pointer to an ndarray of the right size. In the last case it will
// not change.
int
CudaNdarray_prep_output
(
CudaNdarray
**
arr
,
int
nd
,
const
int
*
dims
);
#endif
/*
Local Variables:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论