Skip to content
/ tadashi Public

A library for code transformations with guaranteed legality

Notifications You must be signed in to change notification settings

vatai/tadashi

Repository files navigation

Tadashi

Breaking changes in v0.2.0

Code generation is different. Code like this

scops.generate_code()

should be replace with code like this:

transformed_app = app.generate_code()

Now both the old app, and new transformed_app stay “alive”, i.e. the user can compile and measure both of them.

Documentation:

After the double blind review and the end of the anonymity requirement, detailed API documentation will be uploaded to https://tadashi.readthedocs.io/ (or a similar URL).

Until then these API docs can be downloaded (from the root dir of this repo) as:

  • tadashi.pdf (PDF)
  • apidocs.tgz (tgz-ed html)

Prerequisites

Compile Tadashi (as described below), and set the PYTHONPATH environment variable to point to the repository root.

Quick start

An end-to-end example is provided below (split into parts with comments and outputs). This example can be run from the repository root with the following command:

PYTHONPATH=. python examples/inputs/end2edn.py

End-to-end example

After importing Tadashi we obtain the loop nests (SCoPs) from a Simple app.

import tadashi
from tadashi.apps import Simple
app = Simple("examples/inputs/depnodep.c")
scops = tadashi.Scops(app)

Select a node and a transformation, and check that the transformation is available on the selected node.

node = scops[0].schedule_tree[1]
print(f"{node=}")
tr = tadashi.TrEnum.FULL_SHIFT_VAR
print(f"{tr in node.available_transformations=}")
# output:
node=Node type: NodeType.BAND, [{'params': ['N'], 'vars': ['j', 'i']}], [N] -> L_0[{ S_0[j, i] -> [(j)] }], [0]
tr in node.available_transformations=True

Check the available arguments for the given node-transformation pair.

print(f"{tr=}")
lu = node.available_args(tr)
print(f"{len(lu)=}")
print(f"{lu[0]=}")
print(f"{lu[1]=}")
# output:
tr=<TrEnum.FULL_SHIFT_VAR: 'full_shift_var'>
len(lu)=2
lu[0]=LowerUpperBound(lower=None, upper=None)
lu[1]=LowerUpperBound(lower=0, upper=2)

Perform the transformation and check legality.

args = [13, 1]
print(f"{node.valid_args(tr, *args)=}")
legal = node.transform(tr, *args)
print(f"{legal=}")
# output:
node.valid_args(tr, *args)=True
legal=True

Generate new code, compile it and measure the performance.

scops.generate_code()
app.compile()
print(f"{app.measure()=}")
# output:
app.measure()=22.0

Build instructions:

Before building, install LLVM and other (system) packages (check this file for an exact list of apt-get packages).

git clone --recursive https://github.com/vatai/tadashi.git
mkdir tadashi/build
cd tadashi/build
cmake ..
cmake --build .

Using Docker is also an option.