Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6c955ecf
提交
6c955ecf
authored
8月 23, 2011
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New version of GpuAdvancedSubtensor1 with gpu code when input have up to 3…
New version of GpuAdvancedSubtensor1 with gpu code when input have up to 3 dimensions or is c_contiguous.
上级
6005ac2b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
82 行增加
和
6 行删除
+82
-6
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+31
-5
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+0
-0
cuda_ndarray.cuh
theano/sandbox/cuda/cuda_ndarray.cuh
+6
-0
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+45
-1
没有找到文件。
theano/sandbox/cuda/basic_ops.py
浏览文件 @
6c955ecf
...
@@ -1891,6 +1891,8 @@ class GpuAdvancedSubtensor1(tensor.AdvancedSubtensor1, GpuOp):
...
@@ -1891,6 +1891,8 @@ class GpuAdvancedSubtensor1(tensor.AdvancedSubtensor1, GpuOp):
"""
"""
Implement AdvancedSubtensor1 on the gpu.
Implement AdvancedSubtensor1 on the gpu.
"""
"""
assert_fast
=
None
def
make_node
(
self
,
x
,
ilist
):
def
make_node
(
self
,
x
,
ilist
):
x_
=
as_cuda_ndarray_variable
(
x
)
x_
=
as_cuda_ndarray_variable
(
x
)
ilist_
=
tensor
.
as_tensor_variable
(
ilist
)
ilist_
=
tensor
.
as_tensor_variable
(
ilist
)
...
@@ -1908,11 +1910,35 @@ class GpuAdvancedSubtensor1(tensor.AdvancedSubtensor1, GpuOp):
...
@@ -1908,11 +1910,35 @@ class GpuAdvancedSubtensor1(tensor.AdvancedSubtensor1, GpuOp):
#super(GpuAdvancedSubtensor1, self).perform(node, inp, out_)
#super(GpuAdvancedSubtensor1, self).perform(node, inp, out_)
x
,
idx
=
inp
x
,
idx
=
inp
out
,
=
out_
out
,
=
out_
o
=
cuda_ndarray
.
cuda_ndarray
.
CudaNdarray
.
zeros
((
len
(
idx
),)
+
new_method
=
True
x
.
shape
[
1
:])
#TODO: if more then 3 dims, reshape the inputs if it is contiguous.
for
(
j
,
i
)
in
enumerate
(
idx
):
x_orig
=
x
o
[
j
]
=
x
[
i
]
if
x
.
ndim
>
3
and
x
.
is_c_contiguous
():
out
[
0
]
=
o
x
=
x
.
reshape
((
x
.
shape
[
0
],
numpy
.
prod
(
x
.
shape
[
1
:])))
if
x
.
ndim
<=
3
:
if
self
.
assert_fast
is
not
None
:
assert
self
.
assert_fast
==
True
,
(
"GpuAdvancedSubtensor1 used the fast version"
)
# Support x with dimensions 1,2,3 only.
o
=
x
.
take
(
cuda_ndarray
.
cuda_ndarray
.
CudaNdarray
(
idx
.
astype
(
"float32"
)),
0
,
out_
[
0
][
0
])
# idx, axis, return[, clipmode]
if
x
is
not
x_orig
:
o
=
o
.
reshape
((
len
(
idx
),)
+
x_orig
.
shape
[
1
:])
out
[
0
]
=
o
else
:
if
self
.
assert_fast
is
not
None
:
assert
self
.
assert_fast
==
False
,
(
"GpuAdvancedSubtensor1 didn't used the fast version"
)
if
(
out_
[
0
][
0
]
is
None
or
out_
[
0
][
0
]
.
shape
!=
(
len
(
idx
),)
+
x
.
shape
[
1
:]):
o
=
cuda_ndarray
.
cuda_ndarray
.
CudaNdarray
.
zeros
((
len
(
idx
),)
+
x
.
shape
[
1
:])
else
:
o
=
out_
[
0
][
0
]
for
(
j
,
i
)
in
enumerate
(
idx
):
o
[
j
]
=
x
[
i
]
out
[
0
]
=
o
class
GpuAdvancedIncSubtensor1
(
tensor
.
AdvancedIncSubtensor1
,
GpuOp
):
class
GpuAdvancedIncSubtensor1
(
tensor
.
AdvancedIncSubtensor1
,
GpuOp
):
...
...
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
6c955ecf
差异被折叠。
点击展开。
theano/sandbox/cuda/cuda_ndarray.cuh
浏览文件 @
6c955ecf
...
@@ -338,6 +338,12 @@ DllExport int CudaNdarray_reduce_min(CudaNdarray * self, CudaNdarray * A);
...
@@ -338,6 +338,12 @@ DllExport int CudaNdarray_reduce_min(CudaNdarray * self, CudaNdarray * A);
DllExport
int
CudaNdarray_reduce_max
(
CudaNdarray
*
self
,
CudaNdarray
*
A
);
DllExport
int
CudaNdarray_reduce_max
(
CudaNdarray
*
self
,
CudaNdarray
*
A
);
DllExport
int
CudaNdarray_dimshuffle
(
CudaNdarray
*
self
,
unsigned
int
len
,
const
int
*
pattern
);
DllExport
int
CudaNdarray_dimshuffle
(
CudaNdarray
*
self
,
unsigned
int
len
,
const
int
*
pattern
);
//PyObject* PyArray_TakeFrom(PyArrayObject* self, PyObject* indices, int axis, PyArrayObject* ret, NPY_CLIPMODE clipmode)
//PyObject*
//CudaNdarray_TakeFrom(CudaNdarray* self, PyObject* indices, int axis,
// PyArrayObject* ret, NPY_CLIPMODE clipmode);
PyObject
*
CudaNdarray_TakeFrom
(
CudaNdarray
*
self
,
PyObject
*
args
);
static
void
fprint_CudaNdarray
(
FILE
*
fd
,
const
CudaNdarray
*
self
);
static
void
fprint_CudaNdarray
(
FILE
*
fd
,
const
CudaNdarray
*
self
);
...
...
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
6c955ecf
import
sys
,
time
,
unittest
import
copy
import
sys
import
time
import
unittest
from
theano.compile.pfunc
import
pfunc
from
theano.compile.pfunc
import
pfunc
from
theano
import
tensor
from
theano
import
tensor
...
@@ -846,6 +849,47 @@ class T_subtensor(theano.tensor.tests.test_basic.T_subtensor):
...
@@ -846,6 +849,47 @@ class T_subtensor(theano.tensor.tests.test_basic.T_subtensor):
return
super
(
theano
.
tensor
.
tests
.
test_basic
.
T_subtensor
,
return
super
(
theano
.
tensor
.
tests
.
test_basic
.
T_subtensor
,
self
)
.
__init__
(
name
)
self
)
.
__init__
(
name
)
def
test_adv_sub1_fast
(
self
):
""" We check that we correctly used the fast version"""
rand
=
numpy
.
random
.
rand
for
data
,
idx
,
fast
in
[(
rand
(
70000
),
range
(
70000
),
True
),
(
rand
(
70000
,
5
),
range
(
70000
),
True
),
(
rand
(
70000
,
2
,
3
),
range
(
70000
),
True
),
(
rand
(
4
,
5
),
[
2
,
3
],
True
),
(
rand
(
4
,
2
,
3
),
[
0
,
3
],
True
),
(
rand
(
4
,
2
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
],
True
),
(
rand
(
4
,
2
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
,
-
1
,
-
2
,
-
3
,
-
4
],
True
),
# Test 4 dims as gpu. code use another algo
# in that case. This new algo is not as much
# optimized for that case.
(
rand
(
4
,
4
,
2
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
,
-
1
,
-
2
,
-
3
,
-
4
],
False
),
]:
data
=
numpy
.
asarray
(
data
,
dtype
=
self
.
dtype
)
n
=
self
.
shared
(
data
)
# Test with c_contiguous input
t
=
self
.
adv_sub1
()(
n
,
idx
)
t
.
owner
.
op
.
assert_fast
=
True
# input c_contiguous, so we reshape
val
=
self
.
eval_output_and_check
(
t
,
list
=
True
)
val
=
numpy
.
asarray
(
val
)
good
=
data
[
idx
]
self
.
assertTrue
(
val
.
ndim
==
data
.
ndim
)
self
.
assertTrue
(
numpy
.
allclose
(
val
,
good
),
(
val
,
good
))
# Test with input strided
t
=
self
.
adv_sub1
()(
n
[::
-
1
],
idx
)
t
.
owner
.
op
.
assert_fast
=
fast
val
=
theano
.
function
([],
t
,
mode
=
self
.
mode
)()
val
=
numpy
.
asarray
(
val
)
good
=
data
[::
-
1
][
idx
]
self
.
assertTrue
(
val
.
ndim
==
data
.
ndim
)
self
.
assertTrue
(
numpy
.
allclose
(
val
,
good
),
(
val
,
good
))
def
test_advinc_subtensor1
():
def
test_advinc_subtensor1
():
""" Test the second case in the opt local_gpu_advanced_incsubtensor1 """
""" Test the second case in the opt local_gpu_advanced_incsubtensor1 """
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论