hlsfactory.harp.harp_graph¶
Module Contents¶
Classes¶
Functions¶
Root directory for the upstream batch driver’s output tree. |
|
copy the generated files to the project directory |
|
reads a graph in json format as a netwrokx graph |
|
Resolve the clang used to emit ProGraML-compatible LLVM IR. |
|
Compile {path}/{name}.{c,cpp,cc} to {path}/{name}.ll. |
|
reads a LLVM IR and converts it to a netwrokx graph |
|
gets a json file and beautifies it to make it readable |
|
extract the names of the function in c code along with their line number |
|
get trip count of the for loop |
|
gets an llvm file and returns the icmp instructions of each for loop |
|
gets a c kernel and returns the pragmas of each for loop |
|
creates nodes for each pragma to be added to the graph |
|
|
|
|
|
Data¶
API¶
- hlsfactory.harp.harp_graph.create_dir_if_not_exists(dir_path) None¶
- hlsfactory.harp.harp_graph.atoi(text)¶
- hlsfactory.harp.harp_graph.natural_keys(text)¶
- hlsfactory.harp.harp_graph.get_root_path() str¶
Root directory for the upstream batch driver’s output tree.
Upstream resolves this to the HARP repository checkout. Only run_graph_gen and its helpers use it; the per-design entry point graph_generator does not. HLSFACTORY_HARP_ROOT overrides it.
- hlsfactory.harp.harp_graph.PRAGMA_POSITION = None¶
- hlsfactory.harp.harp_graph.BENCHMARK = 'poly'¶
- hlsfactory.harp.harp_graph.type_graph = 'harp'¶
- hlsfactory.harp.harp_graph.MACHSUITE_KERNEL = ['aes', 'gemm-blocked', 'gemm-ncubed', 'spmv-crs', 'spmv-ellpack', 'stencil_stencil2d', 'nw', 'md', ...¶
- hlsfactory.harp.harp_graph.poly_KERNEL = ['2mm', '3mm', 'adi', 'atax', 'bicg', 'bicg-large', 'covariance', 'doitgen', 'doitgen-red', 'fdtd-2d...¶
- hlsfactory.harp.harp_graph.ALL_KERNEL = None¶
- class hlsfactory.harp.harp_graph.Node(block, function, text, type_n, features=None)¶
Initialization
- get_attr(after_process=True)¶
- args:
- after_processTrue if nodes are added to existing GNN-DSE graphs
False for initial graph generation in GNN-DSE
- hlsfactory.harp.harp_graph.create_pseudo_node_block(block, function)¶
- hlsfactory.harp.harp_graph.add_to_graph(g_nx, nodes, edges) None¶
- hlsfactory.harp.harp_graph.copy_files(name, src, dest) None¶
copy the generated files to the project directory
- args:
name: the kernel name src: the path to the files dest: where you want to copy the files
- hlsfactory.harp.harp_graph.read_json_graph(name, readable=True)¶
reads a graph in json format as a netwrokx graph
- args:
name: name of the json file/ kernel’s name reaable: whether to store a readable format of the json file
- returns:
g_nx: graph in networkx format
- hlsfactory.harp.harp_graph.HLSFACTORY_HARP_CLANG_ENV_VAR = 'HLSFACTORY_HARP_CLANG'¶
- hlsfactory.harp.harp_graph.DEFAULT_HARP_CLANG = 'clang-14'¶
- hlsfactory.harp.harp_graph.SOURCE_EXTENSIONS = ('.c', '.cpp', '.cc')¶
- hlsfactory.harp.harp_graph.get_harp_clang_bin(clang_bin=None) str¶
Resolve the clang used to emit ProGraML-compatible LLVM IR.
The llvm2graph binary bundled with programl is an LLVM 10 parser. It cannot read opaque pointers (clang >= 15) and rejects the noundef attribute (clang >= 12), so a clang no newer than 14 is required.
- hlsfactory.harp.harp_graph.emit_llvm_ir(name, path, clang_bin=None, extra_args=None) str¶
Compile {path}/{name}.{c,cpp,cc} to {path}/{name}.ll.
Replaces upstream HARP’s clang_script.sh, which is not vendored here. Two flags are required:
-disable-noundef-analysis keeps the IR parseable by the LLVM 10 based llvm2graph bundled with programl.
-fno-discard-value-names keeps basic blocks named (for.cond, for.body, …) instead of numbered. get_icmp locates loops by those names, and silently finds none without it.
- Returns:
str: Path to the generated .ll file.
- Raises:
FileNotFoundError: If no source file for name exists under path. RuntimeError: If clang fails.
- hlsfactory.harp.harp_graph.llvm_to_nx(name)¶
reads a LLVM IR and converts it to a netwrokx graph
- args:
name: name of the LLVM file/ kernel’s name
- returns:
g_nx: graph in networkx format
- hlsfactory.harp.harp_graph.make_json_readable(name, js_graph) None¶
gets a json file and beautifies it to make it readable
- args:
name: kernel name js_graph: the graph in networkx format read from the json file
- writes:
a readable json file with name {name}_pretty.json
- hlsfactory.harp.harp_graph.C_CONTROL_KEYWORDS = 'frozenset(...)'¶
- hlsfactory.harp.harp_graph.extract_function_names(c_code)¶
extract the names of the function in c code along with their line number
- args:
c_code: the c_code read with code.read()
- return:
a list of tuples of (function name, line number)
- hlsfactory.harp.harp_graph.get_tc_for_loop(for_loop_text)¶
get trip count of the for loop
- hlsfactory.harp.harp_graph.get_icmp(path, name, log=False)¶
gets an llvm file and returns the icmp instructions of each for loop
- args:
path: parent directory of the llvm file name: kernel name
- returns:
- a dictionary corresponding to the icmp instructions:
{for loop id: [icmp instruction, for.cond line number, icmp line number]}
number of for loops
- hlsfactory.harp.harp_graph.get_pragmas_loops(path, name, EXT='c', log=False)¶
gets a c kernel and returns the pragmas of each for loop
- args:
path: parent directory of the kernel file name: kernel name
- returns:
- a dictionary with each entry showing the for loop and its pragmas
{for loop id: [for loop source code, [list of pragmas]]}
number of for loops
- hlsfactory.harp.harp_graph.create_pragma_nodes(g_nx, g_nx_nodes, for_dict_source, for_dict_llvm, log=True)¶
creates nodes for each pragma to be added to the graph
- args:
g_nx: the graph object g_nx_nodes: number of nodes of the graph object for_dict_source: the for loops along with their pragmas for_dict_llvm: the for loops along with their icmp instruction in llvm
- returns:
a list of nodes and a list of edges to be added to the graph
- hlsfactory.harp.harp_graph.prune_redundant_nodes(g_new) None¶
- hlsfactory.harp.harp_graph.process_graph(name, g, csv_dict=None, output_dir=None) None¶
- adjusts the node/edge attributes, removes redundant nodes,
and writes the final graph to be used by GNN-DSE
- args:
name: kernel name dest: where to store the graph
- hlsfactory.harp.harp_graph.graph_generator(name, path, benchmark, generate_programl=False, csv_dict=None, output_dir=None) None¶
- runs ProGraML [ICML’21] to generate the graph, adds the pragma nodes,
processes the final graph to be accepted by GNN-DSE
- args:
name: kernel name path: path to parent directory of the kernel file benchmark: [machsuite|poly] None: simple program output_dir: destination for the processed graph, defaulting to the upstream batch-driver tree
- hlsfactory.harp.harp_graph.get_for_blocks_info(name, path)¶
- hlsfactory.harp.harp_graph.augment_graph_hierarchy(name, for_blocks_info, src_path, dst_path, csv_dict=None, node_type='block') None¶
- hlsfactory.harp.harp_graph.add_auxiliary_nodes(name, path, processed_path, csv_dict, node_type='block', connected=False) None¶
- hlsfactory.harp.harp_graph.remove_extra_header(src_dir, kernel_name) None¶
- hlsfactory.harp.harp_graph.write_csv_file(csv_dict, csv_header, file_path) None¶
- hlsfactory.harp.harp_graph.run_graph_gen(mode='initial', connected=True, target=None, ALL_KERNEL=ALL_KERNEL) None¶