Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cb566da6
提交
cb566da6
authored
2月 19, 2014
作者:
Markus Roth
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add config flag experimental.unpickle_gpu_on_cpu.
Allows unpickling gpu cudaNdarray as numpy.ndarray. See AddConfigVar comment for more details.
上级
0c9e4255
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
55 行增加
和
15 行删除
+55
-15
configdefaults.py
theano/configdefaults.py
+13
-0
test_type.py
theano/sandbox/cuda/tests/test_type.py
+34
-11
type.py
theano/sandbox/cuda/type.py
+8
-4
没有找到文件。
theano/configdefaults.py
浏览文件 @
cb566da6
...
@@ -266,6 +266,19 @@ AddConfigVar('experimental.mrg',
...
@@ -266,6 +266,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/sandbox/cuda/tests/test_type.py
浏览文件 @
cb566da6
import
cPickle
import
cPickle
from
nose.tools
import
assert_raises
import
numpy
import
numpy
import
os.path
import
os.path
from
theano
import
config
from
theano.sandbox.cuda
import
cuda_available
from
theano.sandbox.cuda
import
cuda_available
if
cuda_available
:
if
cuda_available
:
from
theano.sandbox.cuda
import
CudaNdarray
from
theano.sandbox.cuda
import
CudaNdarray
def
test_unpickle_cudandarray_as_numpy_ndarray
():
# testfile created on cuda enabled machine using
# testfile created on cuda enabled machine using
# >>> with open('CudaNdarray.pkl', 'wb') as fp:
# >>> with open('CudaNdarray.pkl', 'wb') as fp:
# >>> cPickle.dump(theano.sandbox.cuda.CudaNdarray(np.array([-42.0], dtype=np.float32)), 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
def
test_unpickle_cudandarray_as_numpy_ndarray_flag0
():
oldflag
=
config
.
experimental
.
unpickle_gpu_on_cpu
config
.
experimental
.
unpickle_gpu_on_cpu
=
False
testfile_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
testfile_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
with
open
(
os
.
path
.
join
(
testfile_dir
,
'CudaNdarray.pkl'
))
as
fp
:
with
open
(
os
.
path
.
join
(
testfile_dir
,
'CudaNdarray.pkl'
))
as
fp
:
mat
=
cPickle
.
load
(
fp
)
if
cuda_available
:
if
cuda_available
:
assert
isinstance
(
mat
,
CudaNdarray
)
mat
=
cPickle
.
load
(
fp
)
else
:
else
:
assert
isinstance
(
mat
,
numpy
.
ndarray
)
assert_raises
(
ImportError
,
cPickle
.
load
,
fp
)
if
cuda_available
:
assert
isinstance
(
mat
,
CudaNdarray
)
assert
mat
[
0
]
==
-
42.0
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
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
assert
mat
[
0
]
==
-
42.0
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
\ No newline at end of file
theano/sandbox/cuda/type.py
浏览文件 @
cb566da6
...
@@ -7,6 +7,7 @@ import warnings
...
@@ -7,6 +7,7 @@ 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
...
@@ -488,12 +489,15 @@ theano.compile.register_deep_copy_op_c_code(
...
@@ -488,12 +489,15 @@ 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
cuda
:
return
cuda
.
CudaNdarray
(
npa
)
if
config
.
experimental
.
unpickle_gpu_on_cpu
:
else
:
# directly return numpy array
# directly return numpy array
warnings
.
warn
(
"
CUDA not found
. Unpickling CudaNdarray as numpy.ndarray"
)
warnings
.
warn
(
"
config.experimental.unpickle_gpu_on_cpu is set to True
. Unpickling CudaNdarray as numpy.ndarray"
)
return
npa
return
npa
elif
cuda
:
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论