Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ea49570d
提交
ea49570d
authored
12月 13, 2011
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
7de7d093
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
14 行删除
+19
-14
test_pycuda_theano_simple.py
theano/misc/tests/test_pycuda_theano_simple.py
+19
-14
没有找到文件。
theano/misc/tests/test_pycuda_theano_simple.py
浏览文件 @
ea49570d
...
...
@@ -15,7 +15,8 @@ import theano.misc.pycuda_init
if
not
theano
.
misc
.
pycuda_init
.
pycuda_available
:
from
nose.plugins.skip
import
SkipTest
raise
SkipTest
(
"Pycuda not installed. Skip test of theano op with pycuda code."
)
raise
SkipTest
(
"Pycuda not installed."
" We skip test of theano op with pycuda code."
)
if
cuda_ndarray
.
cuda_available
==
False
:
from
nose.plugins.skip
import
SkipTest
...
...
@@ -27,7 +28,7 @@ import pycuda.gpuarray
def
test_pycuda_simple
():
x
=
cuda_ndarray
.
CudaNdarray
.
zeros
((
5
,
5
))
x
=
cuda_ndarray
.
CudaNdarray
.
zeros
((
5
,
5
))
from
pycuda.compiler
import
SourceModule
mod
=
SourceModule
(
"""
...
...
@@ -46,30 +47,32 @@ __global__ void multiply_them(float *dest, float *a, float *b)
dest
=
numpy
.
zeros_like
(
a
)
multiply_them
(
drv
.
Out
(
dest
),
drv
.
In
(
a
),
drv
.
In
(
b
),
block
=
(
400
,
1
,
1
),
grid
=
(
1
,
1
))
assert
(
dest
==
a
*
b
)
.
all
()
block
=
(
400
,
1
,
1
),
grid
=
(
1
,
1
))
assert
(
dest
==
a
*
b
)
.
all
()
def
test_pycuda_memory_to_theano
():
#Test that we can use the GpuArray memory space in pycuda in a CudaNdarray
y
=
pycuda
.
gpuarray
.
zeros
((
3
,
4
,
5
),
'float32'
)
y
=
pycuda
.
gpuarray
.
zeros
((
3
,
4
,
5
),
'float32'
)
print
numpy
.
asarray
(
y
)
print
"gpuarray ref count before creating a CudaNdarray"
,
sys
.
getrefcount
(
y
)
assert
sys
.
getrefcount
(
y
)
==
2
print
"gpuarray ref count before creating a CudaNdarray"
,
print
sys
.
getrefcount
(
y
)
assert
sys
.
getrefcount
(
y
)
==
2
rand
=
numpy
.
random
.
randn
(
*
y
.
shape
)
.
astype
(
numpy
.
float32
)
cuda_rand
=
cuda_ndarray
.
CudaNdarray
(
rand
)
strides
=
[
1
]
for
i
in
y
.
shape
[::
-
1
][:
-
1
]:
strides
.
append
(
strides
[
-
1
]
*
i
)
strides
.
append
(
strides
[
-
1
]
*
i
)
strides
=
tuple
(
strides
[::
-
1
])
print
'strides'
,
strides
assert
cuda_rand
.
_strides
==
strides
,
(
cuda_rand
.
_strides
,
strides
)
y_ptr
=
int
(
y
.
gpudata
)
# in pycuda trunk, y.ptr also works, which is a little cleaner
# in pycuda trunk, y.ptr also works, which is a little cleaner
y_ptr
=
int
(
y
.
gpudata
)
z
=
cuda_ndarray
.
from_gpu_pointer
(
y_ptr
,
y
.
shape
,
strides
,
y
)
print
"gpuarray ref count after creating a CudaNdarray"
,
sys
.
getrefcount
(
y
)
assert
sys
.
getrefcount
(
y
)
==
3
assert
sys
.
getrefcount
(
y
)
==
3
assert
(
numpy
.
asarray
(
z
)
==
0
)
.
all
()
assert
z
.
base
is
y
...
...
@@ -80,7 +83,8 @@ def test_pycuda_memory_to_theano():
del
zz
assert
sys
.
getrefcount
(
y
)
==
3
cuda_ones
=
cuda_ndarray
.
CudaNdarray
(
numpy
.
asarray
([[[
1
]]],
dtype
=
'float32'
))
cuda_ones
=
cuda_ndarray
.
CudaNdarray
(
numpy
.
asarray
([[[
1
]]],
dtype
=
'float32'
))
z
+=
cuda_ones
assert
(
numpy
.
asarray
(
z
)
==
numpy
.
ones
(
y
.
shape
))
.
all
()
assert
(
numpy
.
asarray
(
z
)
==
1
)
.
all
()
...
...
@@ -89,9 +93,10 @@ def test_pycuda_memory_to_theano():
assert
cuda_rand
.
_strides
==
z
.
_strides
,
(
cuda_rand
.
_strides
,
z
.
_strides
)
assert
(
numpy
.
asarray
(
cuda_rand
)
==
rand
)
.
all
()
z
+=
cuda_rand
assert
(
numpy
.
asarray
(
z
)
==
(
rand
+
1
))
.
all
()
assert
(
numpy
.
asarray
(
z
)
==
(
rand
+
1
))
.
all
()
# Check that the ref count to the gpuarray is right.
del
z
print
"gpuarray ref count after deleting the CudaNdarray"
,
sys
.
getrefcount
(
y
)
assert
sys
.
getrefcount
(
y
)
==
2
print
"gpuarray ref count after deleting the CudaNdarray"
,
print
sys
.
getrefcount
(
y
)
assert
sys
.
getrefcount
(
y
)
==
2
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论