Coder Social home page Coder Social logo

zanellia / prometeo Goto Github PK

View Code? Open in Web Editor NEW
618.0 15.0 33.0 1.98 MB

An experimental Python-to-C transpiler and domain specific language for embedded high-performance computing

License: BSD 2-Clause "Simplified" License

Python 90.90% C 8.09% Makefile 0.37% Julia 0.64%
high-performance-computing domain-specific-language transpiler python-to-c python c compiler source-to-source hpc embedded-systems

prometeo's People

Contributors

domoritz avatar pbowyer avatar seelengrab avatar tmmsartor avatar zanellia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prometeo's Issues

Milestones for minimal complete DSL

High-priority

  • Support for basic types: int, double, pmat and pvec
    • declaration of variables of supported types
    • specification of function arguments of supported types
    • simple operations ('+', '-', '*', '/') on int and double types
  • Support for high-level basic linear algebra operations on pmat variables
    • C = A + B
    • C = A - B
    • C = A * B
    • C = A\B
  • Support for subscripting of pmat variables
    • get value (val = A[i,j])
    • set value (A[i,j] = val)
  • Support for functions calls
  • Support for structures
    • structure declaration
    • structure access
  • Support of arrays of all supported types
    • array of pmat declaration through Python Lists
    • array of other supported types declaration through Python Lists
    • array of structures declaration through Python Lists
    • accessing and setting arrays of pmats
  • Support for function definitions (no mem escape)
  • Extend AST parser to keep track of heap usage
  • AST-based verification of user code
  • Unit testing

Low-priority/long-term

  • Support for simple classes
  • Support for CasADi functions

Improvements

  • Remove dims from type hints in declarations (keep only in function signature)
  • Add linear algebra routines with explicit return
  • Add support for slicing

Question

Hey, after reading a little bit about this project, I love it but I'm a little confused one a few parts; does it transpile to exe? Or what does it transpile the python code to so users can run? Also; would I have to write my python programs in such a way so prometeo is able to access and execute it?

TY.

Class and method meta-information definition

This is part of a brainstorming with the development team on how to define meta-information structures for classes and methods within prometeo's parser. Rough draft:

Python example

class ClassA:
    def __init__(self):
        self.attr1 : int = 0

    def method1(self, arg1 : int) -> int:
        return self.attr1 + arg1

class ClassB:
    def __init__(self):
        self.attr1 : int = 0
        self.attr2 : ClassA = ClassA()

    def method1(self, arg1 : int) -> ClassA:
        return self.attr2

Meta-information:

[
    'ClassA' : [
        'constructor_args' : 
            [('self', 'self')],
        'attributes' : 
            [('attr1', 'int', 0)],
        'methods' : [
            'method1' : 
                'args' : 
                [('self','self'), ('arg1', 'int')],
                'return_type' : 'int'
        ]
    ]
]

[
    'ClassB' : [
        'constructor_args' : 
            [('self', 'self')],
        'attributes' : 
            [('attr1', 'int', 0), ('attr2', 'ClassA', 'None')],
        'methods' : [
            'method1' : 
                'args' : 
                [('self','self'), ('arg1', 'int')],
                'return_type' : 'ClassA'
        ]
    ]
]

How do you handle testing?

Sorry if I've missed something, but is there a method you have to allow tests to run on the transpiled C to ensure it's working? (and presumably that it gives the same results as the python code, unless you've got some way of being 100% sure that is guaranteed due to your language restrictions)

Improve and generalize sized type checking

As of now sized type checking is carried out in a rather case-specific fashion. At some point, the typed_record (https://github.com/zanellia/prometeo/blob/master/prometeo/cgen/code_gen_c.py#L324) and the var_dim_record (https://github.com/zanellia/prometeo/blob/master/prometeo/cgen/code_gen_c.py#L328) generated during the static analysis should be merged into a single dictionary and they should support any valid sized type e.g

n : dims = 10
A : pmat = pmat(n,n)
class ClassA():
    A : pmat = pmat(n,n)
class ClassB():
    A : pmat = pmat(n,n)
    B : ClassA = ClassA()

As of now 1) and 2) work fine, but to support 3) and more sophisticated user-defined sized types the code needs some restructuring.

In particular, if we analyze

from prometeo import *

n : dims = 10

class ClassA():
    A : pmat = pmat(n,n)

def main() -> int:
    A : pmat = pmat(n,n)
    return 0

it will result in the following typed_record:

{
    "global": {
        "n": "dims"
    },
    "global@ClassA": {
        "A": "pmat"
    },
    "global@main": {
        "A": "pmat"
    }
}

