From 76871f89b6dc833c21fa097d60f9b99e11a884ef Mon Sep 17 00:00:00 2001 From: Emanuele Ruffaldi Date: Thu, 6 Sep 2018 22:46:49 +0200 Subject: [PATCH 01/10] subprocess fix for Windows added support for cflags for passing e.g. c++ standard to all add_files --- README.md | 2 ++ hlsclt/build_commands/build_commands.py | 8 ++++++-- hlsclt/helper_funcs.py | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd76bc2..372f02c 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ Each Vivado HLS project requires a 'config.py' file in order to use hlsclt. This |Device String |part_name |A device string as used by Vivado HLS (see examples)|Yes| |Clock Period |clock_period |A value in nanoseconds input as a string, e.g. "10"|Yes| |HDL Language |language |Either "vhdl" or "verilog" |No (Default is "vhdl")| +|Compiler Options |cflags |Any flag for GCC (e.g. --std=c++11)|No| Here is an example file taken from the [simple_adder](hlsclt/examples/simple_adder) example shipped with the tool (note that some of the optional items have been commented out in order to use the defaults): @@ -139,6 +140,7 @@ Here is an example file taken from the [simple_adder](hlsclt/examples/simple_add top_level_function_name = "simple_adder" #src_dir_name = "src" #tb_dir_name = "tb" +# cflags = "" src_files = ["dut.h","dut.cpp"] tb_files = ["testbench.cpp"] part_name = "xc7z020clg484-1" diff --git a/hlsclt/build_commands/build_commands.py b/hlsclt/build_commands/build_commands.py index a14150f..d5064c4 100644 --- a/hlsclt/build_commands/build_commands.py +++ b/hlsclt/build_commands/build_commands.py @@ -20,8 +20,12 @@ def do_start_build_stuff(ctx): file = click.open_file("run_hls.tcl","w") file.write("open_project " + config["project_name"] + "\n") file.write("set_top " + config["top_level_function_name"] + "\n") + if config["cflags"] != "": + cf = " -cflags \"%s\"" % config["cflags"] + else: + cf = "" for src_file in config["src_files"]: - file.write("add_files " + config["src_dir_name"] + "/" + src_file + "\n") + file.write("add_files " + config["src_dir_name"] + "/" + src_file + cf + "\n") for tb_file in config["tb_files"]: file.write("add_files -tb " + config["tb_dir_name"] + "/" + tb_file + "\n") if ctx.params['keep']: @@ -134,7 +138,7 @@ def build_end_callback(ctx,sub_command_returns,keep,report): ctx.obj.file.write("exit" + "\n") ctx.obj.file.close() # Call the Vivado HLS process - hls_processs = subprocess.run(["vivado_hls", "-f", "run_hls.tcl"]) + hls_processs = subprocess.run(["vivado_hls", "-f", "run_hls.tcl"],shell=True) # Check return status of the HLS process. if hls_processs.returncode < 0: raise click.Abort() diff --git a/hlsclt/helper_funcs.py b/hlsclt/helper_funcs.py index 2a98e4d..c30fbbc 100644 --- a/hlsclt/helper_funcs.py +++ b/hlsclt/helper_funcs.py @@ -18,6 +18,7 @@ def generate_default_config(): "top_level_function_name" : "", "src_dir_name" : "src", "tb_dir_name" : "tb", + "cflags": "", "src_files" : "", "tb_files" : "", "part_name" : "", From 373ab02bc0e5605ebd6763f468f26ab9d44a63b5 Mon Sep 17 00:00:00 2001 From: Emanuele Ruffaldi Date: Mon, 10 Sep 2018 17:11:12 +0200 Subject: [PATCH 02/10] added support for clangs compiler --- hlsclt/build_commands/build_commands.py | 5 +++-- hlsclt/helper_funcs.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hlsclt/build_commands/build_commands.py b/hlsclt/build_commands/build_commands.py index d5064c4..d557292 100644 --- a/hlsclt/build_commands/build_commands.py +++ b/hlsclt/build_commands/build_commands.py @@ -43,7 +43,7 @@ def do_start_build_stuff(ctx): def do_default_build(ctx): config = ctx.obj.config file = ctx.obj.file - file.write("csim_design -clean" + "\n") + file.write("csim_design -clean" + (" -compiler clang" if config["compiler"] == "clang" else "") + " \n") file.write("csynth_design" + "\n") file.write("cosim_design -O -rtl " + config["language"] + "\n") file.write("export_design -format ip_catalog" + "\n") @@ -52,7 +52,8 @@ def do_default_build(ctx): # Function which defines the main actions of the 'csim' command. def do_csim_stuff(ctx): file = ctx.obj.file - file.write("csim_design -clean" + "\n") + config = ctx.obj.config + file.write("csim_design -clean" + (" -compiler clang" if config["compiler"] == "clang" else "") + "\n") # Function which defines the main actions of the 'syn' command. def do_syn_stuff(ctx): diff --git a/hlsclt/helper_funcs.py b/hlsclt/helper_funcs.py index c30fbbc..826999a 100644 --- a/hlsclt/helper_funcs.py +++ b/hlsclt/helper_funcs.py @@ -20,6 +20,7 @@ def generate_default_config(): "tb_dir_name" : "tb", "cflags": "", "src_files" : "", + "compiler": "", "tb_files" : "", "part_name" : "", "clock_period" : "", From 0ea8b6ba9c9be7a9cb047f9484d531724348af75 Mon Sep 17 00:00:00 2001 From: Emanuele Ruffaldi Date: Thu, 13 Sep 2018 01:00:49 +0200 Subject: [PATCH 03/10] fix check for empty cflags --- hlsclt/build_commands/build_commands.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hlsclt/build_commands/build_commands.py b/hlsclt/build_commands/build_commands.py index d557292..ed9f396 100644 --- a/hlsclt/build_commands/build_commands.py +++ b/hlsclt/build_commands/build_commands.py @@ -20,7 +20,7 @@ def do_start_build_stuff(ctx): file = click.open_file("run_hls.tcl","w") file.write("open_project " + config["project_name"] + "\n") file.write("set_top " + config["top_level_function_name"] + "\n") - if config["cflags"] != "": + if config.get("cflags","") != "": cf = " -cflags \"%s\"" % config["cflags"] else: cf = "" @@ -43,7 +43,7 @@ def do_start_build_stuff(ctx): def do_default_build(ctx): config = ctx.obj.config file = ctx.obj.file - file.write("csim_design -clean" + (" -compiler clang" if config["compiler"] == "clang" else "") + " \n") + file.write("csim_design -clean" + (" -compiler clang" if config.get("compiler","") == "clang" else "") + " \n") file.write("csynth_design" + "\n") file.write("cosim_design -O -rtl " + config["language"] + "\n") file.write("export_design -format ip_catalog" + "\n") @@ -53,7 +53,7 @@ def do_default_build(ctx): def do_csim_stuff(ctx): file = ctx.obj.file config = ctx.obj.config - file.write("csim_design -clean" + (" -compiler clang" if config["compiler"] == "clang" else "") + "\n") + file.write("csim_design -clean" + (" -compiler clang" if config.get("compiler","") == "clang" else "") + "\n") # Function which defines the main actions of the 'syn' command. def do_syn_stuff(ctx): From 9470d4eb577301d4a13a737074b6a4b0cf94093b Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Sat, 15 Sep 2018 07:05:19 +1200 Subject: [PATCH 04/10] Fix subprocess function call for Python 2.7. --- hlsclt/build_commands/build_commands.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hlsclt/build_commands/build_commands.py b/hlsclt/build_commands/build_commands.py index ed9f396..3373f7c 100644 --- a/hlsclt/build_commands/build_commands.py +++ b/hlsclt/build_commands/build_commands.py @@ -139,11 +139,11 @@ def build_end_callback(ctx,sub_command_returns,keep,report): ctx.obj.file.write("exit" + "\n") ctx.obj.file.close() # Call the Vivado HLS process - hls_processs = subprocess.run(["vivado_hls", "-f", "run_hls.tcl"],shell=True) + returncode = subprocess.call(["vivado_hls -f run_hls.tcl"],shell=True) # Check return status of the HLS process. - if hls_processs.returncode < 0: + if returncode < 0: raise click.Abort() - elif hls_processs.returncode > 0: + elif returncode > 0: click.echo("Warning: HLS Process returned an error, skipping report opening!") raise click.Abort() else: From e7e841931137f172c26d7f846e02b11a26261423 Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Fri, 14 Sep 2018 20:10:29 +0100 Subject: [PATCH 05/10] Added classes import to fix error when config parameter is missing. --- hlsclt/helper_funcs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hlsclt/helper_funcs.py b/hlsclt/helper_funcs.py index 826999a..3d138b8 100644 --- a/hlsclt/helper_funcs.py +++ b/hlsclt/helper_funcs.py @@ -9,6 +9,7 @@ import os import imp from glob import glob +from hlsclt.classes import * ### Function Definitions ### # Function to generate the default config dicttionary From 34c5ce6a47db9634c1a17a5fe2da08b426fc54d1 Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Fri, 14 Sep 2018 20:42:05 +0100 Subject: [PATCH 06/10] Changed classes import to support python 2.7. Added code to parse new config options correctly. --- hlsclt/helper_funcs.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/hlsclt/helper_funcs.py b/hlsclt/helper_funcs.py index 3d138b8..496dca0 100644 --- a/hlsclt/helper_funcs.py +++ b/hlsclt/helper_funcs.py @@ -9,7 +9,7 @@ import os import imp from glob import glob -from hlsclt.classes import * +from .classes import * ### Function Definitions ### # Function to generate the default config dicttionary @@ -45,15 +45,35 @@ def parse_config_vars(config_loaded, config, errors): config_loaded_set = set(config_loaded_dict) config_set = set(config) options_defined = config_loaded_set.intersection(config_set) - for name in config: - if str(name) in options_defined: - config[name] = config_loaded_dict[name] + # Do some initial error checking on config options_defined + if "cflags" in options_defined: try: - if not config[name]: - raise ConfigError("Error: " + name + " is not defined in config file. No default exists, please define a value in the config file.") + try : + if config_loaded_dict["compiler"] != "clang": + raise ConfigError("Error: cflags should not be defined unless the compiler switch is set to 'clang'.") + except: + raise ConfigError("Error: cflags should not be defined unless the compiler switch is set to 'clang'.") except ConfigError as err: errors.append(err) - continue + return + del_list = []; + for name in config: + # Catch optional config entries which don't need defaults + if str(name) == "compiler" or str(name) == "cflags": + if str(name) not in options_defined: + del_list.append(name) + else: + config[name] = config_loaded_dict[name] + elif str(name) in options_defined: + config[name] = config_loaded_dict[name] + try: + if not config[name]: + raise ConfigError("Error: " + name + " is not defined in config file. No default exists, please define a value in the config file.") + except ConfigError as err: + errors.append(err) + continue + for name in del_list: + del config[name] # Function to find the highest solution number within a HLS project. def find_solution_num(ctx): From 14bd2e0dd710891f06d8b2df28226e5a5d24b70b Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Fri, 14 Sep 2018 20:43:55 +0100 Subject: [PATCH 07/10] Update config file to show new config options. --- hlsclt/examples/simple_adder/hls_config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hlsclt/examples/simple_adder/hls_config.py b/hlsclt/examples/simple_adder/hls_config.py index 25bb97b..b48f1f5 100644 --- a/hlsclt/examples/simple_adder/hls_config.py +++ b/hlsclt/examples/simple_adder/hls_config.py @@ -9,3 +9,5 @@ part_name = "xc7z020clg484-1" clock_period = "10" language = "vhdl" +#compiler = "" +#cflags = "" From 7a239b0bfc01ff1fd06ac79f7ed38dabe90a99ad Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Fri, 14 Sep 2018 20:47:30 +0100 Subject: [PATCH 08/10] Update readme to show new config options. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 372f02c..0cacd78 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ Each Vivado HLS project requires a 'config.py' file in order to use hlsclt. This |Device String |part_name |A device string as used by Vivado HLS (see examples)|Yes| |Clock Period |clock_period |A value in nanoseconds input as a string, e.g. "10"|Yes| |HDL Language |language |Either "vhdl" or "verilog" |No (Default is "vhdl")| +|Compiler |Compiler |Either "gcc" or "clang" |No (HLS defaults to gcc)| |Compiler Options |cflags |Any flag for GCC (e.g. --std=c++11)|No| From aa59cd149a4f6c8f6e6c6748dcd3801f6d2e08d5 Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Fri, 14 Sep 2018 20:51:36 +0100 Subject: [PATCH 09/10] Removed incorrect checks on compiler being set for clfags to work. --- hlsclt/helper_funcs.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/hlsclt/helper_funcs.py b/hlsclt/helper_funcs.py index 496dca0..c77e5f2 100644 --- a/hlsclt/helper_funcs.py +++ b/hlsclt/helper_funcs.py @@ -45,17 +45,6 @@ def parse_config_vars(config_loaded, config, errors): config_loaded_set = set(config_loaded_dict) config_set = set(config) options_defined = config_loaded_set.intersection(config_set) - # Do some initial error checking on config options_defined - if "cflags" in options_defined: - try: - try : - if config_loaded_dict["compiler"] != "clang": - raise ConfigError("Error: cflags should not be defined unless the compiler switch is set to 'clang'.") - except: - raise ConfigError("Error: cflags should not be defined unless the compiler switch is set to 'clang'.") - except ConfigError as err: - errors.append(err) - return del_list = []; for name in config: # Catch optional config entries which don't need defaults From 01fe52b0c8c44e37f13341f46e9dfd73b3fcaa5f Mon Sep 17 00:00:00 2001 From: Ben Marshall Date: Fri, 14 Sep 2018 20:56:25 +0100 Subject: [PATCH 10/10] Bump version number. --- hlsclt/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hlsclt/_version.py b/hlsclt/_version.py index 26d7acc..071a662 100644 --- a/hlsclt/_version.py +++ b/hlsclt/_version.py @@ -1 +1 @@ -__version__ = '1.0.0.a3' +__version__ = '1.0.0.a4'