Browse Source

Removed even more code: remove all jit specific folders completely

Yentl Van Tendeloo 3 years ago
parent
commit
2371f818ad

+ 0 - 46
hybrid_server/classes/mvkcontroller.xml

@@ -24,52 +24,6 @@
                 if parameter.startswith('--kernel='):
                     kernel_opts = parameter[len('--kernel='):].split(',')
 
-            for opt in kernel_opts:
-                if opt == 'legacy-interpreter':
-                    self.mvk = LegacyModelverseKernel(self.root)
-                elif opt == 'generated':
-                    self.mvk = GeneratedModelverseKernel(self.root)
-                elif opt == 'interpreter':
-                    self.mvk.jit.set_jit_enabled(False)
-                elif opt == 'no-thunks':
-                    self.mvk.jit.enable_thunks(False)
-                elif opt == 'thunks':
-                    self.mvk.jit.enable_thunks()
-                elif opt == 'no-source-maps':
-                    self.mvk.jit.enable_source_maps(False)
-                elif opt == 'source-maps':
-                    self.mvk.jit.enable_source_maps()
-                elif opt == 'no-insert-nops':
-                    self.mvk.jit.enable_nop_insertion(False)
-                elif opt == 'insert-nops':
-                    self.mvk.jit.enable_nop_insertion()
-                elif opt == 'trace':
-                    self.mvk.jit.enable_tracing()
-                elif opt == 'bytecode-interpreter':
-                    self.mvk.jit.set_function_body_compiler(jit.compile_function_body_interpret)
-                elif opt == 'baseline-jit':
-                    self.mvk.jit.set_function_body_compiler(jit.compile_function_body_baseline)
-                elif opt == 'fast-jit':
-                    self.mvk.jit.set_function_body_compiler(jit.compile_function_body_fast)
-                elif opt == 'adaptive-jit-favor-large-functions':
-                    self.mvk.jit.set_function_body_compiler(
-                            lambda *args: jit.compile_function_body_adaptive(
-                                *args, temperature_heuristic=jit.favor_large_functions))
-                elif opt == 'adaptive-jit-favor-small-functions':
-                    self.mvk.jit.set_function_body_compiler(
-                        lambda *args: jit.compile_function_body_adaptive(
-                            *args, temperature_heuristic=jit.favor_small_functions))
-                elif opt == 'adaptive-jit-favor-loops':
-                    self.mvk.jit.set_function_body_compiler(
-                        lambda *args: jit.compile_function_body_adaptive(
-                            *args, temperature_heuristic=jit.favor_loops))
-                elif opt == 'adaptive-jit' or opt == 'adaptive-jit-favor-small-loops':
-                    self.mvk.jit.set_function_body_compiler(
-                        lambda *args: jit.compile_function_body_adaptive(
-                            *args, temperature_heuristic=jit.favor_small_loops))
-                else:
-                    print("warning: unknown kernel option '%s'." % opt)
-
             self.port = int(params[0])
 
             self.sc_map = {}

+ 0 - 3
hybrid_server/server.xml

@@ -23,11 +23,8 @@
         sys.path.append("../state/")
         from modelverse_kernel.primitives import SleepKernel
         from modelverse_kernel.main import ModelverseKernel
-        from modelverse_kernel.legacy import ModelverseKernel as LegacyModelverseKernel
-        from modelverse_kernel.generated import ModelverseKernel as GeneratedModelverseKernel
         from modelverse_state.main import ModelverseState
         #from modelverse_state.rdf import ModelverseState
-        import modelverse_jit.jit as jit
     </top>
 
     <inport name="socket_in"/>

+ 0 - 0
kernel/modelverse_jit/__init__.py


+ 0 - 274
kernel/modelverse_jit/jit.py

