Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c1366d70
提交
c1366d70
authored
4月 03, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #590 from nouiz/test_fix
Test fix
上级
a2027539
72986083
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
67 行增加
和
41 行删除
+67
-41
do_nightly_build
theano/misc/do_nightly_build
+1
-1
pycuda_example.py
theano/misc/pycuda_example.py
+0
-0
test_pycuda_example.py
theano/misc/tests/test_pycuda_example.py
+62
-39
test_pycuda_theano_simple.py
theano/misc/tests/test_pycuda_theano_simple.py
+4
-1
没有找到文件。
theano/misc/do_nightly_build
浏览文件 @
c1366d70
...
...
@@ -59,7 +59,7 @@ echo "Number of elements in the compiledir:"
ls
${
COMPILEDIR
}
|wc
-l
echo
"Executing nosetests with mode=FAST_RUN"
THEANO_FLAGS
=
${
FLAGS
}
,mode
=
FAST_RUN
${
NOSETESTS
}
${
PROFILING
}
${
ARGS
}
THEANO_FLAGS
=
cmodule.warn_no_version
=
True,
${
FLAGS
}
,mode
=
FAST_RUN
${
NOSETESTS
}
${
PROFILING
}
${
ARGS
}
echo
"Number of elements in the compiledir:"
ls
${
COMPILEDIR
}
|wc
-l
...
...
theano/misc/pycuda_example.py
浏览文件 @
c1366d70
差异被折叠。
点击展开。
theano/misc/tests/test_pycuda_example.py
浏览文件 @
c1366d70
...
...
@@ -5,7 +5,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. Skip test of theano op"
" with pycuda code."
)
import
theano.sandbox.cuda
as
cuda_ndarray
if
cuda_ndarray
.
cuda_available
==
False
:
...
...
@@ -14,71 +15,93 @@ if cuda_ndarray.cuda_available == False:
import
theano
import
theano.tensor
as
T
from
theano.misc.pycuda_example
import
PycudaElemwiseSourceModuleOp
,
PycudaElemwiseKernelOp
,
PycudaElemwiseSourceModuleMakeThunkOp
from
theano.misc.pycuda_example
import
(
PycudaElemwiseSourceModuleOp
,
# PycudaElemwiseKernelOp,
PycudaElemwiseSourceModuleMakeThunkOp
)
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
including
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'gpu'
)
else
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'gpu'
)
def
test_pycuda_elemwise_source_module
():
for
shape
in
[(
5
,
5
),
(
10
,
49
),
(
50
,
49
),(
500
,
501
),(
5000
,
50
01
)]:
for
shape
in
[(
5
,
5
),
(
10
,
49
),
(
50
,
49
),
(
500
,
5
01
)]:
for
op
in
[
theano
.
scalar
.
basic
.
mul
,
theano
.
scalar
.
basic
.
add
]:
x
=
T
.
fmatrix
(
'x'
)
y
=
T
.
fmatrix
(
'y'
)
x
=
T
.
fmatrix
(
'x'
)
y
=
T
.
fmatrix
(
'y'
)
elemwise_op
=
theano
.
tensor
.
Elemwise
(
op
)
pycuda_op
=
PycudaElemwiseSourceModuleOp
(
op
)
pycuda_op_thunk
=
PycudaElemwiseSourceModuleMakeThunkOp
(
op
)
f
=
theano
.
function
([
x
,
y
],
elemwise_op
(
x
,
y
),
mode
=
mode_with_gpu
)
f2
=
theano
.
function
([
x
,
y
],
theano
.
sandbox
.
cuda
.
host_from_gpu
(
pycuda_op
(
x
,
y
)))
f3
=
theano
.
function
([
x
,
y
],
elemwise_op
(
x
,
y
),
mode
=
mode_with_gpu
.
including
(
"local_pycuda_gpu_elemwise"
))
f4
=
theano
.
function
([
x
,
y
],
theano
.
sandbox
.
cuda
.
host_from_gpu
(
pycuda_op_thunk
(
x
,
y
)))
f
=
theano
.
function
([
x
,
y
],
elemwise_op
(
x
,
y
),
mode
=
mode_with_gpu
)
f2
=
theano
.
function
([
x
,
y
],
theano
.
sandbox
.
cuda
.
host_from_gpu
(
pycuda_op
(
x
,
y
)),
mode
=
mode_with_gpu
)
mode_pycuda
=
mode_with_gpu
.
including
(
"local_pycuda_gpu_elemwise"
)
f3
=
theano
.
function
([
x
,
y
],
elemwise_op
(
x
,
y
),
mode
=
mode_pycuda
)
f4
=
theano
.
function
([
x
,
y
],
theano
.
sandbox
.
cuda
.
host_from_gpu
(
pycuda_op_thunk
(
x
,
y
)),
mode
=
mode_with_gpu
)
assert
any
([
isinstance
(
node
.
op
,
theano
.
sandbox
.
cuda
.
GpuElemwise
)
for
node
in
f
.
maker
.
env
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
PycudaElemwiseSourceModuleOp
)
for
node
in
f2
.
maker
.
env
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
PycudaElemwiseSourceModuleOp
)
for
node
in
f3
.
maker
.
env
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
PycudaElemwiseSourceModuleMakeThunkOp
)
for
node
in
f4
.
maker
.
env
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
theano
.
sandbox
.
cuda
.
GpuElemwise
)
for
node
in
f
.
maker
.
env
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
PycudaElemwiseSourceModuleOp
)
for
node
in
f2
.
maker
.
env
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
PycudaElemwiseSourceModuleOp
)
for
node
in
f3
.
maker
.
env
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
PycudaElemwiseSourceModuleMakeThunkOp
)
for
node
in
f4
.
maker
.
env
.
toposort
()])
val1
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
val2
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
assert
(
f
(
val1
,
val2
)
==
f2
(
val1
,
val2
))
.
all
()
assert
(
f
(
val1
,
val2
)
==
f3
(
val1
,
val2
))
.
all
()
assert
(
f
(
val1
,
val2
)
==
f4
(
val1
,
val2
))
.
all
()
assert
(
f
(
val1
,
val2
)
==
f2
(
val1
,
val2
))
.
all
()
assert
(
f
(
val1
,
val2
)
==
f3
(
val1
,
val2
))
.
all
()
assert
(
f
(
val1
,
val2
)
==
f4
(
val1
,
val2
))
.
all
()
#print f(val1,val2)
#print f2(val1,val2)
"""
#commented as it work only with old pycuda version.
def test_pycuda_elemwise_kernel():
x
=
T
.
fmatrix
(
'x'
)
y
=
T
.
fmatrix
(
'y'
)
f
=
theano
.
function
([
x
,
y
],
x
+
y
,
mode
=
mode_with_gpu
)
x
=
T.fmatrix('x')
y
=
T.fmatrix('y')
f
= theano.function([x, y], x +
y, mode=mode_with_gpu)
print f.maker.env.toposort()
f2
=
theano
.
function
([
x
,
y
],
x
+
y
,
mode
=
mode_with_gpu
.
including
(
"local_pycuda_gpu_elemwise_kernel"
))
mode_pycuda = mode_with_gpu.including("local_pycuda_gpu_elemwise_kernel")
f2 = theano.function([x, y], x + y, mode=mode_pycuda)
print f2.maker.env.toposort()
assert
any
([
isinstance
(
node
.
op
,
theano
.
sandbox
.
cuda
.
GpuElemwise
)
for
node
in
f
.
maker
.
env
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
PycudaElemwiseKernelOp
)
for
node
in
f2
.
maker
.
env
.
toposort
()])
assert any([isinstance(node.op, theano.sandbox.cuda.GpuElemwise)
for node in f.maker.env.toposort()])
assert any([isinstance(node.op, PycudaElemwiseKernelOp)
for node in f2.maker.env.toposort()])
val1
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
5
,
5
),
dtype
=
'float32'
)
val2
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
5
,
5
),
dtype
=
'float32'
)
val1 = numpy.asarray(numpy.random.rand(5,
5), dtype='float32')
val2 = numpy.asarray(numpy.random.rand(5,
5), dtype='float32')
#val1 = numpy.ones((5,5))
#val2 = numpy.arange(25).reshape(5,5)
assert
(
f
(
val1
,
val2
)
==
f2
(
val1
,
val2
))
.
all
()
print
f
(
val1
,
val2
)
print
f2
(
val1
,
val2
)
assert (f(val1, val2) == f2(val1, val2)).all()
print f(val1, val2)
print f2(val1, val2)
x3
=
T
.
ftensor3
(
'x'
)
y3
=
T
.
ftensor3
(
'y'
)
z3
=
T
.
ftensor3
(
'y'
)
x3
=
T.ftensor3('x')
y3
=
T.ftensor3('y')
z3
=
T.ftensor3('y')
f4
=
theano
.
function
([
x3
,
y3
,
z3
],
x3
*
y3
+
z3
,
mode
=
mode_with_gpu
.
including
(
"local_pycuda_gpu_elemwise_kernel"
)
)
f4 = theano.function([x3,
y3, z3], x3 * y3 + z3, mode=mode_pycuda
)
print f4.maker.env.toposort()
assert
any
([
isinstance
(
node
.
op
,
PycudaElemwiseKernelOp
)
for
node
in
f4
.
maker
.
env
.
toposort
()])
assert any([isinstance(node.op, PycudaElemwiseKernelOp)
for node in f4.maker.env.toposort()])
val1
=
numpy
.
random
.
rand
(
2
,
2
,
2
)
val1 = numpy.random.rand(2,
2,
2)
print val1
print
f4
(
val1
,
val1
,
val1
)
assert
numpy
.
allclose
(
f4
(
val1
,
val1
,
val1
),
val1
*
val1
+
val1
)
print f4(val1, val1, val1)
assert numpy.allclose(f4(val1, val1, val1), val1 * val1 + val1)
"""
theano/misc/tests/test_pycuda_theano_simple.py
浏览文件 @
c1366d70
...
...
@@ -78,7 +78,10 @@ __global__ void multiply_them(float *dest, float *a, float *b)
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'
)
print
numpy
.
asarray
(
y
)
print
sys
.
getrefcount
(
y
)
# This increase the ref count with never pycuda. Do pycuda also
# cache ndarray?
# print y.get()
print
"gpuarray ref count before creating a CudaNdarray"
,
print
sys
.
getrefcount
(
y
)
assert
sys
.
getrefcount
(
y
)
==
2
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论