Improve ngraph python api in debug mode (#2836)
* Update MacOS machine * Update setup.py * Add debug statement * Improvements * Update ngraph/python/setup.py Co-authored-by: Michał Karzyński <4430709+postrational@users.noreply.github.com> * Rollback the last change Co-authored-by: Michał Karzyński <4430709+postrational@users.noreply.github.com>
This commit is contained in:
parent
a1b144d024
commit
797d35ef64
@ -31,6 +31,10 @@ NGRAPH_PYTHON_DEBUG = os.environ.get("NGRAPH_PYTHON_DEBUG")
|
||||
# Change current working dircectory to ngraph/python
|
||||
os.chdir(PYNGRAPH_ROOT_DIR)
|
||||
|
||||
debug_optimization_flags = [
|
||||
"O1", "O2", "O3", "O4", "Ofast", "Os", "Oz", "Og", "O", "DNDEBUG"
|
||||
]
|
||||
|
||||
|
||||
def find_ngraph_dist_dir():
|
||||
"""Return location of compiled ngraph library home."""
|
||||
@ -102,30 +106,15 @@ if len([fn for fn in os.listdir(NGRAPH_CPP_LIBRARY_DIR) if re.search("onnx_impor
|
||||
|
||||
def _remove_compiler_flags(obj):
|
||||
"""Make pybind11 more verbose in debug builds."""
|
||||
try:
|
||||
# pybind11 is much more verbose without the NDEBUG define
|
||||
if sys.platform == "win32":
|
||||
obj.compiler.remove("/DNDEBUG")
|
||||
obj.compiler.remove("/O2")
|
||||
else:
|
||||
obj.compiler.remove("-DNDEBUG")
|
||||
obj.compiler.remove("-O2")
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
|
||||
|
||||
def _remove_compiler_so_flags(obj):
|
||||
"""Make pybind11 more verbose in debug builds."""
|
||||
try:
|
||||
# pybind11 is much more verbose without the NDEBUG define
|
||||
if sys.platform == "win32":
|
||||
obj.compiler_so.remove("/DNDEBUG")
|
||||
obj.compiler_so.remove("/O2")
|
||||
else:
|
||||
obj.compiler_so.remove("-DNDEBUG")
|
||||
obj.compiler_so.remove("-O2")
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
for flag in debug_optimization_flags:
|
||||
try:
|
||||
if sys.platform == "win32":
|
||||
obj.compiler.compile_options.remove("/{}".format(flag))
|
||||
else:
|
||||
obj.compiler.compiler_so.remove("-{}".format(flag))
|
||||
obj.compiler.compiler.remove("-{}".format(flag))
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
|
||||
|
||||
def parallelCCompile(
|
||||
@ -151,10 +140,6 @@ def parallelCCompile(
|
||||
)
|
||||
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
|
||||
|
||||
if NGRAPH_PYTHON_DEBUG in ["TRUE", "ON", True]:
|
||||
_remove_compiler_flags(self)
|
||||
_remove_compiler_so_flags(self)
|
||||
|
||||
# parallel code
|
||||
import multiprocessing.pool
|
||||
|
||||
@ -353,8 +338,6 @@ class BuildExt(build_ext):
|
||||
try:
|
||||
# -Wstrict-prototypes is not a valid option for c++
|
||||
self.compiler.compiler_so.remove("-Wstrict-prototypes")
|
||||
if NGRAPH_PYTHON_DEBUG in ["TRUE", "ON", True]:
|
||||
_remove_compiler_so_flags(self)
|
||||
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
@ -362,6 +345,7 @@ class BuildExt(build_ext):
|
||||
def build_extensions(self):
|
||||
"""Build extension providing extra compiler flags."""
|
||||
self._customize_compiler_flags()
|
||||
|
||||
for ext in self.extensions:
|
||||
ext.extra_compile_args += [cpp_flag(self.compiler)]
|
||||
|
||||
@ -377,6 +361,9 @@ class BuildExt(build_ext):
|
||||
if sys.platform == "darwin":
|
||||
ext.extra_compile_args += ["-stdlib=libc++"]
|
||||
|
||||
if NGRAPH_PYTHON_DEBUG in ["TRUE", "ON", True]:
|
||||
_remove_compiler_flags(self)
|
||||
|
||||
build_ext.build_extensions(self)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user