Skip to content

Commit

Permalink
build returns success status, remove all sys.exit, cleanup unused imp…
Browse files Browse the repository at this point in the history
…orts
  • Loading branch information
thesps committed Aug 30, 2022
1 parent 777f7d4 commit 01743d7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
2 changes: 0 additions & 2 deletions conifer/backends/cpp/writer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
import numpy as np
import json
from shutil import copyfile
import sys
import copy
from conifer.utils import _ap_include, _json_include
import logging
Expand Down
11 changes: 5 additions & 6 deletions conifer/backends/vhdl/writer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
from shutil import copyfile
import numpy as np
from enum import Enum
Expand Down Expand Up @@ -64,7 +63,7 @@ def write(model):
dtype = cfg['Precision']
if not 'ap_fixed' in dtype:
logger.error("Only ap_fixed is currently supported, exiting")
sys.exit()
return
dtype = dtype.replace('ap_fixed<', '').replace('>', '')
dtype_n = int(dtype.split(',')[0].strip()) # total number of bits
dtype_int = int(dtype.split(',')[1].strip()) # number of integer bits
Expand Down Expand Up @@ -205,7 +204,6 @@ def sim_compile(model):
os.chdir(cwd)
if(success > 0):
logger.error("'sim_compile' failed, check {}_compile.log".format(simulator.name))
sys.exit()
return

def decision_function(X, model, trees=False):
Expand All @@ -232,7 +230,7 @@ def decision_function(X, model, trees=False):
dtype = config['Precision']
if not 'ap_fixed' in dtype:
logger.error("Only ap_fixed is currently supported, exiting")
sys.exit()
return
dtype = dtype.replace('ap_fixed<', '').replace('>', '')
dtype_n = int(dtype.split(',')[0].strip()) # total number of bits
dtype_int = int(dtype.split(',')[1].strip()) # number of integer bits
Expand All @@ -249,7 +247,7 @@ def decision_function(X, model, trees=False):
os.chdir(cwd)
if(success > 0):
logger.error("'decision_function' failed, see {}.log".format(logfile))
sys.exit()
return
y = np.loadtxt('{}/SimulationOutput.txt'.format(config['OutputDir'])) * 1. / mult
if trees:
logger.warn("Individual tree output (trees=True) not yet implemented for this backend")
Expand All @@ -268,7 +266,8 @@ def build(config, **kwargs):
logger.info(f'build finished {stop:%H:%M:%S} - took {str(stop-start)}')
if(success > 0):
logger.error("build failed, check build.log")
sys.exit()
return False
return True

def write_sim_scripts(cfg, filedir, n_classes):
from conifer.backends.vhdl import simulator
Expand Down
34 changes: 17 additions & 17 deletions conifer/backends/xilinxhls/writer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
from shutil import copyfile
import warnings
import numpy as np
Expand Down Expand Up @@ -399,22 +398,23 @@ def sim_compile(model):
def build(config, reset=False, csim=False, synth=True, cosim=False, export=False):
cwd = os.getcwd()
os.chdir(config['OutputDir'])


rval = True
hls_tool = get_hls()
if hls_tool == None:
if hls_tool is None:
logger.error("No HLS in PATH. Did you source the appropriate Xilinx Toolchain?")
sys.exit()

cmd = '{hls_tool} -f build_prj.tcl "reset={reset} csim={csim} synth={synth} cosim={cosim} export={export}" > build.log'\
.format(hls_tool=hls_tool, reset=reset, csim=csim, synth=synth, cosim=cosim, export=export)
start = datetime.datetime.now()
logger.info(f'build starting {start:%H:%M:%S}')
logger.debug(f'build invoking {hls_tool} with command "{cmd}"')
success = os.system(cmd)
stop = datetime.datetime.now()
logger.info(f'build finished {stop:%H:%M:%S} - took {str(stop-start)}')
if(success > 0):
logger.error("build failed, check logs")
sys.exit()

rval = False
else:
cmd = '{hls_tool} -f build_prj.tcl "reset={reset} csim={csim} synth={synth} cosim={cosim} export={export}" > build.log'\
.format(hls_tool=hls_tool, reset=reset, csim=csim, synth=synth, cosim=cosim, export=export)
start = datetime.datetime.now()
logger.info(f'build starting {start:%H:%M:%S}')
logger.debug(f'build invoking {hls_tool} with command "{cmd}"')
success = os.system(cmd)
stop = datetime.datetime.now()
logger.info(f'build finished {stop:%H:%M:%S} - took {str(stop-start)}')
if(success > 0):
logger.error("build failed, check logs")
rval = False
os.chdir(cwd)
return rval
11 changes: 10 additions & 1 deletion conifer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,17 @@ def decision_function(self, X, trees=False):
def build(self, **kwargs):
'''
Build the project, running the build function of the backend.
Parameters
----------
kwargs: keyword arguments of backend build method
Returns
----------
success: bool
True if the build completed successfuly, otherwise False
'''
self.backend.build(self.config, **kwargs)
return self.backend.build(self.config, **kwargs)

def profile(self, bins=50, return_data=False, return_figure=True):
try:
Expand Down

0 comments on commit 01743d7

Please sign in to comment.