Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c2a36918
提交
c2a36918
authored
11月 12, 2012
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add c_code support for the type and a c_code version of HostFromGpu.
上级
f1d4a78b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
92 行增加
和
2 行删除
+92
-2
basic_ops.py
theano/sandbox/gpuarray/basic_ops.py
+39
-0
type.py
theano/sandbox/gpuarray/type.py
+53
-2
没有找到文件。
theano/sandbox/gpuarray/basic_ops.py
浏览文件 @
c2a36918
...
@@ -43,6 +43,45 @@ class HostFromGpu(Op):
...
@@ -43,6 +43,45 @@ class HostFromGpu(Op):
z
,
=
out
z
,
=
out
z
[
0
]
=
numpy
.
asarray
(
x
)
z
[
0
]
=
numpy
.
asarray
(
x
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
inp
=
inputs
[
0
]
out
=
outputs
[
0
]
fail
=
sub
[
'fail'
]
return
"""{
GpuArray
%(name)
s_ga_s;
GpuArray *
%(name)
s_ga;
int
%(name)
serr;
PyArray_Descr *
%(name)
s_dtype;
if (!GpuArray_ISONESEGMENT(&
%(inp)
s->ga)) {
if (GpuArray_copy(&
%(name)
s_ga_s, &
%(inp)
s->ga, GA_C_ORDER) != GA_NO_ERROR) {
%(fail)
s;
}
%(name)
s_ga = &
%(name)
s_ga_s;
} else {
%(name)
s_ga = &
%(inp)
s->ga;
}
%(name)
s_dtype = typecode_to_dtype(
%(inp)
s->ga.typecode);
// PyArray_Empty below steals a reference to the dtype we pass it
// so we need an extra one to spare.
Py_INCREF(
%(name)
s_dtype);
%(out)
s = (PyArrayObject *)PyArray_Empty(
%(inp)
s->ga.nd,
(npy_intp *)
%(inp)
s->ga.dimensions,
%(name)
s_dtype,
(
%(inp)
s->ga.flags & GA_F_CONTIGUOUS) &&
!(
%(inp)
s->ga.flags & GA_C_CONTIGUOUS));
if (
%(out)
s == NULL) {
if (
%(name)
s_ga == &
%(name)
s_ga_s) GpuArray_clear(
%(name)
s_ga);
%(fail)
s
}
%(name)
serr = GpuArray_read(PyArray_DATA(
%(out)
s),
PyArray_NBYTES(
%(out)
s),
%(name)
s_ga);
if (
%(name)
s_ga == &
%(name)
s_ga_s) GpuArray_clear(
%(name)
s_ga);
if (
%(name)
serr != GA_NO_ERROR) {
%(fail)
s
}
}"""
%
{
'name'
:
name
,
'fail'
:
sub
[
'fail'
],
'inp'
:
inp
,
'out'
:
out
}
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
gz
,
=
grads
gz
,
=
grads
return
[
gpu_from_host
(
gz
)]
return
[
gpu_from_host
(
gz
)]
...
...
theano/sandbox/gpuarray/type.py
浏览文件 @
c2a36918
...
@@ -114,8 +114,59 @@ class GpuArrayType(Type):
...
@@ -114,8 +114,59 @@ class GpuArrayType(Type):
hash
(
self
.
kind
)
^
hash
(
self
.
context
))
hash
(
self
.
kind
)
^
hash
(
self
.
context
))
def
__str__
(
self
):
def
__str__
(
self
):
return
"GpuArray<
%
s>"
%
self
.
dtype
return
"GpuArray[
%
s,
%
s]<
%
s>"
%
(
self
.
kind
,
self
.
context
,
self
.
dtype
)
def
c_declare
(
self
,
name
,
sub
):
return
"GpuArrayObject *
%
s;"
%
(
name
,)
def
c_init
(
self
,
name
,
sub
):
return
"
%
s = NULL;"
%
(
name
,)
def
c_extract
(
self
,
name
,
sub
):
# TODO I don't check broadcast stuff for now.
return
"""
%(name)
s = NULL;
if (py_
%(name)
s == Py_None) {
PyErr_SetString(PyExc_ValueError, "expected an ndarray, not None");
%(fail)
s
}
if (py_
%(name)
s->ob_type != &GpuArrayType &&
!PyObject_TypeCheck(py_
%(name)
s, &GpuArrayType)) {
PyErr_SetString(PyExc_ValueError, "expected a GpuArray");
%(fail)
s
}
%(name)
s = (GpuArrayObject *)py_
%(name)
s;
Py_INCREF(
%(name)
s);
"""
%
{
'name'
:
name
,
'fail'
:
sub
[
'fail'
]}
def
c_cleanup
(
self
,
name
,
sub
):
return
""
def
c_sync
(
self
,
name
,
sub
):
return
"""
if (!
%(name)
s) {
Py_XDECREF(py_
%(name)
s);
Py_INCREF(Py_None);
py_
%(name)
s = Py_None;
} else if ((void *)py_
%(name)
s != (void *)
%(name)
s) {
Py_XDECREF(py_
%(name)
s);
py_
%(name)
s = (PyObject *)
%(name)
s;
Py_INCREF(py_
%(name)
s);
}
"""
%
{
'name'
:
name
}
def
c_headers
(
self
):
return
[
'pygpu/gpuarray.h'
,
'compyte/array.h'
,
'compyte/kernel.h'
,
'compyte/error.h'
]
def
c_libraries
(
self
):
return
[
'compyte'
]
def
c_header_dirs
(
self
):
return
[
pygpu
.
get_include
()]
def
c_code_cache_version
(
self
):
return
()
# TODO: This is temporary
class
_operators
(
tensor
.
basic
.
_tensor_py_operators
):
class
_operators
(
tensor
.
basic
.
_tensor_py_operators
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论