Skip to content

Commit

Permalink
add pyproject.toml (#50)
Browse files Browse the repository at this point in the history
* add toml

* implement xdsl config

* add newline

* make changes
  • Loading branch information
jorendumoulin authored Dec 22, 2023
1 parent 118075f commit 21871fb
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 47 deletions.
1 change: 1 addition & 0 deletions compiler/snax-opt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import sys

from tools.snax_opt_main import main

if __name__ == "__main__":
Expand Down
12 changes: 7 additions & 5 deletions compiler/tools/snax_opt_main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import argparse
from xdsl.xdsl_opt_main import xDSLOptMain
from collections.abc import Sequence

from xdsl.ir import MLContext
from xdsl.xdsl_opt_main import xDSLOptMain

from compiler.dialects.snax import Snax
from compiler.transforms.clear_memory_space import ClearMemorySpace
from compiler.transforms.dispatch_elementwise_mult import DispatchElementWiseMult
from compiler.transforms.dispatch_regions import DispatchRegions
from compiler.transforms.insert_sync_barrier import InsertSyncBarrier
from compiler.transforms.linalg_to_library_call import LinalgToLibraryCall
from compiler.transforms.set_memory_space import SetMemorySpace
from compiler.transforms.insert_sync_barrier import InsertSyncBarrier
from compiler.transforms.dispatch_regions import DispatchRegions
from compiler.transforms.snax_copy_to_dma import SNAXCopyToDMA
from compiler.transforms.snax_to_func import SNAXToFunc
from compiler.transforms.clear_memory_space import ClearMemorySpace
from collections.abc import Sequence


class SNAXOptMain(xDSLOptMain):
Expand Down
2 changes: 1 addition & 1 deletion compiler/transforms/clear_memory_space.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from xdsl.dialects import builtin, memref, func
from xdsl.dialects import builtin, func, memref
from xdsl.ir import MLContext
from xdsl.passes import ModulePass

Expand Down
6 changes: 3 additions & 3 deletions compiler/transforms/dispatch_elementwise_mult.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from xdsl.dialects import builtin, linalg, arith
from xdsl.dialects import arith, builtin, linalg
from xdsl.dialects.memref import MemRefType
from xdsl.ir import MLContext
from xdsl.passes import ModulePass
from xdsl.dialects.memref import MemRefType
from xdsl.pattern_rewriter import (
PatternRewriteWalker,
PatternRewriter,
PatternRewriteWalker,
RewritePattern,
op_type_rewrite_pattern,
)
Expand Down
9 changes: 5 additions & 4 deletions compiler/transforms/dispatch_regions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from collections.abc import Callable, Iterable

from xdsl.dialects import builtin, func, scf
from xdsl.ir.core import Operation, Block
from xdsl.ir import MLContext
from xdsl.ir import Block, MLContext, Operation
from xdsl.passes import ModulePass
from collections.abc import Iterable, Callable
from xdsl.pattern_rewriter import (
PatternRewriteWalker,
PatternRewriter,
PatternRewriteWalker,
RewritePattern,
op_type_rewrite_pattern,
)
from xdsl.traits import SymbolTable

from compiler.util.dispatching_rules import dispatch_to_compute, dispatch_to_dm


Expand Down
5 changes: 3 additions & 2 deletions compiler/transforms/insert_sync_barrier.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from xdsl.dialects import builtin
from compiler.dialects import snax
from xdsl.ir import MLContext
from xdsl.passes import ModulePass
from xdsl.pattern_rewriter import (
PatternRewriteWalker,
PatternRewriter,
PatternRewriteWalker,
RewritePattern,
op_type_rewrite_pattern,
)

from compiler.dialects import snax
from compiler.util.dispatching_rules import dispatch_to_compute, dispatch_to_dm


Expand Down
2 changes: 1 addition & 1 deletion compiler/transforms/linalg_to_library_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from xdsl.ir import MLContext
from xdsl.passes import ModulePass
from xdsl.pattern_rewriter import (
PatternRewriteWalker,
PatternRewriter,
PatternRewriteWalker,
RewritePattern,
op_type_rewrite_pattern,
)
Expand Down
9 changes: 4 additions & 5 deletions compiler/transforms/set_memory_space.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from xdsl.dialects import func, builtin, memref, linalg, arith
from xdsl.ir import MLContext
from xdsl.ir.core import SSAValue
from xdsl.dialects import arith, builtin, func, linalg, memref
from xdsl.ir import MLContext, SSAValue
from xdsl.passes import ModulePass
from xdsl.pattern_rewriter import (
RewritePattern,
PatternRewriter,
op_type_rewrite_pattern,
PatternRewriteWalker,
RewritePattern,
op_type_rewrite_pattern,
)


Expand Down
4 changes: 2 additions & 2 deletions compiler/transforms/snax_copy_to_dma.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from xdsl.dialects import builtin, func, memref, arith
from xdsl.dialects import arith, builtin, func, memref
from xdsl.ir import MLContext
from xdsl.passes import ModulePass
from xdsl.pattern_rewriter import (
PatternRewriteWalker,
PatternRewriter,
PatternRewriteWalker,
RewritePattern,
op_type_rewrite_pattern,
)
Expand Down
5 changes: 3 additions & 2 deletions compiler/transforms/snax_to_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from xdsl.ir import MLContext
from xdsl.passes import ModulePass
from xdsl.pattern_rewriter import (
PatternRewriteWalker,
PatternRewriter,
PatternRewriteWalker,
RewritePattern,
op_type_rewrite_pattern,
)
from compiler.dialects import snax
from xdsl.traits import SymbolTable

from compiler.dialects import snax


class InsertFunctionCall(RewritePattern):
@op_type_rewrite_pattern
Expand Down
2 changes: 1 addition & 1 deletion compiler/util/dispatching_rules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from xdsl.dialects import memref, linalg
from xdsl.dialects import linalg, memref


def dispatch_to_dm(op):
Expand Down
6 changes: 3 additions & 3 deletions kernels/simple_copy/gendata.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# simple script to generate inputs and expected outputs for simple_mult

import numpy as np
from numpy import typing as npt
from typing import Dict


def create_header(file_name: str, size: int, variables: Dict[str, npt.NDArray]) -> None:
def create_header(file_name: str, size: int, variables: dict[str, npt.NDArray]) -> None:
with open(file_name, "w") as f:
includes = ["#include <stdint.h>", "#pragma once", "", f"#define N {size}", ""]
includes = "\n".join(includes)
Expand All @@ -16,7 +16,7 @@ def create_header(file_name: str, size: int, variables: Dict[str, npt.NDArray])
f.write("\n")


def create_data(file_name: str, size: int, variables: Dict[str, npt.NDArray]):
def create_data(file_name: str, size: int, variables: dict[str, npt.NDArray]):
includes = ['#include "data.h"', "", ""]
includes = "\n".join(includes)
with open(file_name, "w") as f:
Expand Down
6 changes: 3 additions & 3 deletions kernels/simple_matmul/gendata.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# simple script to generate inputs and expected outputs for simple_matmult

import numpy as np
from numpy import typing as npt
from typing import Dict


def create_header(
file_name: str, sizes: Dict[str, int], variables: Dict[str, npt.NDArray]
file_name: str, sizes: dict[str, int], variables: dict[str, npt.NDArray]
) -> None:
with open(file_name, "w") as f:
includes = ["#include <stdint.h>", "#pragma once", ""]
Expand All @@ -22,7 +22,7 @@ def create_header(
f.write("\n")


def create_data(file_name: str, variables: Dict[str, npt.NDArray]):
def create_data(file_name: str, variables: dict[str, npt.NDArray]):
includes = ['#include "data.h"', "", ""]
includes = "\n".join(includes)
variables = {i: np.reshape(j, j.size) for i, j in variables.items()}
Expand Down
6 changes: 3 additions & 3 deletions kernels/simple_mult/gendata.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# simple script to generate inputs and expected outputs for simple_mult

import numpy as np
from numpy import typing as npt
from typing import Dict


def create_header(file_name: str, size: int, variables: Dict[str, npt.NDArray]) -> None:
def create_header(file_name: str, size: int, variables: dict[str, npt.NDArray]) -> None:
with open(file_name, "w") as f:
includes = ["#include <stdint.h>", "#pragma once", "", f"#define N {size}", ""]
includes = "\n".join(includes)
Expand All @@ -16,7 +16,7 @@ def create_header(file_name: str, size: int, variables: Dict[str, npt.NDArray])
f.write("\n")


def create_data(file_name: str, size: int, variables: Dict[str, npt.NDArray]):
def create_data(file_name: str, size: int, variables: dict[str, npt.NDArray]):
includes = ['#include "data.h"', "", ""]
includes = "\n".join(includes)
with open(file_name, "w") as f:
Expand Down
33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[tool.ruff]
select = ["E", "F", "W", "I", "UP", "PT", "TID251"]
ignore = [
"E741", # https://beta.ruff.rs/docs/rules/ambiguous-variable-name/
"PT006", # https://beta.ruff.rs/docs/rules/pytest-parametrize-names-wrong-type/
"PT007", # https://beta.ruff.rs/docs/rules/pytest-parametrize-values-wrong-type/
"PT011", # https://beta.ruff.rs/docs/rules/pytest-raises-too-broad/
"PT012", # https://beta.ruff.rs/docs/rules/pytest-raises-with-multiple-statements/
"PT015", # https://beta.ruff.rs/docs/rules/pytest-assert-always-false/
]
target-version = "py310"

[tool.ruff.flake8-tidy-imports.banned-api]
"xdsl.parser.core".msg = "Use xdsl.parser instead."
"xdsl.parser.attribute_parser".msg = "Use xdsl.parser instead."
"xdsl.parser.affine_parser".msg = "Use xdsl.parser instead."
"xdsl.ir.core".msg = "Use xdsl.ir instead."
"xdsl.irdl.irdl".msg = "Use xdsl.irdl instead"
"xdsl.ir.affine.affine_expr".msg = "Use xdsl.ir.affine instead"
"xdsl.ir.affine.affine_map".msg = "Use xdsl.ir.affine instead"
"xdsl.ir.affine.affine_set".msg = "Use xdsl.ir.affine instead"


[tool.ruff.per-file-ignores]
"__init__.py" = ["F403"]
"tests/filecheck/frontend/programs/invalid.py" = ["F811", "F841"]
"tests/filecheck/frontend/dialects/invalid.py" = ["F811"]
"tests/test_declarative_assembly_format.py" = ["F811"]
"versioneer.py" = ["ALL"]
"_version.py" = ["ALL"]

[tool.ruff.mccabe]
max-complexity = 10
12 changes: 6 additions & 6 deletions runtime/tollvm12.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# Courtesy of Federico Ficarelli

import argparse
import re
import sys
import argparse

PARSER = argparse.ArgumentParser(
prog="tollvm12.py",
Expand Down Expand Up @@ -47,11 +47,11 @@ def get_availale_metadata_id(ir):

if __name__ == "__main__":
args = PARSER.parse_args()
LLVM_TARGET_TRIPLE = re.compile('target\s+triple\s*=\s*".+"')
LLVM_TARGET_DATALAYOUT = re.compile('target\s+datalayout\s*=\s*".+"')
LLVM_NAMED_METADATA = re.compile("!(\d+)\s*=\s*!")
LLVM_MODULE_FLAGS = re.compile("!llvm\.module\.flags\s*=\s*.+")
LLVM_ATTR_SIDEEFFECT = re.compile("memory\(.*\)")
LLVM_TARGET_TRIPLE = re.compile(r'target\s+triple\s*=\s*".+"')
LLVM_TARGET_DATALAYOUT = re.compile(r'target\s+datalayout\s*=\s*".+"')
LLVM_NAMED_METADATA = re.compile(r"!(\d+)\s*=\s*!")
LLVM_MODULE_FLAGS = re.compile(r"!llvm\.module\.flags\s*=\s*.+")
LLVM_ATTR_SIDEEFFECT = re.compile(r"memory\(.*\)")
ir = sys.stdin.read()
# Remove offending stuff:
ir = re.sub(LLVM_TARGET_TRIPLE, "", ir)
Expand Down
5 changes: 2 additions & 3 deletions runtime/tomlir16.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
""" Convert an MLIR18 file to MLIR16
This program performs the following conversion steps:
* take properties enclosed in <{}> and make them attributes:
change enclosing to {} and move them to come after the
change enclosing to {} and move them to come after the
region of the operation
* change operandSegmentSizes to operand_segment_sizes
* remove double quotes from attribute names
* remove double quotes from attribute names
"""

import re
import sys


if __name__ == "__main__":
ir = sys.stdin.read()

Expand Down
3 changes: 1 addition & 2 deletions runtime/tomlir18.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
""" Convert an MLIR18 file to MLIR16
This program performs the following conversion steps:
* change operand_segment_sizes to operandSegmentSizes
* add double quotes to attribute names
* add double quotes to attribute names
"""

import re
import sys


if __name__ == "__main__":
ir = sys.stdin.read()
# add quotes
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup

setup(
name="compiler",
Expand Down

0 comments on commit 21871fb

Please sign in to comment.