hercules-py

Static Python AOT Compiler


License
Apache-2.0
Install
pip install hercules-py==0.2.11

Documentation

Hercules

Hercules is an ahead of time compiler for a subset of the Python language.

Installation

pip install hercules-jit

A Quick Example

import hercules
import timeit

def fib(n: int) -> int:
    if n <= 1:
        return n
    else:
        return fib(n - 1) + fib(n - 2)


if __name__ == '__main__':
    fib_script = hercules.script(fib)
    
    # test on Macbook with m1 chip
    print(f'Python execution time: {timeit.timeit(lambda: fib(30), number=10)}s')  # 1.59s
    print(f'Hercules execution time: {timeit.timeit(lambda: fib_script(30), number=10)}s') # 0.03s

Acknowledgement

We learned a lot from the following projects when building Hercules.

  • TVM: Part of Hercules's IR and Runtime originates from TVM. We also learned and adapted some part of codegen pipeline from TVM.

  • Python: Part of the runtime code comes from cpython for align the semantics

  • Folly: We adopted the idea of FBString to design our runtime::string_core

  • abseil-cpp: The string_view structure and ByteHash algorithm originates from abseil

  • rapidjson: The json module is implemented based on rapidjson

  • CV-CUDA: The vision CUDA runtime is developed using the operators provided by CV-CUDA.