提交 1227604c authored 作者: Frederic Bastien's avatar Frederic Bastien

added fct c_no_compile_args that allow to remove some args from the compile cmd.…

added fct c_no_compile_args that allow to remove some args from the compile cmd. This is usefull to remove some agression optimisation that break some Op.
上级 bb724bc6
...@@ -38,11 +38,13 @@ There are less methods to define for an Op than for a Type: ...@@ -38,11 +38,13 @@ There are less methods to define for an Op than for a Type:
*Default:* The default behavior is to do nothing. *Default:* The default behavior is to do nothing.
.. function:: c_compile_args() .. function:: c_compile_args()
c_no_compile_args()
c_headers() c_headers()
c_libraries() c_libraries()
c_support_code() c_support_code()
Allows you to specify headers, libraries, special g++ arguments or Allows you to specify headers, libraries,
special g++ arguments to add/exclude or
helper functions/structs that the type needs. See :ref:`op`. helper functions/structs that the type needs. See :ref:`op`.
......
...@@ -75,11 +75,13 @@ the most important ones: ...@@ -75,11 +75,13 @@ the most important ones:
decrease the appropriate reference counts. decrease the appropriate reference counts.
.. function:: c_compile_args() .. function:: c_compile_args()
c_no_compile_args()
c_headers() c_headers()
c_libraries() c_libraries()
c_support_code() c_support_code()
Allows you to specify headers, libraries, special g++ arguments or Allows you to specify headers, libraries,
special g++ arguments to add/exclude or
helper functions/structs that the type needs. See :ref:`type`. helper functions/structs that the type needs. See :ref:`type`.
......
...@@ -260,7 +260,7 @@ Glossary of terminology ...@@ -260,7 +260,7 @@ Glossary of terminology
* making :term:`Apply` instances, which mean "apply this TOI to some particular inputs" (via the ``make_node``), * making :term:`Apply` instances, which mean "apply this TOI to some particular inputs" (via the ``make_node``),
* performing the calculation of outputs from given inputs (via the ``perform``), * performing the calculation of outputs from given inputs (via the ``perform``),
* producing c code to perform calculation of outputs from inputs (via ``c_code, c_code_cleanup, c_support_code, c_headers, c_libraries, c_compile_args``) * producing c code to perform calculation of outputs from inputs (via ``c_code, c_code_cleanup, c_support_code, c_headers, c_libraries, c_compile_args, c_no_compile_args``)
* [optionally] building gradient-calculating graphs (via ``grad``). * [optionally] building gradient-calculating graphs (via ``grad``).
See :ref:`intro_to_ops`. See :ref:`intro_to_ops`.
......
...@@ -526,10 +526,24 @@ class CLinker(link.Linker): ...@@ -526,10 +526,24 @@ class CLinker(link.Linker):
This might contain duplicates. This might contain duplicates.
""" """
ret = [] ret = ["-O3", "-w"]#-w means supress all warnings
# this is the param the -ffast-math activate. I put the explicitly as FillMissing must disable "-ffinite-math-only". 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"]
for x in [y.type for y in self.variables] + [y.op for y in self.node_order]: for x in [y.type for y in self.variables] + [y.op for y in self.node_order]:
try: ret += x.c_compile_args() try: ret += x.c_compile_args()
except utils.MethodNotDefined: pass except utils.MethodNotDefined: pass
ret=list(set(ret))#to remove duplicate
for x in [y.type for y in self.variables] + [y.op for y in self.node_order]:
try:
for i in x.c_no_compile_args():
try:
ret.remove(i)
except ValueError:
pass# in case the value is not there
except utils.MethodNotDefined: pass
print ret
return ret return ret
def headers(self): def headers(self):
...@@ -703,22 +717,7 @@ class CLinker(link.Linker): ...@@ -703,22 +717,7 @@ class CLinker(link.Linker):
instantiate.customize.add_support_code(support_code) instantiate.customize.add_support_code(support_code)
instantiate.customize.add_support_code(self.struct_code) instantiate.customize.add_support_code(self.struct_code)
instantiate.customize.add_support_code(static) instantiate.customize.add_support_code(static)
for extra_arg in (
"-O3",
# "-fno-signaling-nans",
#"-fno-finite-math-only",
#"-fmath-errno", "-fno-unsafe-math-optimizations", "-fno-finite-math-only", "-frounding-math", "-fsignaling-nans","-fno-cx-limited-range","-fno-fast-math",
"-ffast-math",
#"-fno-finite-math-only",
# "-fno-signaling-nans",
#"-fmath-errno", "-fno-unsafe-math-optimizations", "-fno-finite-math-only", "-frounding-math", "-fsignaling-nans","-fno-cx-limited-range","-fno-fast-math",
#"-fprefetch-loop-arrays",
#"-ftree-vect-loop-version",
#"-ftree-loop-optimize",
#"-ftree-vectorize",
"-w" #-w means supress all warnings
):
instantiate.customize.add_extra_compile_arg(extra_arg)
for arg in self.compile_args(): for arg in self.compile_args():
instantiate.customize.add_extra_compile_arg(arg) instantiate.customize.add_extra_compile_arg(arg)
for header in self.headers(): for header in self.headers():
......
...@@ -97,6 +97,21 @@ class CLinkerOp(object): ...@@ -97,6 +97,21 @@ class CLinkerOp(object):
raise utils.MethodNotDefined('%s.c_compile_args' \ raise utils.MethodNotDefined('%s.c_compile_args' \
% self.__class__.__name__) % self.__class__.__name__)
def c_no_compile_args(self):
"""Optional: Return a list of incompabitle gcc compiler arguments.
We will remove those argument from the command line of gcc. So if
another Op add a compile args in the graph that is incompatible
with this op, the incompatible args won't be used.
Usefull to remove -ffast-math.
EXAMPLE
WRITEME
"""
raise utils.MethodNotDefined('%s.c_no_compile_args' \
% self.__class__.__name__)
def c_headers(self): def c_headers(self):
"""Optional: Return a list of header files that must be included to compile the C code. """Optional: Return a list of header files that must be included to compile the C code.
......
...@@ -148,6 +148,20 @@ class CLinkerType(object): ...@@ -148,6 +148,20 @@ class CLinkerType(object):
""" """
raise MethodNotDefined("c_compile_args", type(self), self.__class__.__name__) raise MethodNotDefined("c_compile_args", type(self), self.__class__.__name__)
def c_no_compile_args(self):
"""Optional: Return a list of incompabitle gcc compiler arguments.
We will remove those argument from the command line of gcc. So if
another Op add a compile args in the graph that is incompatible
with this op, the incompatible args won't be used.
Usefull to remove -ffast-math.
:Exceptions:
- `MethodNotDefined`: Subclass does not implement this method
"""
raise MethodNotDefined("c_no_compile_args", type(self), self.__class__.__name__)
def c_headers(self): def c_headers(self):
"""Optional: Return a list of header files required by code returned by """Optional: Return a list of header files required by code returned by
this class. this class.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论