Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
09928b08
提交
09928b08
authored
9月 11, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed conv.py for type context.
上级
f8de0e04
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
22 行增加
和
73 行删除
+22
-73
conv.cu
theano/sandbox/gpuarray/conv.cu
+1
-1
conv.py
theano/sandbox/gpuarray/conv.py
+21
-72
没有找到文件。
theano/sandbox/gpuarray/conv.cu
浏览文件 @
09928b08
...
@@ -1465,7 +1465,7 @@ PyGpuArray_Conv(PyGpuArrayObject *img, PyGpuArrayObject * kern,
...
@@ -1465,7 +1465,7 @@ PyGpuArray_Conv(PyGpuArrayObject *img, PyGpuArrayObject * kern,
rval
=
pygpu_zeros
(
4
,
out_dim
,
rval
=
pygpu_zeros
(
4
,
out_dim
,
img
->
ga
.
typecode
,
GA_C_ORDER
,
img
->
ga
.
typecode
,
GA_C_ORDER
,
pygpu_default_context
()
,
Py_None
);
img
->
ctx
,
Py_None
);
//rval might be null
//rval might be null
}
}
if
((
rval
==
NULL
)
if
((
rval
==
NULL
)
...
...
theano/sandbox/gpuarray/conv.py
浏览文件 @
09928b08
import
copy
import
copy
import
os
import
os
import
theano
from
theano
import
gof
from
theano
import
config
,
gof
try
:
try
:
from
pygpu
import
gpuarray
from
pygpu
import
gpuarray
...
@@ -10,7 +9,8 @@ except ImportError:
...
@@ -10,7 +9,8 @@ except ImportError:
pass
pass
from
.type
import
GpuArrayType
from
.type
import
GpuArrayType
from
.basic_ops
import
as_gpuarray_variable
,
GpuKernelBase
,
Kernel
from
.basic_ops
import
(
as_gpuarray_variable
,
GpuKernelBase
,
Kernel
,
infer_context_name
)
from
theano.gof
import
utils
from
theano.gof
import
utils
...
@@ -58,6 +58,9 @@ class GpuConv(GpuKernelBase, gof.Op):
...
@@ -58,6 +58,9 @@ class GpuConv(GpuKernelBase, gof.Op):
them.
them.
"""
"""
__props__
=
(
'border_mode'
,
'subsample'
,
'logical_img_hw'
,
'logical_kern_hw'
,
'logical_kern_align_top'
,
'version'
,
'verbose'
,
'kshp'
,
'imshp'
,
'max_threads_dim0'
)
@staticmethod
@staticmethod
def
logical_output_shape_2d
(
imshp
,
kshp
,
mode
):
def
logical_output_shape_2d
(
imshp
,
kshp
,
mode
):
...
@@ -67,20 +70,13 @@ class GpuConv(GpuKernelBase, gof.Op):
...
@@ -67,20 +70,13 @@ class GpuConv(GpuKernelBase, gof.Op):
return
imshp
[
0
]
+
kshp
[
0
]
-
1
,
imshp
[
1
]
+
kshp
[
1
]
-
1
return
imshp
[
0
]
+
kshp
[
0
]
-
1
,
imshp
[
1
]
+
kshp
[
1
]
-
1
raise
ValueError
(
mode
)
raise
ValueError
(
mode
)
def
__init__
(
self
,
border_mode
,
def
__init__
(
self
,
border_mode
,
subsample
=
(
1
,
1
),
subsample
=
(
1
,
1
),
logical_img_hw
=
None
,
logical_kern_hw
=
None
,
logical_img_hw
=
None
,
logical_kern_hw
=
None
,
logical_kern_align_top
=
True
,
logical_kern_align_top
=
True
,
version
=-
1
,
version
=-
1
,
direction_hint
=
None
,
direction_hint
=
None
,
verbose
=
0
,
kshp
=
None
,
imshp
=
None
,
verbose
=
0
,
kshp
=
None
,
imshp
=
None
,
max_threads_dim0
=
None
,
max_threads_dim0
=
None
,
nkern
=
None
,
nkern
=
None
,
bsize
=
None
,
fft_opt
=
True
):
bsize
=
None
,
fft_opt
=
True
):
self
.
border_mode
=
border_mode
self
.
border_mode
=
border_mode
self
.
subsample
=
subsample
self
.
subsample
=
subsample
if
logical_img_hw
is
not
None
:
if
logical_img_hw
is
not
None
:
...
@@ -108,19 +104,6 @@ class GpuConv(GpuKernelBase, gof.Op):
...
@@ -108,19 +104,6 @@ class GpuConv(GpuKernelBase, gof.Op):
self
.
bsize
=
bsize
self
.
bsize
=
bsize
self
.
fft_opt
=
fft_opt
self
.
fft_opt
=
fft_opt
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
\
and
self
.
border_mode
==
other
.
border_mode
\
and
self
.
subsample
==
other
.
subsample
\
and
self
.
logical_img_hw
==
other
.
logical_img_hw
\
and
self
.
logical_kern_hw
==
other
.
logical_kern_hw
\
and
self
.
logical_kern_align_top
==
other
.
logical_kern_align_top
\
and
self
.
version
==
other
.
version
\
and
self
.
verbose
==
other
.
verbose
\
and
self
.
kshp
==
other
.
kshp
\
and
self
.
imshp
==
other
.
imshp
\
and
self
.
max_threads_dim0
==
other
.
max_threads_dim0
def
__setstate__
(
self
,
d
):
def
__setstate__
(
self
,
d
):
self
.
__dict__
.
update
(
d
)
self
.
__dict__
.
update
(
d
)
if
not
hasattr
(
self
,
"imshp"
):
if
not
hasattr
(
self
,
"imshp"
):
...
@@ -136,32 +119,6 @@ class GpuConv(GpuKernelBase, gof.Op):
...
@@ -136,32 +119,6 @@ class GpuConv(GpuKernelBase, gof.Op):
if
not
hasattr
(
self
,
"fft_opt"
):
if
not
hasattr
(
self
,
"fft_opt"
):
self
.
fft_opt
=
True
self
.
fft_opt
=
True
def
__hash__
(
self
):
# don't use hash(self.version) as hash(-1)==-2 and
# hash(-2)==-2 in python!
return
hash
(
type
(
self
))
\
^
hash
(
self
.
border_mode
)
\
^
hash
(
self
.
subsample
)
\
^
hash
(
self
.
logical_img_hw
)
\
^
hash
(
self
.
logical_kern_hw
)
\
^
hash
(
self
.
logical_kern_align_top
)
\
^
self
.
version
\
^
hash
(
self
.
verbose
)
\
^
hash
(
self
.
kshp
)
\
^
hash
(
self
.
imshp
)
\
^
hash
(
self
.
max_threads_dim0
)
def
__str__
(
self
):
return
'
%
s{
%
s,
%
s,
%
s,
%
s,
%
s,
%
s,
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
border_mode
,
str
(
self
.
subsample
),
str
(
self
.
logical_img_hw
),
str
(
self
.
logical_kern_hw
),
str
(
self
.
logical_kern_align_top
),
str
(
self
.
imshp
),
str
(
self
.
kshp
))
def
make_node
(
self
,
img
,
kern
):
def
make_node
(
self
,
img
,
kern
):
if
img
.
dtype
!=
"float32"
or
kern
.
dtype
!=
"float32"
:
if
img
.
dtype
!=
"float32"
or
kern
.
dtype
!=
"float32"
:
raise
NotImplementedError
(
"GpuConv currently only work"
raise
NotImplementedError
(
"GpuConv currently only work"
...
@@ -170,13 +127,17 @@ class GpuConv(GpuKernelBase, gof.Op):
...
@@ -170,13 +127,17 @@ class GpuConv(GpuKernelBase, gof.Op):
raise
TypeError
(
'img must be 4D tensor'
)
raise
TypeError
(
'img must be 4D tensor'
)
if
kern
.
type
.
ndim
!=
4
:
if
kern
.
type
.
ndim
!=
4
:
raise
TypeError
(
'kern must be 4D tensor'
)
raise
TypeError
(
'kern must be 4D tensor'
)
img
=
as_gpuarray_variable
(
img
)
ctx_name
=
infer_context_name
(
img
,
kern
)
kern
=
as_gpuarray_variable
(
kern
)
img
=
as_gpuarray_variable
(
img
,
ctx_name
)
kern
=
as_gpuarray_variable
(
kern
,
ctx_name
)
broadcastable
=
[
img
.
type
.
broadcastable
[
0
],
kern
.
type
.
broadcastable
[
0
],
broadcastable
=
[
img
.
type
.
broadcastable
[
0
],
kern
.
type
.
broadcastable
[
0
],
False
,
False
]
False
,
False
]
out
=
GpuArrayType
(
img
.
dtype
,
broadcastable
)()
out
=
GpuArrayType
(
img
.
dtype
,
broadcastable
,
context_name
=
ctx_name
)()
return
gof
.
Apply
(
self
,
[
img
,
kern
],
[
out
])
return
gof
.
Apply
(
self
,
[
img
,
kern
],
[
out
])
def
get_context
(
self
,
node
):
return
node
.
inputs
[
0
]
.
type
.
context
def
flops
(
self
,
inputs
,
outputs
):
def
flops
(
self
,
inputs
,
outputs
):
"""
"""
Useful with the hack in profilemode to print the MFlops.
Useful with the hack in profilemode to print the MFlops.
...
@@ -202,22 +163,8 @@ class GpuConv(GpuKernelBase, gof.Op):
...
@@ -202,22 +163,8 @@ class GpuConv(GpuKernelBase, gof.Op):
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
):
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
):
node_
=
copy
.
copy
(
node
)
node_
=
copy
.
copy
(
node
)
assert
node
.
op
is
node_
.
op
assert
node
.
op
is
node_
.
op
if
config
.
gpuarray
.
sync
:
raise
NotImplementedError
(
"GpuConv do not implement gpuarray.sync Theano flag"
)
if
node_
.
op
.
max_threads_dim0
is
None
:
if
node_
.
op
.
max_threads_dim0
is
None
:
cuda
=
theano
.
sandbox
.
cuda
node_
.
op
.
max_threads_dim0
=
node
.
_inputs
[
0
]
.
type
.
context
.
maxlsize
device_id
=
cuda
.
use
.
device_number
if
device_id
is
None
:
cuda
.
use
(
"gpu"
,
force
=
False
,
default_to_move_computation_to_gpu
=
False
,
move_shared_float32_to_gpu
=
False
,
enable_cuda
=
False
,
test_driver
=
True
)
device_id
=
cuda
.
use
.
device_number
cuda_ndarray
=
theano
.
sandbox
.
cuda
.
cuda_ndarray
.
cuda_ndarray
prop
=
cuda_ndarray
.
device_properties
(
device_id
)
node_
.
op
.
max_threads_dim0
=
prop
[
'maxThreadsDim0'
]
return
super
(
GpuConv
,
node_
.
op
)
.
make_thunk
(
node_
,
storage_map
,
return
super
(
GpuConv
,
node_
.
op
)
.
make_thunk
(
node_
,
storage_map
,
compute_map
,
no_recycling
)
compute_map
,
no_recycling
)
...
@@ -235,6 +182,8 @@ class GpuConv(GpuKernelBase, gof.Op):
...
@@ -235,6 +182,8 @@ class GpuConv(GpuKernelBase, gof.Op):
return
(
0
,
22
)
return
(
0
,
22
)
def
c_code
(
self
,
node
,
nodename
,
inp
,
out_
,
sub
):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out_
,
sub
):
if
node
.
inputs
[
0
]
.
type
.
context
.
kind
!=
"cuda"
:
raise
NotImplementedError
(
"GpuConv only works for cuda devices"
)
img
,
kern
=
inp
img
,
kern
=
inp
out
,
=
out_
out
,
=
out_
dx
=
self
.
subsample
[
0
]
dx
=
self
.
subsample
[
0
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论