Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a4d2db75
提交
a4d2db75
authored
1月 07, 2015
作者:
Dustin Webb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Started applying local_elemwise_alloc to GpuElemwise.
上级
c4a2fd88
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
96 行增加
和
0 行删除
+96
-0
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+18
-0
opt.py
theano/sandbox/cuda/opt.py
+9
-0
test_opt.py
theano/sandbox/cuda/tests/test_opt.py
+69
-0
没有找到文件。
theano/sandbox/cuda/basic_ops.py
浏览文件 @
a4d2db75
...
@@ -313,6 +313,13 @@ class GpuDimShuffle(GpuOp):
...
@@ -313,6 +313,13 @@ class GpuDimShuffle(GpuOp):
" dimension."
,
" dimension."
,
(
input_broadcastable
,
new_order
))
(
input_broadcastable
,
new_order
))
# this is the list of the original dimensions that we keep
self
.
shuffle
=
[
x
for
x
in
new_order
if
x
!=
'x'
]
# list of dimensions of the output that are broadcastable and were not
# in the original input
self
.
augment
=
[
i
for
i
,
x
in
enumerate
(
new_order
)
if
x
==
'x'
]
self
.
view_map
=
{
0
:
[
0
]}
self
.
view_map
=
{
0
:
[
0
]}
self
.
_rehash
()
self
.
_rehash
()
...
@@ -486,6 +493,17 @@ class GpuDimShuffle(GpuOp):
...
@@ -486,6 +493,17 @@ class GpuDimShuffle(GpuOp):
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
1
,
0
)
return
(
1
,
0
)
def
infer_shape
(
self
,
node
,
shapes
):
ishp
,
=
shapes
# transpose
rval
=
[
ishp
[
i
]
for
i
in
self
.
shuffle
]
# augment
for
augm
in
self
.
augment
:
rval
.
insert
(
augm
,
1
)
return
[
rval
]
class
GpuCAReduce
(
GpuOp
):
class
GpuCAReduce
(
GpuOp
):
"""GpuCAReduce is a Reduction along some dimensions by a scalar op.
"""GpuCAReduce is a Reduction along some dimensions by a scalar op.
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
a4d2db75
...
@@ -1814,6 +1814,15 @@ gpu_inplace_elemwise_optimizer = tensor.opt.inplace_elemwise_optimizer_op(
...
@@ -1814,6 +1814,15 @@ gpu_inplace_elemwise_optimizer = tensor.opt.inplace_elemwise_optimizer_op(
optdb
.
register
(
'gpu_inplace_elemwise_opt'
,
gpu_inplace_elemwise_optimizer
,
75
,
optdb
.
register
(
'gpu_inplace_elemwise_opt'
,
gpu_inplace_elemwise_optimizer
,
75
,
'fast_run'
,
'inplace'
,
'gpu_inplace'
)
'fast_run'
,
'inplace'
,
'gpu_inplace'
)
gpu_local_elemwise_alloc
=
tensor
.
opt
.
register_specialize_device
(
gof
.
local_optimizer
([
GpuElemwise
])(
tensor
.
opt
.
local_elemwise_alloc_op
(
GpuElemwise
,
GpuAlloc
,
GpuDimShuffle
)
)
)
@register_opt
()
@register_opt
()
@local_optimizer
([
tensor
.
alloc
])
@local_optimizer
([
tensor
.
alloc
])
...
...
theano/sandbox/cuda/tests/test_opt.py
浏览文件 @
a4d2db75
import
operator
import
operator
import
sys
import
sys
import
unittest
import
numpy
import
numpy
# Skip test if cuda_ndarray is not available.
# Skip test if cuda_ndarray is not available.
...
@@ -86,6 +87,74 @@ def test_gpualloc():
...
@@ -86,6 +87,74 @@ def test_gpualloc():
assert
numpy
.
any
([
isinstance
(
x
.
op
,
cuda
.
GpuAlloc
)
for
x
in
l
])
assert
numpy
.
any
([
isinstance
(
x
.
op
,
cuda
.
GpuAlloc
)
for
x
in
l
])
class
Test_local_elemwise_alloc
(
unittest
.
TestCase
):
dtype
=
config
.
floatX
def
setUp
(
self
):
self
.
vec
=
tensor
.
vector
(
'vec'
,
dtype
=
theano
.
config
.
floatX
)
self
.
mat
=
tensor
.
matrix
(
'mat'
,
dtype
=
theano
.
config
.
floatX
)
self
.
tens
=
tensor
.
tensor3
(
'tens'
,
dtype
=
theano
.
config
.
floatX
)
self
.
alloc_wo_dep
=
basic_ops
.
gpu_alloc
(
self
.
vec
,
2
)
self
.
alloc_w_dep
=
basic_ops
.
gpu_alloc
(
self
.
vec
,
*
self
.
vec
.
shape
)
def
_verify_alloc_count
(
self
,
f
,
count
):
assert
(
sum
([
isinstance
(
elem
.
op
,
basic_ops
.
GpuAlloc
)
for
elem
in
f
.
maker
.
fgraph
.
toposort
()
if
elem
.
op
is
not
None
])
==
count
)
def
_verify_assert_count
(
self
,
f
,
count
):
assert
(
sum
([
isinstance
(
elem
.
op
,
tensor
.
opt
.
Assert
)
for
elem
in
f
.
maker
.
fgraph
.
toposort
()
if
elem
.
op
is
not
None
])
==
count
)
def
test_remove_alloc_wo_dimshuffle
(
self
):
# No optimization on alloc
from
theano.printing
import
debugprint
as
dp
func
=
theano
.
function
(
[
self
.
vec
,
self
.
mat
],
self
.
alloc_wo_dep
+
self
.
mat
,
mode
=
'FAST_COMPILE'
)
self
.
_verify_alloc_count
(
func
,
1
)
self
.
_verify_assert_count
(
func
,
0
)
# Optimization on alloc with assert
"""
func = theano.function(
[self.vec, self.mat],
self.alloc_wo_dep + self.mat,
mode=mode_with_gpu
)
import ipdb; ipdb.set_trace()
self._verify_alloc_count(func, 0)
self._verify_assert_count(func, 1)
"""
# No optimization on alloc without assert
func
=
theano
.
function
(
[
self
.
vec
,
self
.
mat
],
self
.
alloc_w_dep
+
self
.
mat
,
mode
=
'FAST_COMPILE'
)
self
.
_verify_alloc_count
(
func
,
1
)
self
.
_verify_assert_count
(
func
,
0
)
# Optimization on alloc without assert
func
=
theano
.
function
(
[
self
.
vec
,
self
.
mat
],
self
.
alloc_w_dep
+
self
.
mat
,
mode
=
mode_with_gpu
)
import
ipdb
;
ipdb
.
set_trace
()
self
.
_verify_alloc_count
(
func
,
0
)
self
.
_verify_assert_count
(
func
,
0
)
def
test_alloc_memset_0
():
def
test_alloc_memset_0
():
i
=
tensor
.
iscalar
()
i
=
tensor
.
iscalar
()
z
=
numpy
.
zeros
((
1
,),
dtype
=
'float32'
)
z
=
numpy
.
zeros
((
1
,),
dtype
=
'float32'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论