2021-07-28 07:10:10 +08:00
|
|
|
include(AddMLIRPython)
|
|
|
|
include(MLIRDetectPythonEnv)
|
|
|
|
|
2021-08-23 03:17:12 +08:00
|
|
|
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=npcomp.")
|
|
|
|
|
2020-07-11 13:45:30 +08:00
|
|
|
################################################################################
|
|
|
|
# Resources that must be packaged into the python tree
|
|
|
|
################################################################################
|
|
|
|
|
2020-08-07 14:51:05 +08:00
|
|
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/npcomp/compiler/backend/refjit_resources")
|
2021-07-28 07:10:10 +08:00
|
|
|
add_custom_target(NPCOMPPythonResources ALL)
|
2020-07-11 13:45:30 +08:00
|
|
|
add_custom_command(
|
2020-08-07 14:51:05 +08:00
|
|
|
TARGET NPCOMPPythonResources
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
2020-07-11 13:45:30 +08:00
|
|
|
# TODO: Make the runtime library work for windows.
|
2021-07-28 07:10:10 +08:00
|
|
|
# TODO: Use $<TARGET-FILE:> for this.
|
2020-12-28 17:30:45 +08:00
|
|
|
${CMAKE_BINARY_DIR}/lib/libNPCOMPCompilerRuntimeShlib${CMAKE_SHARED_LIBRARY_SUFFIX}
|
2021-07-28 07:10:10 +08:00
|
|
|
${MLIR_NPCOMP_PYTHON_PACKAGES_DIR}/npcomp_core/npcomp/compiler/generic/backend/libNPCOMPCompilerRuntimeShlib${CMAKE_SHARED_LIBRARY_SUFFIX}
|
2020-07-11 13:45:30 +08:00
|
|
|
)
|
|
|
|
add_dependencies(NPCOMPPythonResources
|
|
|
|
NPCOMPCompilerRuntimeShlib
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-27 06:50:23 +08:00
|
|
|
################################################################################
|
2021-07-28 07:10:10 +08:00
|
|
|
# Declare sources
|
2020-04-27 06:50:23 +08:00
|
|
|
################################################################################
|
2021-07-28 07:10:10 +08:00
|
|
|
|
2021-07-30 01:43:18 +08:00
|
|
|
declare_mlir_python_sources(NPCOMPPythonSources)
|
2021-07-28 07:10:10 +08:00
|
|
|
|
2021-07-30 01:43:18 +08:00
|
|
|
declare_mlir_python_sources(NPCOMPPythonSources.Core
|
|
|
|
ADD_TO_PARENT NPCOMPPythonSources
|
2021-08-23 03:17:12 +08:00
|
|
|
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/npcomp"
|
2021-07-28 07:10:10 +08:00
|
|
|
SOURCES
|
2021-08-23 03:17:12 +08:00
|
|
|
build.py
|
2021-09-11 02:44:38 +08:00
|
|
|
__init__.py
|
2021-07-28 07:10:10 +08:00
|
|
|
SOURCES_GLOB
|
2021-08-23 03:17:12 +08:00
|
|
|
compiler/*.py
|
|
|
|
utils/*.py
|
2021-07-28 07:10:10 +08:00
|
|
|
)
|
2021-07-30 01:43:18 +08:00
|
|
|
|
2021-07-28 07:10:10 +08:00
|
|
|
declare_mlir_python_sources(NPCOMPPythonSources.Dialects
|
|
|
|
ADD_TO_PARENT NPCOMPPythonSources
|
|
|
|
)
|
|
|
|
declare_mlir_python_sources(NPCOMPPythonExtensions)
|
|
|
|
|
2021-07-30 01:43:18 +08:00
|
|
|
declare_mlir_python_sources(NPCOMPPythonCAPIHeaderSources
|
|
|
|
ROOT_DIR "${MLIR_NPCOMP_SOURCE_DIR}/include"
|
|
|
|
SOURCES_GLOB "npcomp-c/*.h"
|
|
|
|
DEST_PREFIX "_mlir_libs/include"
|
|
|
|
)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Extensions
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
set(_addl_extension_sources)
|
|
|
|
if(NPCOMP_ENABLE_REFJIT)
|
|
|
|
list(APPEND _addl_extension_sources "${CMAKE_CURRENT_SOURCE_DIR}/RefJITBackend.cpp")
|
|
|
|
endif()
|
|
|
|
|
2021-07-28 07:10:10 +08:00
|
|
|
declare_mlir_python_extension(NPCOMPPythonExtensions.Core
|
|
|
|
MODULE_NAME _npcomp
|
|
|
|
ADD_TO_PARENT NPCOMPPythonExtensions
|
|
|
|
SOURCES
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/NpcompModule.cpp
|
|
|
|
${_addl_extension_sources}
|
|
|
|
EMBED_CAPI_LINK_LIBS
|
|
|
|
NPCOMPCAPI
|
|
|
|
PRIVATE_LINK_LIBS
|
|
|
|
LLVMSupport
|
|
|
|
)
|
2020-08-04 08:46:34 +08:00
|
|
|
|
|
|
|
################################################################################
|
2021-07-28 07:10:10 +08:00
|
|
|
# Declare dialects
|
2020-08-04 08:46:34 +08:00
|
|
|
################################################################################
|
|
|
|
|
2021-09-11 02:44:38 +08:00
|
|
|
# Declare dialects with `declare_mlir_dialect_python_bindings`.
|
|
|
|
# Currently there are none, because the interesting ones to bind have been
|
|
|
|
# removed or moved into torch-mlir.
|
2021-07-28 07:10:10 +08:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Build composite binaries
|
|
|
|
################################################################################
|
2020-08-04 08:46:34 +08:00
|
|
|
|
2021-07-28 07:10:10 +08:00
|
|
|
# Bundle our own, self-contained CAPI library with all of our deps.
|
|
|
|
add_mlir_python_common_capi_library(NPCOMPPythonCAPI
|
|
|
|
INSTALL_COMPONENT NPCOMPPythonModules
|
2021-08-23 03:17:12 +08:00
|
|
|
INSTALL_DESTINATION python_packages/npcomp_core/npcomp/_mlir_libs
|
|
|
|
OUTPUT_DIRECTORY "${MLIR_NPCOMP_PYTHON_PACKAGES_DIR}/npcomp_core/npcomp/_mlir_libs"
|
2021-07-28 07:10:10 +08:00
|
|
|
RELATIVE_INSTALL_ROOT "../../../.."
|
|
|
|
DECLARED_SOURCES
|
2021-08-23 03:17:12 +08:00
|
|
|
# TODO: Common MLIR deps can be reduced substantially.
|
|
|
|
MLIRPythonSources.Core
|
|
|
|
MLIRPythonSources.Dialects
|
|
|
|
MLIRPythonSources.ExecutionEngine
|
2021-07-28 07:10:10 +08:00
|
|
|
MLIRPythonExtension.AllPassesRegistration
|
|
|
|
NPCOMPPythonSources
|
|
|
|
NPCOMPPythonExtensions
|
2020-08-04 08:46:34 +08:00
|
|
|
)
|
|
|
|
|
2021-08-23 03:17:12 +08:00
|
|
|
# Bundle MLIR and NPCOMP into the top-level npcomp package.
|
|
|
|
add_mlir_python_modules(NPCOMPPythonModules
|
|
|
|
ROOT_PREFIX "${MLIR_NPCOMP_PYTHON_PACKAGES_DIR}/npcomp_core/npcomp"
|
|
|
|
INSTALL_PREFIX "python_packages/npcomp_core/npcomp"
|
2021-07-28 07:10:10 +08:00
|
|
|
DECLARED_SOURCES
|
|
|
|
MLIRPythonSources
|
|
|
|
MLIRPythonExtension.AllPassesRegistration
|
2021-07-30 01:43:18 +08:00
|
|
|
MLIRPythonCAPIHeaderSources
|
2021-08-23 03:17:12 +08:00
|
|
|
NPCOMPPythonSources
|
2021-07-28 07:10:10 +08:00
|
|
|
NPCOMPPythonExtensions
|
2021-07-30 01:43:18 +08:00
|
|
|
NPCOMPPythonCAPIHeaderSources
|
2021-07-28 07:10:10 +08:00
|
|
|
COMMON_CAPI_LINK_LIBS
|
|
|
|
NPCOMPPythonCAPI
|
|
|
|
)
|
2021-09-17 02:39:53 +08:00
|
|
|
|
|
|
|
add_dependencies(NPCOMPPythonModules NPCOMPPythonResources)
|