@@ -1,274 +0,0 @@
-import math
-import keyword
-from collections import defaultdict
-import modelverse_kernel.primitives as primitive_functions
-import modelverse_jit.runtime as jit_runtime
-
-# Import JitCompilationFailedException because it used to be defined
-# in this module.
-JitCompilationFailedException = jit_runtime.JitCompilationFailedException
-
-class ModelverseJit(object):
-    """A high-level interface to the modelverse JIT compiler."""
-    def __init__(self):
-        self.todo_entry_points = set()
-        self.no_jit_entry_points = set()
-        self.jitted_parameters = {}
-        self.jit_globals = {
-            'PrimitiveFinished' : primitive_functions.PrimitiveFinished,
-        }
-        # jitted_entry_points maps body ids to values in jit_globals.
-        self.jitted_entry_points = {}
-        # global_functions maps global value names to body ids.
-        self.global_functions = {}
-        # global_functions_inv maps body ids to global value names.
-        self.global_functions_inv = {}
-        # jitted_function_aliases maps body ids to known aliases.
-        self.jitted_function_aliases = defaultdict(set)
-        self.jit_count = 0
-        self.compilation_dependencies = {}
-        self.jit_enabled = True
-
-    def set_jit_enabled(self, is_enabled=True):
-        """Enables or disables the JIT."""
-        self.jit_enabled = is_enabled
-
-    def allow_direct_calls(self, is_allowed=True):
-        """Allows or disallows direct calls from jitted to jitted code."""
-        self.direct_calls_allowed = is_allowed
-
-    def use_input_function(self, is_enabled=True):
-        """Configures the JIT to compile 'input' instructions as function calls."""
-        self.input_function_enabled = is_enabled
-
-    def enable_tracing(self, is_enabled=True):
-        """Enables or disables tracing for jitted code."""
-        self.tracing_enabled = is_enabled
-
-    def enable_source_maps(self, is_enabled=True):
-        """Enables or disables the creation of source maps for jitted code. Source maps
-           convert lines in the generated code to debug information.
-
-           Source maps are enabled by default."""
-        self.source_maps_enabled = is_enabled
-
-    def enable_nop_insertion(self, is_enabled=True):
-        """Enables or disables nop insertion for jitted code. If enabled, the JIT will
-           insert nops at loop back-edges. Inserting nops sacrifices performance to
-           keep the jitted code from blocking the thread of execution and consuming
-           all resources; nops give the Modelverse server an opportunity to interrupt
-           the currently running code."""
-        self.nop_insertion_enabled = is_enabled
-
-    def set_function_body_compiler(self, compile_function_body):
-        """Sets the function that the JIT uses to compile function bodies."""
-        self.compile_function_body = compile_function_body
-
-    def mark_entry_point(self, body_id):
-        """Marks the node with the given identifier as a function entry point."""
-        if body_id not in self.no_jit_entry_points and body_id not in self.jitted_entry_points:
-            self.todo_entry_points.add(body_id)
-
-    def is_entry_point(self, body_id):
-        """Tells if the node with the given identifier is a function entry point."""
-        return body_id in self.todo_entry_points or \
-               body_id in self.no_jit_entry_points or \
-               body_id in self.jitted_entry_points
-
-    def is_jittable_entry_point(self, body_id):
-        """Tells if the node with the given identifier is a function entry point that
-           has not been marked as non-jittable. This only returns `True` if the JIT
-           is enabled and the function entry point has been marked jittable, or if
-           the function has already been compiled."""
-        return ((self.jit_enabled and body_id in self.todo_entry_points) or
-                self.has_compiled(body_id))
-
-    def has_compiled(self, body_id):
-        """Tests if the function belonging to the given body node has been compiled yet."""
-        return body_id in self.jitted_entry_points
-
-    def get_compiled_name(self, body_id):
-        """Gets the name of the compiled version of the given body node in the JIT
-           global state."""
-        if body_id in self.jitted_entry_points:
-            return self.jitted_entry_points[body_id]
-        else:
-            return None
-
-    def mark_no_jit(self, body_id):
-        """Informs the JIT that the node with the given identifier is a function entry
-           point that must never be jitted."""
-        self.no_jit_entry_points.add(body_id)
-        if body_id in self.todo_entry_points:
-            self.todo_entry_points.remove(body_id)
-
-    def generate_name(self, infix, suggested_name=None):
-        """Generates a new name or picks the suggested name if it is still
-           available."""
-        if suggested_name is not None \
-            and suggested_name not in self.jit_globals \
-            and not keyword.iskeyword(suggested_name):
-            self.jit_count += 1
-            return suggested_name
-        else:
-            function_name = 'jit_%s%d' % (infix, self.jit_count)
-            self.jit_count += 1
-            return function_name
-
-    def generate_function_name(self, body_id, suggested_name=None):
-        """Generates a new function name or picks the suggested name if it is still
-           available."""
-        if suggested_name is None:
-            suggested_name = self.get_global_name(body_id)
-
-        return self.generate_name('func', suggested_name)
-
-    def register_global(self, body_id, global_name):
-        """Associates the given body id with the given global name."""
-        self.global_functions[global_name] = body_id
-        self.global_functions_inv[body_id] = global_name
-
-    def get_global_name(self, body_id):
-        """Gets the name of the global function with the given body id.
-           Returns None if no known global exists with the given id."""
-        if body_id in self.global_functions_inv:
-            return self.global_functions_inv[body_id]
-        else:
-            return None
-
-    def get_global_body_id(self, global_name):
-        """Gets the body id of the global function with the given name.
-           Returns None if no known global exists with the given name."""
-        if global_name in self.global_functions:
-            return self.global_functions[global_name]
-        else:
-            return None
-
-    def register_compiled(self, body_id, compiled_function, function_name=None):
-        """Registers a compiled entry point with the JIT."""
-        # Get the function's name.
-        actual_function_name = self.generate_function_name(body_id,
-        function_name)
-        # Map the body id to the given parameter list.
-        self.jitted_entry_points[body_id] = actual_function_name
-        self.jit_globals[actual_function_name] = compiled_function
-        if function_name is not None:
-            self.register_global(body_id, function_name)
-
-        if body_id in self.todo_entry_points:
-            self.todo_entry_points.remove(body_id)
-
-    def import_value(self, value, suggested_name=None):
-        """Imports the given value into the JIT's global scope, with the given suggested name.
-           The actual name of the value (within the JIT's global scope) is returned."""
-        actual_name = self.generate_name('import', suggested_name)
-        self.jit_globals[actual_name] = value
-        return actual_name
-
-    def __lookup_compiled_body_impl(self, body_id):
-        """Looks up a compiled function by body id. Returns a matching function,
-           or None if no function was found."""
-        if body_id is not None and body_id in self.jitted_entry_points:
-            return self.jit_globals[self.jitted_entry_points[body_id]]
-        else:
-            return None
-
-    def __lookup_external_body_impl(self, global_name, body_id):
-        """Looks up an external function by global name. Returns a matching function,
-           or None if no function was found."""
-        if global_name is not None and self.compiled_function_lookup is not None:
-            result = self.compiled_function_lookup(global_name)
-            if result is not None and body_id is not None:
-                self.register_compiled(body_id, result, global_name)
-
-            return result
-        else:
-            return None
-
-    def lookup_compiled_body(self, body_id):
-        """Looks up a compiled function by body id. Returns a matching function,
-           or None if no function was found."""
-        result = self.__lookup_compiled_body_impl(body_id)
-        if result is not None:
-            return result
-        else:
-            global_name = self.get_global_name(body_id)
-            return self.__lookup_external_body_impl(global_name, body_id)
-
-    def lookup_compiled_function(self, global_name):
-        """Looks up a compiled function by global name. Returns a matching function,
-           or None if no function was found."""
-        body_id = self.get_global_body_id(global_name)
-        result = self.__lookup_compiled_body_impl(body_id)
-        if result is not None:
-            return result
-        else:
-            return self.__lookup_external_body_impl(global_name, body_id)
-
-    def jit_signature(self, body_id):
-        """Acquires the signature for the given body id node, which consists of the
-           parameter variables, parameter name and a flag that tells if the given function
-           is mutable."""
-        if body_id not in self.jitted_parameters:
-            signature_id, = yield [("RRD", [body_id, jit_runtime.FUNCTION_BODY_KEY])]
-            signature_id = signature_id[0]
-            param_set_id, is_mutable = yield [
-                ("RD", [signature_id, "params"]),
-                ("RD", [signature_id, jit_runtime.MUTABLE_FUNCTION_KEY])]
-            if param_set_id is None:
-                self.jitted_parameters[body_id] = ([], [], is_mutable)
-            else:
-                param_name_ids, = yield [("RDK", [param_set_id])]
-                param_names = yield [("RV", [n]) for n in param_name_ids]
-                #NOTE Patch up strange links...
-                param_names = [i for i in param_names if i is not None]
-                param_vars = yield [("RD", [param_set_id, k]) for k in param_names]
-
-                #NOTE that variables might not be in the correct order, as we just read them out!
-                lst = sorted([(name, var) for name, var in zip(param_names, param_vars)])
-                param_vars = [i[1] for i in lst]
-                param_names = [i[0] for i in lst]
-                self.jitted_parameters[body_id] = (param_vars, param_names, is_mutable)
-
-        raise primitive_functions.PrimitiveFinished(self.jitted_parameters[body_id])
-
-    def check_jittable(self, body_id, suggested_name=None):
-        """Checks if the function with the given body id is obviously non-jittable. If it's
-           non-jittable, then a `JitCompilationFailedException` exception is thrown."""
-        if body_id is None:
-            raise ValueError('body_id cannot be None: ' + suggested_name)
-        elif body_id in self.no_jit_entry_points:
-            # We're not allowed to jit this function or have tried and failed before.
-            raise JitCompilationFailedException(
-                'Cannot jit function %s at %d because it is marked non-jittable.' % (
-                    '' if suggested_name is None else "'" + suggested_name + "'",
-                    body_id))
-        elif not self.jit_enabled:
-            # We're not allowed to jit anything.
-            raise JitCompilationFailedException(
-                'Cannot jit function %s at %d because the JIT has been disabled.' % (
-                    '' if suggested_name is None else "'" + suggested_name + "'",
-                    body_id))
-
-    def jit_define_function(self, function_name, function_def):
-        """Converts the given tree-IR function definition to Python code, defines it,
-           and extracts the resulting function."""
-        # The comment below makes pylint shut up about our (hopefully benign) use of exec here.
-        # pylint: disable=I0011,W0122
-        if self.jit_code_log_function is not None:
-            self.jit_code_log_function(function_def)
-
-        # Convert the function definition to Python code, and compile it.
-        code_generator = tree_ir.PythonGenerator()
-        function_def.generate_python_def(code_generator)
-        source_map_name = self.get_source_map_name(function_name)
-        if source_map_name is not None:
-            self.jit_globals[source_map_name] = code_generator.source_map_builder.source_map
-        exec(str(code_generator), self.jit_globals)
-
-        # Extract the compiled function from the JIT global state.
-        return self.jit_globals[function_name]
-
-    def jit_delete_function(self, function_name):
-        """Deletes the function with the given function name."""
-        del self.jit_globals[function_name]

