ソースを参照

Try to push in a new JIT framework which always fails and falls back to interpretation

Yentl Van Tendeloo 7 年 前
コミット
44e56eb685

+ 32 - 3
kernel/modelverse_jit/jit.py

@@ -499,6 +499,7 @@ class ModelverseJit(object):
 
         def handle_jit_exception(exception):
             # If analysis fails, then a JitCompilationFailedException will be thrown.
+            print("EXCEPTION with mutable")
             del self.compilation_dependencies[body_id]
             for dep in dependencies:
                 self.mark_no_jit(dep)
@@ -723,7 +724,14 @@ class ModelverseJit(object):
                 tree_ir.LiteralInstruction(jit_runtime.FUNCTION_BODY_KEY)),
             global_name)
 
+    def new_compile(self, body_id):
+        print("Compiling body ID " + str(body_id))
+        raise JitCompilationFailedException("Function was marked '%s'." % jit_runtime.MUTABLE_FUNCTION_KEY)
+
+        #raise primitive_functions.PrimitiveFinished("pass")
+
 def compile_function_body_interpret(jit, function_name, body_id, task_root, header=None):
+    print("INTERPRET")
     """Create a function that invokes the interpreter on the given function."""
     (parameter_ids, parameter_list, _), = yield [
         ("CALL_ARGS", [jit.jit_signature, (body_id,)])]
@@ -751,6 +759,7 @@ def compile_function_body_interpret(jit, function_name, body_id, task_root, head
 def compile_function_body_baseline(
         jit, function_name, body_id, task_root,
         header=None, compatible_temporary_protects=False):
+    print("BASELINE")
     """Have the baseline JIT compile the function with the given name and body id."""
     (parameter_ids, parameter_list, _), = yield [
         ("CALL_ARGS", [jit.jit_signature, (body_id,)])]
@@ -779,6 +788,25 @@ def compile_function_body_baseline(
         jit.jit_define_function(function_name, constructed_function))
 
 def compile_function_body_fast(jit, function_name, body_id, _):
+    print("FAST2")
+    """Have the fast JIT compile the function with the given name and body id."""
+    (parameter_ids, parameter_list, _), = yield [
+        ("CALL_ARGS", [jit.jit_signature, (body_id,)])]
+    param_dict = dict(list(zip(parameter_ids, parameter_list)))
+
+    print("Got body bytecode: " + str(body_id))
+    constructed_body, = yield [("CALL_ARGS", [jit.new_compile, (body_id,)])]
+    print("Constructed body:")
+    print(constructed_body)
+
+    constructed_function = create_bare_function(function_name, parameter_list, constructed_body)
+
+    # Convert the function definition to Python code, and compile it.
+    raise primitive_functions.PrimitiveFinished(
+        jit.jit_define_function(function_name, constructed_function))
+
+def compile_function_body_fast_original(jit, function_name, body_id, _):
+    print("FAST_ORIGINAL")
     """Have the fast JIT compile the function with the given name and body id."""
     (parameter_ids, parameter_list, _), = yield [
         ("CALL_ARGS", [jit.jit_signature, (body_id,)])]
@@ -799,6 +827,7 @@ def compile_function_body_fast(jit, function_name, body_id, _):
 
     # Optimize the tree that was generated.
     constructed_body, = yield [("CALL_ARGS", [optimize_tree_ir, (constructed_body,)])]
+    print("OUTPUT: " + str(constructed_body))
     constructed_function = create_bare_function(function_name, parameter_list, constructed_body)
 
     # Convert the function definition to Python code, and compile it.
@@ -985,6 +1014,7 @@ class AdaptiveJitState(object):
 def compile_function_body_adaptive(
         jit, function_name, body_id, task_root,
         temperature_heuristic=favor_loops):
+    print("ADAPTIVE")
     """Compile the function with the given name and body id. An execution engine is picked
        automatically, and the function may be compiled again at a later time."""
     # The general idea behind this compilation technique is to first use the baseline JIT
@@ -1004,9 +1034,8 @@ def compile_function_body_adaptive(
         if jit.jit_success_log_function is not None:
             jit.jit_success_log_function(
                 "Compiling '%s' with fast-jit." % function_name)
-        yield [
-            ("TAIL_CALL_ARGS",
-             [compile_function_body_fast, (jit, function_name, body_id, task_root)])]
+        yield [("CALL_ARGS", [compile_function_body_fast, (jit, function_name, body_id, task_root)])]
+        print("NEXT...")
 
     temperature_counter_name = jit.import_value(
         initial_temperature, function_name + "_temperature_counter")

+ 21 - 2
kernel/modelverse_kernel/main.py

@@ -132,7 +132,7 @@ class ModelverseKernel(object):
                 elif inst_v is None:
                     raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info[taskname], inst_v, self.phase_v))
                 else:
-                    #print("%-30s(%s) -- %s" % (inst_v["value"], self.phase_v, taskname))
+                    print("%-30s(%s) -- %s" % (inst_v["value"], self.phase_v, taskname))
                     gen = self.get_inst_phase_generator(inst_v, self.phase_v, task_root)
             elif inst_v is None:
                 raise Exception("%s: error understanding command (%s, %s)" % (self.debug_info[taskname], inst_v, self.phase_v))
@@ -184,7 +184,26 @@ class ModelverseKernel(object):
         # Try to retrieve the suggested name.
         suggested_name = self.jit.get_global_name(inst)
         # Have the JIT compile the function.
-        return self.jit.jit_compile(task_root, inst, suggested_name)
+        #return self.jit.jit_compile(task_root, inst, suggested_name)
+
+        if inst is None:
+            raise ValueError('body_id cannot be None: ' + str(suggested_name))
+        elif inst in self.jit.jitted_entry_points:
+            raise primitive_functions.PrimitiveFinished(
+                self.jit.jit_globals[self.jit.jitted_entry_points[inst]])
+
+        compiled_func = self.jit.lookup_compiled_body(inst)
+        if compiled_func is not None:
+            raise primitive_functions.PrimitiveFinished(compiled_func)
+
+        """
+        def func(**kwargs):
+            print("KWARGS: " + str(kwargs))
+            #raise primitive_functions.PrimitiveFinished(None)
+        """
+        raise jit.JitCompilationFailedException("FAIL")
+
+        raise primitive_functions.PrimitiveFinished(func)
 
     def execute_jit(self, task_root, inst, taskname):
         # execute_jit

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Tue Mar 20 15:56:14 2018
+Date:   Wed Mar 21 13:56:49 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server