From 41a94a7800cb5149f659db67dcba4761bd2c031e Mon Sep 17 00:00:00 2001 From: max Date: Mon, 11 Dec 2023 16:55:26 -0600 Subject: [PATCH] refactor aiecc and python --- CMakeLists.txt | 23 +- python/CMakeLists.txt | 56 +++- python/compiler/CMakeLists.txt | 17 -- {tools/aiecc => python/compiler}/aiecc.py | 0 .../compiler}/aiecc/configure.py.in | 12 +- python/dialects/aie.py | 2 +- .../extras => extras/dialects}/__init__.py | 0 .../extras => extras/dialects}/arith.py | 19 +- python/extras/dialects/func.py | 249 ++++++++++++++++++ .../extras => extras/dialects}/memref.py | 4 +- python/extras/meta.py | 179 +++++++++++++ python/{ => extras}/util.py | 10 +- reference_designs/CMakeLists.txt | 6 +- .../code_hdiff.py | 5 - .../gen_hdiff_cpp.py | 6 - .../gen_hdiff_mlir.py | 6 - .../ipu-xrt/add_one_objFifo/aie2.py | 9 +- .../log_hello_world/elfStringParser.py | 4 +- .../ipu-xrt/log_hello_world/hello_world.py | 7 +- .../ipu-xrt/matrix_multiplication/aie2.py | 8 +- .../ipu-xrt/passthrough_hardware/aie2.py | 9 +- .../ipu-xrt/vector_scalar/aie2.py | 7 +- .../color_threshold/aie2_colorThreshold.py | 8 +- .../edge_detect/aie2_edgeDetect.py | 8 +- .../vision_pipelines/passthrough/aie2.py | 8 +- reference_designs/lit.cfg.py | 5 - .../prime_sieve_large/code_gen.py | 7 +- test/CMakeLists.txt | 4 +- test/python/aie_ops.py | 4 +- test/python/aiex_ops.py | 2 +- test/python/core_ext_kernel.py | 2 +- test/python/ipu.py | 2 +- test/python/objFifo.py | 2 +- test/python/python_passes.py | 2 +- test/python/simple_with_bindings.py | 2 +- test/python/tosa_aievec.py | 108 +++++--- tools/CMakeLists.txt | 1 - tools/aiecc/CMakeLists.txt | 73 ----- tutorials/CMakeLists.txt | 2 +- tutorials/lit.cfg.py | 6 +- 40 files changed, 619 insertions(+), 265 deletions(-) delete mode 100644 python/compiler/CMakeLists.txt rename {tools/aiecc => python/compiler}/aiecc.py (100%) mode change 100644 => 100755 rename {tools/aiecc => python/compiler}/aiecc/configure.py.in (56%) rename python/{dialects/extras => extras/dialects}/__init__.py (100%) rename python/{dialects/extras => extras/dialects}/arith.py (80%) create mode 100644 python/extras/dialects/func.py rename python/{dialects/extras => extras/dialects}/memref.py (97%) create mode 100644 python/extras/meta.py rename python/{ => extras}/util.py (98%) delete mode 100644 tools/aiecc/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d896dbb42e..6525912042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(AIE_TOOLS_BINARY_DIR ${AIE_BINARY_DIR}/bin) +set(AIE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) find_package(Vitis 2023.2 COMPONENTS AIE AIE2) configure_file(./utils/vitisVariables.config.in @@ -139,13 +140,27 @@ include_directories(${PROJECT_SOURCE_DIR}/include) include_directories(${PROJECT_BINARY_DIR}/include) add_definitions(${LLVM_DEFINITIONS}) - cmake_dependent_option(AIE_ENABLE_BINDINGS_PYTHON "Enables building of Python bindings." ON "MLIR_ENABLE_BINDINGS_PYTHON" OFF) cmake_dependent_option(AIE_ENABLE_PYTHON_PASSES "Enables building of passes that connect to python." ON "AIE_ENABLE_BINDINGS_PYTHON;LLVM_ENABLE_RTTI" OFF) +cmake_dependent_option(AIECC_COMPILE + "Set aiecc to compile." ON "NOT AIE_COMPILER STREQUAL NONE" OFF) + +cmake_dependent_option(AIECC_LINK + "Set aiecc to link." ON "NOT AIE_LINKER STREQUAL NONE" OFF) + +cmake_dependent_option(AIECC_HOST_COMPILE + "Set aiecc to host compile." ON "NOT HOST_COMPILER STREQUAL NONE" OFF) + +cmake_dependent_option(AIECC_COMPILE_WITH_XCHESSCC + "Set aiecc to compile with chess." ON "AIECC_COMPILE;AIE_COMPILER STREQUAL XCHESSCC" OFF) + +cmake_dependent_option(AIECC_LINK_WITH_XCHESSCC + "Set aiecc to link with chess." ON "AIECC_LINK;AIE_LINKER STREQUAL XCHESSCC" OFF) + add_flag_if_supported("-Werror=sign-compare" WERROR_SIGN_COMPARE) @@ -198,11 +213,7 @@ if(AIE_ENABLE_BINDINGS_PYTHON) mlir_configure_python_dev_packages() if(NOT AIE_PYTHON_PACKAGES_DIR) - set(AIE_PYTHON_PACKAGES_DIR "${CMAKE_CURRENT_BINARY_DIR}/python") - endif() - - if(NOT AIE_PYTHON_INSTALL_DIR) - set(AIE_PYTHON_INSTALL_DIR "python") + set(AIE_PYTHON_PACKAGES_DIR "${AIE_BINARY_DIR}/python") endif() endif() diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index d55dd2bc53..6ef04a0be7 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -3,11 +3,6 @@ include(AddMLIRPython) -# The directory at which the Python import tree begins. -# See documentation for `declare_mlir_python_sources`'s ROOT_DIR -# argument. -set(AIE_PYTHON_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - # The AIE copy of the MLIR bindings is in the `aie.mlir` namespace. add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=aie.") @@ -16,7 +11,7 @@ add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=aie.") ################################################################################ declare_mlir_python_sources(AIEPythonSources - ROOT_DIR "${AIE_PYTHON_ROOT_DIR}" + ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ) declare_mlir_python_sources(AIEPythonExtensions) @@ -27,28 +22,53 @@ declare_mlir_python_sources(AIEPythonSources.Dialects declare_mlir_dialect_python_bindings( ADD_TO_PARENT AIEPythonSources.Dialects - ROOT_DIR "${AIE_PYTHON_ROOT_DIR}" + ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" TD_FILE dialects/AIEBinding.td SOURCES dialects/aie.py - dialects/extras/__init__.py - dialects/extras/arith.py - dialects/extras/memref.py - util.py DIALECT_NAME AIE GEN_ENUM_BINDINGS_TD_FILE "dialects/AIEBinding.td" ) +declare_mlir_python_sources(AIEPythonSources.Extras + ADD_TO_PARENT AIEPythonSources + SOURCES + extras/meta.py + extras/util.py +) + +declare_mlir_python_sources(AIEPythonSources.DialectExtras + ADD_TO_PARENT AIEPythonSources + SOURCES_GLOB + extras/dialects/*.py + extras/dialects/**/*.py +) + declare_mlir_dialect_python_bindings( ADD_TO_PARENT AIEPythonSources.Dialects - ROOT_DIR "${AIE_PYTHON_ROOT_DIR}" + ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" TD_FILE dialects/AIEXBinding.td SOURCES dialects/aiex.py DIALECT_NAME AIEX ) +configure_file(compiler/aiecc/configure.py.in aie/compiler/aiecc/configure.py) +add_custom_target(aiecc_configure + ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/aie/compiler/aiecc/configure.py" +) + +# Note that compiler/ is not globbed but compiler/aiecc/ +# this is so that compiler/aiecc.py does not get distributed +# through this dir but actually through bin (see all the way at the bottom of this file) +declare_mlir_python_sources(AIEPythonSources.Compiler + ADD_TO_PARENT AIEPythonSources + SOURCES_GLOB + compiler/aiecc/*.py +) +add_dependencies(AIEPythonSources.Compiler aiecc_configure) + ################################################################################ # Extensions ################################################################################ @@ -258,5 +278,13 @@ foreach(r ${_runtimes}) ) endforeach() -add_subdirectory(compiler) -add_dependencies(AIEPythonModules AIECompilerPythonModules) +# during build +add_custom_command( + TARGET AIEPythonModules PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/compiler/aiecc.py + ${CMAKE_BINARY_DIR}/bin +) +# during install +install(PROGRAMS compiler/aiecc.py DESTINATION bin) + diff --git a/python/compiler/CMakeLists.txt b/python/compiler/CMakeLists.txt deleted file mode 100644 index 15e8090218..0000000000 --- a/python/compiler/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -declare_mlir_python_sources(AIECompilerPythonSources) - -declare_mlir_python_sources(AIECompilerPythonSources.Core - ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" - ADD_TO_PARENT AIECompilerPythonSources - SOURCES_GLOB - aiecc/*.py -) - -add_mlir_python_modules(AIECompilerPythonModules - ROOT_PREFIX "${AIE_PYTHON_PACKAGES_DIR}/aie/compiler" - INSTALL_PREFIX "${AIE_PYTHON_INSTALL_DIR}/aie/compiler" - DECLARED_SOURCES AIECompilerPythonSources -) diff --git a/tools/aiecc/aiecc.py b/python/compiler/aiecc.py old mode 100644 new mode 100755 similarity index 100% rename from tools/aiecc/aiecc.py rename to python/compiler/aiecc.py diff --git a/tools/aiecc/aiecc/configure.py.in b/python/compiler/aiecc/configure.py.in similarity index 56% rename from tools/aiecc/aiecc/configure.py.in rename to python/compiler/aiecc/configure.py.in index ec66aec71a..3ac3625f13 100644 --- a/tools/aiecc/aiecc/configure.py.in +++ b/python/compiler/aiecc/configure.py.in @@ -7,12 +7,14 @@ import os -aie_link_with_xchesscc = @CONFIG_LINK_WITH_XCHESSCC@ -aie_compile_with_xchesscc = @CONFIG_COMPILE_WITH_XCHESSCC@ -aie_disable_link = @CONFIG_DISABLE_LINK@ -aie_disable_compile = @CONFIG_DISABLE_COMPILE@ +from aie.extras.util import pythonize_bool + +aie_link_with_xchesscc = pythonize_bool("@AIECC_LINK_WITH_XCHESSCC@") +aie_compile_with_xchesscc = pythonize_bool("@AIECC_COMPILE_WITH_XCHESSCC@") +aie_disable_link = not pythonize_bool("@AIECC_LINK@") +aie_disable_compile = not pythonize_bool("@AIECC_COMPILE@") aie_unified_compile = True -host_disable_compile = @CONFIG_DISABLE_HOST_COMPILE@ +host_disable_compile = not pythonize_bool("@AIECC_HOST_COMPILE@") host_architecture = "@LLVM_HOST_TRIPLE@" def install_path(): diff --git a/python/dialects/aie.py b/python/dialects/aie.py index 7a0c8d5f8a..3a7f0839a4 100644 --- a/python/dialects/aie.py +++ b/python/dialects/aie.py @@ -8,7 +8,7 @@ from ._AIE_enum_gen import * from ._AIE_ops_gen import * -from .extras.arith import constant +from ..extras.dialects.arith import constant from .func import CallOp, FuncOp from .._mlir_libs import get_dialect_registry from .._mlir_libs._aie import * diff --git a/python/dialects/extras/__init__.py b/python/extras/dialects/__init__.py similarity index 100% rename from python/dialects/extras/__init__.py rename to python/extras/dialects/__init__.py diff --git a/python/dialects/extras/arith.py b/python/extras/dialects/arith.py similarity index 80% rename from python/dialects/extras/arith.py rename to python/extras/dialects/arith.py index db270135b6..8d224b2bfb 100644 --- a/python/dialects/extras/arith.py +++ b/python/extras/dialects/arith.py @@ -1,9 +1,11 @@ -import numpy as np -from typing import Union, Optional +from typing import Optional -from ..arith import * -from .. import complex -from ..linalg.opdsl.lang.emitter import ( +from ..meta import get_user_code_loc +from ..util import infer_mlir_type, mlir_type_to_np_dtype +from ...dialects import arith as arith_dialect +from ...dialects import complex as complex_dialect +from ...dialects.arith import * +from ...dialects.linalg.opdsl.lang.emitter import ( _is_floating_point_type, _is_complex_type, ) @@ -17,7 +19,6 @@ Type, Value, ) -from ...util import infer_mlir_type def constant( @@ -42,6 +43,8 @@ def constant( Returns: ir.OpView instance that corresponds to instantiated arith.constant op. """ + if loc is None: + loc = get_user_code_loc() if index is not None and index: type = IndexType.get() if type is None: @@ -51,7 +54,7 @@ def constant( if _is_complex_type(type): value = complex(value) - return complex.ConstantOp( + return complex_dialect.constant( type, list( map( @@ -80,4 +83,4 @@ def constant( type=type, ) - return ConstantOp(type, value, loc=loc, ip=ip) + return arith_dialect.ConstantOp(type, value, loc=loc, ip=ip).result diff --git a/python/extras/dialects/func.py b/python/extras/dialects/func.py new file mode 100644 index 0000000000..d815747782 --- /dev/null +++ b/python/extras/dialects/func.py @@ -0,0 +1,249 @@ +import inspect +import sys +from typing import Union, Optional + +from ..meta import make_maybe_no_args_decorator, op_region_builder, get_user_code_loc +from ...dialects.func import FuncOp, ReturnOp, CallOp +from ...ir import ( + InsertionPoint, + FunctionType, + StringAttr, + TypeAttr, + FlatSymbolRefAttr, + Type, + Value, +) + + +def call( + callee_or_results: Union[FuncOp, list[Type]], + arguments_or_callee: Union[list[Value], FlatSymbolRefAttr, str], + arguments: Optional[list] = None, + *, + call_op_ctor=CallOp.__base__, + loc=None, + ip=None, +): + if loc is None: + loc = get_user_code_loc() + if isinstance(callee_or_results, FuncOp.__base__): + if not isinstance(arguments_or_callee, (list, tuple)): + raise ValueError( + "when constructing a call to a function, expected " + + "the second argument to be a list of call arguments, " + + f"got {type(arguments_or_callee)}" + ) + if arguments is not None: + raise ValueError( + "unexpected third argument when constructing a call" + "to a function" + ) + return call_op_ctor( + callee_or_results.function_type.value.results, + FlatSymbolRefAttr.get(callee_or_results.sym_name.value), + arguments_or_callee, + loc=loc, + ip=ip, + ) + + if isinstance(arguments_or_callee, list): + raise ValueError( + "when constructing a call to a function by name, " + + "expected the second argument to be a string or a " + + f"FlatSymbolRefAttr, got {type(arguments_or_callee)}" + ) + + if isinstance(arguments_or_callee, FlatSymbolRefAttr): + return call_op_ctor( + callee_or_results, arguments_or_callee, arguments, loc=loc, ip=ip + ) + elif isinstance(arguments_or_callee, str): + return call_op_ctor( + callee_or_results, + FlatSymbolRefAttr.get(arguments_or_callee), + arguments, + loc=loc, + ip=ip, + ) + else: + raise ValueError(f"unexpected type {callee_or_results=}") + + +def prep_func_types(sig, return_types): + assert not ( + not sig.return_annotation is inspect.Signature.empty and len(return_types) > 0 + ), f"func can use return annotation or explicit return_types but not both" + return_types = ( + sig.return_annotation + if not sig.return_annotation is inspect.Signature.empty + else return_types + ) + if not isinstance(return_types, (tuple, list)): + return_types = [return_types] + return_types = list(return_types) + assert all( + isinstance(r, Type) for r in return_types + ), f"all return types must be mlir types {return_types=}" + + input_types = [ + p.annotation + for p in sig.parameters.values() + if not p.annotation is inspect.Signature.empty + ] + assert all( + isinstance(r, Type) for r in input_types + ), f"all input types must be mlir types {input_types=}" + return input_types, return_types, [get_user_code_loc()] * len(sig.parameters) + + +class FuncBase: + def __init__( + self, + body_builder, + func_op_ctor, + return_op_ctor, + call_op_ctor, + return_types=None, + sym_visibility=None, + arg_attrs=None, + res_attrs=None, + func_attrs=None, + loc=None, + ip=None, + qualname=None, + ): + assert inspect.isfunction(body_builder), body_builder + assert inspect.isclass(func_op_ctor), func_op_ctor + assert inspect.isclass(return_op_ctor), return_op_ctor + assert inspect.isclass(call_op_ctor), call_op_ctor + + self.body_builder = body_builder + self.func_name = self.body_builder.__name__ + self.func_op_ctor = func_op_ctor + self.return_op_ctor = return_op_ctor + self.call_op_ctor = call_op_ctor + self.arg_attrs = arg_attrs + self.res_attrs = res_attrs + self.loc = loc + self.ip = ip + self._func_op = None + # in case this function lives inside a class + self.qualname = qualname + + self.sym_visibility = sym_visibility + if self.sym_visibility is not None: + self.sym_visibility = StringAttr.get(str(sym_visibility)) + + self.func_attrs = func_attrs + if self.func_attrs is None: + self.func_attrs = {} + + if return_types is None: + return_types = [] + sig = inspect.signature(self.body_builder) + self.input_types, self.return_types, self.arg_locs = prep_func_types( + sig, return_types + ) + + if self._is_decl(): + assert len(self.input_types) == len( + sig.parameters + ), f"func decl needs all input types annotated" + self.sym_visibility = StringAttr.get("private") + self.emit() + + def _is_decl(self): + # magic constant found from looking at the code for an empty fn + if sys.version_info.minor == 12: + return self.body_builder.__code__.co_code == b"\x97\x00y\x00" + elif sys.version_info.minor == 11: + return self.body_builder.__code__.co_code == b"\x97\x00d\x00S\x00" + elif sys.version_info.minor == 10: + return self.body_builder.__code__.co_code == b"d\x00S\x00" + else: + raise NotImplementedError(f"{sys.version_info.minor} not supported.") + + def __str__(self): + return str(f"{self.__class__} {self.__dict__}") + + def emit(self, *call_args) -> FuncOp: + if self._func_op is None: + if len(call_args) == 0: + input_types = self.input_types + else: + input_types = [a.type for a in call_args] + function_type = TypeAttr.get( + FunctionType.get( + inputs=input_types, + results=self.return_types, + ) + ) + self._func_op = self.func_op_ctor( + self.func_name, + function_type, + sym_visibility=self.sym_visibility, + arg_attrs=self.arg_attrs, + res_attrs=self.res_attrs, + loc=self.loc, + ip=self.ip or InsertionPoint.current, + ) + for k, v in self.func_attrs.items(): + self._func_op.attributes[k] = v + if self._is_decl(): + return self._func_op + + self._func_op.regions[0].blocks.append(*input_types, arg_locs=self.arg_locs) + builder_wrapper = op_region_builder( + self._func_op, self._func_op.regions[0], terminator=self.return_op_ctor + ) + + return_types = [] + + def grab_results(*args): + nonlocal return_types + results = self.body_builder(*args) + if isinstance(results, (tuple, list)): + return_types.extend([r.type for r in results]) + elif results is not None: + return_types.append(results.type) + return results + + builder_wrapper(grab_results) + + function_type = FunctionType.get(inputs=input_types, results=return_types) + self._func_op.attributes["function_type"] = TypeAttr.get(function_type) + return self._func_op + + def __call__(self, *call_args): + return call(self.emit(*call_args), call_args) + + +@make_maybe_no_args_decorator +def func( + f, + *, + sym_visibility=None, + arg_attrs=None, + res_attrs=None, + func_attrs=None, + emit=False, + loc=None, + ip=None, +) -> FuncBase: + if loc is None: + loc = get_user_code_loc() + func = FuncBase( + body_builder=f, + func_op_ctor=FuncOp.__base__, + return_op_ctor=ReturnOp, + call_op_ctor=CallOp.__base__, + sym_visibility=sym_visibility, + arg_attrs=arg_attrs, + res_attrs=res_attrs, + func_attrs=func_attrs, + loc=loc, + ip=ip, + ) + func.__name__ = f.__name__ + if emit: + func.emit() + return func diff --git a/python/dialects/extras/memref.py b/python/extras/dialects/memref.py similarity index 97% rename from python/dialects/extras/memref.py rename to python/extras/dialects/memref.py index 6123eda2c0..c8c5b4ed1d 100644 --- a/python/dialects/extras/memref.py +++ b/python/extras/dialects/memref.py @@ -2,8 +2,8 @@ from typing import Union, Optional, Sequence from .arith import constant -from .. import memref -from .._ods_common import get_op_result_or_op_results +from ...dialects import memref +from ...dialects._ods_common import get_op_result_or_op_results from ...extras import types as T from ...ir import MLIRError, ShapedType, Type, Value diff --git a/python/extras/meta.py b/python/extras/meta.py new file mode 100644 index 0000000000..fa9136e3ef --- /dev/null +++ b/python/extras/meta.py @@ -0,0 +1,179 @@ +import ctypes +import inspect +import sys +from functools import wraps +from pathlib import Path +from typing import Optional +from typing import Sequence + +from ..dialects._ods_common import ( + get_op_result_or_op_results, +) +from ..ir import Context, Location, Type, InsertionPoint + + +def get_user_code_loc(user_base: Optional[Path] = None): + if Context.current is None: + return + + mlir_utils_root_path = Path(__file__).parent + + prev_frame = inspect.currentframe().f_back + if user_base is None: + user_base = Path(prev_frame.f_code.co_filename) + + while prev_frame.f_back and ( + Path(prev_frame.f_code.co_filename).is_relative_to(mlir_utils_root_path) + or Path(prev_frame.f_code.co_filename).is_relative_to(sys.prefix) + or Path(prev_frame.f_code.co_filename).is_relative_to(user_base) + ): + prev_frame = prev_frame.f_back + frame_info = inspect.getframeinfo(prev_frame) + if sys.version_info.minor >= 11: + return Location.file( + frame_info.filename, frame_info.lineno, frame_info.positions.col_offset + ) + elif sys.version_info.minor == 10: + return Location.file(frame_info.filename, frame_info.lineno, col=0) + else: + raise NotImplementedError(f"{sys.version_info.minor} not supported.") + + +# builds the decorator +def make_maybe_no_args_decorator(decorator): + """ + a decorator decorator, allowing the decorator to be used as: + @decorator(with, arguments, and=kwargs) + or + @decorator + """ + + @wraps(decorator) + def new_dec(*args, **kwargs): + if len(args) == 1 and len(kwargs) == 0 and callable(args[0]): + # actual decorated function + return decorator(args[0]) + else: + # decorator arguments + return lambda realf: decorator(realf, *args, **kwargs) + + return new_dec + + +def op_region_builder(op, op_region, terminator=None): + def builder_wrapper(body_builder): + # add a block with block args having types ... + if len(op_region.blocks) == 0: + sig = inspect.signature(body_builder) + types = [p.annotation for p in sig.parameters.values()] + if not ( + len(types) == len(sig.parameters) + and all(isinstance(t, Type) for t in types) + ): + raise ValueError( + f"for {body_builder=} either missing a type annotation or type annotation isn't a mlir type: {sig}" + ) + + arg_locs = list(filter(None, [get_user_code_loc()] * len(sig.parameters))) + if len(arg_locs) == 0: + arg_locs = None + op_region.blocks.append(*types, arg_locs=arg_locs) + + with InsertionPoint(op_region.blocks[0]): + results = body_builder(*list(op_region.blocks[0].arguments)) + + with InsertionPoint(list(op_region.blocks)[-1]): + if terminator is not None: + res = [] + if isinstance(results, (tuple, list)): + res.extend(results) + elif results is not None: + res.append(results) + terminator(res) + + return get_op_result_or_op_results(op) + + return builder_wrapper + + +def region_adder(terminator=None): + def wrapper(op_region_adder): + def region_adder_decorator(op, *args, **kwargs): + region = op_region_adder(op, *args, **kwargs) + + return op_region_builder(op, region, terminator) + + return region_adder_decorator + + return wrapper + + +def region_op(op_constructor, terminator=None): + # the decorator itself + def op_decorator(*args, **kwargs): + op = op_constructor(*args, **kwargs) + op_region = op.regions[0] + + return op_region_builder(op, op_region, terminator) + + # this is like make_maybe_no_args_decorator but a little different because the decorators here + # are already wrapped (or something like that) + @wraps(op_decorator) + def maybe_no_args(*args, **kwargs): + if len(args) == 1 and len(kwargs) == 0 and callable(args[0]): + return op_decorator()(args[0]) + else: + return op_decorator(*args, **kwargs) + + return maybe_no_args + + +def _update_caller_vars(previous_frame, args: Sequence, replacements: Sequence): + """Update caller vars passed as args. + + This function uses CPython API to update the values + of the caller's args (not the caller of this function but the caller of caller of this function). + It does this by searching for a match in the caller's f_locals based on identity (A is A) and then + updating all corresponding values in the f_locals dict. Finally, it uses PyFrame_LocalsToFast to signal + to the CPython runtime that an update has been made to f_locals. + + Args: + previous_frame: The frame in which vars will be updated. + args: The args to the callee. + replacements: The values that should replace the values of the vars in the caller. + """ + + if len(args) != len(replacements): + raise ValueError(f"updates must be 1-1: {args=} {replacements=}") + # find the name of the iter args in the previous frame + var_names = [ + [ + var_name + for var_name, var_val in previous_frame.f_locals.items() + if var_val is arg + ] + for arg in args + ] + for i, var_names in enumerate(var_names): + for var_name in var_names: + previous_frame.f_locals[var_name] = replacements[i] + # signal to update + # for some reason you can only update one at a time? + ctypes.pythonapi.PyFrame_LocalsToFast( + ctypes.py_object(previous_frame), ctypes.c_int(1) + ) + + +class ModuleMeta(type): + def __new__(cls, name, bases, classdict, **kwargs): + ip = classdict.pop("ip") + loc = classdict.pop("loc") + module_terminator = classdict.pop("module_terminator", None) + new = super().__new__(cls, name, bases, classdict) + if module_terminator is not None: + module_terminator(loc=loc, ip=ip) + for k, v in classdict.items(): + if callable(v): + v.qualname = name + ip.__exit__(None, None, None) + return new diff --git a/python/util.py b/python/extras/util.py similarity index 98% rename from python/util.py rename to python/extras/util.py index a805033df2..a1f4944b59 100644 --- a/python/util.py +++ b/python/extras/util.py @@ -13,8 +13,8 @@ import networkx as nx import numpy as np -from .extras import types as T -from .ir import ( +from . import types as T +from ..ir import ( F32Type, F64Type, IntegerType, @@ -134,7 +134,7 @@ def mlir_mod_ctx( def build_graph(max_cols, max_rows, target_model): - from ._mlir_libs._aie_python_passes import WireBundle, Switchbox + from .._mlir_libs._aie_python_passes import WireBundle, Switchbox DG = nx.DiGraph() for c in range(max_cols + 1): @@ -419,7 +419,7 @@ def plot_src_paths(DG, flow_paths): def get_routing_solution(DG, flow_paths, used_channels): - from ._mlir_libs._aie_python_passes import ( + from .._mlir_libs._aie_python_passes import ( SwitchSetting, Port, get_connecting_bundle, @@ -528,7 +528,7 @@ def add_flow(self, src: "PathEndPoint", tgt: "PathEndPoint"): self.flows.append((src, tgt)) def add_fixed_connection(self, connect_op): - from ._mlir_libs._aie_python_passes import get_connecting_bundle + from .._mlir_libs._aie_python_passes import get_connecting_bundle tileid = connect_op.get_switchbox().get_tileid() lhs_port = connect_op.get_src_port() diff --git a/reference_designs/CMakeLists.txt b/reference_designs/CMakeLists.txt index 42d1f6e13d..044e5347bc 100755 --- a/reference_designs/CMakeLists.txt +++ b/reference_designs/CMakeLists.txt @@ -129,16 +129,16 @@ configure_lit_site_cfg( set(TEST_DEPENDS FileCheck count not - aiecc.py + AIEPythonModules aie-opt aie-translate - ) +) add_lit_testsuite(check-reference-designs "Running the aie reference designs" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${TEST_DEPENDS} ARGS "-sv --timeout 300 --time-tests" - ) +) set_target_properties(check-reference-designs PROPERTIES FOLDER "Tutorials") add_lit_testsuites(REFERENCE_DESIGNS ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${TEST_DEPENDS} ARGS "-sv --timeout 300 --time-tests") diff --git a/reference_designs/horizontal_diffusion/HDIFF_single_AIE_objectFIFO_ping_pong_scaled/code_hdiff.py b/reference_designs/horizontal_diffusion/HDIFF_single_AIE_objectFIFO_ping_pong_scaled/code_hdiff.py index 584ab49f1e..0e3d5057e6 100644 --- a/reference_designs/horizontal_diffusion/HDIFF_single_AIE_objectFIFO_ping_pong_scaled/code_hdiff.py +++ b/reference_designs/horizontal_diffusion/HDIFF_single_AIE_objectFIFO_ping_pong_scaled/code_hdiff.py @@ -7,11 +7,6 @@ # -import sys -import re -import math -import random - noc_columns = [2, 3, 6, 7, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 46, 47] arraycols = 32 # must be even until 32 diff --git a/reference_designs/horizontal_diffusion/HDIFF_tri_AIE_objectFIFO_ping_pong_scaled/gen_hdiff_cpp.py b/reference_designs/horizontal_diffusion/HDIFF_tri_AIE_objectFIFO_ping_pong_scaled/gen_hdiff_cpp.py index 226caec911..00f870b96b 100644 --- a/reference_designs/horizontal_diffusion/HDIFF_tri_AIE_objectFIFO_ping_pong_scaled/gen_hdiff_cpp.py +++ b/reference_designs/horizontal_diffusion/HDIFF_tri_AIE_objectFIFO_ping_pong_scaled/gen_hdiff_cpp.py @@ -7,14 +7,8 @@ # -import sys -import re -import math -import random - noc_columns = [2, 3, 6, 7, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 46, 47] - total_b_block = 8 # only 1 b_block_depth = 4 # set how many rows input_rows = 9 # data input per block row diff --git a/reference_designs/horizontal_diffusion/HDIFF_tri_AIE_objectFIFO_ping_pong_scaled/gen_hdiff_mlir.py b/reference_designs/horizontal_diffusion/HDIFF_tri_AIE_objectFIFO_ping_pong_scaled/gen_hdiff_mlir.py index 75b393c894..5e4cbec2a7 100644 --- a/reference_designs/horizontal_diffusion/HDIFF_tri_AIE_objectFIFO_ping_pong_scaled/gen_hdiff_mlir.py +++ b/reference_designs/horizontal_diffusion/HDIFF_tri_AIE_objectFIFO_ping_pong_scaled/gen_hdiff_mlir.py @@ -6,14 +6,8 @@ # SPDX-License-Identifier: MIT # -import sys -import re -import math -import random - noc_columns = [2, 3, 6, 7, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 46, 47] - total_b_block = 5 # only 1 b_block_depth = 4 # set how many rows input_rows = 9 # data input per block row diff --git a/reference_designs/ipu-xrt/add_one_objFifo/aie2.py b/reference_designs/ipu-xrt/add_one_objFifo/aie2.py index a568879a16..32c8f200a1 100644 --- a/reference_designs/ipu-xrt/add_one_objFifo/aie2.py +++ b/reference_designs/ipu-xrt/add_one_objFifo/aie2.py @@ -5,14 +5,11 @@ # # (c) Copyright 2023 AMD Inc. -import aie -from aie.ir import * -from aie.dialects.func import * -from aie.dialects.scf import * from aie.dialects.aie import * from aie.dialects.aiex import * -from aie.dialects.extras import memref, arith -from aie.util import mlir_mod_ctx +from aie.dialects.scf import * +from aie.extras.dialects import memref, arith +from aie.extras.util import mlir_mod_ctx def my_add_one_objFifo(): diff --git a/reference_designs/ipu-xrt/log_hello_world/elfStringParser.py b/reference_designs/ipu-xrt/log_hello_world/elfStringParser.py index 6b77c8891e..c50415cc1e 100755 --- a/reference_designs/ipu-xrt/log_hello_world/elfStringParser.py +++ b/reference_designs/ipu-xrt/log_hello_world/elfStringParser.py @@ -6,9 +6,9 @@ # (c) Copyright 2023 AMD Inc. import argparse -import subprocess -import re import os +import re +import subprocess from typing import Dict diff --git a/reference_designs/ipu-xrt/log_hello_world/hello_world.py b/reference_designs/ipu-xrt/log_hello_world/hello_world.py index 7d4979bbf5..487b667d64 100644 --- a/reference_designs/ipu-xrt/log_hello_world/hello_world.py +++ b/reference_designs/ipu-xrt/log_hello_world/hello_world.py @@ -4,13 +4,10 @@ # # (c) Copyright 2023 AMD Inc. -import aie -from aie.ir import * -from aie.dialects.func import * -from aie.dialects.scf import * from aie.dialects.aie import * from aie.dialects.aiex import * -from aie.util import mlir_mod_ctx +from aie.dialects.scf import * +from aie.extras.util import mlir_mod_ctx def printf(): diff --git a/reference_designs/ipu-xrt/matrix_multiplication/aie2.py b/reference_designs/ipu-xrt/matrix_multiplication/aie2.py index a201803461..e2a64626c9 100644 --- a/reference_designs/ipu-xrt/matrix_multiplication/aie2.py +++ b/reference_designs/ipu-xrt/matrix_multiplication/aie2.py @@ -5,14 +5,10 @@ # # (c) Copyright 2023 AMD Inc. -import aie -from aie.ir import * -from aie.dialects.func import * -from aie.dialects.scf import * from aie.dialects.aie import * from aie.dialects.aiex import * -from aie.dialects.extras import memref, arith -from aie.util import mlir_mod_ctx +from aie.dialects.scf import * +from aie.extras.util import mlir_mod_ctx def my_matmul(): diff --git a/reference_designs/ipu-xrt/passthrough_hardware/aie2.py b/reference_designs/ipu-xrt/passthrough_hardware/aie2.py index e18d5289cf..3a3d8390fd 100755 --- a/reference_designs/ipu-xrt/passthrough_hardware/aie2.py +++ b/reference_designs/ipu-xrt/passthrough_hardware/aie2.py @@ -7,14 +7,11 @@ import sys -import aie -from aie.ir import * -from aie.dialects.func import * -from aie.dialects.scf import * from aie.dialects.aie import * from aie.dialects.aiex import * -from aie.dialects.extras import memref, arith -from aie.util import mlir_mod_ctx +from aie.dialects.scf import * +from aie.extras.dialects import memref, arith +from aie.extras.util import mlir_mod_ctx N = 4096 N_in_bytes = N * 4 diff --git a/reference_designs/ipu-xrt/vector_scalar/aie2.py b/reference_designs/ipu-xrt/vector_scalar/aie2.py index f096927fe9..7b5a7d4b6b 100755 --- a/reference_designs/ipu-xrt/vector_scalar/aie2.py +++ b/reference_designs/ipu-xrt/vector_scalar/aie2.py @@ -7,13 +7,10 @@ import sys -import aie -from aie.ir import * -from aie.dialects.func import * -from aie.dialects.scf import * from aie.dialects.aie import * from aie.dialects.aiex import * -from aie.util import mlir_mod_ctx +from aie.dialects.scf import * +from aie.extras.util import mlir_mod_ctx def my_vector_scalar(): diff --git a/reference_designs/ipu-xrt/vision_pipelines/color_threshold/aie2_colorThreshold.py b/reference_designs/ipu-xrt/vision_pipelines/color_threshold/aie2_colorThreshold.py index aa9f0de7b9..9f6d6e2805 100644 --- a/reference_designs/ipu-xrt/vision_pipelines/color_threshold/aie2_colorThreshold.py +++ b/reference_designs/ipu-xrt/vision_pipelines/color_threshold/aie2_colorThreshold.py @@ -7,13 +7,11 @@ import sys -from aie.ir import * -from aie.dialects.func import * -from aie.dialects.scf import * from aie.dialects.aie import * from aie.dialects.aiex import * -from aie.dialects.extras import memref, arith -from aie.util import mlir_mod_ctx +from aie.dialects.scf import * +from aie.extras.dialects import memref, arith +from aie.extras.util import mlir_mod_ctx width = 512 height = 9 diff --git a/reference_designs/ipu-xrt/vision_pipelines/edge_detect/aie2_edgeDetect.py b/reference_designs/ipu-xrt/vision_pipelines/edge_detect/aie2_edgeDetect.py index e769cc294f..7a9acf6a15 100644 --- a/reference_designs/ipu-xrt/vision_pipelines/edge_detect/aie2_edgeDetect.py +++ b/reference_designs/ipu-xrt/vision_pipelines/edge_detect/aie2_edgeDetect.py @@ -7,13 +7,11 @@ import sys -from aie.ir import * -from aie.dialects.func import * -from aie.dialects.scf import * from aie.dialects.aie import * from aie.dialects.aiex import * -from aie.dialects.extras import memref, arith -from aie.util import mlir_mod_ctx +from aie.dialects.scf import * +from aie.extras.dialects import memref, arith +from aie.extras.util import mlir_mod_ctx width = 64 height = 36 diff --git a/reference_designs/ipu-xrt/vision_pipelines/passthrough/aie2.py b/reference_designs/ipu-xrt/vision_pipelines/passthrough/aie2.py index c32e9e400e..1df76144d0 100644 --- a/reference_designs/ipu-xrt/vision_pipelines/passthrough/aie2.py +++ b/reference_designs/ipu-xrt/vision_pipelines/passthrough/aie2.py @@ -7,14 +7,10 @@ import sys -import aie -from aie.ir import * -from aie.dialects.func import * -from aie.dialects.scf import * from aie.dialects.aie import * from aie.dialects.aiex import * -from aie.dialects.extras import memref, arith -from aie.util import mlir_mod_ctx +from aie.dialects.scf import * +from aie.extras.util import mlir_mod_ctx width = 512 # 1920 // 8 height = 9 # 1080 // 8 diff --git a/reference_designs/lit.cfg.py b/reference_designs/lit.cfg.py index ea964feefb..fa3854db90 100755 --- a/reference_designs/lit.cfg.py +++ b/reference_designs/lit.cfg.py @@ -7,19 +7,14 @@ # Copyright (C) 2022, Advanced Micro Devices, Inc. import os -import platform import re import shutil import subprocess -import tempfile import lit.formats import lit.util from lit.llvm import llvm_config -from lit.llvm.subst import ToolSubst -from lit.llvm.subst import FindTool - # Configuration file for the 'lit' test runner. # name: The name of this test suite. diff --git a/reference_designs/prime_sieve_large/code_gen.py b/reference_designs/prime_sieve_large/code_gen.py index 797c8af16a..77107e4de3 100644 --- a/reference_designs/prime_sieve_large/code_gen.py +++ b/reference_designs/prime_sieve_large/code_gen.py @@ -5,11 +5,6 @@ # # (c) Copyright 2021 Xilinx Inc. -import sys -import re -import math -import random - # The number of cores to use. Will generate a 2D chain of cores of the given size. arrayrows = 8 arraycols = 50 # must be even @@ -173,7 +168,7 @@ def gen_buffer(row, col, lastrow): # unchanged part tilecode = ( """ - %core""" + %core""" + str(startcol) + """_1 = AIE.core(%tile""" + str(startcol) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 02cb0f67d1..0f97e00089 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -91,8 +91,6 @@ include_directories(${PROJECT_SOURCE_DIR}/include) include_directories(${PROJECT_BINARY_DIR}/include) add_definitions(${LLVM_DEFINITIONS}) -cmake_dependent_option(ENABLE_PYTHON_TESTS "Enable Python tests" ON "AIE_ENABLE_BINDINGS_PYTHON" OFF) - configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py @@ -102,7 +100,7 @@ configure_lit_site_cfg( set(TEST_DEPENDS FileCheck count not - aiecc.py + AIEPythonModules aie-opt aie-translate ) diff --git a/test/python/aie_ops.py b/test/python/aie_ops.py index c8fd622ed3..9933729e6b 100644 --- a/test/python/aie_ops.py +++ b/test/python/aie_ops.py @@ -21,9 +21,9 @@ objectfifo_subview_access, tile, ) -from aie.extras import types as T from aie.ir import InsertionPoint, Block, TypeAttr -from aie.util import mlir_mod_ctx +from aie.extras.util import mlir_mod_ctx +from aie.extras import types as T from util import construct_and_print_module diff --git a/test/python/aiex_ops.py b/test/python/aiex_ops.py index fbd49a8449..417ae68bdc 100644 --- a/test/python/aiex_ops.py +++ b/test/python/aiex_ops.py @@ -4,7 +4,7 @@ # RUN: %PYTHON %s | FileCheck %s from aie.dialects.aiex import GetTileOp -from aie.dialects.extras import arith +from aie.extras.dialects import arith from aie.extras import types as T from util import construct_and_print_module diff --git a/test/python/core_ext_kernel.py b/test/python/core_ext_kernel.py index b1973d7796..4b39cc5845 100644 --- a/test/python/core_ext_kernel.py +++ b/test/python/core_ext_kernel.py @@ -19,7 +19,7 @@ objectfifo_release, tile, ) -from aie.dialects.extras import arith +from aie.extras.dialects import arith from aie.dialects.scf import for_, yield_ from aie.ir import TypeAttr, Block, InsertionPoint diff --git a/test/python/ipu.py b/test/python/ipu.py index 9d0f6ac45a..e923fa823e 100644 --- a/test/python/ipu.py +++ b/test/python/ipu.py @@ -22,7 +22,7 @@ tile, ) from aie.dialects.aiex import ipu_sync, ipu_dma_memcpy_nd -from aie.dialects.extras import memref, arith +from aie.extras.dialects import memref, arith from aie.dialects.func import FuncOp from aie.dialects.scf import for_ from aie.dialects.scf import yield_ diff --git a/test/python/objFifo.py b/test/python/objFifo.py index 63552ac601..4b49dbb4e0 100644 --- a/test/python/objFifo.py +++ b/test/python/objFifo.py @@ -16,7 +16,7 @@ Core, end, ) -from aie.dialects.extras import memref, arith +from aie.extras.dialects import memref, arith from aie.ir import InsertionPoint, TypeAttr, Block from util import construct_and_print_module diff --git a/test/python/python_passes.py b/test/python/python_passes.py index 1adafa4705..20685bf1b4 100644 --- a/test/python/python_passes.py +++ b/test/python/python_passes.py @@ -16,7 +16,7 @@ from aie.ir import Context, Location, Module from aie.passmanager import PassManager -from aie.util import Router +from aie.extras.util import Router TIMEOUT = 10 diff --git a/test/python/simple_with_bindings.py b/test/python/simple_with_bindings.py index 018b6ca6f0..7da44400a2 100644 --- a/test/python/simple_with_bindings.py +++ b/test/python/simple_with_bindings.py @@ -12,7 +12,7 @@ end, Buffer, ) -from aie.dialects.extras import memref, arith +from aie.extras.dialects import memref, arith from aie.ir import InsertionPoint, Block from util import construct_and_print_module diff --git a/test/python/tosa_aievec.py b/test/python/tosa_aievec.py index ed77845a91..733d58b3fe 100644 --- a/test/python/tosa_aievec.py +++ b/test/python/tosa_aievec.py @@ -1,49 +1,75 @@ # Copyright (C) 2023, Advanced Micro Devices, Inc. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +import inspect +from pathlib import Path +from textwrap import dedent + +from aie.extras.dialects import arith +from aie.extras.dialects.func import func +from aie.extras.util import mlir_mod_ctx +from aie.ir import ShapedType +from util import construct_and_print_module +from inspect import currentframe, getframeinfo # RUN: %python %s | FileCheck %s -import aie.extras.types as T -from aie.dialects.aie import ( - AIEDevice, - tile, - Device, - Core, - end, - Buffer, -) -from aie.dialects.extras import memref, arith -from aie.ir import InsertionPoint, Block +S = ShapedType.get_dynamic_size() + +THIS_DIR = Path(__file__).parent.absolute() -from util import construct_and_print_module -# CHECK: module { -# CHECK: AIE.device(xcve2802) { -# CHECK: %tile_1_4 = AIE.tile(1, 4) -# CHECK: %buffer_1_4 = AIE.buffer(%tile_1_4) : memref<256xi32> -# CHECK: %core_1_4 = AIE.core(%tile_1_4) { -# CHECK: %c3 = arith.constant 3 : index -# CHECK: %0 = memref.load %buffer_1_4[%c3] : memref<256xi32> -# CHECK: %c4_i32 = arith.constant 4 : i32 -# CHECK: %1 = arith.addi %0, %c4_i32 : i32 -# CHECK: %c3_0 = arith.constant 3 : index -# CHECK: memref.store %1, %buffer_1_4[%c3_0] : memref<256xi32> -# CHECK: AIE.end -# CHECK: } -# CHECK: } -# CHECK: } +def get_asm(operation): + return operation.get_asm(enable_debug_info=True, pretty_debug_info=True).replace( + str(THIS_DIR), "THIS_DIR" + ) + + +# CHECK-LABEL: TEST: test_emit +# CHECK: module { +# CHECK: func.func @demo_fun1() -> i32 { +# CHECK: %c1_i32 = arith.constant 1 : i32 +# CHECK: return %c1_i32 : i32 +# CHECK: } +# CHECK: } @construct_and_print_module -def simple_with_bindings_example(): - dev = Device(AIEDevice.xcve2802) - dev_block = Block.create_at_start(dev.bodyRegion) - with InsertionPoint(dev_block): - tile_a = tile(1, 4) - buff = Buffer(tile=tile_a, size=(256,), datatype=T.i32()) - - C = Core(tile_a) - bb = Block.create_at_start(C.body) - with InsertionPoint(bb): - val = memref.load(buff, [3]) - add = arith.addi(val, arith.constant(4)) - memref.store(add, buff, [3]) - end() +def test_emit(): + @func + def demo_fun1(): + one = arith.constant(1) + return one + + assert hasattr(demo_fun1, "emit") + assert inspect.ismethod(demo_fun1.emit) + demo_fun1.emit() + + +def test_location_tracking(): + with mlir_mod_ctx() as ctx: + + frameinfo = getframeinfo(currentframe()) + + @func + def demo_fun1(): + one = arith.constant(1) + return one + + demo_fun1.emit() + + asm = get_asm(ctx.module.operation) + correct = dedent( + f"""\ + module {{ + func.func @demo_fun1() -> i32 {{ + %c1_i32 = arith.constant 1 : i32 THIS_DIR/tosa_aievec.py:{frameinfo.lineno + 4}:18 + return %c1_i32 : i32 [unknown] + }} THIS_DIR/tosa_aievec.py:{frameinfo.lineno + 2}:9 + }} [unknown] + #loc = [unknown] + #loc1 = THIS_DIR/tosa_aievec.py:{frameinfo.lineno + 2}:9 + #loc2 = THIS_DIR/tosa_aievec.py:{frameinfo.lineno + 4}:18 + """ + ) + assert asm == correct + + +test_location_tracking() diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index d0ad7c9669..e960de8915 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -5,7 +5,6 @@ # # (c) Copyright 2021 Xilinx Inc. -add_subdirectory(aiecc) add_subdirectory(aie-opt) if(NOT WIN32) add_subdirectory(aie-reset) diff --git a/tools/aiecc/CMakeLists.txt b/tools/aiecc/CMakeLists.txt deleted file mode 100644 index 67177a6bef..0000000000 --- a/tools/aiecc/CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -# This file is licensed 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 -# -# Copyright (C) 2023, Advanced Micro Devices, Inc. - -set(AIECC_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/bin) - -set(AIECC_FILES aiecc.py) - -set(AIECC_TARGETS ${AIECC_FILES}) -list(TRANSFORM AIECC_TARGETS PREPEND ${PROJECT_BINARY_DIR}/bin/) - -if(${AIE_COMPILER} STREQUAL XCHESSCC) - set(CONFIG_COMPILE_WITH_XCHESSCC True) -else() - set(CONFIG_COMPILE_WITH_XCHESSCC False) -endif() - -if(${AIE_COMPILER} STREQUAL NONE) - set(CONFIG_DISABLE_COMPILE True) -else() - set(CONFIG_DISABLE_COMPILE False) -endif() - -if(${HOST_COMPILER} STREQUAL NONE) - set(CONFIG_DISABLE_HOST_COMPILE True) -else() - set(CONFIG_DISABLE_HOST_COMPILE False) -endif() - -if(${AIE_LINKER} STREQUAL XCHESSCC) - set(CONFIG_LINK_WITH_XCHESSCC True) -else() - set(CONFIG_LINK_WITH_XCHESSCC False) -endif() - -if(${AIE_LINKER} STREQUAL NONE) - set(CONFIG_DISABLE_LINK True) -else() - set(CONFIG_DISABLE_LINK False) -endif() - -set(CONFIG_PEANO_INSTALL_DIR ${PEANO_INSTALL_DIR}) - -configure_file(aiecc/configure.py.in - ${PROJECT_BINARY_DIR}/python/aie/compiler/aiecc/configure.py -) - -install( - PROGRAMS ${PROJECT_BINARY_DIR}/python/aie/compiler/aiecc/configure.py - DESTINATION ${AIE_PYTHON_INSTALL_DIR}/aie/compiler/aiecc -) - -# Stuff our python into the build area: -add_custom_target(aiecc.py ALL DEPENDS ${AIECC_TARGETS}) - -# This chicanery is necessary to ensure executable permissions. -file( - WRITE "${CMAKE_CURRENT_BINARY_DIR}/copy_aiecc.cmake" -"file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/aiecc.py -DESTINATION ${PROJECT_BINARY_DIR}/bin -FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_WRITE -GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)" -) - -add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/bin/aiecc.py - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/copy_aiecc.cmake -) - -# Install our python stuff too. -install(PROGRAMS aiecc.py DESTINATION ${AIECC_INSTALL_PATH}) diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index 60ba289439..44bbba8dbf 100755 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -127,7 +127,7 @@ configure_lit_site_cfg( set(TEST_DEPENDS FileCheck count not - aiecc.py + AIEPythonModules aie-opt aie-translate ) diff --git a/tutorials/lit.cfg.py b/tutorials/lit.cfg.py index 0bd548db04..9ad07492b9 100755 --- a/tutorials/lit.cfg.py +++ b/tutorials/lit.cfg.py @@ -17,15 +17,15 @@ import lit.util from lit.llvm import llvm_config -from lit.llvm.subst import ToolSubst -from lit.llvm.subst import FindTool - # Configuration file for the 'lit' test runner. # name: The name of this test suite. config.name = 'AIE_TUTORIALS' config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) +config.environment["PYTHONPATH"] = "{}".format( + os.path.join(config.aie_obj_root, "python") +) # suffixes: A list of file extensions to treat as test files. config.suffixes = ['.mlir']