+ 0 - 53
kernel/modelverse_jit/runtime.py

@@ -1,53 +0,0 @@
-import modelverse_kernel.primitives as primitive_functions
-
-class JitCompilationFailedException(Exception):
-    """A type of exception that is raised when the jit fails to compile a function."""
-    pass
-
-MUTABLE_FUNCTION_KEY = "mutable"
-"""A dictionary key for functions that are mutable."""
-
-FUNCTION_BODY_KEY = "body"
-"""A dictionary key for function bodies."""
-
-KWARGS_PARAMETER_NAME = "kwargs"
-"""The name of the kwargs parameter in jitted functions."""
-
-CALL_FUNCTION_NAME = "__call_function"
-"""The name of the '__call_function' function, in the jitted function scope."""
-
-GET_INPUT_FUNCTION_NAME = "__get_input"
-"""The name of the '__get_input' function, in the jitted function scope."""
-
-JIT_THUNK_CONSTANT_FUNCTION_NAME = "__jit_thunk_constant_function"
-"""The name of the jit_thunk_constant_function function in the JIT's global context."""
-
-JIT_THUNK_GLOBAL_FUNCTION_NAME = "__jit_thunk_global"
-"""The name of the jit_thunk_global function in the JIT's global context."""
-
-JIT_REJIT_FUNCTION_NAME = "__jit_rejit"
-"""The name of the rejit function in the JIT's global context."""
-
-JIT_COMPILE_FUNCTION_BODY_FAST_FUNCTION_NAME = "__jit_compile_function_body_fast"
-"""The name of the compile_function_body_fast function in the JIT's global context."""
-
-UNREACHABLE_FUNCTION_NAME = "__unreachable"
-"""The name of the unreachable function in the JIT's global context."""
-
-LOCALS_NODE_NAME = "jit_locals"
-"""The name of the node that is connected to all JIT locals in a given function call."""
-
-LOCALS_EDGE_NAME = "jit_locals_edge"
-"""The name of the edge that connects the LOCALS_NODE_NAME node to a user root."""
-
-GLOBAL_NOT_FOUND_MESSAGE_FORMAT = "Not found as global: %s"
-"""The format of the 'not found as global' message. Takes a single argument."""
-
-BYTECODE_INTERPRETER_ORIGIN_NAME = "bytecode-interpreter"
-"""The origin name for functions that were produced by the bytecode interpreter."""
-
-BASELINE_JIT_ORIGIN_NAME = "baseline-jit"
-"""The origin name for functions that were produced by the baseline JIT."""
-
-FAST_JIT_ORIGIN_NAME = "fast-jit"
-"""The origin name for functions that were produced by the fast JIT."""

