Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
de08b763
提交
de08b763
authored
7月 10, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flake8 of theano/gof/cc.py
上级
11a78c73
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
56 行增加
和
62 行删除
+56
-62
cc.py
theano/gof/cc.py
+56
-61
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/gof/cc.py
浏览文件 @
de08b763
"""
Defines Linkers that deal with C implementations.
"""
from
__future__
import
print_function
# Python imports
from
copy
import
copy
import
os
import
sys
from
theano.compat
import
izip
import
logging
import
numpy
import
theano
from
theano
import
config
from
theano.compat
import
PY3
from
theano.compat
import
izip
from
six
import
string_types
,
reraise
from
six.moves
import
StringIO
,
xrange
from
theano.gof.utils
import
MethodNotDefined
import
theano
from
theano
import
config
# Note that we need to do this before importing cutils, since when there is
# no theano cache dir initialized yet, importing cutils may require compilation
# of cutils_ext.
from
theano.configparser
import
AddConfigVar
,
StrParam
# gof imports
from
theano.gof
import
graph
from
theano.gof
import
link
from
theano.gof
import
utils
from
theano.gof
import
cmodule
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano.gof.callcache
import
CallCache
AddConfigVar
(
'gcc.cxxflags'
,
"Extra compiler flags for gcc"
,
StrParam
(
""
))
if
PY3
:
import
hashlib
...
...
@@ -41,35 +58,14 @@ else:
assert
isinstance
(
msg
,
numpy
.
ndarray
)
return
hashlib
.
md5
(
numpy
.
getbuffer
(
msg
))
.
hexdigest
()
_logger
=
logging
.
getLogger
(
"theano.gof.cc"
)
def
hash_from_file
(
file_path
):
"""Return the MD5 hash of a file."""
return
hash_from_code
(
open
(
file_path
,
'rb'
)
.
read
())
# Note that we need to do this before importing cutils, since when there is
# no theano cache dir initialized yet, importing cutils may require compilation
# of cutils_ext.
from
theano.configparser
import
AddConfigVar
,
StrParam
AddConfigVar
(
'gcc.cxxflags'
,
"Extra compiler flags for gcc"
,
StrParam
(
""
))
# gof imports
from
theano.gof
import
graph
from
theano.gof
import
link
from
theano.gof
import
utils
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano.gof
import
cmodule
import
logging
_logger
=
logging
.
getLogger
(
"theano.gof.cc"
)
from
theano.gof.callcache
import
CallCache
run_cthunk
=
None
# Will be imported only when needed.
...
...
@@ -314,9 +310,8 @@ def get_c_declare(r, name, sub):
"""Wrapper around c_declare that declares py_name"""
if
any
([
c
!=
"output"
and
getattr
(
c
.
op
,
'check_input'
,
config
.
check_input
)
for
(
c
,
_
)
in
r
.
clients
])
or
(
r
.
owner
and
getattr
(
r
.
owner
.
op
,
'check_input'
,
True
)):
config
.
check_input
)
for
(
c
,
_
)
in
r
.
clients
])
or
(
r
.
owner
and
getattr
(
r
.
owner
.
op
,
'check_input'
,
True
)):
c_declare
=
r
.
type
.
c_declare
(
name
,
sub
,
True
)
else
:
c_declare
=
r
.
type
.
c_declare
(
name
,
sub
,
False
)
...
...
@@ -532,7 +527,7 @@ class CLinker(link.Linker):
if
isinstance
(
r
,
graph
.
Constant
)
and
r
not
in
self
.
inputs
)
self
.
temps
=
list
(
set
(
self
.
variables
)
.
difference
(
self
.
inputs
)
.
difference
(
self
.
outputs
)
.
difference
(
self
.
orphans
))
self
.
inputs
)
.
difference
(
self
.
outputs
)
.
difference
(
self
.
orphans
))
self
.
consts
=
[]
def
code_gen
(
self
):
...
...
@@ -821,7 +816,7 @@ class CLinker(link.Linker):
ret
=
[]
# generic support code
for
x
in
[
y
.
type
for
y
in
self
.
variables
]
+
[
y
.
op
for
y
in
self
.
node_order
]:
y
.
op
for
y
in
self
.
node_order
]:
try
:
ret
.
append
(
x
.
c_support_code
())
except
utils
.
MethodNotDefined
:
...
...
@@ -840,11 +835,11 @@ class CLinker(link.Linker):
# FillMissing must disable some of them. Putting -ffast-math would
# make it disable all other parameter at the same time.
ret
+=
[
"-fno-math-errno"
,
#"-funsafe-math-optimizations",
#"-fno-signaling-nans",
#"-fcx-limited-range",
#"-fno-rounding-math",
#"-ffinite-math-only",
#
"-funsafe-math-optimizations",
#
"-fno-signaling-nans",
#
"-fcx-limited-range",
#
"-fno-rounding-math",
#
"-ffinite-math-only",
# the current code generate label event if they are not used.
# Could use gcc attribute for those label only
...
...
@@ -853,7 +848,7 @@ class CLinker(link.Linker):
"-Wno-write-strings"
,
# generated by our code generator...
]
for
x
in
[
y
.
type
for
y
in
self
.
variables
]
+
[
y
.
op
for
y
in
self
.
node_order
]:
y
.
op
for
y
in
self
.
node_order
]:
try
:
ret
+=
x
.
c_compile_args
()
except
utils
.
MethodNotDefined
:
...
...
@@ -866,7 +861,7 @@ class CLinker(link.Linker):
# to reorder them
ret
+=
c_compiler
.
compile_args
()
for
x
in
[
y
.
type
for
y
in
self
.
variables
]
+
[
y
.
op
for
y
in
self
.
node_order
]:
y
.
op
for
y
in
self
.
node_order
]:
try
:
for
i
in
x
.
c_no_compile_args
():
try
:
...
...
@@ -886,7 +881,7 @@ class CLinker(link.Linker):
"""
ret
=
[]
for
x
in
[
y
.
type
for
y
in
self
.
variables
]
+
[
y
.
op
for
y
in
self
.
node_order
]:
y
.
op
for
y
in
self
.
node_order
]:
try
:
ret
+=
x
.
c_headers
()
except
utils
.
MethodNotDefined
:
...
...
@@ -901,7 +896,7 @@ class CLinker(link.Linker):
"""
ret
=
[]
for
x
in
[
y
.
type
for
y
in
self
.
variables
]
+
[
y
.
op
for
y
in
self
.
node_order
]:
y
.
op
for
y
in
self
.
node_order
]:
try
:
ret
+=
x
.
c_init_code
()
except
utils
.
MethodNotDefined
:
...
...
@@ -911,7 +906,7 @@ class CLinker(link.Linker):
def
c_compiler
(
self
):
c_compiler
=
None
for
x
in
[
y
.
type
for
y
in
self
.
variables
]
+
[
y
.
op
for
y
in
self
.
node_order
]:
y
.
op
for
y
in
self
.
node_order
]:
if
hasattr
(
x
,
'c_compiler'
):
x_compiler
=
x
.
c_compiler
()
else
:
...
...
@@ -938,7 +933,7 @@ class CLinker(link.Linker):
"""
ret
=
[]
for
x
in
[
y
.
type
for
y
in
self
.
variables
]
+
[
y
.
op
for
y
in
self
.
node_order
]:
y
.
op
for
y
in
self
.
node_order
]:
try
:
ret
+=
x
.
c_header_dirs
()
except
utils
.
MethodNotDefined
:
...
...
@@ -954,7 +949,7 @@ class CLinker(link.Linker):
"""
ret
=
[]
for
x
in
[
y
.
type
for
y
in
self
.
variables
]
+
[
y
.
op
for
y
in
self
.
node_order
]:
y
.
op
for
y
in
self
.
node_order
]:
try
:
ret
+=
x
.
c_libraries
()
except
utils
.
MethodNotDefined
:
...
...
@@ -970,7 +965,7 @@ class CLinker(link.Linker):
"""
ret
=
[]
for
x
in
[
y
.
type
for
y
in
self
.
variables
]
+
[
y
.
op
for
y
in
self
.
node_order
]:
y
.
op
for
y
in
self
.
node_order
]:
try
:
ret
+=
x
.
c_lib_dirs
()
except
utils
.
MethodNotDefined
:
...
...
@@ -1150,7 +1145,7 @@ class CLinker(link.Linker):
libraries
=
self
.
libraries
(),
header_dirs
=
self
.
header_dirs
(),
c_compiler
=
self
.
c_compiler
(),
)
)
def
cmodule_key_
(
self
,
fgraph
,
no_recycling
,
compile_args
=
None
,
libraries
=
None
,
header_dirs
=
None
,
insert_config_md5
=
True
,
...
...
@@ -1335,7 +1330,6 @@ class CLinker(link.Linker):
preargs
.
remove
(
'-DREPLACE_WITH_AMDLIBM'
)
if
'amdlibm'
in
libs
:
libs
.
remove
(
'amdlibm'
)
src_code
=
mod
.
code
()
get_lock
()
try
:
_logger
.
debug
(
"LOCATION
%
s"
,
str
(
location
))
...
...
@@ -1371,9 +1365,9 @@ class CLinker(link.Linker):
code
=
self
.
instantiate_code
(
1
+
len
(
self
.
args
))
instantiate
=
cmodule
.
ExtFunction
(
'instantiate'
,
code
,
method
=
cmodule
.
METH_VARARGS
)
#
['error_storage'] + argnames,
#
local_dict = d,
# global_dict = {})
#
['error_storage'] + argnames,
#
local_dict = d,
# global_dict = {})
# Static methods that can run and destroy the struct built by
# instantiate.
...
...
@@ -1498,7 +1492,7 @@ class _CThunk(object):
global
run_cthunk
if
run_cthunk
is
None
:
# Lazy import to avoid compilation when importing theano.
from
theano.gof.cutils
import
run_cthunk
from
theano.gof.cutils
import
run_cthunk
# noqa
self
.
cthunk
=
cthunk
self
.
init_tasks
=
init_tasks
self
.
tasks
=
tasks
...
...
@@ -1534,7 +1528,8 @@ class _CThunk(object):
exc_value
.
__thunk_trace__
=
trace
except
Exception
:
print
((
'ERROR retrieving error_storage.'
' Was the error set in the c code?'
),
end
=
' '
,
file
=
sys
.
stderr
)
'Was the error set in the c code?'
),
end
=
' '
,
file
=
sys
.
stderr
)
print
(
self
.
error_storage
,
file
=
sys
.
stderr
)
raise
reraise
(
exc_type
,
exc_value
,
exc_trace
)
...
...
@@ -1641,11 +1636,11 @@ class OpWiseCLinker(link.LocalLinker):
for
node
in
order
:
if
self
.
allow_gc
:
post_thunk_old_storage
.
append
(
[
storage_map
[
input
]
for
input
in
node
.
inputs
if
((
input
in
computed
)
and
(
input
not
in
fgraph
.
outputs
)
and
node
==
last_user
[
input
])])
post_thunk_old_storage
.
append
(
[
storage_map
[
input
]
for
input
in
node
.
inputs
if
((
input
in
computed
)
and
(
input
not
in
fgraph
.
outputs
)
and
node
==
last_user
[
input
])])
if
no_recycling
is
True
:
no_recycling
=
list
(
storage_map
.
values
())
...
...
@@ -1741,12 +1736,12 @@ class DualLinker(link.Linker):
no_recycling
=
self
.
no_recycling
_f
,
i1
,
o1
,
thunks1
,
order1
=
(
link
.
PerformLinker
(
schedule
=
self
.
schedule
)
.
accept
(
fgraph
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
))
link
.
PerformLinker
(
schedule
=
self
.
schedule
)
.
accept
(
fgraph
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
))
kwargs
.
pop
(
'input_storage'
,
None
)
_f
,
i2
,
o2
,
thunks2
,
order2
=
(
OpWiseCLinker
(
schedule
=
self
.
schedule
)
.
accept
(
fgraph
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
))
OpWiseCLinker
(
schedule
=
self
.
schedule
)
.
accept
(
fgraph
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
))
def
f
():
for
input1
,
input2
in
izip
(
i1
,
i2
):
...
...
theano/tests/test_flake8.py
浏览文件 @
de08b763
...
...
@@ -244,7 +244,6 @@ whitelist_flake8 = [
"gof/unify.py"
,
"gof/graph.py"
,
"gof/__init__.py"
,
"gof/cc.py"
,
"gof/opt.py"
,
"gof/link.py"
,
"gof/fg.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论