Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8da054b7
提交
8da054b7
authored
7月 26, 2014
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1994 from nouiz/lazy
[CRASH] fix tutorial example related to lazy evaluation.
上级
389d4911
677710cb
全部展开
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
37 行增加
和
27 行删除
+37
-27
cop.txt
doc/extending/cop.txt
+12
-12
op.txt
doc/extending/op.txt
+8
-8
using_gpu.txt
doc/tutorial/using_gpu.txt
+11
-6
vm.py
theano/gof/vm.py
+5
-0
test_pycuda_example.py
theano/misc/tests/test_pycuda_example.py
+1
-1
test_tutorial.py
theano/tests/test_tutorial.py
+0
-0
没有找到文件。
doc/extending/cop.txt
浏览文件 @
8da054b7
...
@@ -211,18 +211,18 @@ version that it produces in the code I gave above.
...
@@ -211,18 +211,18 @@ version that it produces in the code I gave above.
return self.ccode % locals()
return self.ccode % locals()
add = BinaryDoubleOp(name
=
'add',
add = BinaryDoubleOp(name
=
'add',
fn
=
lambda x, y: x + y,
fn
=
lambda x, y: x + y,
ccode
=
"%(z)s = %(x)s + %(y)s;")
ccode
=
"%(z)s = %(x)s + %(y)s;")
sub = BinaryDoubleOp(name
=
'sub',
sub = BinaryDoubleOp(name
=
'sub',
fn
=
lambda x, y: x - y,
fn
=
lambda x, y: x - y,
ccode
=
"%(z)s = %(x)s - %(y)s;")
ccode
=
"%(z)s = %(x)s - %(y)s;")
mul = BinaryDoubleOp(name
=
'mul',
mul = BinaryDoubleOp(name
=
'mul',
fn
=
lambda x, y: x * y,
fn
=
lambda x, y: x * y,
ccode
=
"%(z)s = %(x)s * %(y)s;")
ccode
=
"%(z)s = %(x)s * %(y)s;")
div = BinaryDoubleOp(name
=
'div',
div = BinaryDoubleOp(name
=
'div',
fn
=
lambda x, y: x / y,
fn
=
lambda x, y: x / y,
ccode
=
"%(z)s = %(x)s / %(y)s;")
ccode
=
"%(z)s = %(x)s / %(y)s;")
doc/extending/op.txt
浏览文件 @
8da054b7
...
@@ -633,17 +633,17 @@ arithmetic operators:
...
@@ -633,17 +633,17 @@ arithmetic operators:
def __str__(self):
def __str__(self):
return self.name
return self.name
add = BinaryDoubleOp(name
=
'add',
add = BinaryDoubleOp(name
=
'add',
fn
=
lambda x, y: x + y)
fn
=
lambda x, y: x + y)
sub = BinaryDoubleOp(name
=
'sub',
sub = BinaryDoubleOp(name
=
'sub',
fn
=
lambda x, y: x - y)
fn
=
lambda x, y: x - y)
mul = BinaryDoubleOp(name
=
'mul',
mul = BinaryDoubleOp(name
=
'mul',
fn
=
lambda x, y: x * y)
fn
=
lambda x, y: x * y)
div = BinaryDoubleOp(name
=
'div',
div = BinaryDoubleOp(name
=
'div',
fn
=
lambda x, y: x / y)
fn
=
lambda x, y: x / y)
Instead of working directly on an instance of Op, we create a subclass of
Instead of working directly on an instance of Op, we create a subclass of
Op that we can parametrize. All the operations we define are binary. They
Op that we can parametrize. All the operations we define are binary. They
...
...
doc/tutorial/using_gpu.txt
浏览文件 @
8da054b7
...
@@ -685,15 +685,19 @@ Modify and execute to work for a matrix of shape (20, 10).
...
@@ -685,15 +685,19 @@ Modify and execute to work for a matrix of shape (20, 10).
class PyCUDADoubleOp(theano.Op):
class PyCUDADoubleOp(theano.Op):
def __eq__(self, other):
def __eq__(self, other):
return type(self) == type(other)
return type(self) == type(other)
def __hash__(self):
def __hash__(self):
return hash(type(self))
return hash(type(self))
def __str__(self):
def __str__(self):
return self.__class__.__name__
return self.__class__.__name__
def make_node(self, inp):
def make_node(self, inp):
inp = cuda.basic_ops.gpu_contiguous(
inp = cuda.basic_ops.gpu_contiguous(
cuda.basic_ops.as_cuda_ndarray_variable(inp))
cuda.basic_ops.as_cuda_ndarray_variable(inp))
assert inp.dtype == "float32"
assert inp.dtype == "float32"
return theano.Apply(self, [inp], [inp.type()])
return theano.Apply(self, [inp], [inp.type()])
def make_thunk(self, node, storage_map, _, _2):
def make_thunk(self, node, storage_map, _, _2):
mod = SourceModule("""
mod = SourceModule("""
__global__ void my_fct(float * i0, float * o0, int size) {
__global__ void my_fct(float * i0, float * o0, int size) {
...
@@ -703,15 +707,16 @@ Modify and execute to work for a matrix of shape (20, 10).
...
@@ -703,15 +707,16 @@ Modify and execute to work for a matrix of shape (20, 10).
}
}
}""")
}""")
pycuda_fct = mod.get_function("my_fct")
pycuda_fct = mod.get_function("my_fct")
inputs = [ storage_map[v] for v in node.inputs]
inputs = [storage_map[v] for v in node.inputs]
outputs = [ storage_map[v] for v in node.outputs]
outputs = [storage_map[v] for v in node.outputs]
def thunk():
def thunk():
z = outputs[0]
z = outputs[0]
if z[0] is None or z[0].shape
!=
inputs[0][0].shape:
if z[0] is None or z[0].shape
!=
inputs[0][0].shape:
z[0] = cuda.CudaNdarray.zeros(inputs[0][0].shape)
z[0] = cuda.CudaNdarray.zeros(inputs[0][0].shape)
grid = (int(numpy.ceil(inputs[0][0].size / 512.)),1)
grid = (int(numpy.ceil(inputs[0][0].size / 512.)),
1)
pycuda_fct(inputs[0][0], z[0], numpy.intc(inputs[0][0].size),
pycuda_fct(inputs[0][0], z[0], numpy.intc(inputs[0][0].size),
block=(512,
1,
1), grid=grid)
block=(512,
1,
1), grid=grid)
return thunk
return thunk
...
@@ -719,7 +724,7 @@ Use this code to test it:
...
@@ -719,7 +724,7 @@ Use this code to test it:
>>> x = theano.tensor.fmatrix()
>>> x = theano.tensor.fmatrix()
>>> f = theano.function([x], PyCUDADoubleOp()(x))
>>> f = theano.function([x], PyCUDADoubleOp()(x))
>>> xv
=numpy.ones((4,
5), dtype="float32")
>>> xv
= numpy.ones((4,
5), dtype="float32")
>>> assert numpy.allclose(f(xv), xv*2)
>>> assert numpy.allclose(f(xv), xv*2)
>>> print numpy.asarray(f(xv))
>>> print numpy.asarray(f(xv))
...
...
theano/gof/vm.py
浏览文件 @
8da054b7
...
@@ -886,6 +886,11 @@ class VM_Linker(link.LocalLinker):
...
@@ -886,6 +886,11 @@ class VM_Linker(link.LocalLinker):
storage_map
,
storage_map
,
compute_map
,
compute_map
,
no_recycling
))
no_recycling
))
if
not
hasattr
(
thunks
[
-
1
],
'lazy'
):
# We don't want all ops maker to think about lazy Ops.
# So if they didn't specify that its lazy or not, it isn't.
# If this member isn't present, it will crash later.
thunks
[
-
1
]
.
lazy
=
False
except
Exception
,
e
:
except
Exception
,
e
:
e
.
args
=
(
"The following error happened while"
e
.
args
=
(
"The following error happened while"
" compiling the node"
,
node
,
"
\n
"
)
+
e
.
args
" compiling the node"
,
node
,
"
\n
"
)
+
e
.
args
...
...
theano/misc/tests/test_pycuda_example.py
浏览文件 @
8da054b7
...
@@ -9,7 +9,7 @@ if not theano.misc.pycuda_init.pycuda_available:
...
@@ -9,7 +9,7 @@ if not theano.misc.pycuda_init.pycuda_available:
" with pycuda code."
)
" with pycuda code."
)
import
theano.sandbox.cuda
as
cuda_ndarray
import
theano.sandbox.cuda
as
cuda_ndarray
if
cuda_ndarray
.
cuda_available
==
Fals
e
:
if
not
cuda_ndarray
.
cuda_availabl
e
:
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
raise
SkipTest
(
'Optional package cuda disabled'
)
raise
SkipTest
(
'Optional package cuda disabled'
)
...
...
theano/tests/test_tutorial.py
浏览文件 @
8da054b7
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论