diff --git a/conifer/backends/cpp/writer.py b/conifer/backends/cpp/writer.py index 47a50e1..df6cdc5 100644 --- a/conifer/backends/cpp/writer.py +++ b/conifer/backends/cpp/writer.py @@ -2,7 +2,7 @@ import numpy as np from shutil import copyfile import copy -from conifer.utils import _ap_include, _json_include, copydocstring +from conifer.utils import _ap_include, _json_include, _gcc_opts, _py_executable, copydocstring from conifer.model import ModelBase from conifer.backends.common import MultiPrecisionConfig import logging @@ -19,8 +19,6 @@ def _extra_validate(self): # TODO: proagate different precisions properly through backend # for now enforce that all the precisions are equal assert self.input_precision == self.threshold_precision, f'input & threshold precision must be equal, got: {self.input_precision} & {self.threshold_precision}' - assert self.threshold_precision == self.score_precision, f'threshold & score precision must be equal, got: {self.threshold_precision} & {self.score_precision}' - class CPPModel(ModelBase): def __init__(self, ensembleDict, config, metadata=None): @@ -89,7 +87,7 @@ def compile(self): conifer_include = f'-I{filedir}/include/' # Do the compile - cmd = f"g++ -O3 -shared -std=c++14 -fPIC $(python3 -m pybind11 --includes) {ap_include} {json_include} {conifer_include} bridge.cpp -o conifer_bridge_{self._stamp}.so" + cmd = f"g++ -O3 -shared -std=c++14 -fPIC $({_py_executable()} -m pybind11 --includes) {ap_include} {json_include} {conifer_include} {_gcc_opts()} bridge.cpp -o conifer_bridge_{self._stamp}.so" logger.debug(f'Compiling with command {cmd}') try: ret_val = os.system(cmd) diff --git a/conifer/backends/xilinxhls/writer.py b/conifer/backends/xilinxhls/writer.py index ed5c3ba..4b9d4d8 100644 --- a/conifer/backends/xilinxhls/writer.py +++ b/conifer/backends/xilinxhls/writer.py @@ -3,7 +3,7 @@ import warnings import numpy as np import copy -from conifer.utils import _ap_include, copydocstring +from conifer.utils import _ap_include, _gcc_opts, _py_executable, copydocstring from conifer.backends.common import BottomUpDecisionTree, MultiPrecisionConfig, read_hls_report from conifer.model import ModelBase import datetime @@ -452,7 +452,7 @@ def compile(self): if ap_include is None: os.chdir(curr_dir) raise Exception("Couldn't find Xilinx ap_ headers. Source the Vivado/Vitis HLS toolchain, or set XILINX_AP_INCLUDE environment variable.") - cmd = f"g++ -O3 -shared -std=c++14 -fPIC $(python3 -m pybind11 --includes) {ap_include} bridge.cpp firmware/BDT.cpp firmware/{cfg.project_name}.cpp -o conifer_bridge_{self._stamp}.so" + cmd = f"g++ -O3 -shared -std=c++14 -fPIC $({_py_executable()} -m pybind11 --includes) {ap_include} {_gcc_opts()} bridge.cpp firmware/BDT.cpp firmware/{cfg.project_name}.cpp -o conifer_bridge_{self._stamp}.so" logger.debug(f'Compiling with command {cmd}') try: ret_val = os.system(cmd) diff --git a/conifer/utils/__init__.py b/conifer/utils/__init__.py index e696ad4..5d31bf8 100644 --- a/conifer/utils/__init__.py +++ b/conifer/utils/__init__.py @@ -1,2 +1,2 @@ from .fixed_point import FixedPointConverter -from conifer.utils.misc import _ap_include, _json_include, copydocstring +from conifer.utils.misc import _ap_include, _json_include, _gcc_opts, _py_executable, copydocstring diff --git a/conifer/utils/misc.py b/conifer/utils/misc.py index 1cc8eda..1104d2b 100644 --- a/conifer/utils/misc.py +++ b/conifer/utils/misc.py @@ -1,4 +1,5 @@ import os +import sys import logging logger = logging.getLogger(__name__) @@ -32,6 +33,21 @@ def _json_include(): logger.warn('Could not find JSON headers. JSON_ROOT not defined') return ret +def _gcc_opts(): + ''' + Get extra platform specific g++ compile options + ''' + if sys.platform == 'darwin': + return '-undefined dynamic_lookup' + else: + return '' + +def _py_executable(): + ''' + Get the python executable + ''' + return sys.executable + def copydocstring(fromfunc, sep="\n"): """ Decorator: Copy the docstring of `fromfunc`