Giter Club home page Giter Club logo

numba-rvsdg's Introduction

Numba

Gitter

Discourse

Zenodo DOI

PyPI

A Just-In-Time Compiler for Numerical Functions in Python

Numba is an open source, NumPy-aware optimizing compiler for Python sponsored by Anaconda, Inc. It uses the LLVM compiler project to generate machine code from Python syntax.

Numba can compile a large subset of numerically-focused Python, including many NumPy functions. Additionally, Numba has support for automatic parallelization of loops, generation of GPU-accelerated code, and creation of ufuncs and C callbacks.

For more information about Numba, see the Numba homepage: https://numba.pydata.org and the online documentation: https://numba.readthedocs.io/en/stable/index.html

Installation

Please follow the instructions:

https://numba.readthedocs.io/en/stable/user/installing.html

Demo

Please have a look and the demo notebooks via the mybinder service:

https://mybinder.org/v2/gh/numba/numba-examples/master?filepath=notebooks

Contact

Numba has a discourse forum for discussions:

numba-rvsdg's People

Contributors

apmasell avatar esc avatar guilhermeleobas avatar kc611 avatar sklam avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

numba-rvsdg's Issues

Refactor: Make `jump_target` a property of SCFG

The attribute jump_target of BasicBlock class is mutated over the course of various transformations, this leads to the blocks being rebuilt and the SCFG being deep copied every time a transformation is applied.

It should be made a mutable property of the SCFG class instead of an immutable property of the BasicBlock frozen data class. This will prevent unnecessary copies.

Refactor: Remove `ByteFlow` and `FlowInfo` classes.

As titled,

The ByteFlow and FlowInfo classes can be removed to reduce complexity. All of the methods of the classes can either be made part of the SCFG object or can be made into a function rather than a part of the class.

Feature request: Data structure to hide details of graph rendering

Graph rendering code can be messy. Sometimes we need viz-backend specific logic. It's also hard to test.

The suggestion is to add a AbstractDataType for hiding the details of graph rendering. All it needs is really a set of nodes, edges and node grouping for regions.

Sample implementation in: https://github.com/numba/numba/blob/edfc1b95bf633abb346fbbe265acf2bb20560a6e/numba/core/frontend2/regionrenderer.py#L56

Such a class will also allow us to exercise graph rendering in tests. For instance, the sample implementation has a .verify() method to ensure the graph is wellformed; e.g. edges points to existing locations.

This ADT will allow backend specific code to be isolated: https://github.com/numba/numba/blob/edfc1b95bf633abb346fbbe265acf2bb20560a6e/numba/core/frontend2/regionrenderer.py#L127
Testing for this will be hard to automate but now it's contained in one place without mixing with other logic.

Add `conda` package building to `release.yml`

Currently the release.yml only produces sdist and wheel artifacts. As part of the release process, as a developer, I also want this workflow to produce conda packages. They should be built and uploaded to the GitHub release in addition to the PyPi generated packages.

Remove for-loop concept from transformation

synth_for_iter = SyntheticForIter(str(bbmap.clg.new_index()))

To stay pure and faithful to the original paper, i'd suggest removing the SyntheticForIter. As mentioned in OOB discussion, the transformation should be able to operate base on a interface of:

class OpIFace:
    def is_jump(self) -> bool: ...
    def get_jump_targets(self)  -> Tuple[Label]: ...

If the FOR_ITER bytecode is doing too much, i suggest preprocessing it into synthetic small operations before the rvsdg transform.

Triage: potential bug

Screen Shot 2023-06-22 at 08 59 42

