Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a concise introduction for dynjit #3

Open
thautwarm opened this issue Sep 28, 2020 · 1 comment
Open

a concise introduction for dynjit #3

thautwarm opened this issue Sep 28, 2020 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@thautwarm
Copy link
Owner

  1. @aware decorator

       import jit
       @jit.aware
        def f(x):
            return ...
  2. specifying optimizable global variables via __fix__.

    so far due to the restriction of python runtime, an embedded jit compiler cannot easily aware the change of global variables and trigger recompilation. To make the problem simpler, we request users to fill constant global variables.

    __fix__ = ['f1', 'f2']
    @jit.aware
    def f1(x):
      return x + x
    
    @jit.aware
    def f2(x):
      if x < 3:
          y = x * 10
      else:
          y = f1("aaa")
      return y + y

    If f1 is not provided in __fix__, we cannot assume f2 is referencing the function object f1 visually defined with def f1. That is because it's possible to change f1 later in python. Beside of providing __fix__, users should maintain the constant property of all variables in __fix__.

  3. the capability of dynjit compiler.

    1. method lookup specialisation.

      code like a = []; a.append(1) will be at least more performant than a = []; $(list.append)(a, 1), $ is not a real language construct, it means the splicing of constants, hence we don't need tricks like a = []; append = a.append; # use append later any more.

    2. Union split(supercompiler). The overhead of functions that returns a value of union type is only a single runtime type check.

      a = f(...) # if a can be int or float or str
      return a + a # by dynjit, '+' operator here  
      # is not the generic one, but the specialised one
    3. Bool split(supercompiler).

      Every boolean value will be specialised to True or False and help to specialise control flows.

    4. Control flow specialisation.

    if expression:
    # if expression can be partially evaluated to True(False), 
    # then statically choose the first(second) arm
          ...
    1. eliminate use of shallow data structures.
     a = ...
     return a[1]

    If a partially evaluated to a static value (1, 2, 3), then the code is identical to

    return 2

    This is much more powerful than the usual constant propagation due to our online partial evaluation.
    For termination guarantee, we cannot optimize use of nested/mutable data structures like [1, 2, 3] and ((1, 2, 3), ()).
    P.S: after getting dynjit ir we can emit LLVM IR code or C code to gain more kinds of optimizations. dynjit compiler itself is used for handling dynamisms of runtime.

@thautwarm thautwarm added the documentation Improvements or additions to documentation label Nov 3, 2020
@thautwarm
Copy link
Owner Author

need to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant