Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fe87d02b
提交
fe87d02b
authored
2月 16, 2017
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move copy/addapt max_inputs_to_GpuElemwise and split_huge_add_or_mul
上级
0dc3913f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
52 行增加
和
15 行删除
+52
-15
elemwise.py
theano/gpuarray/elemwise.py
+24
-0
opt.py
theano/gpuarray/opt.py
+28
-15
没有找到文件。
theano/gpuarray/elemwise.py
浏览文件 @
fe87d02b
...
...
@@ -41,6 +41,27 @@ def get_scal(dt):
return
scalar
.
get_scalar_type
(
dt
)
def
max_inputs_to_GpuElemwise
(
node_or_outputs
):
if
isinstance
(
node_or_outputs
,
Apply
):
outputs
=
node_or_outputs
.
outputs
else
:
outputs
=
node_or_outputs
ptr_size
=
8
int_size
=
4
# we take the limit from CUDA for now
argument_limit
=
232
ndim
=
outputs
[
0
]
.
type
.
ndim
# number of elements and shape
size_param_mandatory
=
(
int_size
*
(
ndim
+
1
))
+
\
(
ptr_size
+
int_size
*
ndim
)
*
len
(
outputs
)
nb_bytes_avail
=
argument_limit
-
size_param_mandatory
nb_bytes_per_input
=
ptr_size
+
ndim
*
int_size
max_nb_inputs
=
nb_bytes_avail
//
nb_bytes_per_input
return
max_nb_inputs
class
GpuElemwise
(
HideC
,
Elemwise
):
"""
Elemwise on the GPU.
...
...
@@ -57,6 +78,9 @@ class GpuElemwise(HideC, Elemwise):
items
=
str
(
sorted
(
self
.
inplace_pattern
.
items
()))
return
"GpuElemwise{
%
s}
%
s<gpuarray>"
%
(
self
.
scalar_op
,
items
)
def
max_inputs
(
self
,
node_or_outputs
):
return
max_inputs_to_GpuElemwise
(
node_or_outputs
)
def
make_node
(
self
,
*
inputs
):
ctx_name
=
infer_context_name
(
*
inputs
)
inputs
=
[
as_gpuarray_variable
(
i
,
ctx_name
)
for
i
in
inputs
]
...
...
theano/gpuarray/opt.py
浏览文件 @
fe87d02b
...
...
@@ -63,7 +63,8 @@ from .nnet import (gpu_crossentropy_softmax_1hot_with_bias_dx,
gpu_softmax_with_bias
,
gpu_softmax
)
from
.elemwise
import
(
GpuElemwise
,
GpuDimShuffle
,
GpuCAReduceCuda
,
GpuCAReduceCPY
,
gpu_ca_reduce_cuda
,
gpu_erfinv
,
gpu_erfcinv
)
GpuCAReduceCPY
,
gpu_ca_reduce_cuda
,
gpu_erfinv
,
gpu_erfcinv
,
max_inputs_to_GpuElemwise
)
from
.subtensor
import
(
GpuIncSubtensor
,
GpuSubtensor
,
GpuAdvancedSubtensor
,
GpuAdvancedSubtensor1
,
...
...
@@ -752,26 +753,38 @@ def local_gpua_elemwise(op, context_name, inputs, outputs):
# cpu.
gpu_output
=
res
(
*
new_inputs
)
return
[
gpu_output
]
elif
op
.
scalar_op
in
(
scalar
.
add
,
scalar
.
mul
):
max_nb_inputs
=
max_inputs_to_GpuElemwise
(
outputs
)
while
len
(
inputs
)
>
max_nb_inputs
:
inputs
=
inputs
[:
-
max_nb_inputs
]
+
[
res
(
*
inputs
[
-
max_nb_inputs
:])]
return
res
(
*
inputs
)
else
:
return
res
def
max_inputs_to_GpuElemwise
(
node
):
ptr_size
=
8
int_size
=
4
# we take the limit from CUDA for now
argument_limit
=
232
ndim
=
node
.
inputs
[
0
]
.
type
.
ndim
# number of elements and shape
size_param_mandatory
=
(
int_size
*
(
ndim
+
1
))
+
\
(
ptr_size
+
int_size
*
ndim
)
*
len
(
node
.
outputs
)
def
split_huge_add_or_mul
(
node
):
"""
For add and mul, it can happen that we have too much input
That will make nvcc fail compilation of our current code.
We don't want node in the graph that can't execute
as this break DebugMode.
nb_bytes_avail
=
argument_limit
-
size_param_mandatory
nb_bytes_per_input
=
ptr_size
+
ndim
*
int_size
max_nb_inputs
=
nb_bytes_avail
//
nb_bytes_per_input
This should not happen for other GpuElemwise as their is only the fusion
that can generate op with too much input and it check for that.
return
max_nb_inputs
"""
if
node
.
op
.
scalar_op
in
(
scal
.
add
,
scal
.
mul
):
max_nb_inputs
=
max_inputs_to_GpuElemwise
(
node
)
if
max_nb_inputs
<=
1
and
len
(
node
.
inputs
)
>
1
:
return
False
while
len
(
node
.
inputs
)
>
max_nb_inputs
:
inner_op
=
[]
for
i
in
xrange
(
0
,
len
(
node
.
inputs
),
max_nb_inputs
):
inner_op
.
append
(
node
.
op
(
*
node
.
inputs
[
i
:
i
+
max_nb_inputs
]))
node
=
node
.
op
(
*
inner_op
)
.
owner
return
node
gpu_local_elemwise_fusion
=
tensor
.
opt
.
local_elemwise_fusion_op
(
GpuElemwise
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论