Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
48f621b0
提交
48f621b0
authored
1月 25, 2016
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Alloc pickling of GpuArray object
上级
8020a38f
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
133 行增加
和
2 行删除
+133
-2
GpuArray.pkl
theano/sandbox/gpuarray/tests/GpuArray.pkl
+42
-0
test_type.py
theano/sandbox/gpuarray/tests/test_type.py
+55
-0
type.py
theano/sandbox/gpuarray/type.py
+36
-2
没有找到文件。
theano/sandbox/gpuarray/tests/GpuArray.pkl
0 → 100644
浏览文件 @
48f621b0
ctheano.sandbox.gpuarray.type
GpuArray_unpickler
p0
(cnumpy.core.multiarray
_reconstruct
p1
(cnumpy
ndarray
p2
(I0
tp3
S'b'
p4
tp5
Rp6
(I1
(I1
tp7
cnumpy
dtype
p8
(S'f4'
p9
I0
I1
tp10
Rp11
(I3
S'<'
p12
NNNI-1
I-1
I0
tp13
bI00
S'\x00\x00(\xc2'
p14
tp15
bNtp16
Rp17
.
\ No newline at end of file
theano/sandbox/gpuarray/tests/test_type.py
浏览文件 @
48f621b0
import
os
from
nose.tools
import
assert_raises
import
numpy
import
numpy
import
theano
import
theano
from
theano.compat
import
PY3
from
theano
import
config
from
theano.compile
import
DeepCopyOp
from
theano.compile
import
DeepCopyOp
from
theano.misc.pkl_utils
import
CompatUnpickler
from
.config
import
test_ctx_name
from
.config
import
test_ctx_name
from
.test_basic_ops
import
rand_gpuarray
from
.test_basic_ops
import
rand_gpuarray
from
..type
import
GpuArrayType
from
..type
import
GpuArrayType
from
..
import
pygpu_activated
if
pygpu_activated
:
import
pygpu
def
test_deep_copy
():
def
test_deep_copy
():
...
@@ -43,3 +53,48 @@ def test_specify_shape():
...
@@ -43,3 +53,48 @@ def test_specify_shape():
def
test_filter_float
():
def
test_filter_float
():
s
=
theano
.
shared
(
numpy
.
array
(
0.0
,
dtype
=
'float32'
),
target
=
test_ctx_name
)
s
=
theano
.
shared
(
numpy
.
array
(
0.0
,
dtype
=
'float32'
),
target
=
test_ctx_name
)
theano
.
function
([],
updates
=
[(
s
,
0.0
)])
theano
.
function
([],
updates
=
[(
s
,
0.0
)])
def
test_unpickle_gpuarray_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__
))
fname
=
'GpuArray.pkl'
with
open
(
os
.
path
.
join
(
testfile_dir
,
fname
),
'rb'
)
as
fp
:
if
PY3
:
u
=
CompatUnpickler
(
fp
,
encoding
=
"latin1"
)
else
:
u
=
CompatUnpickler
(
fp
)
if
pygpu_activated
:
mat
=
u
.
load
()
assert
isinstance
(
mat
,
pygpu
.
gpuarray
.
GpuArray
)
assert
numpy
.
asarray
(
mat
)[
0
]
==
-
42.0
else
:
assert_raises
(
ImportError
,
u
.
load
)
finally
:
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
def
test_unpickle_gpuarray_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__
))
fname
=
'GpuArray.pkl'
with
open
(
os
.
path
.
join
(
testfile_dir
,
fname
),
'rb'
)
as
fp
:
if
PY3
:
u
=
CompatUnpickler
(
fp
,
encoding
=
"latin1"
)
else
:
u
=
CompatUnpickler
(
fp
)
mat
=
u
.
load
()
assert
isinstance
(
mat
,
numpy
.
ndarray
)
assert
mat
[
0
]
==
-
42.0
finally
:
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
theano/sandbox/gpuarray/type.py
浏览文件 @
48f621b0
import
numpy
import
numpy
import
six.moves.copyreg
as
copyreg
from
six
import
iteritems
import
warnings
import
theano
import
theano
from
theano.tensor.var
import
_tensor_py_operators
from
theano.tensor.var
import
_tensor_py_operators
...
@@ -12,7 +15,7 @@ try:
...
@@ -12,7 +15,7 @@ try:
from
pygpu
import
gpuarray
from
pygpu
import
gpuarray
from
pygpu.elemwise
import
compare
,
elemwise2
from
pygpu.elemwise
import
compare
,
elemwise2
except
ImportError
:
except
ImportError
:
p
ass
p
ygpu
=
None
_context_reg
=
{}
_context_reg
=
{}
...
@@ -74,7 +77,7 @@ def list_contexts():
...
@@ -74,7 +77,7 @@ def list_contexts():
# Private method
# Private method
def
_name_for_ctx
(
ctx
):
def
_name_for_ctx
(
ctx
):
for
k
,
v
in
_context_reg
:
for
k
,
v
in
iteritems
(
_context_reg
)
:
if
v
==
ctx
:
if
v
==
ctx
:
return
k
return
k
raise
ContextNotDefined
(
'context is not registered'
)
raise
ContextNotDefined
(
'context is not registered'
)
...
@@ -751,3 +754,34 @@ Instance of :class:`GpuContextType` to use for the context_type
...
@@ -751,3 +754,34 @@ Instance of :class:`GpuContextType` to use for the context_type
declaration of an operation.
declaration of an operation.
"""
"""
gpu_context_type
=
GpuContextType
()
gpu_context_type
=
GpuContextType
()
# THIS WORKS But CudaNdarray instances don't compare equal to one
# another, and what about __hash__ ? So the unpickled version doesn't
# equal the pickled version, and the cmodule cache is not happy with
# the situation.
def
GpuArray_unpickler
(
npa
,
ctx_name
):
if
config
.
experimental
.
unpickle_gpu_on_cpu
:
# directly return numpy array
warnings
.
warn
(
"config.experimental.unpickle_gpu_on_cpu is set to True. "
"Unpickling GpuArray as numpy.ndarray"
)
return
npa
elif
pygpu
:
ctx
=
get_context
(
ctx_name
)
return
pygpu
.
gpuarray
.
array
(
npa
,
copy
=
True
,
context
=
ctx
)
else
:
raise
ImportError
(
"Cuda not found. Cannot unpickle GpuArray"
)
copyreg
.
constructor
(
GpuArray_unpickler
)
def
GpuArray_pickler
(
cnda
):
ctx_name
=
_name_for_ctx
(
cnda
.
context
)
return
(
GpuArray_unpickler
,
(
numpy
.
asarray
(
cnda
),
ctx_name
))
# In case pygpu is not imported.
if
pygpu
is
not
None
:
copyreg
.
pickle
(
pygpu
.
gpuarray
.
GpuArray
,
GpuArray_pickler
,
GpuArray_unpickler
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论