+ 0 - 1
kernel/modelverse_kernel/compiled.py

@@ -1,5 +1,4 @@
 from modelverse_kernel.primitives import PrimitiveFinished
-import modelverse_jit.runtime as jit_runtime
 import time
 
 def get_superclasses(a, b, **remainder):

File diff suppressed because it is too large
+ 0 - 1261
kernel/modelverse_kernel/generated.py


File diff suppressed because it is too large
+ 0 - 1061
kernel/modelverse_kernel/legacy.py


+ 4 - 56
kernel/modelverse_kernel/main.py

@@ -1,8 +1,7 @@
 import modelverse_kernel.primitives as primitive_functions
 import modelverse_kernel.compiled as compiled_functions
 from modelverse_kernel.request_handler import RequestHandler
-import modelverse_jit.jit as jit
-import modelverse_jit.runtime as jit_runtime
+import modelverse_kernel.jit as jit
 from collections import defaultdict
 import sys
 import time
@@ -32,60 +31,9 @@ class ModelverseKernel(object):
         self.allow_compiled = True
         #self.allow_compiled = False
 
-        # Set `self.suggest_function_names` to True to associate global function names
-        # with their function bodies.
-        self.suggest_function_names = True
-
         # `self.jit` handles most JIT-related functionality.
         self.jit = jit.ModelverseJit()
