Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
48607a1d
提交
48607a1d
authored
4月 07, 2014
作者:
Pierre Luc Carrier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated comments and error messages. Also modified the assert for dtypes.
上级
a0700ef0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
22 行删除
+26
-22
neighbours.py
theano/sandbox/gpuarray/neighbours.py
+26
-22
没有找到文件。
theano/sandbox/gpuarray/neighbours.py
浏览文件 @
48607a1d
# This is work in progress
import
numpy
from
theano
import
Op
,
Apply
,
config
from
theano.gof
import
local_optimizer
from
theano.sandbox.cuda.nvcc_compiler
import
NVCC_compiler
...
...
@@ -29,10 +29,11 @@ class GpuImages2Neibs(Images2Neibs, Op):
def
make_node
(
self
,
ten4
,
neib_shape
,
neib_step
):
assert
ten4
.
dtype
in
[
'int64'
,
'float32'
,
'float64'
]
assert
ten4
.
ndim
==
4
assert
neib_shape
.
ndim
==
1
assert
neib_step
.
ndim
==
1
assert
"int"
in
neib_shape
.
dtype
assert
"int"
in
neib_step
.
dtype
ten4
=
as_gpuarray_variable
(
ten4
)
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
...
...
@@ -220,6 +221,8 @@ class GpuImages2Neibs(Images2Neibs, Op):
z
,
=
out
fail
=
sub
[
'fail'
]
mode
=
self
.
mode
import
pdb
pdb
.
set_trace
()
if
config
.
gpuarray
.
sync
:
cnda_thread_sync
=
"GpuArray_sync(&
%(zz)
s->ga);"
%
dict
(
zz
=
zz
)
else
:
...
...
@@ -235,19 +238,22 @@ class GpuImages2Neibs(Images2Neibs, Op):
{
if (PyGpuArray_NDIM(
%(ten4)
s) != 4)
{
PyErr_Format(PyExc_TypeError, "pvals wrong rank");
PyErr_Format(PyExc_TypeError,
"GpuImages2Neibs: pvals wrong rank");
%(fail)
s;
}
if (PyArray_NDIM(
%(neib_shape)
s) != 1)
{
PyErr_Format(PyExc_TypeError, "unis wrong rank");
PyErr_Format(PyExc_TypeError,
"GpuImages2Neibs: unis wrong rank");
%(fail)
s;
}
if (PyArray_DIMS(
%(neib_shape)
s)[0] != 2)
{
PyErr_Format(PyExc_ValueError,
"neib_shape has to contain two elements");
"GpuImages2Neibs: neib_shape has to contain two"
" elements");
%(fail)
s;
}
...
...
@@ -263,16 +269,16 @@ class GpuImages2Neibs(Images2Neibs, Op):
if ( "
%(mode)
s" == "wrap_centered") {
if (c
%%2
!=1 || d
%%2
!=1){
PyErr_Format(PyExc_TypeError,
"Images2Neibs: in mode wrap_centered need patch with odd shapes");
"
Gpu
Images2Neibs: in mode wrap_centered need patch with odd shapes");
%(fail)
s;
}
if ( PyGpuArray_DIMS(
%(ten4)
s)[2] < c ||
PyGpuArray_DIMS(
%(ten4)
s)[3] < d)
{
PyErr_Format(PyExc_TypeError,
"
Images2Neibs: in wrap_centered mode, don't
"
"
support image shapes smaller then the patch
"
" shapes: neib_shape=(
%%
d,
%%
d),"
"
GpuImages2Neibs: in wrap_centered mode,
"
"
don't support image shapes smaller then
"
"
the patch
shapes: neib_shape=(
%%
d,
%%
d),"
" ten4[2:]=[
%%
d,
%%
d]",
c, d, PyGpuArray_DIMS(
%(ten4)
s)[2],
PyGpuArray_DIMS(
%(ten4)
s)[3]);
...
...
@@ -288,8 +294,8 @@ class GpuImages2Neibs(Images2Neibs, Op):
if ( ((PyGpuArray_DIMS(
%(ten4)
s))[2] < c) ||
((((PyGpuArray_DIMS(
%(ten4)
s))[2]-c)
%%
step_x)!=0))
{
PyErr_Format(PyExc_TypeError,
"neib_shape[0]=
%%
d, neib_step[0]=
%%
d and"
PyErr_Format(PyExc_TypeError,
"GpuImages2Neibs:"
"
neib_shape[0]=
%%
d, neib_step[0]=
%%
d and"
" ten4.shape[2]=
%%
d not consistent",
c, step_x,
PyGpuArray_DIMS(
%(ten4)
s)[2]);
...
...
@@ -298,8 +304,8 @@ class GpuImages2Neibs(Images2Neibs, Op):
if ( ((PyGpuArray_DIMS(
%(ten4)
s))[3] < d) ||
((((PyGpuArray_DIMS(
%(ten4)
s))[3]-d)
%%
step_y)!=0))
{
PyErr_Format(PyExc_TypeError,
"neib_shape[1]=
%%
d, neib_step[1]=
%%
d and"
PyErr_Format(PyExc_TypeError,
"GpuImages2Neibs:"
"
neib_shape[1]=
%%
d, neib_step[1]=
%%
d and"
" ten4.shape[3]=
%%
d not consistent",
d, step_y,
PyGpuArray_DIMS(
%(ten4)
s)[3]);
...
...
@@ -316,7 +322,7 @@ class GpuImages2Neibs(Images2Neibs, Op):
grid_d = 1+(((PyGpuArray_DIMS(
%(ten4)
s))[3]-d)/step_y);
}else{
PyErr_Format(PyExc_TypeError,
"
Images2Neibs
: unknow mode '
%(mode)
s'");
"
GpuImages2Neibs:
: unknow mode '
%(mode)
s'");
%(fail)
s;
}
...
...
@@ -340,8 +346,8 @@ class GpuImages2Neibs(Images2Neibs, Op):
Py_None);
if (!
%(z)
s)
{
PyErr_SetString(PyExc_MemoryError,
"failed to alloc z output");
PyErr_SetString(PyExc_MemoryError,
"GpuImages2Neibs:"
"
failed to alloc z output");
%(fail)
s;
}
}
...
...
@@ -419,8 +425,8 @@ class GpuImages2Neibs(Images2Neibs, Op):
cudaError_t sts = cudaGetLastError();
if (cudaSuccess != sts)
{
PyErr_Format(PyExc_RuntimeError,
"Cuda error:
%%
s:
%%
s. (grid:
%%
i x
%%
i;"
PyErr_Format(PyExc_RuntimeError,
"GpuImages2Neibs:"
"
Cuda error:
%%
s:
%%
s. (grid:
%%
i x
%%
i;"
" block:
%%
i x
%%
i x
%%
i; shared:
%%
i)
\\
n",
"k_multi_warp_
%(name)
s",
cudaGetErrorString(sts),
...
...
@@ -441,12 +447,10 @@ def gpu_images2neibs(ten4, neib_shape, neib_step=None, mode='valid'):
return
GpuImages2Neibs
(
mode
)(
ten4
,
neib_shape
,
neib_step
)
@
local_optimiz
er
([
Images2Neibs
])
@
op_lift
er
([
Images2Neibs
])
def
use_gpu_images2neibs
(
node
):
if
(
type
(
node
.
op
)
is
Images2Neibs
and
node
.
inputs
[
0
]
.
dtype
in
[
'int64'
,
'float32'
,
'float64'
]
and
node
.
op
.
mode
in
[
'valid'
,
'ignore_borders'
,
'wrap_centered'
]):
node
.
op
.
mode
in
[
'valid'
,
'ignore_borders'
,
'wrap_centered'
]):
return
[
host_from_gpu
(
gpu_images2neibs
(
gpu_from_host
(
node
.
inputs
[
0
]),
node
.
inputs
[
1
],
node
.
inputs
[
2
],
mode
=
node
.
op
.
mode
))]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论