The code here should probably read _jump_targets. The `jump_targets are the "discounted" targets, i.e. w/o the backedges. Thus, if a block has only a single backedge, under this code it would also be considered an "exiting" block. However, exiting blocks are blocks that contain a return statement or equivalent and basically denote the termination block of a program.

Feature request: RegionVisitor and RegionTransformer

Sample implementation used in Numba RVSDG frontend: https://github.com/numba/numba/blob/edfc1b95bf633abb346fbbe265acf2bb20560a6e/numba/core/frontend2/regionpasses.py

RegionVisitor and RegionTransformers enables a hierarchical thinking for compiler pass implementation. This simplifies compiler passes to just 3 abstract methods:

  • visit_block(): handle a purely data-dependence block in RVSDG.
  • visit_loop(): handle a loop region.
  • visit_switch(): handle a switch region.

Feature Request: better rendering

As a numba-rvsdg user and as a developer, I want to be able to view an SCFG both from the terminal.

The proposed API should perhaps look like:

scfg.view()

And then, if we are in an IPython notebook environment render the SCFG inside the notebook and if we are in a Python or IPython terminal session, attempt to render the SCFG to a PDF files and open it in an existing viewer.

Multi-header assertion error

This is a variant on the SCC algorithm, mainly the yield statement are replaced: https://gist.github.com/sklam/dbe21c6df5b882bc41a27ff3e6cf79a0

Error:

Traceback (most recent call last):
  File "/path/to/numba-rvsdg/test_fig_scc.py", line 72, in <module>
    lflow = cflow._restructure_loop()
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/numba-rvsdg/byteflow2.py", line 637, in _restructure_loop
    restructure_loop(region.subregion)
  File "/path/to/numba-rvsdg/byteflow2.py", line 928, in restructure_loop
    extract_region(bbmap, loop, "loop")
  File "/path/to/numba-rvsdg/byteflow2.py", line 1002, in extract_region
    assert len(headers) == 1
AssertionError

Feature Request: add region testing to YAML

Currently, only the block structure is part of the YAML representation, this means the Regions and their placement can not be tested effectively. As a numba developer I want to be able to test loop_restructure and branch_restructure effectively and for this I will need to be able to encode the expected result, including regions, in a simple YAML syntax.

Then -- once this syntax is established -- all the existing tests need to be refactored such that region testing is added to them.

Incorrect restructuring of multi-head loop

From DEBUGGRAPH=1 pytest numba_rvsdg/tests/test_mock_asm.py::test_mock_scfg_fuzzer_case9 in #42.

CFG:

Screenshot 2023-04-18 at 4 24 11 PM

Loop restructured:

Screenshot 2023-04-18 at 4 24 50 PM

The loop should switch between offset 4 and offset 6 blocks but there are no assignment to control-variable a within the loop.

Code assume conditional-branch cannot go to the same target

From DEBUGGRAPH=1 pytest numba_rvsdg/tests/test_mock_asm.py::test_mock_scfg_fuzzer_case146 in #42

CFG:

Screenshot 2023-04-18 at 5 34 37 PM

Traceback:

    def test_mock_scfg_fuzzer_case146():
>       run_fuzzer(seed=146)

numba_rvsdg/tests/test_mock_asm.py:611:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
numba_rvsdg/tests/test_mock_asm.py:562: in run_fuzzer
    compare_simulated_scfg(asm)
numba_rvsdg/tests/test_mock_asm.py:442: in compare_simulated_scfg
    scfg = to_scfg(instlist)
numba_rvsdg/tests/test_mock_asm.py:312: in to_scfg
    restructure_loop(scfg)
numba_rvsdg/core/transformations.py:228: in restructure_loop
    loop_restructure_helper(bbmap, loop)
numba_rvsdg/core/transformations.py:165: in loop_restructure_helper
    bbmap.add_block(block.replace_jump_targets(jump_targets=tuple(jts)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = BranchBlock(label=SyntheticHead(index='8'), _jump_targets=(MockAsmLabel(index='2'), MockAsmLabel(index='1')), backedges=set(), variable='a', branch_value_table={0: MockAsmLabel(index='1'), 1: MockAsmLabel(index='2')})
jump_targets = ()

    def replace_jump_targets(self, jump_targets: Tuple) -> "BasicBlock":
        fallthrough = len(jump_targets) == 1
        old_branch_value_table = self.branch_value_table
        new_branch_value_table = {}
        for target in self.jump_targets:
            if target not in jump_targets:
                # ASSUMPTION: only one jump_target is being updated
                diff = set(jump_targets).difference(self.jump_targets)
>               assert len(diff) == 1
E               AssertionError

numba_rvsdg/core/datastructures/basic_block.py:94: AssertionError

Include package building in `test.yml` workflow.

The test.yaml workflow only tests the installation via pip and tests the software. As a developer I would like to see inclusion of testing the package building too to make sure that none of my PRs break packaging. The idea is to try to build a sdist and wheel for PyPi and a noarch package using conda and to check that these packages are sane, i.e. they can be installed and the included tests can be run successfully.

Unifying RETURN_VALUE bytecode

The RETURN_VALUE bytecode is not unified by when SCFG join returns. This leads to SCFG that semantically terminates in the middle of switches.

For example:

import dis
from numba_rvsdg.core.datastructures.scfg import SCFG
from numba_rvsdg.core.datastructures.byte_flow import ByteFlow

def example(x):
    if x:
        return 1
    else:
        return 2


dis.dis(example)

bf = ByteFlow.from_bytecode(example).restructure()
bf.scfg.view()

The bytecode is:

  5           0 RESUME                   0

  6           2 LOAD_FAST                0 (x)
              4 POP_JUMP_FORWARD_IF_FALSE     2 (to 10)

  7           6 LOAD_CONST               1 (1)
              8 RETURN_VALUE

  9     >>   10 LOAD_CONST               2 (2)
             12 RETURN_VALUE

The SCFG
Screenshot 2023-07-31 at 6 28 27 PM

Notice that both "branch" regions contain a RETURN_VALUE.

I have two workarounds at sklam/numba@c9d3634:

Update - Aug 4

I have a new workaround that solely addresses the problem in RVSDG->NumbaIR (bcinterp.py) at numba/numba@a117aae. It relies on interpreting RETURN_VALUE as non terminating.

release.yml is broken

When attempting to release 0.0.3 it turned out that when pushing the tag, the release.yml workflow didn't trigger. The assumption is that this didn't work because the regex looks for a tag with v prefix. During testing this was found to not make a difference, but it seems like either that discovery was erroneous or that something has changed in the meantime. For the 0.0.4 release an experimental fix has been included:

4284250

Branch transformation creates invalid edge

See images below. Loop block has edge violating the region structures.

Reproducer 1

YAML:

"mock_block_0":
    jt: ["mock_block_2", "mock_block_10"]
"mock_block_2":
    jt: ["mock_block_5", "mock_block_11"]
"mock_block_5":
    jt: ["mock_block_10", "mock_block_5"]
"mock_block_10":
    jt: ["mock_block_11"]
"mock_block_11":
    jt: []

original graph:
Screenshot 2023-06-23 at 10 50 17 AM
section of transformed graph showing the bad edge:
Screenshot 2023-06-23 at 10 49 59 AM

Reproducer 2

YAML:

"mock_block_0":
    jt: ["mock_block_11", "mock_block_2"]
"mock_block_1":
    jt: ["mock_block_7", "mock_block_6"]
"mock_block_2":
    jt: ["mock_block_3"]
"mock_block_3":
    jt: ["mock_block_4"]
"mock_block_4":
    jt: ["mock_block_5"]
"mock_block_5":
    jt: ["mock_block_4", "mock_block_1"]
"mock_block_6":
    jt: ["mock_block_18", "mock_block_5"]
"mock_block_7":
    jt: ["mock_block_10", "mock_block_8"]
"mock_block_8":
    jt: ["mock_block_5", "mock_block_11"]
"mock_block_9":
    jt: ["mock_block_3", "mock_block_12"]
"mock_block_10":
    jt: ["mock_block_10", "mock_block_6"]
"mock_block_11":
    jt: ["mock_block_12"]
"mock_block_12":
    jt: ["mock_block_15", "mock_block_17"]
"mock_block_15":
    jt: ["mock_block_9", "mock_block_17"]
"mock_block_17":
    jt: ["mock_block_18"]
"mock_block_18":
    jt: []

section of transformed graph showing the bad edge:
Screenshot 2023-06-23 at 10 43 24 AM

Feature Request: conda packages

As a developer I will need conda packages for numba-rvsdg such that it can be included in Numba as a dependency. Otherwise people installing numba via conda will not be able to resolve the dependency chain. Ideally these can be produced on uploading tags for stable release and on merged to main as nightly builds. They should arrive on the numba/label/main channel and numba/label/dev respectively.

Ref: numba/numba#9043

Write demonstrator of Python bytecode โ†’ Python AST

From #80 (comment), I noticed that it's possible to make RVSDG from Python bytecode already. (I hadn't been paying close attention to all the progress that was being made here, but I just noticed it now.)

This is a note to myself (which I will assign to myself) to write a demonstrator of Python bytecode โ†’ Python AST, at least for a subset of simple expressions, to get a sense of how it will go. I understand that the RVSDG development is very much in flux and that the demonstrator will get out of date quickly, but it would be good for me to do a first test-run, to get familiar with RVSDG as a concept and discover what the fundamental issues are.

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.