diff --git a/llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py b/llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py index 79a512fa94e7345a978c4f4b6274e87406763ad3..d587a3b7b57b96c8eb61b2e3e63709c7745ed466 100644 --- a/llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py +++ b/llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py @@ -113,19 +113,19 @@ def get_new_function_calls(complete_line, knob_config): return ''.join(new_line) -def generate_fp32_source(new_file, source_file): - # Copy the source code over - new_file.write(source_file.read()) - - -def generate_fp16_source(knob_config, new_file, source_file, orig_source_dir): - file_contents = source_file.read() +def convert_local_paths(file_contents, orig_source_dir): + ''' + Converts all local paths wrt the original source file's directory to paths compatible + with the current source code directory - # Fix all local paths + Args: + file_contents: String containing source code read from file + orig_source_dir: Path of original source code dir wrt the current directory + ''' last_include_ind = file_contents.rfind("#include") last_include_newline_ind = file_contents.find("\n", last_include_ind) include_lines = file_contents[ : last_include_newline_ind].split("\n") - + new_file_contents = [] for line in include_lines: if line.startswith("#"): @@ -136,7 +136,19 @@ def generate_fp16_source(knob_config, new_file, source_file, orig_source_dir): else: new_file_contents.append(line) new_file_contents.append(file_contents[last_include_newline_ind : ]) - new_file_contents = '\n'.join(new_file_contents) + return '\n'.join(new_file_contents) + + +def generate_fp32_source(new_file, source_file, orig_source_dir): + # Copy the source code over + new_file_contents = convert_local_paths(source_file.read(), orig_source_dir) + new_file.write(new_file_contents) + + +def generate_fp16_source(knob_config, new_file, source_file, orig_source_dir): + file_contents = source_file.read() + + new_file_contents = convert_local_paths(file_contents, orig_source_dir) # Replace all tensorOperation calls with tensorHalfOperation calls # Derived from ../bin/replace_half_calls.py @@ -207,7 +219,7 @@ def generate_source_code(table, dir_name, filename, source_name): if knob_config.approx == Approx.FP16: generate_fp16_source(knob_config, new_file, source_file, orig_source_dir) elif knob_config.approx == Approx.FP32: - generate_fp32_source(new_file, source_file) + generate_fp32_source(new_file, source_file, orig_source_dir) else: generate_approx_source(knob_config, new_file, source_file, orig_source_dir)