Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
69267c88
提交
69267c88
authored
6月 27, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reuse the old code for GpuAdvancedIncSubtensor1 when the new code isn't used.
This is needed when ndim !=2 and for older GPU like the GTX285.
上级
a240803c
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
155 行增加
和
14 行删除
+155
-14
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+139
-13
opt.py
theano/sandbox/cuda/opt.py
+16
-1
没有找到文件。
theano/sandbox/cuda/basic_ops.py
浏览文件 @
69267c88
...
@@ -2308,6 +2308,7 @@ class GpuSubtensor(GpuOp, tensor.Subtensor):
...
@@ -2308,6 +2308,7 @@ class GpuSubtensor(GpuOp, tensor.Subtensor):
return
()
return
()
return
(
3
,
hv
)
return
(
3
,
hv
)
class
GpuAdvancedSubtensor1
(
tensor
.
AdvancedSubtensor1
,
GpuOp
):
class
GpuAdvancedSubtensor1
(
tensor
.
AdvancedSubtensor1
,
GpuOp
):
"""
"""
Implement AdvancedSubtensor1 on the gpu.
Implement AdvancedSubtensor1 on the gpu.
...
@@ -2392,14 +2393,6 @@ class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1, GpuOp):
...
@@ -2392,14 +2393,6 @@ class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1, GpuOp):
y_
=
as_cuda_ndarray_variable
(
y
)
y_
=
as_cuda_ndarray_variable
(
y
)
ilist_
=
tensor
.
as_tensor_variable
(
ilist
)
ilist_
=
tensor
.
as_tensor_variable
(
ilist
)
convert_map
=
{
8
:
tensor
.
basic
.
_convert_to_int8
,
16
:
tensor
.
basic
.
_convert_to_int16
,
32
:
tensor
.
basic
.
_convert_to_int32
,
64
:
tensor
.
basic
.
_convert_to_int64
}
intwidth
=
theano
.
gof
.
compiledir
.
python_int_bitwidth
()
ilist_
=
convert_map
[
intwidth
](
ilist_
)
assert
x_
.
type
.
dtype
==
y_
.
type
.
dtype
assert
x_
.
type
.
dtype
==
y_
.
type
.
dtype
assert
x_
.
type
.
ndim
>=
y_
.
type
.
ndim
assert
x_
.
type
.
ndim
>=
y_
.
type
.
ndim
...
@@ -2450,16 +2443,150 @@ class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1, GpuOp):
...
@@ -2450,16 +2443,150 @@ class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1, GpuOp):
x
[
i
]
+=
y
x
[
i
]
+=
y
out
[
0
]
=
x
out
[
0
]
=
x
def
c_code_cache_version
(
self
):
return
(
3
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
if
(
self
.
set_instead_of_inc
)
or
\
(
node
.
inputs
[
0
]
.
ndim
!=
node
.
inputs
[
1
]
.
ndim
):
raise
NotImplementedError
(
"This case does not have C code yet."
)
x
=
inputs
[
0
]
y
=
inputs
[
1
]
ind
=
inputs
[
2
]
out
=
outputs
[
0
]
fail
=
sub
[
'fail'
]
inplace
=
int
(
self
.
inplace
)
return
"""
PyObject *x_obj, *y_obj, *row_x, *row_y;
PyObject *x_rowind_obj, *y_rowind_obj;
dtype_
%(ind)
s *p_index;
int num_indices, j;
int ret;
num_indices = PyArray_SIZE(
%(ind)
s);
if ((num_indices - 1) > LONG_MAX) {
PyErr_Format(PyExc_AssertionError,
"num_indices
%%
d exceeds LONG_MAX + 1", num_indices);
%(fail)
s;
}
Py_XDECREF(
%(out)
s);
if (!
%(inplace)
s) {
%(out)
s = (CudaNdarray*)CudaNdarray_Copy(
%(x)
s);
} else {
%(out)
s =
%(x)
s;
Py_XINCREF(
%(out)
s);
}
x_obj = (PyObject*)CudaNdarray_View(
%(out)
s);
y_obj = (PyObject*)CudaNdarray_View(
%(y)
s);
for (j = 0;j < num_indices; j++) {
p_index = (dtype_
%(ind)
s *)PyArray_GETPTR1(
%(ind)
s, j);
x_rowind_obj = PyInt_FromLong(*p_index);
if (PyInt_AsLong(x_rowind_obj) != (*p_index)) {
PyErr_Format(PyExc_AssertionError,
"Error in converting row index to integer from long");
// Dec Ref what ever we have increfed or allocated so far
// We deallocate objects exactly in the reverse order they were allocated.
Py_XDECREF(x_rowind_obj);
Py_XDECREF(y_obj);
Py_XDECREF(x_obj);
%(fail)
s;
}
y_rowind_obj = PyInt_FromLong(j);
row_x = CudaNdarray_Subscript(x_obj, x_rowind_obj);
row_y = CudaNdarray_Subscript(y_obj, y_rowind_obj);
if ((row_x == NULL) || (row_y == NULL)) {
Py_XDECREF(row_y);
Py_XDECREF(row_x);
Py_XDECREF(y_rowind_obj);
Py_XDECREF(x_rowind_obj);
Py_XDECREF(y_obj);
Py_XDECREF(x_obj);
%(fail)
s;
}
ret = CudaNdarray_inplace_elemwise(row_x, row_y, IADD);
if (ret != 0) {
Py_XDECREF(row_y);
Py_XDECREF(row_x);
Py_XDECREF(y_rowind_obj);
Py_XDECREF(x_rowind_obj);
Py_XDECREF(y_obj);
Py_XDECREF(x_obj);
%(fail)
s;
}
Py_XDECREF(row_y);
Py_XDECREF(row_x);
Py_XDECREF(y_rowind_obj);
Py_XDECREF(x_rowind_obj);
}
Py_XDECREF(y_obj);
Py_XDECREF(x_obj);
if (!
%(out)
s) {
%(fail)
s
}
"""
%
locals
()
class
GpuAdvancedIncSubtensor1_dev20
(
GpuAdvancedIncSubtensor1
):
"""Implement AdvancedIncSubtensor1 on the gpu, but use function
only avail on compute capability 2.0 and more recent.
"""
def
make_node
(
self
,
x
,
y
,
ilist
):
"""It defer from GpuAdvancedIncSubtensor1 in that it make sure
the index are of type long.
"""
x_
=
as_cuda_ndarray_variable
(
x
)
y_
=
as_cuda_ndarray_variable
(
y
)
ilist_
=
tensor
.
as_tensor_variable
(
ilist
)
convert_map
=
{
8
:
tensor
.
basic
.
_convert_to_int8
,
16
:
tensor
.
basic
.
_convert_to_int16
,
32
:
tensor
.
basic
.
_convert_to_int32
,
64
:
tensor
.
basic
.
_convert_to_int64
}
intwidth
=
theano
.
gof
.
compiledir
.
python_int_bitwidth
()
ilist_
=
convert_map
[
intwidth
](
ilist_
)
assert
x_
.
type
.
dtype
==
y_
.
type
.
dtype
assert
x_
.
type
.
ndim
>=
y_
.
type
.
ndim
if
ilist_
.
type
.
dtype
[:
3
]
not
in
(
'int'
,
'uin'
):
raise
TypeError
(
'index must be integers'
)
if
ilist_
.
type
.
broadcastable
!=
(
False
,):
raise
TypeError
(
'index must be vector'
)
if
x_
.
type
.
ndim
==
0
:
raise
TypeError
(
'cannot index into a scalar'
)
if
x_
.
type
.
broadcastable
[
0
]:
# the caller should have made a copy of x len(ilist) times
raise
TypeError
(
'cannot index into a broadcastable dimension'
)
return
Apply
(
self
,
[
x_
,
y_
,
ilist_
],
[
x_
.
type
()])
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
2
,)
return
(
2
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
active_device_no
=
theano
.
sandbox
.
cuda
.
active_device_number
()
active_device_no
=
theano
.
sandbox
.
cuda
.
active_device_number
()
compute_capability
=
device_properties
(
active_device_no
)[
'major'
]
compute_capability
=
device_properties
(
active_device_no
)[
'major'
]
if
(
self
.
set_instead_of_inc
)
or
\
if
(
(
self
.
set_instead_of_inc
)
or
(
node
.
inputs
[
0
]
.
ndim
!=
node
.
inputs
[
1
]
.
ndim
)
or
\
(
node
.
inputs
[
0
]
.
ndim
!=
node
.
inputs
[
1
]
.
ndim
)
or
(
node
.
inputs
[
0
]
.
ndim
!=
2
)
or
\
(
node
.
inputs
[
0
]
.
ndim
!=
2
)
or
(
compute_capability
<
2
):
(
compute_capability
<
2
)
):
raise
NotImplementedError
(
"This case does not have C code yet."
)
raise
NotImplementedError
(
"This case does not have C code yet."
)
x
=
inputs
[
0
]
x
=
inputs
[
0
]
...
@@ -2468,7 +2595,6 @@ class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1, GpuOp):
...
@@ -2468,7 +2595,6 @@ class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1, GpuOp):
out
=
outputs
[
0
]
out
=
outputs
[
0
]
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
inplace
=
int
(
self
.
inplace
)
inplace
=
int
(
self
.
inplace
)
return
"""
return
"""
Py_XDECREF(
%(out)
s);
Py_XDECREF(
%(out)
s);
if (!
%(inplace)
s) {
if (!
%(inplace)
s) {
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
69267c88
...
@@ -776,9 +776,16 @@ def local_gpu_advanced_incsubtensor1(node):
...
@@ -776,9 +776,16 @@ def local_gpu_advanced_incsubtensor1(node):
'either set the `warn.gpu_set_subtensor1` config '
'either set the `warn.gpu_set_subtensor1` config '
'option to False, or `warn.ignore_bug_before` to at '
'option to False, or `warn.ignore_bug_before` to at '
'least
\'
0.6
\'
.'
,
stacklevel
=
1
)
'least
\'
0.6
\'
.'
,
stacklevel
=
1
)
active_device_no
=
theano
.
sandbox
.
cuda
.
active_device_number
()
compute_capability
=
device_properties
(
active_device_no
)[
'major'
]
if
(
compute_capability
<
2
or
x
.
ndim
!=
2
or
y
.
ndim
!=
2
):
gpu_op
=
GpuAdvancedIncSubtensor1
(
gpu_op
=
GpuAdvancedIncSubtensor1
(
set_instead_of_inc
=
set_instead_of_inc
)
set_instead_of_inc
=
set_instead_of_inc
)
else
:
gpu_op
=
GpuAdvancedIncSubtensor1_dev20
(
set_instead_of_inc
=
set_instead_of_inc
)
return
[
gpu_op
(
gpu_from_host
(
x
),
gpu_from_host
(
y
),
*
coords
)]
return
[
gpu_op
(
gpu_from_host
(
x
),
gpu_from_host
(
y
),
*
coords
)]
# Should not execute for GpuAdvancedIncSubtensor1
# Should not execute for GpuAdvancedIncSubtensor1
...
@@ -809,8 +816,16 @@ def local_gpu_advanced_incsubtensor1(node):
...
@@ -809,8 +816,16 @@ def local_gpu_advanced_incsubtensor1(node):
'option to False, or `warn.ignore_bug_before` to at '
'option to False, or `warn.ignore_bug_before` to at '
'least
\'
0.6
\'
.'
,
stacklevel
=
1
)
'least
\'
0.6
\'
.'
,
stacklevel
=
1
)
active_device_no
=
theano
.
sandbox
.
cuda
.
active_device_number
()
compute_capability
=
device_properties
(
active_device_no
)[
'major'
]
if
(
compute_capability
<
2
or
x
.
ndim
!=
2
or
y
.
ndim
!=
2
):
gpu_op
=
GpuAdvancedIncSubtensor1
(
gpu_op
=
GpuAdvancedIncSubtensor1
(
set_instead_of_inc
=
set_instead_of_inc
)
set_instead_of_inc
=
set_instead_of_inc
)
else
:
gpu_op
=
GpuAdvancedIncSubtensor1_dev20
(
set_instead_of_inc
=
set_instead_of_inc
)
return
[
host_from_gpu
(
gpu_op
(
gpu_x
,
gpu_y
,
*
coords
))]
return
[
host_from_gpu
(
gpu_op
(
gpu_x
,
gpu_y
,
*
coords
))]
return
False
return
False
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论