Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
890b9af0
提交
890b9af0
authored
10月 23, 2013
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8 fixes
上级
2b1d70cc
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
33 行增加
和
10 行删除
+33
-10
__init__.py
theano/sandbox/gpuarray/__init__.py
+1
-0
basic_ops.py
theano/sandbox/gpuarray/basic_ops.py
+6
-4
blas.py
theano/sandbox/gpuarray/blas.py
+5
-0
elemwise.py
theano/sandbox/gpuarray/elemwise.py
+5
-0
opt.py
theano/sandbox/gpuarray/opt.py
+10
-1
subtensor.py
theano/sandbox/gpuarray/subtensor.py
+3
-2
type.py
theano/sandbox/gpuarray/type.py
+3
-3
没有找到文件。
theano/sandbox/gpuarray/__init__.py
浏览文件 @
890b9af0
...
@@ -30,6 +30,7 @@ from type import (GpuArrayType, GpuArrayVariable, GpuArrayConstant,
...
@@ -30,6 +30,7 @@ from type import (GpuArrayType, GpuArrayVariable, GpuArrayConstant,
GpuArraySharedVariable
,
gpuarray_shared_constructor
)
GpuArraySharedVariable
,
gpuarray_shared_constructor
)
import
opt
import
opt
def
init_dev
(
dev
):
def
init_dev
(
dev
):
global
pygpu_activated
global
pygpu_activated
context
=
pygpu
.
init
(
dev
)
context
=
pygpu
.
init
(
dev
)
...
...
theano/sandbox/gpuarray/basic_ops.py
浏览文件 @
890b9af0
...
@@ -19,6 +19,7 @@ except ImportError:
...
@@ -19,6 +19,7 @@ except ImportError:
from
type
import
GpuArrayType
from
type
import
GpuArrayType
def
as_gpuarray_variable
(
x
):
def
as_gpuarray_variable
(
x
):
if
hasattr
(
x
,
'_as_GpuArrayVariable'
):
if
hasattr
(
x
,
'_as_GpuArrayVariable'
):
return
x
.
_as_GpuArrayVariable
()
return
x
.
_as_GpuArrayVariable
()
...
@@ -30,6 +31,7 @@ def as_gpuarray_variable(x):
...
@@ -30,6 +31,7 @@ def as_gpuarray_variable(x):
def
as_gpuarray
(
x
):
def
as_gpuarray
(
x
):
return
gpuarray
.
array
(
x
,
copy
=
False
)
return
gpuarray
.
array
(
x
,
copy
=
False
)
class
HideC
(
object
):
class
HideC
(
object
):
def
__hide
(
*
args
):
def
__hide
(
*
args
):
raise
MethodNotDefined
()
raise
MethodNotDefined
()
...
@@ -116,7 +118,7 @@ class HostFromGpu(Op):
...
@@ -116,7 +118,7 @@ class HostFromGpu(Op):
%(fail)
s
%(fail)
s
}
}
"""
%
{
'name'
:
name
,
'fail'
:
sub
[
'fail'
],
'inp'
:
inputs
[
0
],
"""
%
{
'name'
:
name
,
'fail'
:
sub
[
'fail'
],
'inp'
:
inputs
[
0
],
'out'
:
outputs
[
0
]}
'out'
:
outputs
[
0
]}
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
1
,)
return
(
1
,)
...
@@ -124,7 +126,7 @@ class HostFromGpu(Op):
...
@@ -124,7 +126,7 @@ class HostFromGpu(Op):
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
gz
,
=
grads
gz
,
=
grads
return
[
gpu_from_host
(
gz
)]
return
[
gpu_from_host
(
gz
)]
def
R_op
(
self
,
inputs
,
eval_points
):
def
R_op
(
self
,
inputs
,
eval_points
):
ev
,
=
eval_points
ev
,
=
eval_points
if
isinstance
(
ev
,
tensor
.
TensorType
):
if
isinstance
(
ev
,
tensor
.
TensorType
):
...
@@ -320,7 +322,7 @@ class GpuFromCuda(Op):
...
@@ -320,7 +322,7 @@ class GpuFromCuda(Op):
if (
%(out)
s == NULL) {
if (
%(out)
s == NULL) {
%(fail)
s
%(fail)
s
}
}
"""
%
{
'name'
:
name
,
'in'
:
inputs
[
0
],
'out'
:
outputs
[
0
],
"""
%
{
'name'
:
name
,
'in'
:
inputs
[
0
],
'out'
:
outputs
[
0
],
'fail'
:
sub
[
'fail'
]}
'fail'
:
sub
[
'fail'
]}
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
...
@@ -508,7 +510,7 @@ class GpuAlloc(HideC, Alloc):
...
@@ -508,7 +510,7 @@ class GpuAlloc(HideC, Alloc):
"""
%
dict
(
name
=
name
,
ndim
=
ndim
,
zz
=
zz
,
vv
=
vv
,
fail
=
sub
[
'fail'
])
"""
%
dict
(
name
=
name
,
ndim
=
ndim
,
zz
=
zz
,
vv
=
vv
,
fail
=
sub
[
'fail'
])
if
config
.
gpuarray
.
sync
:
if
config
.
gpuarray
.
sync
:
code
+=
"GpuArray_sync(&
%(zz)
s->ga);"
%
dict
(
zz
=
zz
)
;
code
+=
"GpuArray_sync(&
%(zz)
s->ga);"
%
dict
(
zz
=
zz
)
return
code
return
code
...
...
theano/sandbox/gpuarray/blas.py
浏览文件 @
890b9af0
...
@@ -10,6 +10,7 @@ except ImportError, e:
...
@@ -10,6 +10,7 @@ except ImportError, e:
# To make sure theano is importable
# To make sure theano is importable
pass
pass
class
BlasOp
(
HideC
):
class
BlasOp
(
HideC
):
def
c_headers
(
self
):
def
c_headers
(
self
):
return
[
'<blas_api.h>'
]
return
[
'<blas_api.h>'
]
...
@@ -20,6 +21,7 @@ class BlasOp(HideC):
...
@@ -20,6 +21,7 @@ class BlasOp(HideC):
def
c_init_code
(
self
):
def
c_init_code
(
self
):
return
[
'import_pygpu__blas();'
]
return
[
'import_pygpu__blas();'
]
class
GpuGemv
(
BlasOp
,
Gemv
):
class
GpuGemv
(
BlasOp
,
Gemv
):
def
make_node
(
self
,
y
,
alpha
,
A
,
x
,
beta
):
def
make_node
(
self
,
y
,
alpha
,
A
,
x
,
beta
):
res
=
Gemv
.
make_node
(
self
,
y
,
alpha
,
A
,
x
,
beta
)
res
=
Gemv
.
make_node
(
self
,
y
,
alpha
,
A
,
x
,
beta
)
...
@@ -71,6 +73,7 @@ class GpuGemv(BlasOp, Gemv):
...
@@ -71,6 +73,7 @@ class GpuGemv(BlasOp, Gemv):
gpugemv_no_inplace
=
GpuGemv
(
inplace
=
False
)
gpugemv_no_inplace
=
GpuGemv
(
inplace
=
False
)
gpugemv_inplace
=
GpuGemv
(
inplace
=
True
)
gpugemv_inplace
=
GpuGemv
(
inplace
=
True
)
class
GpuGemm
(
BlasOp
,
Gemm
):
class
GpuGemm
(
BlasOp
,
Gemm
):
def
make_node
(
self
,
C
,
alpha
,
A
,
B
,
beta
):
def
make_node
(
self
,
C
,
alpha
,
A
,
B
,
beta
):
res
=
Gemm
.
make_node
(
self
,
C
,
alpha
,
A
,
B
,
beta
)
res
=
Gemm
.
make_node
(
self
,
C
,
alpha
,
A
,
B
,
beta
)
...
@@ -127,11 +130,13 @@ from theano.compile import optdb
...
@@ -127,11 +130,13 @@ from theano.compile import optdb
from
theano.gof
import
local_optimizer
,
LocalOptGroup
from
theano.gof
import
local_optimizer
,
LocalOptGroup
from
theano.tensor.opt
import
in2out
from
theano.tensor.opt
import
in2out
@local_optimizer
([
gpugemv_no_inplace
])
@local_optimizer
([
gpugemv_no_inplace
])
def
local_inplace_gpuagemv
(
node
):
def
local_inplace_gpuagemv
(
node
):
if
node
.
op
==
gpugemv_no_inplace
:
if
node
.
op
==
gpugemv_no_inplace
:
return
[
gpugemv_inplace
(
*
node
.
inputs
)]
return
[
gpugemv_inplace
(
*
node
.
inputs
)]
@local_optimizer
([
gpugemm_no_inplace
])
@local_optimizer
([
gpugemm_no_inplace
])
def
local_inplace_gpuagemm
(
node
):
def
local_inplace_gpuagemm
(
node
):
if
node
.
op
==
gpugemm_no_inplace
:
if
node
.
op
==
gpugemm_no_inplace
:
...
...
theano/sandbox/gpuarray/elemwise.py
浏览文件 @
890b9af0
...
@@ -18,15 +18,18 @@ from theano.sandbox.gpuarray.type import GpuArrayType
...
@@ -18,15 +18,18 @@ from theano.sandbox.gpuarray.type import GpuArrayType
from
theano.gof.utils
import
MethodNotDefined
from
theano.gof.utils
import
MethodNotDefined
def
_is_scalar
(
v
):
def
_is_scalar
(
v
):
False
False
def
make_argument
(
v
,
name
):
def
make_argument
(
v
,
name
):
if
_is_scalar
(
v
):
if
_is_scalar
(
v
):
return
ScalarArg
(
numpy
.
dtype
(
v
.
type
.
dtype
),
name
)
return
ScalarArg
(
numpy
.
dtype
(
v
.
type
.
dtype
),
name
)
else
:
else
:
return
ArrayArg
(
numpy
.
dtype
(
v
.
type
.
dtype
),
name
)
return
ArrayArg
(
numpy
.
dtype
(
v
.
type
.
dtype
),
name
)
def
ensure_allocated
(
storage
,
shape
,
dtype
):
def
ensure_allocated
(
storage
,
shape
,
dtype
):
odat
=
storage
[
0
]
odat
=
storage
[
0
]
if
odat
is
not
None
:
if
odat
is
not
None
:
...
@@ -39,10 +42,12 @@ def ensure_allocated(storage, shape, dtype):
...
@@ -39,10 +42,12 @@ def ensure_allocated(storage, shape, dtype):
storage
[
0
]
=
odat
storage
[
0
]
=
odat
return
odat
return
odat
def
as_C_string_const
(
s
):
def
as_C_string_const
(
s
):
return
'
\n
'
.
join
(
'"
%
s
\\
n"'
%
(
l
.
replace
(
'"'
,
'
\\
"'
))
return
'
\n
'
.
join
(
'"
%
s
\\
n"'
%
(
l
.
replace
(
'"'
,
'
\\
"'
))
for
l
in
s
.
split
(
'
\n
'
))
for
l
in
s
.
split
(
'
\n
'
))
class
GpuElemwise
(
HideC
,
Elemwise
):
class
GpuElemwise
(
HideC
,
Elemwise
):
nin
=
property
(
lambda
self
:
self
.
scalar_op
.
nin
)
nin
=
property
(
lambda
self
:
self
.
scalar_op
.
nin
)
nout
=
property
(
lambda
self
:
self
.
scalar_op
.
nout
)
nout
=
property
(
lambda
self
:
self
.
scalar_op
.
nout
)
...
...
theano/sandbox/gpuarray/opt.py
浏览文件 @
890b9af0
import
copy
import
copy
import
theano
,
numpy
import
theano
import
numpy
from
theano
import
tensor
,
scalar
from
theano
import
tensor
,
scalar
from
theano.compile
import
optdb
from
theano.compile
import
optdb
from
theano.gof
import
(
local_optimizer
,
EquilibriumDB
,
SequenceDB
,
ProxyDB
,
from
theano.gof
import
(
local_optimizer
,
EquilibriumDB
,
SequenceDB
,
ProxyDB
,
...
@@ -31,6 +32,7 @@ optdb.register('gpuarray_opt', gpu_seqopt,
...
@@ -31,6 +32,7 @@ optdb.register('gpuarray_opt', gpu_seqopt,
optdb
.
__position__
.
get
(
'add_destroy_handler'
,
49.5
)
-
1
,
optdb
.
__position__
.
get
(
'add_destroy_handler'
,
49.5
)
-
1
,
'gpuarray'
)
'gpuarray'
)
def
register_opt
(
*
tags
,
**
kwargs
):
def
register_opt
(
*
tags
,
**
kwargs
):
def
f
(
local_opt
):
def
f
(
local_opt
):
name
=
(
kwargs
and
kwargs
.
pop
(
'name'
))
or
local_opt
.
__name__
name
=
(
kwargs
and
kwargs
.
pop
(
'name'
))
or
local_opt
.
__name__
...
@@ -40,6 +42,7 @@ def register_opt(*tags, **kwargs):
...
@@ -40,6 +42,7 @@ def register_opt(*tags, **kwargs):
register_opt
()(
theano
.
tensor
.
opt
.
local_track_shape_i
)
register_opt
()(
theano
.
tensor
.
opt
.
local_track_shape_i
)
def
op_lifter
(
OP
):
def
op_lifter
(
OP
):
"""
"""
OP(..., host_from_gpu(), ...) -> host_from_gpu(GpuOP(...))
OP(..., host_from_gpu(), ...) -> host_from_gpu(GpuOP(...))
...
@@ -65,6 +68,7 @@ def op_lifter(OP):
...
@@ -65,6 +68,7 @@ def op_lifter(OP):
return
local_optimizer
([
OP
])(
local_opt
)
return
local_optimizer
([
OP
])(
local_opt
)
return
f
return
f
class
InputToGpuOptimizer
(
Optimizer
):
class
InputToGpuOptimizer
(
Optimizer
):
"Transfer the input to the gpu to start the rolling wave."
"Transfer the input to the gpu to start the rolling wave."
...
@@ -93,6 +97,7 @@ class InputToGpuOptimizer(Optimizer):
...
@@ -93,6 +97,7 @@ class InputToGpuOptimizer(Optimizer):
gpu_seqopt
.
register
(
'InputToGpuArrayOptimizer'
,
InputToGpuOptimizer
(),
gpu_seqopt
.
register
(
'InputToGpuArrayOptimizer'
,
InputToGpuOptimizer
(),
0
,
'fast_run'
,
'fast_compile'
,
'merge'
)
0
,
'fast_run'
,
'fast_compile'
,
'merge'
)
@local_optimizer
([])
@local_optimizer
([])
def
local_cut_gpu_host_gpu
(
node
):
def
local_cut_gpu_host_gpu
(
node
):
if
tensor
.
opt
.
opt
.
check_chain
(
node
,
gpu_from_host
,
host_from_gpu
):
if
tensor
.
opt
.
opt
.
check_chain
(
node
,
gpu_from_host
,
host_from_gpu
):
...
@@ -108,11 +113,13 @@ gpu_cut_copies.register('cut_gpua_constant_transfers',
...
@@ -108,11 +113,13 @@ gpu_cut_copies.register('cut_gpua_constant_transfers',
optdb
[
'canonicalize'
]
.
register
(
'local_cut_gpua_host_gpua'
,
optdb
[
'canonicalize'
]
.
register
(
'local_cut_gpua_host_gpua'
,
local_cut_gpu_host_gpu
,
'fast_run'
,
'gpuarray'
)
local_cut_gpu_host_gpu
,
'fast_run'
,
'gpuarray'
)
@register_opt
()
@register_opt
()
@op_lifter
(
tensor
.
Alloc
)
@op_lifter
(
tensor
.
Alloc
)
def
local_gpualloc
(
node
):
def
local_gpualloc
(
node
):
return
gpu_alloc
return
gpu_alloc
@register_opt
()
@register_opt
()
@op_lifter
(
tensor
.
Elemwise
)
@op_lifter
(
tensor
.
Elemwise
)
def
local_gpu_elemwise
(
node
):
def
local_gpu_elemwise
(
node
):
...
@@ -125,6 +132,7 @@ def local_gpu_elemwise(node):
...
@@ -125,6 +132,7 @@ def local_gpu_elemwise(node):
nfunc_spec
=
op
.
nfunc_spec
)
nfunc_spec
=
op
.
nfunc_spec
)
return
res
return
res
def
max_inputs_to_GpuElemwise
(
node
):
def
max_inputs_to_GpuElemwise
(
node
):
ptr_size
=
8
ptr_size
=
8
int_size
=
4
int_size
=
4
...
@@ -173,6 +181,7 @@ def local_gpua_specifyShape(node):
...
@@ -173,6 +181,7 @@ def local_gpua_specifyShape(node):
def
local_gpua_subtensor
(
node
):
def
local_gpua_subtensor
(
node
):
return
GpuSubtensor
(
node
.
op
.
idx_list
)
return
GpuSubtensor
(
node
.
op
.
idx_list
)
@register_opt
()
@register_opt
()
@op_lifter
(
tensor
.
CAReduce
)
@op_lifter
(
tensor
.
CAReduce
)
def
local_gpua_careduce
(
node
):
def
local_gpua_careduce
(
node
):
...
...
theano/sandbox/gpuarray/subtensor.py
浏览文件 @
890b9af0
...
@@ -17,6 +17,7 @@ except ImportError:
...
@@ -17,6 +17,7 @@ except ImportError:
from
theano.sandbox.gpuarray.type
import
GpuArrayType
from
theano.sandbox.gpuarray.type
import
GpuArrayType
from
theano.sandbox.gpuarray.basic_ops
import
as_gpuarray_variable
,
HideC
from
theano.sandbox.gpuarray.basic_ops
import
as_gpuarray_variable
,
HideC
class
GpuSubtensor
(
HideC
,
Subtensor
):
class
GpuSubtensor
(
HideC
,
Subtensor
):
def
make_node
(
self
,
x
,
*
inputs
):
def
make_node
(
self
,
x
,
*
inputs
):
rval
=
tensor
.
Subtensor
.
make_node
(
self
,
x
,
*
inputs
)
rval
=
tensor
.
Subtensor
.
make_node
(
self
,
x
,
*
inputs
)
...
@@ -31,13 +32,13 @@ class GpuSubtensor(HideC, Subtensor):
...
@@ -31,13 +32,13 @@ class GpuSubtensor(HideC, Subtensor):
if
self
.
perform_cache_cdata
is
not
None
:
if
self
.
perform_cache_cdata
is
not
None
:
out
[
0
]
=
x
.
__getitem__
(
self
.
perform_cache_cdata
)
out
[
0
]
=
x
.
__getitem__
(
self
.
perform_cache_cdata
)
return
return
cdata
=
get_idx_list
(
inputs
,
self
.
idx_list
)
cdata
=
get_idx_list
(
inputs
,
self
.
idx_list
)
if
len
(
cdata
)
==
1
:
if
len
(
cdata
)
==
1
:
cdata
=
cdata
[
0
]
cdata
=
cdata
[
0
]
if
len
(
inputs
)
==
1
:
if
len
(
inputs
)
==
1
:
self
.
perform_cache_cdata
=
cdata
self
.
perform_cache_cdata
=
cdata
out
[
0
]
=
x
.
__getitem__
(
cdata
)
out
[
0
]
=
x
.
__getitem__
(
cdata
)
def
c_support_code
(
self
):
def
c_support_code
(
self
):
...
...
theano/sandbox/gpuarray/type.py
浏览文件 @
890b9af0
...
@@ -107,8 +107,8 @@ class GpuArrayType(Type):
...
@@ -107,8 +107,8 @@ class GpuArrayType(Type):
return
GpuArrayType
.
values_eq
(
a
,
b
)
return
GpuArrayType
.
values_eq
(
a
,
b
)
else
:
else
:
res
=
elemwise2
(
a
,
''
,
b
,
a
,
odtype
=
numpy
.
dtype
(
'bool'
),
res
=
elemwise2
(
a
,
''
,
b
,
a
,
odtype
=
numpy
.
dtype
(
'bool'
),
op_tmpl
=
"res[i] = ((
%(a)
s -
%(b)
s) <"
\
op_tmpl
=
"res[i] = ((
%(a)
s -
%(b)
s) <"
"(1e-8 + 1e-5 * fabs(
%(b)
s)))"
)
"(1e-8 + 1e-5 * fabs(
%(b)
s)))"
)
return
numpy
.
asarray
(
res
)
.
all
()
return
numpy
.
asarray
(
res
)
.
all
()
def
value_zeros
(
self
,
shape
):
def
value_zeros
(
self
,
shape
):
...
@@ -163,7 +163,7 @@ class GpuArrayType(Type):
...
@@ -163,7 +163,7 @@ class GpuArrayType(Type):
"""
%
{
'name'
:
name
,
'fail'
:
sub
[
'fail'
]}
"""
%
{
'name'
:
name
,
'fail'
:
sub
[
'fail'
]}
def
c_cleanup
(
self
,
name
,
sub
):
def
c_cleanup
(
self
,
name
,
sub
):
return
"Py_XDECREF(
%(name)
s);
%(name)
s = NULL;"
%
{
'name'
:
name
}
return
"Py_XDECREF(
%(name)
s);
%(name)
s = NULL;"
%
{
'name'
:
name
}
def
c_sync
(
self
,
name
,
sub
):
def
c_sync
(
self
,
name
,
sub
):
return
"""
return
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论