Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c23321fb
提交
c23321fb
authored
2月 21, 2014
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1734 from herr-biber/nocuda-unpickle-cudandarray-as-nparray
Unpickle CudaNdarray as numpy.ndarray, controlled by an experimental flag.
上级
0bf0e5a3
8f2ecc01
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
109 行增加
和
1 行删除
+109
-1
configdefaults.py
theano/configdefaults.py
+13
-0
configparser.py
theano/configparser.py
+1
-1
CudaNdarray.pkl
theano/sandbox/cuda/tests/CudaNdarray.pkl
+30
-0
test_type.py
theano/sandbox/cuda/tests/test_type.py
+54
-0
type.py
theano/sandbox/cuda/type.py
+11
-0
没有找到文件。
theano/configdefaults.py
浏览文件 @
c23321fb
...
@@ -268,6 +268,19 @@ AddConfigVar('experimental.mrg',
...
@@ -268,6 +268,19 @@ AddConfigVar('experimental.mrg',
"Another random number generator that work on the gpu"
,
"Another random number generator that work on the gpu"
,
BoolParam
(
False
))
BoolParam
(
False
))
AddConfigVar
(
'experimental.unpickle_gpu_on_cpu'
,
"Allow unpickling of pickled CudaNdarrays as numpy.ndarrays."
"This is useful, if you want to open a CudaNdarray without "
"having cuda installed."
"If you have cuda installed, this will force unpickling to"
"be done on the cpu to numpy.ndarray."
"Please be aware that this may get you access to the data,"
"however, trying to unpicke gpu functions will not succeed."
"This flag is experimental and may be removed any time, when"
"gpu<>cpu transparency is solved."
,
BoolParam
(
default
=
False
),
in_c_key
=
False
)
AddConfigVar
(
'numpy.seterr_all'
,
AddConfigVar
(
'numpy.seterr_all'
,
(
"Sets numpy's behaviour for floating-point errors, "
,
(
"Sets numpy's behaviour for floating-point errors, "
,
"see numpy.seterr. "
"see numpy.seterr. "
...
...
theano/configparser.py
浏览文件 @
c23321fb
...
@@ -185,7 +185,7 @@ def AddConfigVar(name, doc, configparam, root=config, in_c_key=True):
...
@@ -185,7 +185,7 @@ def AddConfigVar(name, doc, configparam, root=config, in_c_key=True):
parameter
parameter
:type root: object
:type root: object
:param root: used for recusive calls -- do not provide an argument for
:param root: used for recu
r
sive calls -- do not provide an argument for
this parameter.
this parameter.
:type in_c_key: boolean
:type in_c_key: boolean
...
...
theano/sandbox/cuda/tests/CudaNdarray.pkl
0 → 100644
浏览文件 @
c23321fb
ctheano.sandbox.cuda.type
CudaNdarray_unpickler
p1
(cnumpy.core.multiarray
_reconstruct
p2
(cnumpy
ndarray
p3
(I0
tS'b'
tRp4
(I1
(I1
tcnumpy
dtype
p5
(S'f4'
I0
I1
tRp6
(I3
S'<'
NNNI-1
I-1
I0
tbI00
S'\x00\x00(\xc2'
tbtR.
\ No newline at end of file
theano/sandbox/cuda/tests/test_type.py
0 → 100644
浏览文件 @
c23321fb
import
cPickle
from
nose.tools
import
assert_raises
import
numpy
import
os.path
from
theano
import
config
from
theano.sandbox.cuda
import
cuda_available
if
cuda_available
:
from
theano.sandbox.cuda
import
CudaNdarray
# testfile created on cuda enabled machine using
# >>> with open('CudaNdarray.pkl', 'wb') as fp:
# >>> cPickle.dump(theano.sandbox.cuda.CudaNdarray(np.array([-42.0], dtype=np.float32)), fp)
def
test_unpickle_flag_is_false_by_default
():
assert
not
config
.
experimental
.
unpickle_gpu_on_cpu
,
"Config flag experimental.unpickle_gpu_on_cpu is "
\
+
"set to true. Make sure the default value stays false "
\
+
"and that you have not set the flag manually."
def
test_unpickle_cudandarray_as_numpy_ndarray_flag0
():
oldflag
=
config
.
experimental
.
unpickle_gpu_on_cpu
config
.
experimental
.
unpickle_gpu_on_cpu
=
False
try
:
testfile_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
with
open
(
os
.
path
.
join
(
testfile_dir
,
'CudaNdarray.pkl'
))
as
fp
:
if
cuda_available
:
mat
=
cPickle
.
load
(
fp
)
else
:
assert_raises
(
ImportError
,
cPickle
.
load
,
fp
)
if
cuda_available
:
assert
isinstance
(
mat
,
CudaNdarray
)
assert
numpy
.
asarray
(
mat
)[
0
]
==
-
42.0
finally
:
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
def
test_unpickle_cudandarray_as_numpy_ndarray_flag1
():
oldflag
=
config
.
experimental
.
unpickle_gpu_on_cpu
config
.
experimental
.
unpickle_gpu_on_cpu
=
True
try
:
testfile_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
with
open
(
os
.
path
.
join
(
testfile_dir
,
'CudaNdarray.pkl'
))
as
fp
:
mat
=
cPickle
.
load
(
fp
)
assert
isinstance
(
mat
,
numpy
.
ndarray
)
assert
mat
[
0
]
==
-
42.0
finally
:
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
theano/sandbox/cuda/type.py
浏览文件 @
c23321fb
...
@@ -2,10 +2,12 @@
...
@@ -2,10 +2,12 @@
"""
"""
import
os
import
os
import
copy_reg
import
copy_reg
import
warnings
import
numpy
import
numpy
import
theano
import
theano
from
theano
import
config
from
theano
import
Type
,
Variable
from
theano
import
Type
,
Variable
from
theano
import
tensor
,
config
from
theano
import
tensor
,
config
from
theano
import
scalar
as
scal
from
theano
import
scalar
as
scal
...
@@ -487,7 +489,16 @@ theano.compile.register_deep_copy_op_c_code(
...
@@ -487,7 +489,16 @@ theano.compile.register_deep_copy_op_c_code(
# equal the pickled version, and the cmodule cache is not happy with
# equal the pickled version, and the cmodule cache is not happy with
# the situation.
# the situation.
def
CudaNdarray_unpickler
(
npa
):
def
CudaNdarray_unpickler
(
npa
):
if
config
.
experimental
.
unpickle_gpu_on_cpu
:
# directly return numpy array
warnings
.
warn
(
"config.experimental.unpickle_gpu_on_cpu is set to True. Unpickling CudaNdarray as numpy.ndarray"
)
return
npa
elif
cuda
:
return
cuda
.
CudaNdarray
(
npa
)
return
cuda
.
CudaNdarray
(
npa
)
else
:
raise
ImportError
(
"Cuda not found. Cannot unpickle CudaNdarray"
)
copy_reg
.
constructor
(
CudaNdarray_unpickler
)
copy_reg
.
constructor
(
CudaNdarray_unpickler
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论