-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the boiler plate and basic rtgtool with a minimal example to run.
- Loading branch information
Showing
14 changed files
with
610 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
# /src/circt created via | ||
# `ln -s <build dir>/tools/circt/python_packages/pyrtg/pyrtg/circt frontends/PyRTG/src/circt` | ||
# to help PyRTG devs with code completion. | ||
/src/pyrtg/circt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# ===- CMakeLists.txt - PyRTG top level cmake -----------------*- cmake -*-===// | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ===----------------------------------------------------------------------===// | ||
|
||
llvm_canonicalize_cmake_booleans( | ||
CIRCT_BINDINGS_PYTHON_ENABLED | ||
) | ||
|
||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) | ||
message(FATAL_ERROR "PyRTG cannot be built as separate project") | ||
endif() | ||
|
||
if (NOT CIRCT_BINDINGS_PYTHON_ENABLED) | ||
message(FATAL_ERROR "PyRTG requires that CIRCT python bindings be enabled") | ||
endif() | ||
|
||
add_subdirectory(src) | ||
add_subdirectory(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[build-system] | ||
requires = [ | ||
"setuptools>=68", | ||
"setuptools_scm>=8.0", | ||
"wheel", | ||
"cmake>=3.12", | ||
|
||
# MLIR build depends. | ||
"numpy", | ||
"pybind11>=2.11,<=2.12", | ||
"nanobind==2.4.0", | ||
"PyYAML", | ||
|
||
# PyRTG depends | ||
] | ||
build-backend = "setuptools.build_meta" | ||
|
||
# Enable version inference from Git. | ||
[tool.setuptools_scm] | ||
root = "../.." | ||
tag_regex = "^pyrtg-(\\d+\\.\\d+\\.\\d+)?$" | ||
local_scheme = "no-local-version" | ||
git_describe_command = "git describe --dirty --tags --long --match pyrtg*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# ===- CMakeLists.txt - PyRTG sources -------------------------*- cmake -*-===// | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ===----------------------------------------------------------------------===// | ||
|
||
include(AddMLIRPython) | ||
|
||
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=pyrtg.circt.") | ||
|
||
declare_mlir_python_sources(PyRTGSources | ||
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" | ||
SOURCES | ||
pyrtg/__init__.py | ||
pyrtg/tests.py | ||
rtgtool/rtgtool.py | ||
) | ||
|
||
################################################################################ | ||
# Build composite binaries | ||
################################################################################ | ||
|
||
set(PYRTG_PYTHON_PACKAGE_DIR "${CIRCT_PYTHON_PACKAGES_DIR}/pyrtg/") | ||
|
||
# Bundle our own, self-contained CAPI library with all of our deps. | ||
add_mlir_python_common_capi_library(PyRTG_CIRCTPythonCAPI | ||
INSTALL_COMPONENT CIRCTBindingsPythonModules | ||
INSTALL_DESTINATION python_packages/pyrtg/circt/_mlir_libs | ||
OUTPUT_DIRECTORY "${PYRTG_PYTHON_PACKAGE_DIR}/pyrtg/circt/_mlir_libs" | ||
RELATIVE_INSTALL_ROOT "../../.." | ||
DECLARED_SOURCES | ||
MLIRPythonSources.Core | ||
CIRCTBindingsPythonExtension | ||
) | ||
|
||
add_mlir_python_modules(PyRTG_CIRCTPythonModules | ||
ROOT_PREFIX "${PYRTG_PYTHON_PACKAGE_DIR}/pyrtg/circt" | ||
INSTALL_PREFIX "python_packages/pyrtg/circt" | ||
DECLARED_SOURCES | ||
MLIRPythonSources.Core | ||
CIRCTBindingsPythonExtension | ||
CIRCTBindingsPythonSources | ||
COMMON_CAPI_LINK_LIBS | ||
PyRTG_CIRCTPythonCAPI | ||
) | ||
|
||
add_mlir_python_modules(PyRTG | ||
ROOT_PREFIX "${PYRTG_PYTHON_PACKAGE_DIR}/" | ||
INSTALL_PREFIX "python_packages/" | ||
DECLARED_SOURCES | ||
PyRTGSources | ||
COMMON_CAPI_LINK_LIBS | ||
PyRTG_CIRCTPythonCAPI | ||
) | ||
|
||
install(TARGETS PyRTG_CIRCTPythonCAPI | ||
DESTINATION python_packages/pyrtg/circt/_mlir_libs | ||
RUNTIME_DEPENDENCIES | ||
PRE_EXCLUDE_REGEXES ".*" | ||
PRE_INCLUDE_REGEXES ".*zlib.*" | ||
COMPONENT PyRTG | ||
) | ||
add_dependencies(PyRTG PyRTG_CIRCTPythonModules) | ||
add_dependencies(install-PyRTG install-PyRTG_CIRCTPythonModules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
from . import circt | ||
from . import tests | ||
from .tests import test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
import inspect | ||
|
||
from .circt import ir | ||
from .circt.dialects import rtg | ||
|
||
|
||
class Test: | ||
""" | ||
Represents an RTG Test. Stores the test function and location. | ||
""" | ||
|
||
type: ir.Type | ||
|
||
def __init__(self, test_func): | ||
self.test_func = test_func | ||
|
||
sig = inspect.signature(test_func) | ||
assert len(sig.parameters) == 0, "test arguments not supported yet" | ||
|
||
self.type = rtg.DictType.get(None, []) | ||
|
||
@property | ||
def name(self) -> str: | ||
return self.test_func.__name__ | ||
|
||
def codegen(self): | ||
test = rtg.TestOp(self.name, ir.TypeAttr.get(self.type)) | ||
block = ir.Block.create_at_start(test.bodyRegion, []) | ||
with ir.InsertionPoint(block): | ||
self.test_func(*block.arguments) | ||
|
||
|
||
def test(func): | ||
""" | ||
Decorator for RTG test functions. | ||
""" | ||
|
||
return Test(func) |
Oops, something went wrong.