Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d79b7647
提交
d79b7647
authored
5月 30, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
d16b5cfa
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
35 行增加
和
22 行删除
+35
-22
elemwise.py
theano/sandbox/cuda/elemwise.py
+35
-22
没有找到文件。
theano/sandbox/cuda/elemwise.py
浏览文件 @
d79b7647
"""
"""This file implement 3 different version of the elemwise op on the
This file implement 3 different version of the elemwise op on the gpu. Only NaiveAlgo is used and it is not very naive now.
gpu. Only NaiveAlgo is used and it is not very naive now.
The elemwise fct are also used with scalar operation! So it can happen
that ndim is 0 as with all scalar type.
The elemwise fct are also used with scalar operation! So it can happen that ndim is 0 as with all scalar type.
"""
"""
...
@@ -25,17 +27,23 @@ _logger.addHandler(logging.StreamHandler()) #TO REMOVE
...
@@ -25,17 +27,23 @@ _logger.addHandler(logging.StreamHandler()) #TO REMOVE
def
_logical_scalar
(
x
):
def
_logical_scalar
(
x
):
return
numpy
.
all
(
x
.
type
.
broadcastable
)
return
numpy
.
all
(
x
.
type
.
broadcastable
)
def
get_str_list_logical_scalar
(
node
,
value_str
=
'ii_i
%
i_value'
,
data_str
=
'ii_i
%
i_data[0]'
):
l
=
[]
def
get_str_list_logical_scalar
(
node
,
value_str
=
'ii_i
%
i_value'
,
data_str
=
'ii_i
%
i_data[0]'
):
l
=
[]
for
ipos
,
i
in
enumerate
(
node
.
inputs
):
for
ipos
,
i
in
enumerate
(
node
.
inputs
):
if
_logical_scalar
(
i
):
if
_logical_scalar
(
i
):
l
+=
[
value_str
%
ipos
]
l
+=
[
value_str
%
ipos
]
else
:
l
+=
[
data_str
%
ipos
]
else
:
l
+=
[
data_str
%
ipos
]
return
l
return
l
class
SupportCodeError
(
Exception
):
class
SupportCodeError
(
Exception
):
"""It is currently not possible to auto-generate a GPU implementation for
"""It is currently not possible to auto-generate a GPU implementation for
an elementwise Op with support code."""
an elementwise Op with c_support_code_apply().
But we support Op.c_support_code."""
class
NaiveAlgo
(
object
):
class
NaiveAlgo
(
object
):
verbose
=
0
# 1, 2 or 3 for more verbose output.
verbose
=
0
# 1, 2 or 3 for more verbose output.
...
@@ -73,16 +81,20 @@ class NaiveAlgo(object):
...
@@ -73,16 +81,20 @@ class NaiveAlgo(object):
print
>>
sio
,
"// Input "
,
ipos
,
str
(
i
.
type
)
print
>>
sio
,
"// Input "
,
ipos
,
str
(
i
.
type
)
for
ipos
,
i
in
enumerate
(
node
.
outputs
):
for
ipos
,
i
in
enumerate
(
node
.
outputs
):
print
>>
sio
,
"// Output "
,
ipos
,
str
(
i
.
type
)
print
>>
sio
,
"// Output "
,
ipos
,
str
(
i
.
type
)
print
>>
sio
,
"static __global__ void kernel_
%
s_
%
s_
%
s(unsigned int numEls"
%
(
self
.
scalar_op
.
__class__
.
__name__
,
nodename
,
nd
)
print
>>
sio
,
"static __global__ void kernel_
%
s_
%
s_
%
s(unsigned int numEls"
%
(
self
.
scalar_op
.
__class__
.
__name__
,
nodename
,
nd
)
if
(
nd
):
if
(
nd
):
print
>>
sio
,
"
\t
,"
,
", "
.
join
(
"const int dim
%
i"
%
i
for
i
in
xrange
(
nd
))
print
>>
sio
,
"
\t
,"
,
", "
.
join
(
"const int dim
%
i"
%
i
for
i
in
xrange
(
nd
))
#declare inputs
#declare inputs
for
ipos
,
i
in
enumerate
(
node
.
inputs
):
for
ipos
,
i
in
enumerate
(
node
.
inputs
):
s
=
", "
.
join
([
"const float * i
%
i_data"
%
ipos
]
+
list
(
"int i
%
i_str_
%
i"
%
(
ipos
,
d
)
for
d
in
xrange
(
nd
)))
s
=
", "
.
join
([
"const float * i
%
i_data"
%
ipos
]
+
[
"int i
%
i_str_
%
i"
%
(
ipos
,
d
)
for
d
in
xrange
(
nd
)])
print
>>
sio
,
"
\t
,"
,
s
print
>>
sio
,
"
\t
,"
,
s
#declare outputs
#declare outputs
for
ipos
,
i
in
enumerate
(
node
.
outputs
):
for
ipos
,
i
in
enumerate
(
node
.
outputs
):
s
=
", "
.
join
([
"float * o
%
i_data"
%
ipos
]
+
list
(
"int o
%
i_str_
%
i"
%
(
ipos
,
d
)
for
d
in
xrange
(
nd
)))
s
=
", "
.
join
([
"float * o
%
i_data"
%
ipos
]
+
[
"int o
%
i_str_
%
i"
%
(
ipos
,
d
)
for
d
in
xrange
(
nd
)])
print
>>
sio
,
"
\t
,"
,
s
print
>>
sio
,
"
\t
,"
,
s
#print >> sio, "\t,", ", ".join("int o%i_str_%i" % (ipos, d) for d in xrange(nd))
#print >> sio, "\t,", ", ".join("int o%i_str_%i" % (ipos, d) for d in xrange(nd))
#print >> sio, "\t,", "float * o%i_data" % ipos
#print >> sio, "\t,", "float * o%i_data" % ipos
...
@@ -122,12 +134,14 @@ class NaiveAlgo(object):
...
@@ -122,12 +134,14 @@ class NaiveAlgo(object):
#TODO: What if the scalar_op needs support_code??
#TODO: What if the scalar_op needs support_code??
task_code
=
self
.
scalar_op
.
c_code
(
task_code
=
self
.
scalar_op
.
c_code
(
Apply
(
self
.
scalar_op
,
Apply
(
self
.
scalar_op
,
[
scalar
.
Scalar
(
dtype
=
input
.
type
.
dtype
)()
for
input
in
node
.
inputs
],
[
scalar
.
Scalar
(
dtype
=
input
.
type
.
dtype
)()
[
scalar
.
Scalar
(
dtype
=
output
.
type
.
dtype
)()
for
output
in
node
.
outputs
])
for
input
in
node
.
inputs
],
,
nodename
+
'_scalar_'
[
scalar
.
Scalar
(
dtype
=
output
.
type
.
dtype
)()
,
get_str_list_logical_scalar
(
node
)
for
output
in
node
.
outputs
]),
,
[
'ii_o
%
i_data[0]'
%
ipos
for
ipos
,
i
in
enumerate
(
node
.
outputs
)]
nodename
+
'_scalar_'
,
,
sub
=
dict
(
fail
=
'return;'
))
#TODO: set a failure code somehow!!!
get_str_list_logical_scalar
(
node
),
[
'ii_o
%
i_data[0]'
%
ipos
for
ipos
,
i
in
enumerate
(
node
.
outputs
)],
sub
=
dict
(
fail
=
'return;'
))
# TODO: set a failure code somehow!!!
print
>>
sio
,
" "
,
task_code
print
>>
sio
,
" "
,
task_code
print
>>
sio
,
" }"
print
>>
sio
,
" }"
...
@@ -837,7 +851,6 @@ nd_collapse_[i]=0;
...
@@ -837,7 +851,6 @@ nd_collapse_[i]=0;
#N.B. cudaGetLastError is called by c_code
#N.B. cudaGetLastError is called by c_code
return
sio
.
getvalue
()
return
sio
.
getvalue
()
def
c_support_code_apply
(
self
,
node
,
nodename
):
def
c_support_code_apply
(
self
,
node
,
nodename
):
nd
=
node
.
outputs
[
0
]
.
type
.
ndim
nd
=
node
.
outputs
[
0
]
.
type
.
ndim
defines
=
"""
defines
=
"""
...
@@ -867,7 +880,7 @@ nd_collapse_[i]=0;
...
@@ -867,7 +880,7 @@ nd_collapse_[i]=0;
print
>>
sio
,
"""
print
>>
sio
,
"""
//std::cerr << "C_CODE
%(opname)
s START
\\
n";
//std::cerr << "C_CODE
%(opname)
s START
\\
n";
//standard elemwise size checks
//standard elemwise size checks
"""
%
locals
()
"""
%
locals
()
if
nd
>
0
:
if
nd
>
0
:
print
>>
sio
,
"""
print
>>
sio
,
"""
int dims[
%(nd)
s] = {
%(initial_dims)
s};
int dims[
%(nd)
s] = {
%(initial_dims)
s};
...
@@ -931,11 +944,11 @@ nd_collapse_[i]=0;
...
@@ -931,11 +944,11 @@ nd_collapse_[i]=0;
%(fail)
s;
%(fail)
s;
}
}
}
}
"""
%
locals
()
"""
%
locals
()
emitted_inames
[
iname
]
=
True
emitted_inames
[
iname
]
=
True
#check that all outputs have valid dimensions
#check that all outputs have valid dimensions
for
idx
,
oname
in
enumerate
(
outputs
):
for
idx
,
oname
in
enumerate
(
outputs
):
if
idx
not
in
self
.
inplace_pattern
.
keys
():
if
idx
not
in
self
.
inplace_pattern
.
keys
():
print
>>
sio
,
"""
print
>>
sio
,
"""
for (int i = 0; (i<
%(nd)
s) && (
%(oname)
s); ++i) {
for (int i = 0; (i<
%(nd)
s) && (
%(oname)
s); ++i) {
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论