From 5837cfe5abc7ed3e62a945136b781fd660af9a82 Mon Sep 17 00:00:00 2001
From: Elizabeth <hashim.sharif91@gmail.com>
Date: Sun, 27 Oct 2019 22:33:39 -0500
Subject: [PATCH] Added code to handle local paths for fp32 row

---
 .../source_code_autogenerator.py              | 34 +++++++++++++------
 1 file changed, 23 insertions(+), 11 deletions(-)

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 79a512fa94..d587a3b7b5 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)
 
-- 
GitLab