Skip to content

Commit

Permalink
refactor python (and aiecc) (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental authored Dec 12, 2023
1 parent c0341aa commit b6f2519
Show file tree
Hide file tree
Showing 40 changed files with 627 additions and 224 deletions.
23 changes: 17 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()

Expand Down
56 changes: 42 additions & 14 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand All @@ -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)
Expand All @@ -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
################################################################################
Expand Down Expand Up @@ -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)

17 changes: 0 additions & 17 deletions python/compiler/CMakeLists.txt

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion python/dialects/aie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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,
)
Expand All @@ -17,7 +19,6 @@
Type,
Value,
)
from ...util import infer_mlir_type


def constant(
Expand All @@ -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:
Expand All @@ -51,7 +54,7 @@ def constant(

if _is_complex_type(type):
value = complex(value)
return complex.ConstantOp(
return complex_dialect.constant(
type,
list(
map(
Expand Down Expand Up @@ -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
Loading

0 comments on commit b6f2519

Please sign in to comment.