-        if self.allow_compiled:
-            self.jit.compiled_function_lookup = lambda func_name: \
-                getattr(compiled_functions, func_name, None)
-
-        # To disable the JIT, uncomment the line below:
-        #
-        #     self.jit.set_jit_enabled(False)
-        #
-        # To disable direct calls in the JIT, uncomment the line below:
-        #
-        #     self.jit.allow_direct_calls(False)
-        #
-        # To disable thunks in the JIT, uncomment the line below:
-        #
-        #     self.jit.enable_thunks(False)
-        #
-        # To make the JIT compile 'input' instructions as calls to
-        # modelverse_jit.runtime.get_input, uncomment the line below:
-        #
-        #     self.jit.use_input_function()
-        #
-        # To disable source maps in the JIT, uncomment the line below:
-        #
-        #     self.jit.enable_source_maps(False)
-        #
-        # To enable tracing in the JIT (for debugging purposes), uncomment
-        # the line below:
-        #
-        # self.jit.enable_tracing()
-        #
-        # To make the JIT print JIT successes and errors to the command-line,
-        # uncomment the line below:
-        #
-        #     self.jit.set_jit_success_log()
-        #
-        # If you want, you can use a custom logging function:
-        #
-        #     self.jit.set_jit_success_log(logging_function)
-        #
-        # To make the JIT print jitted code to the command-line, uncomment the
-        # line below:
-        #
-        # self.jit.set_jit_code_log()
-        #
-        # If you want, you can use a custom logging function:
-        #
-        #     self.jit.set_jit_code_log(logging_function)
-        #
+        self.jit.compiled_function_lookup = lambda func_name : getattr(compiled_functions, func_name, None)
 
         self.debug_info = defaultdict(list)
 
@@ -843,7 +791,7 @@ class ModelverseKernel(object):
                 print("Globals: " + str(globs))
                 globs = yield [("RV", [i]) for i in globs]
                 print("Resolved globals: " + str(globs))
-                raise Exception(jit_runtime.GLOBAL_NOT_FOUND_MESSAGE_FORMAT % var_name)
+                raise Exception(jit.GLOBAL_NOT_FOUND_MESSAGE_FORMAT % var_name)
 
             # Resolved a global, so this is a string
             # Potentially, this might even be a function that we have precompiled already!
@@ -860,7 +808,7 @@ class ModelverseKernel(object):
 
             # If we're dealing with a function, then we might want to figure out what its body id
             # is now so we can suggest a name to the JIT later.
-            if self.suggest_function_names and self.jit.get_global_body_id(var_name) is None:
+            if self.jit.get_global_body_id(var_name) is None:
                 compiler_val, = yield [("RD", [variable, "value"])]
                 if compiler_val is not None:
                     compiler_body, = yield [("RD", [compiler_val, "body"])]

+ 2 - 2
kernel/modelverse_kernel/request_handler.py

@@ -1,6 +1,6 @@
 import sys
 import modelverse_kernel.primitives as primitive_functions
-import modelverse_jit.runtime as jit_runtime
+import modelverse_kernel.jit as jit
 from collections import defaultdict
 
 class KnownRequestHandled(Exception):
@@ -9,7 +9,7 @@ class KnownRequestHandled(Exception):
 
 def format_stack_trace(stack_trace):
     """Formats a list of (function name, debug info, origin) triples."""
-    return '\n'.join([jit_runtime.format_stack_frame(*triple) for triple in stack_trace])
+    return '\n'.join([jit.format_stack_frame(*triple) for triple in stack_trace])
 
 class UnhandledRequestHandlerException(Exception):
     """The type of exception that is thrown when the request handler encounters an

+ 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 Apr 24 10:04:54 2018
+Date:   Tue Apr 24 12:55:50 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server