Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1584e29d
提交
1584e29d
authored
8月 22, 2013
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add GpuSubtensor.
上级
382d2ed1
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
114 行增加
和
1 行删除
+114
-1
basic_ops.py
theano/sandbox/gpuarray/basic_ops.py
+96
-0
test_basic_ops.py
theano/sandbox/gpuarray/tests/test_basic_ops.py
+18
-1
没有找到文件。
theano/sandbox/gpuarray/basic_ops.py
浏览文件 @
1584e29d
...
@@ -499,3 +499,99 @@ class GpuAlloc(Op):
...
@@ -499,3 +499,99 @@ class GpuAlloc(Op):
return
True
return
True
gpu_alloc
=
GpuAlloc
()
gpu_alloc
=
GpuAlloc
()
class
GpuSubtensor
(
tensor
.
Subtensor
):
def
make_node
(
self
,
x
,
*
inputs
):
assert
isinstance
(
x
.
type
,
GpuArrayType
)
rval
=
tensor
.
Subtensor
.
make_node
(
self
,
x
,
*
inputs
)
otype
=
GpuArrayType
(
dtype
=
rval
.
outputs
[
0
]
.
type
.
dtype
,
broadcastable
=
rval
.
outputs
[
0
]
.
type
.
broadcastable
)
return
Apply
(
self
,
[
x
]
+
rval
.
inputs
[
1
:],
[
otype
()])
def
perform
(
self
,
node
,
inputs
,
out_
):
out
,
=
out_
x
=
inputs
[
0
]
indices
=
list
(
reversed
(
inputs
[
1
:]))
def
convert
(
entry
):
if
isinstance
(
entry
,
Type
):
rval
=
indices
.
pop
()
if
sys
.
version_info
<
(
2
,
5
):
# Before Python 2.5, PySlice_GetIndicesEx requires
# Python int to be passed.
rval_
=
int
(
rval
)
if
rval_
!=
rval
:
raise
IndexError
((
"Invalid value for indexing:
%
s. "
"That value may be too big."
)
%
rval
)
return
rval_
return
rval
elif
isinstance
(
entry
,
slice
):
return
slice
(
convert
(
entry
.
start
),
convert
(
entry
.
stop
),
convert
(
entry
.
step
))
else
:
return
entry
cdata
=
tuple
(
map
(
convert
,
self
.
idx_list
))
if
len
(
cdata
)
==
1
:
cdata
=
cdata
[
0
]
out
[
0
]
=
x
.
__getitem__
(
cdata
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
view_ndim
=
node
.
outputs
[
0
]
.
ndim
indices
=
inputs
[
1
:]
sio
=
StringIO
.
StringIO
(
"""
ssize_t
%(name)
s_starts[
%(sz)
s];
ssize_t
%(name)
s_stops[
%(sz)
s];
ssize_t
%(name)
s_steps[
%(sz)
s];
"""
%
dict
(
name
=
name
,
sz
=
len
(
self
.
idx_list
)))
ndim
=
0
for
i
,
idx
in
enumerate
(
self
.
idx_list
):
if
isinstance
(
idx
,
Type
):
# Index by an input number
print
>>
sio
,
"""
%(name)
s_starts[
%(i)
s] =
%(start)
s;
%(name)
s_steps[
%(i)
s] =
%(step)
s;
"""
%
dict
(
name
=
name
,
i
=
i
,
start
=
indices
.
pop
(),
step
=
0
)
elif
isinstance
(
idx
,
slice
):
# index by a fixed slice
print
>>
sio
,
"""
%(name)
s_starts[
%(i)
s] =
%(start)
s;
%(name)
s_stops[
%(i)
s] =
%(stop)
s;
%(name)
s_steps[
%(i)
s] =
%(step)
s;
"""
%
dict
(
i
=
i
,
name
=
name
,
start
=
idx
.
start
,
stop
=
idx
.
stop
,
step
=
idx
.
step
)
ndim
+=
1
else
:
# Index by a fixed number
print
>>
sio
,
"""
%(name)
s_starts[
%(i)
s] =
%(start)
s;
%(name)
s_steps[
%(i)
s] =
%(step)
s;
"""
%
dict
(
name
=
name
,
i
=
i
,
start
=
idx
,
step
=
0
)
print
>>
sio
,
"""
if (
%(out)
s) {
// Try to reuse the python object.
GpuArray_clear(&
%(out)
s->ga);
} else {
%(out)
s = new_GpuArray((PyObject *)&GpuArrayType, GpuArray_default_context);
}
if (!
%(out)
s) {
%(fail)
s }
int
%(name)
s_err;
%(name)
s_err = GpuArray_index(&
%(out)
s->ga, &
%(inp)
s->ga,
%(name)
s_starts,
%(name)
s_steps,
%(name)
s_stops)
if (
%(name)
s_err != GA_NO_ERROR) {
Py_DECREF(
%(out)
s);
%(out)
s = NULL;
PyErr_SetString(PyExc_RuntimeError, "Error during index");
%(fail)
s
}
"""
%
dict
(
name
=
name
,
fail
=
sub
[
'fail'
],
inp
=
inputs
[
0
],
out
=
outputs
[
0
])
return
sio
.
getvalue
()
def
c_code_cache_version
(
self
):
return
()
# for testing
theano/sandbox/gpuarray/tests/test_basic_ops.py
浏览文件 @
1584e29d
...
@@ -9,6 +9,7 @@ from theano.compile import DeepCopyOp
...
@@ -9,6 +9,7 @@ from theano.compile import DeepCopyOp
from
theano.tensor.tests.test_basic
import
safe_make_node
from
theano.tensor.tests.test_basic
import
safe_make_node
from
theano.tests.unittest_tools
import
SkipTest
from
theano.tests.unittest_tools
import
SkipTest
from
numpy.testing.noseclasses
import
KnownFailureTest
from
numpy.testing.noseclasses
import
KnownFailureTest
from
theano.tensor.tests.test_subtensor
import
T_subtensor
import
theano.sandbox.gpuarray
import
theano.sandbox.gpuarray
...
@@ -33,7 +34,8 @@ from theano.sandbox.gpuarray.type import (GpuArrayType,
...
@@ -33,7 +34,8 @@ from theano.sandbox.gpuarray.type import (GpuArrayType,
gpuarray_shared_constructor
)
gpuarray_shared_constructor
)
from
theano.sandbox.gpuarray.basic_ops
import
(
host_from_gpu
,
gpu_from_host
,
from
theano.sandbox.gpuarray.basic_ops
import
(
host_from_gpu
,
gpu_from_host
,
gpu_alloc
,
gpu_from_cuda
,
gpu_alloc
,
gpu_from_cuda
,
cuda_from_gpu
)
cuda_from_gpu
,
HostFromGpu
,
GpuFromHost
,
GpuSubtensor
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
utt
.
seed_rng
()
utt
.
seed_rng
()
...
@@ -328,3 +330,18 @@ def test_deep_copy():
...
@@ -328,3 +330,18 @@ def test_deep_copy():
res
=
f
(
a
)
res
=
f
(
a
)
assert
GpuArrayType
.
values_eq
(
res
,
a
)
assert
GpuArrayType
.
values_eq
(
res
,
a
)
class
G_subtensor
(
T_subtensor
):
def
shortDescription
(
self
):
return
None
shared
=
staticmethod
(
gpuarray_shared_constructor
)
sub
=
GpuSubtensor
mode
=
mode_with_gpu
dtype
=
'float32'
# avoid errors on gpus which do not support float64
ignore_topo
=
(
HostFromGpu
,
GpuFromHost
)
fast_compile
=
False
ops
=
(
GpuSubtensor
,)
def
__init__
(
self
,
name
):
T_subtensor
.
__init__
(
self
,
name
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论