and the following var_dim_record:

{
    "global": {},
    "global@ClassA": {
        "A": [
            "n",
            "n"
        ]
    },
    "global@main": {
        "A": [
            "n",
            "n"
        ]
    }
}

Fix overload

It should suffice mangling function and method names everywhere.

(Apple M1) OSError: dlopen(/Users/.../prometeo/prometeo/linalg/../lib/blasfeo/libblasfeo.so, 6): image not found

macOs BigSur 11.4
MacBookPro 13-inch, M1, 2020

I cloned the repo, installed with pip install -e ., ran ipython, and tried import prometeo. I get the error:

Python 3.8.8 (default, Apr 13 2021, 12:59:45)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import prometeo
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-371e560288bc> in <module>
----> 1 import prometeo

~/repos/lib/prometeo/prometeo/__init__.py in <module>
      1 from . import cgen
----> 2 from . import linalg
      3 from . import mem
      4 from . import auxl
      5 from . import cmdline

~/repos/lib/prometeo/prometeo/linalg/__init__.py in <module>
----> 1 from .pmat_blasfeo_wrapper import *
      2 from .pvec_blasfeo_wrapper import *
      3 from .pmat import *
      4 from .pvec import *
      5 from .blasfeo_wrapper import *

~/repos/lib/prometeo/prometeo/linalg/pmat_blasfeo_wrapper.py in <module>
----> 1 from .blasfeo_wrapper import *
      2 from ctypes import *
      3
      4
      5 bw.blasfeo_dgeex1.restype = c_double

~/repos/lib/prometeo/prometeo/linalg/blasfeo_wrapper.py in <module>
      2 import os
      3
----> 4 bw = CDLL(os.path.dirname(__file__) + '/../lib/blasfeo/libblasfeo.so')
      5
      6 class blasfeo_dmat(Structure):

~/opt/anaconda3/lib/python3.8/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    379
    380         if handle is None:
--> 381             self._handle = _dlopen(self._name, mode)
    382         else:
    383             self._handle = handle

OSError: dlopen(/Users/vas/repos/lib/prometeo/prometeo/linalg/../lib/blasfeo/libblasfeo.so, 6): image not found

Issue installing on Python 3.9.10

Hi!
I was looking forward to installing the module but came across this error while trying to install the module on Python v3.9.10:

C:\Users\HP>py -3.9 -m pip install prometeo-dsl
ERROR: Ignored the following versions that require a different python version: 0.0.1 Requires-Python >=3.6, <=3.9; 0.0.10 Requires-Python >=3.6, <=3.9; 0.0.2 Requires-Python >=3.6, <=3.9; 0.0.3 Requires-Python >=3.6, <=3.9; 0.0.4 Requires-Python >=3.6, <=3.9; 0.0.5 Requires-Python >=3.6, <=3.9; 0.0.6 Requires-Python >=3.6, <=3.9; 0.0.7 Requires-Python >=3.6, <=3.9; 0.0.9 Requires-Python >=3.6, <=3.9
ERROR: Could not find a version that satisfies the requirement prometeo-dsl (from versions: none)
ERROR: No matching distribution found for prometeo-dsl

The screenshot for the same:
image

Flexible BLAS and LAPACK interface

The current interface to BLAS and LAPACK routines should be made more flexible, in the sense that different levels of granularity should be accessible though the same method without adding unnecessary complexity to simple calls. Below is a draft signature for gemm suggested by @giaf:

gemm(A[1:2,1:2], B.T, C[3:4,1:2], D=None, alpha=1.0, beta=1.0) ,

where A, B, C and D can also be transposed through e.g. A.T and views are possible too, for example:

gemm(A[1:2,1:2], B.T, C[3:4,1:2], D, beta=2.0).

This is easily implementable in Python, but will require some work in prometeo's parser. In particular in the argument inspection here

for arg in args:
)

we'd need to do something like this:

nargs = len(args)

# extract keyword arguments
...

# check expression in views (if any) using https://github.com/zanellia/prometeo/blob/f45a6347ea524164cc812fad80c9db1f4f94e17f/prometeo/cgen/code_gen_c.py#L244

# extract and unparse views of matrix arguments (if any)
first_index = astu.unparse(node.targets[0].slice.value.elts[0]).strip('\n')
second_index = astu.unparse(node.targets[0].slice.value.elts[1]).strip('\n')

# check for transposition (look if arg has an attribute an if it is 'T')

# pass this info to a generic `process_arg()` method

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.