mirror of https://github.com/llvm/torch-mlir
Remove old stuff in prep for move-to-root.
parent
404bd74ddf
commit
d8f603a4e5
211
CMakeLists.txt
211
CMakeLists.txt
|
@ -1,211 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.13.4)
|
||||
|
||||
# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()`
|
||||
# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html
|
||||
if(POLICY CMP0116)
|
||||
cmake_policy(SET CMP0116 OLD)
|
||||
endif()
|
||||
if(POLICY CMP0068)
|
||||
cmake_policy(SET CMP0068 NEW)
|
||||
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
|
||||
endif()
|
||||
|
||||
if(POLICY CMP0075)
|
||||
cmake_policy(SET CMP0075 NEW)
|
||||
endif()
|
||||
|
||||
if(POLICY CMP0077)
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Options and settings
|
||||
#-------------------------------------------------------------------------------
|
||||
set(NPCOMP_MINIMUM_PYTHON_VERSION 3.6)
|
||||
|
||||
# Turn on -gsplit-dwarf if requested in debug builds.
|
||||
if (NPCOMP_USE_SPLIT_DWARF AND
|
||||
((CMAKE_BUILD_TYPE STREQUAL "Debug") OR
|
||||
(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")))
|
||||
# Limit to clang and gcc so far. Add compilers supporting this option.
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
|
||||
CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
add_compile_options(-gsplit-dwarf)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MSVC defaults
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if(MSVC)
|
||||
add_compile_options(
|
||||
$<$<CONFIG:>:/MD>
|
||||
$<$<CONFIG:Debug>:/MD>
|
||||
$<$<CONFIG:Release>:/MD>
|
||||
)
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Directory setup
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
set(MLIR_NPCOMP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(MLIR_NPCOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(MLIR_NPCOMP_PYTHON_PACKAGES_DIR ${CMAKE_CURRENT_BINARY_DIR}/python_packages)
|
||||
set(TORCH_MLIR_PYTHON_PACKAGES_DIR "${MLIR_NPCOMP_PYTHON_PACKAGES_DIR}")
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
# If we are not building as a part of LLVM, build NPCOMP as a standalone
|
||||
# project, including LLVM as a subdirectory. This gives us the most control
|
||||
# and is used for standalone releases.
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Project setup and globals
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
project(npcomp LANGUAGES CXX C)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Default and required options.
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# CMake library generation settings.
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "We are actually building a static mondo-lib")
|
||||
set(CMAKE_PLATFORM_NO_VERSIONED_SONAME ON CACHE BOOL "Python soname linked libraries are bad")
|
||||
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON CACHE BOOL "Hide inlines")
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Improved LLVM defaults for a standalone build.
|
||||
set(LLVM_ENABLE_PROJECTS mlir CACHE STRING "LLVM projects")
|
||||
set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "Disable Z3")
|
||||
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "Disable ZLIB")
|
||||
set(LLVM_TARGETS_TO_BUILD "host" CACHE STRING "Only build for the host")
|
||||
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "Disable examples")
|
||||
# TODO: MLIR is a "tool"
|
||||
set(LLVM_INCLUDE_TOOLS ON CACHE BOOL "Disable tools")
|
||||
set(LLVM_INCLUDE_TESTS ON CACHE BOOL "Disable tests")
|
||||
set(MLIR_BINDINGS_PYTHON_LOCK_VERSION ON CACHE BOOL "Link against libpython for development (should be disabled for production)")
|
||||
|
||||
# Required LLVM settings.
|
||||
set(MLIR_ENABLE_BINDINGS_PYTHON ON CACHE BOOL "Enable MLIR python bindings" FORCE)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# MLIR/LLVM Build Setup
|
||||
# TODO: It would be nice to have a better setup than this for sub including
|
||||
# MLIR.
|
||||
#-------------------------------------------------------------------------------
|
||||
if(NOT LLVM_MAIN_SRC_DIR)
|
||||
set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/llvm-project/llvm")
|
||||
endif()
|
||||
if(NOT MLIR_MAIN_SRC_DIR)
|
||||
set(MLIR_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR}/../mlir")
|
||||
endif()
|
||||
|
||||
set(LLVM_MAIN_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/llvm")
|
||||
set(MLIR_MAIN_BINARY_DIR "${LLVM_MAIN_BINARY_DIR}/tools/mlir")
|
||||
|
||||
set(LLVM_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include")
|
||||
set(LLVM_GENERATED_INCLUDE_DIR "${LLVM_MAIN_BINARY_DIR}/include")
|
||||
set(MLIR_INCLUDE_DIR "${MLIR_MAIN_SRC_DIR}/include")
|
||||
set(MLIR_GENERATED_INCLUDE_DIR "${MLIR_MAIN_BINARY_DIR}/include")
|
||||
set(MLIR_TABLEGEN_EXE "$<TARGET_FILE:mlir-tblgen>")
|
||||
include_directories(SYSTEM "${LLVM_INCLUDE_DIR}")
|
||||
include_directories(SYSTEM "${LLVM_GENERATED_INCLUDE_DIR}")
|
||||
include_directories(SYSTEM "${MLIR_INCLUDE_DIR}")
|
||||
include_directories(SYSTEM "${MLIR_GENERATED_INCLUDE_DIR}")
|
||||
list(APPEND CMAKE_MODULE_PATH "${MLIR_MAIN_SRC_DIR}/cmake/modules")
|
||||
list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
|
||||
|
||||
# Pre-configure the Python environment using the MLIR macros so that they
|
||||
# are in scope and subsequent include of LLVM will match them.
|
||||
include(MLIRDetectPythonEnv)
|
||||
find_package(Python3 ${NPCOMP_MINIMUM_PYTHON_VERSION}
|
||||
COMPONENTS Interpreter Development NumPy REQUIRED)
|
||||
message(STATUS "Found python include dirs: ${Python3_INCLUDE_DIRS}")
|
||||
message(STATUS "Found python libraries: ${Python3_LIBRARIES}")
|
||||
mlir_detect_pybind11_install()
|
||||
find_package(pybind11 2.6 CONFIG REQUIRED)
|
||||
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIR}")
|
||||
message(STATUS "Python prefix = '${PYTHON_MODULE_PREFIX}', "
|
||||
"suffix = '${PYTHON_MODULE_SUFFIX}', "
|
||||
"extension = '${PYTHON_MODULE_EXTENSION}")
|
||||
|
||||
# Include LLVM_EXTERNAL_PROJECTS.
|
||||
set(LLVM_EXTERNAL_PROJECTS "torch-mlir")
|
||||
set(LLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/torch-mlir")
|
||||
|
||||
# LLVM configuration.
|
||||
message(STATUS "*** ADDING LLVM ***")
|
||||
add_subdirectory(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/external/llvm-project/llvm"
|
||||
"${LLVM_MAIN_BINARY_DIR}"
|
||||
EXCLUDE_FROM_ALL)
|
||||
message(STATUS "*** LLVM DONE ***")
|
||||
|
||||
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
|
||||
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
set(LLVM_EXTERNAL_LIT "${LLVM_MAIN_BINARY_DIR}/bin/llvm-lit")
|
||||
set(LLVM_TOOLS_DIR "${LLVM_MAIN_BINARY_DIR}/bin")
|
||||
|
||||
# Define the default arguments to use with 'lit', and an option for the user to
|
||||
# override.
|
||||
set(LIT_ARGS_DEFAULT "-sv")
|
||||
if (MSVC_IDE OR XCODE)
|
||||
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
|
||||
endif()
|
||||
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
|
||||
|
||||
include(TableGen)
|
||||
include(AddLLVM)
|
||||
include(AddMLIR)
|
||||
include(AddMLIRPython)
|
||||
include(HandleLLVMOptions)
|
||||
set(NPCOMP_BUILT_STANDALONE 1)
|
||||
else()
|
||||
# TODO: RE-ENABLE EXTERNAL UNIFIED BUILD
|
||||
message(FATAL_ERROR "External project builds of npcomp are currently not available")
|
||||
# Otherwise, we are building as a part of LLVM, and we need to set up some
|
||||
# variables and includes.
|
||||
# set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include ) # --src-root
|
||||
# set(MLIR_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include ) # --includedir
|
||||
# set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)
|
||||
# set(MLIR_TABLEGEN_EXE $<TARGET_FILE:mlir-tblgen>)
|
||||
# include_directories(SYSTEM ${MLIR_INCLUDE_DIR})
|
||||
# include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
|
||||
|
||||
# set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
|
||||
include(AddNPCOMP)
|
||||
include_directories(${LLVM_INCLUDE_DIRS})
|
||||
include_directories(${MLIR_INCLUDE_DIRS})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/torch-mlir/include)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/llvm/tools/torch-mlir/include)
|
||||
link_directories(${LLVM_BUILD_LIBRARY_DIR})
|
||||
add_definitions(${LLVM_DEFINITIONS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Optional feature selection
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Subdirectories and aggregate testing targets.
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
add_custom_target(check-npcomp)
|
||||
add_custom_target(check-npcomp-all)
|
||||
add_dependencies(check-npcomp-all
|
||||
check-npcomp
|
||||
check-torch-mlir-all
|
||||
)
|
||||
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(python)
|
||||
add_subdirectory(tools)
|
235
LICENSE
235
LICENSE
|
@ -1,235 +0,0 @@
|
|||
==============================================================================
|
||||
The LLVM Project is under the Apache License v2.0 with LLVM Exceptions:
|
||||
As an incubator project with ambition to become part of the LLVM Project,
|
||||
CIRCT is under the same license.
|
||||
==============================================================================
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
---- LLVM Exceptions to the Apache 2.0 License ----
|
||||
|
||||
As an exception, if, as a result of your compiling your source code, portions
|
||||
of this Software are embedded into an Object form of such source code, you
|
||||
may redistribute such embedded portions in such Object form without complying
|
||||
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
|
||||
|
||||
In addition, if you combine or link compiled forms of this Software with
|
||||
software that is licensed under the GPLv2 ("Combined Software") and if a
|
||||
court of competent jurisdiction determines that the patent provision (Section
|
||||
3), the indemnity provision (Section 9) or other Section of the License
|
||||
conflicts with the conditions of the GPLv2, you may retroactively and
|
||||
prospectively choose to deem waived or otherwise exclude such Section(s) of
|
||||
the License, but only in their entirety and only with respect to the Combined
|
||||
Software.
|
||||
|
||||
==============================================================================
|
||||
Software from third parties included in the LLVM Project:
|
||||
==============================================================================
|
||||
The LLVM Project contains third party software which is under different license
|
||||
terms. All such code will be identified clearly using at least one of two
|
||||
mechanisms:
|
||||
1) It will be in a separate directory tree with its own `LICENSE.txt` or
|
||||
`LICENSE` file at the top containing the specific license and restrictions
|
||||
which apply to that software, or
|
||||
2) It will contain specific license and restriction terms at the top of every
|
||||
file.
|
|
@ -1,82 +0,0 @@
|
|||
# Declare an npcomp library which can be compiled in libNPCOMP.so.
|
||||
# This is adapted from add_mlir_library.
|
||||
function(add_npcomp_library name)
|
||||
cmake_parse_arguments(ARG
|
||||
"SHARED;EXCLUDE_FROM_LIBNPCOMP"
|
||||
""
|
||||
"ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS"
|
||||
${ARGN})
|
||||
set(srcs)
|
||||
# TODO: Port the source description logic for IDEs from add_mlir_library.
|
||||
|
||||
|
||||
if(ARG_SHARED)
|
||||
# Rule explicitly requested a shared library.
|
||||
set(LIBTYPE SHARED)
|
||||
else()
|
||||
if(NOT ARG_EXCLUDE_FROM_LIBNPCOMP)
|
||||
set_property(GLOBAL APPEND PROPERTY NPCOMP_STATIC_LIBS ${name})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# TODO: Enable npcomp header export.
|
||||
# list(APPEND ARG_DEPENDS npcomp-generic-headers)
|
||||
llvm_add_library(
|
||||
${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs}
|
||||
OBJECT
|
||||
DEPENDS ${ARG_DEPENDS}
|
||||
LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
|
||||
LINK_LIBS ${ARG_LINK_LIBS})
|
||||
|
||||
set_target_properties(${name} PROPERTIES FOLDER "NPCOMP libraries")
|
||||
|
||||
install(TARGETS ${name}
|
||||
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
|
||||
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
|
||||
RUNTIME DESTINATION bin COMPONENT ${name})
|
||||
|
||||
endfunction()
|
||||
|
||||
# Declare the library associated with a dialect.
|
||||
function(add_npcomp_dialect_library name)
|
||||
set_property(GLOBAL APPEND PROPERTY NPCOMP_DIALECT_LIBS ${name})
|
||||
# TODO: Add DEPENDS npcomp-headers
|
||||
add_npcomp_library(${ARGV})
|
||||
endfunction()
|
||||
|
||||
# Declare the library associated with a conversion.
|
||||
function(add_npcomp_conversion_library name)
|
||||
set_property(GLOBAL APPEND PROPERTY NPCOMP_CONVERSION_LIBS ${name})
|
||||
# TODO: Add DEPENDS npcomp-headers
|
||||
add_npcomp_library(${ARGV})
|
||||
endfunction()
|
||||
|
||||
function(add_npcomp_executable name)
|
||||
add_executable(${ARGV})
|
||||
llvm_update_compile_flags(${name})
|
||||
add_link_opts( ${name} )
|
||||
set_output_directory(${name}
|
||||
BINARY_DIR ${PROJECT_BINARY_DIR}/bin
|
||||
LIBRARY_DIR ${PROJECT_BINARY_DIR}/lib)
|
||||
if (LLVM_PTHREAD_LIB)
|
||||
# libpthreads overrides some standard library symbols, so main
|
||||
# executable must be linked with it in order to provide consistent
|
||||
# API for all shared libaries loaded by this executable.
|
||||
target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB})
|
||||
endif()
|
||||
|
||||
install(TARGETS ${name}
|
||||
RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR}
|
||||
COMPONENT ${name})
|
||||
|
||||
endfunction()
|
||||
|
||||
function(npcomp_enable_exceptions name)
|
||||
target_compile_options(${name} PRIVATE
|
||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
|
||||
-fexceptions
|
||||
>
|
||||
$<$<CXX_COMPILER_ID:MSVC>:
|
||||
/EHsc>
|
||||
)
|
||||
endfunction()
|
|
@ -1,29 +0,0 @@
|
|||
# Forked and adapted from MLIRDetectPythonEnv.cmake upstream. The eventual
|
||||
# goal is to use the upstream configuration but until that is ready, just
|
||||
# move/adapt these facilities. Please try to not diverge.
|
||||
|
||||
# Macros and functions related to detecting details of the Python environment.
|
||||
|
||||
# Detects a pybind11 package installed in the current python environment
|
||||
# and sets variables to allow it to be found. This allows pybind11 to be
|
||||
# installed via pip, which typically yields a much more recent version than
|
||||
# the OS install, which will be available otherwise.
|
||||
function(npcomp_detect_pybind11_install)
|
||||
if(pybind11_DIR)
|
||||
message(STATUS "Using explicit pybind11 cmake directory: ${pybind11_DIR} (-Dpybind11_DIR to change)")
|
||||
else()
|
||||
message(STATUS "Checking for pybind11 in python path...")
|
||||
execute_process(
|
||||
COMMAND "${Python3_EXECUTABLE}"
|
||||
-c "import pybind11;print(pybind11.get_cmake_dir(), end='')"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
RESULT_VARIABLE STATUS
|
||||
OUTPUT_VARIABLE PACKAGE_DIR
|
||||
ERROR_QUIET)
|
||||
if(NOT STATUS EQUAL "0")
|
||||
message(CHECK_FAIL "not found (install via 'pip install pybind11' or set pybind11_DIR)")
|
||||
return()
|
||||
endif()
|
||||
set(pybind11_DIR "${PACKAGE_DIR}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
|
@ -1,29 +0,0 @@
|
|||
function(npcomp_python_create_symlinks binary_dir source_dir)
|
||||
# Do nothing if building in-source
|
||||
if (${binary_dir} STREQUAL ${source_dir})
|
||||
return()
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE python_files RELATIVE ${source_dir} *.py)
|
||||
foreach (path_file ${python_files})
|
||||
get_filename_component(folder ${path_file} PATH)
|
||||
|
||||
# Create REAL folder
|
||||
file(MAKE_DIRECTORY "${binary_dir}/${folder}")
|
||||
|
||||
# Get OS dependent path to use in `execute_process`
|
||||
file(TO_NATIVE_PATH "${binary_dir}/${path_file}" link)
|
||||
file(TO_NATIVE_PATH "${source_dir}/${path_file}" target)
|
||||
|
||||
# TODO: Switch to copy on windows if symlink still not supported by
|
||||
# then.
|
||||
set(cmake_verb create_symlink)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E ${cmake_verb} ${target} ${link}
|
||||
RESULT_VARIABLE result
|
||||
ERROR_VARIABLE output)
|
||||
|
||||
if (NOT ${result} EQUAL 0)
|
||||
message(FATAL_ERROR "Could not create symbolic link for: ${target} --> ${output}")
|
||||
endif()
|
||||
endforeach(path_file)
|
||||
endfunction(npcomp_python_create_symlinks)
|
|
@ -1,27 +0,0 @@
|
|||
/*===-- npcomp-c/InitLLVM.h - C API for initializing LLVM --------*- C -*-===*\
|
||||
|* *|
|
||||
|* 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 *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef NPCOMP_C_INITLLVM_H
|
||||
#define NPCOMP_C_INITLLVM_H
|
||||
|
||||
#include "mlir-c/Support.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Initializes LLVM codegen infrastructure and related MLIR bridge components.
|
||||
*/
|
||||
MLIR_CAPI_EXPORTED void npcompInitializeLLVMCodegen();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NPCOMP_C_INITLLVM_H
|
|
@ -1,32 +0,0 @@
|
|||
/*===-- npcomp-c/Registration.h - Registration functions ---------*- C -*-===*\
|
||||
|* *|
|
||||
|* 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 *|
|
||||
|* *|
|
||||
\*===----------------------------------------------------------------------===*/
|
||||
|
||||
#ifndef NPCOMP_C_REGISTRATION_H
|
||||
#define NPCOMP_C_REGISTRATION_H
|
||||
|
||||
#include "mlir-c/IR.h"
|
||||
#include "mlir-c/Support.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Registers all NPComp dialects with a context.
|
||||
* This is needed before creating IR for these Dialects.
|
||||
*/
|
||||
MLIR_CAPI_EXPORTED void npcompRegisterAllDialects(MlirContext context);
|
||||
|
||||
/** Registers all NPComp passes for symbolic access with the global registry. */
|
||||
MLIR_CAPI_EXPORTED void npcompRegisterAllPasses();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NPCOMP_C_REGISTRATION_H
|
|
@ -1,23 +0,0 @@
|
|||
//===------------------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef NPCOMP_INITALL_H
|
||||
#define NPCOMP_INITALL_H
|
||||
|
||||
#include "mlir/IR/Dialect.h"
|
||||
|
||||
namespace mlir {
|
||||
namespace NPCOMP {
|
||||
|
||||
void registerAllDialects(mlir::DialectRegistry ®istry);
|
||||
void registerAllPasses();
|
||||
|
||||
} // namespace NPCOMP
|
||||
} // namespace mlir
|
||||
|
||||
#endif // NPCOMP_INITALL_H
|
|
@ -1,21 +0,0 @@
|
|||
//===------------------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef NPCOMP_INTERFACES_TRAITS_H
|
||||
#define NPCOMP_INTERFACES_TRAITS_H
|
||||
|
||||
#include "mlir/IR/OpDefinition.h"
|
||||
|
||||
namespace mlir {
|
||||
namespace NPCOMP {
|
||||
namespace OpTrait {} // namespace OpTrait
|
||||
|
||||
} // namespace NPCOMP
|
||||
} // namespace mlir
|
||||
|
||||
#endif // NPCOMP_INTERFACES_TRAITS_H
|
|
@ -1,24 +0,0 @@
|
|||
//===-------------------------------------------------------*- tablegen -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Traits for cross-cutting concerns in the npcomp project.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef NPCOMP_INTERFACES_TRAITS
|
||||
#define NPCOMP_INTERFACES_TRAITS
|
||||
|
||||
include "mlir/IR/OpBase.td"
|
||||
|
||||
class NpcompOpTrait<string name> : OpTrait, NativeTrait<"", ""> {
|
||||
let trait = name;
|
||||
let cppNamespace = "::mlir::NPCOMP::OpTrait";
|
||||
}
|
||||
|
||||
// Empty for now. Kept as boilerplate placeholder.
|
||||
|
||||
#endif // NPCOMP_INTERFACES_TRAITS
|
|
@ -1,22 +0,0 @@
|
|||
set(LLVM_LINK_COMPONENTS
|
||||
Core
|
||||
Support
|
||||
nativecodegen
|
||||
)
|
||||
|
||||
add_npcomp_library(NPCOMPCAPI
|
||||
InitLLVM.cpp
|
||||
Registration.cpp
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRExecutionEngine
|
||||
MLIRLLVMIR
|
||||
MLIRTargetLLVMIRExport
|
||||
NPCOMPInitAll
|
||||
TorchMLIRTorchDialect
|
||||
TorchMLIRInitAll
|
||||
|
||||
# MLIR CAPI deps
|
||||
MLIRCAPIIR
|
||||
MLIRCAPIRegistration # TODO: Remove
|
||||
)
|
|
@ -1,18 +0,0 @@
|
|||
//===- InitLLVM.cpp - C API for initializing LLVM -------------------------===//
|
||||
//
|
||||
// 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 "npcomp-c/InitLLVM.h"
|
||||
|
||||
#include "mlir/ExecutionEngine/OptUtils.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
|
||||
void npcompInitializeLLVMCodegen() {
|
||||
llvm::InitializeNativeTarget();
|
||||
llvm::InitializeNativeTargetAsmPrinter();
|
||||
mlir::initializeLLVMPasses();
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
//===- Registration.cpp - C Interface for MLIR Registration ---------------===//
|
||||
//
|
||||
// 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 "npcomp-c/Registration.h"
|
||||
|
||||
#include "mlir/CAPI/IR.h"
|
||||
#include "mlir/Conversion/Passes.h"
|
||||
#include "mlir/Dialect/Linalg/Passes.h"
|
||||
#include "mlir/Transforms/Passes.h"
|
||||
#include "npcomp/InitAll.h"
|
||||
#include "torch-mlir/InitAll.h"
|
||||
|
||||
void npcompRegisterAllDialects(MlirContext context) {
|
||||
mlir::DialectRegistry registry;
|
||||
mlir::NPCOMP::registerAllDialects(registry);
|
||||
mlir::torch::registerAllDialects(registry);
|
||||
unwrap(context)->appendDialectRegistry(registry);
|
||||
// TODO: Don't eagerly load once D88162 is in and clients can do this.
|
||||
unwrap(context)->loadAllAvailableDialects();
|
||||
}
|
||||
|
||||
void npcompRegisterAllPasses() {
|
||||
::mlir::NPCOMP::registerAllPasses();
|
||||
::mlir::torch::registerAllPasses();
|
||||
|
||||
// Upstream passes we depend on.
|
||||
::mlir::registerSymbolDCEPass();
|
||||
::mlir::registerInlinerPass();
|
||||
::mlir::registerCanonicalizerPass();
|
||||
::mlir::registerSCFToStandardPass();
|
||||
::mlir::registerConvertElementwiseToLinalgPass();
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
add_subdirectory(CAPI)
|
||||
add_subdirectory(Interfaces)
|
||||
|
||||
################################################################################
|
||||
# Setup the initialization target.
|
||||
# This includes conditional dependencies based on whether features are enabled.
|
||||
################################################################################
|
||||
|
||||
get_property(mlir_dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
||||
get_property(mlir_conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
||||
|
||||
get_property(npcomp_dialect_libs GLOBAL PROPERTY NPCOMP_DIALECT_LIBS)
|
||||
get_property(npcomp_conversion_libs GLOBAL PROPERTY NPCOMP_CONVERSION_LIBS)
|
||||
|
||||
message(STATUS "NPCOMP Dialect libs: ${npcomp_dialect_libs}")
|
||||
message(STATUS "NPCOMP Conversion libs: ${npcomp_conversion_libs}")
|
||||
|
||||
add_npcomp_library(NPCOMPInitAll
|
||||
InitAll.cpp
|
||||
|
||||
LINK_LIBS
|
||||
|
||||
PUBLIC
|
||||
# Local depends
|
||||
# TODO: add_torch_mlir_dialect_library to automate enueration of all dialects.
|
||||
TorchMLIRTorchDialect
|
||||
TorchMLIRTorchConversionDialect
|
||||
TorchMLIRConversionPasses
|
||||
|
||||
# TODO: We shouldn't need npcomp_conversion_libs here, but we have
|
||||
# some dialect transform libraries accumulating into that property.
|
||||
${npcomp_conversion_libs}
|
||||
${npcomp_dialect_libs}
|
||||
${mlir_dialect_libs}
|
||||
${mlir_conversion_libs}
|
||||
)
|
|
@ -1,18 +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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "npcomp/InitAll.h"
|
||||
|
||||
#include "mlir/IR/Dialect.h"
|
||||
|
||||
void mlir::NPCOMP::registerAllDialects(mlir::DialectRegistry ®istry) {
|
||||
}
|
||||
|
||||
void mlir::NPCOMP::registerAllPasses() {
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
add_npcomp_library(NPCOMPInterfaces
|
||||
Traits.cpp
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
${PROJECT_SRC_DIR}/include/npcomp/Interfaces
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRStandard
|
||||
)
|
||||
|
||||
mlir_check_all_link_libraries(NPCOMPInterfaces)
|
|
@ -1,13 +0,0 @@
|
|||
//===- Traits.cpp ------------------------------------------------*- C++-*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "npcomp/Interfaces/Traits.h"
|
||||
#include "mlir/Dialect/StandardOps/IR/Ops.h"
|
||||
|
||||
using namespace mlir;
|
||||
using namespace mlir::NPCOMP;
|
|
@ -1,116 +0,0 @@
|
|||
include(AddMLIRPython)
|
||||
include(MLIRDetectPythonEnv)
|
||||
|
||||
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=npcomp.")
|
||||
|
||||
################################################################################
|
||||
# Declare sources
|
||||
################################################################################
|
||||
|
||||
declare_mlir_python_sources(NPCOMPPythonSources)
|
||||
|
||||
declare_mlir_python_sources(NPCOMPPythonSources.Core
|
||||
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/npcomp"
|
||||
ADD_TO_PARENT NPCOMPPythonSources
|
||||
SOURCES_GLOB
|
||||
*.py
|
||||
)
|
||||
|
||||
declare_mlir_python_sources(NPCOMPPythonSources.Dialects
|
||||
ADD_TO_PARENT NPCOMPPythonSources
|
||||
)
|
||||
declare_mlir_python_sources(NPCOMPPythonExtensions)
|
||||
|
||||
declare_mlir_python_sources(NPCOMPPythonCAPIHeaderSources
|
||||
ROOT_DIR "${MLIR_NPCOMP_SOURCE_DIR}/include"
|
||||
SOURCES_GLOB "npcomp-c/*.h"
|
||||
DEST_PREFIX "_mlir_libs/include"
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Extensions
|
||||
################################################################################
|
||||
|
||||
declare_mlir_python_extension(NPCOMPPythonExtensions.Core
|
||||
MODULE_NAME _npcomp
|
||||
ADD_TO_PARENT NPCOMPPythonExtensions
|
||||
SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/NpcompModule.cpp
|
||||
EMBED_CAPI_LINK_LIBS
|
||||
NPCOMPCAPI
|
||||
PRIVATE_LINK_LIBS
|
||||
LLVMSupport
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Declare dialects
|
||||
################################################################################
|
||||
|
||||
# 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.
|
||||
|
||||
################################################################################
|
||||
# Build composite binaries
|
||||
################################################################################
|
||||
|
||||
# Bundle our own, self-contained CAPI library with all of our deps.
|
||||
add_mlir_python_common_capi_library(NPCOMPPythonCAPI
|
||||
INSTALL_COMPONENT NPCOMPPythonModules
|
||||
INSTALL_DESTINATION python_packages/npcomp_core/npcomp/_mlir_libs
|
||||
OUTPUT_DIRECTORY "${MLIR_NPCOMP_PYTHON_PACKAGES_DIR}/npcomp_core/npcomp/_mlir_libs"
|
||||
RELATIVE_INSTALL_ROOT "../../../.."
|
||||
DECLARED_SOURCES
|
||||
# TODO: Common MLIR deps can be reduced substantially.
|
||||
MLIRPythonSources.Core
|
||||
MLIRPythonSources.Dialects
|
||||
MLIRPythonSources.ExecutionEngine
|
||||
MLIRPythonExtension.AllPassesRegistration
|
||||
NPCOMPPythonSources
|
||||
NPCOMPPythonExtensions
|
||||
)
|
||||
|
||||
# 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"
|
||||
DECLARED_SOURCES
|
||||
MLIRPythonSources
|
||||
MLIRPythonExtension.AllPassesRegistration
|
||||
MLIRPythonCAPIHeaderSources
|
||||
NPCOMPPythonSources
|
||||
NPCOMPPythonExtensions
|
||||
NPCOMPPythonCAPIHeaderSources
|
||||
COMMON_CAPI_LINK_LIBS
|
||||
NPCOMPPythonCAPI
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Torch support libraries.
|
||||
################################################################################
|
||||
|
||||
# Torch-related modules that are too broad of a scope/opinion for torch-mlir
|
||||
# belong there.
|
||||
declare_mlir_python_sources(NPCOMPTorchSupportPythonSources
|
||||
ADD_TO_PARENT NPCOMPPythonSources
|
||||
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/torch_support"
|
||||
SOURCES_GLOB
|
||||
npcomp_torchscript/*.py
|
||||
torch_mlir_e2e_test.torchscript.configs/*.py
|
||||
)
|
||||
|
||||
add_mlir_python_modules(NPCOMPTorchSupportPythonModules
|
||||
ROOT_PREFIX "${MLIR_NPCOMP_PYTHON_PACKAGES_DIR}/npcomp_core"
|
||||
INSTALL_PREFIX "python_packages/npcomp_core"
|
||||
DECLARED_SOURCES
|
||||
NPCOMPTorchSupportPythonSources
|
||||
)
|
||||
add_dependencies(NPCOMPTorchSupportPythonModules
|
||||
NPCOMPPythonModules
|
||||
)
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
# Recurse into the tests.
|
||||
################################################################################
|
|
@ -1,41 +0,0 @@
|
|||
//===- NpcompModule.cpp - MLIR Python bindings ----------------------------===//
|
||||
//
|
||||
// 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 <cstddef>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "./NpcompModule.h"
|
||||
#include "./NpcompPybindUtils.h"
|
||||
|
||||
#include "mlir-c/BuiltinAttributes.h"
|
||||
#include "mlir-c/BuiltinTypes.h"
|
||||
#include "mlir-c/Diagnostics.h"
|
||||
#include "npcomp-c/InitLLVM.h"
|
||||
#include "npcomp-c/Registration.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// TODO: Move this upstream.
|
||||
void emitError(MlirLocation loc, std::string message) {
|
||||
::mlirEmitError(loc, message.c_str());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
PYBIND11_MODULE(_npcomp, m) {
|
||||
m.doc() = "Npcomp native python bindings";
|
||||
::npcompRegisterAllPasses();
|
||||
::npcompInitializeLLVMCodegen();
|
||||
|
||||
m.def("register_all_dialects", ::npcompRegisterAllDialects);
|
||||
m.def("emit_error", emitError);
|
||||
|
||||
// Optional backend modules.
|
||||
auto backend_m = m.def_submodule("backend", "Backend support");
|
||||
(void)backend_m;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
//===- NpcompModule.h - Headers for the python module ---------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef NPCOMP_PYTHON_NPCOMP_MODULE_H
|
||||
#define NPCOMP_PYTHON_NPCOMP_MODULE_H
|
||||
|
||||
#include "./NpcompPybindUtils.h"
|
||||
|
||||
namespace npcomp {
|
||||
namespace python {
|
||||
|
||||
/// Defines an "refbackend" module with backend support definitions.
|
||||
void defineBackendrefbackendModule(py::module &m);
|
||||
|
||||
} // namespace python
|
||||
} // namespace npcomp
|
||||
|
||||
#endif // NPCOMP_PYTHON_NPCOMP_MODULE_H
|
|
@ -1,55 +0,0 @@
|
|||
//===- NpcompPybindUtils.h - Utilities for interop with python ------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// TODO: Most of this lives upstream now and should be taken from there.
|
||||
|
||||
#ifndef NPCOMP_PYTHON_NPCOMP_PYBIND_UTILS_H
|
||||
#define NPCOMP_PYTHON_NPCOMP_PYBIND_UTILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/pytypes.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#include "mlir-c/Bindings/Python/Interop.h"
|
||||
#include "mlir-c/IR.h"
|
||||
#include "mlir-c/Pass.h"
|
||||
#include "mlir/Bindings/Python/PybindAdaptors.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace pybind11 {
|
||||
|
||||
/// Raises a python exception with the given message.
|
||||
/// Correct usage:
|
||||
// throw RaiseValueError(PyExc_ValueError, "Foobar'd");
|
||||
inline pybind11::error_already_set raisePyError(PyObject *exc_class,
|
||||
const char *message) {
|
||||
PyErr_SetString(exc_class, message);
|
||||
return pybind11::error_already_set();
|
||||
}
|
||||
|
||||
/// Raises a value error with the given message.
|
||||
/// Correct usage:
|
||||
/// throw RaiseValueError("Foobar'd");
|
||||
inline pybind11::error_already_set raiseValueError(const char *message) {
|
||||
return raisePyError(PyExc_ValueError, message);
|
||||
}
|
||||
|
||||
/// Raises a value error with the given message.
|
||||
/// Correct usage:
|
||||
/// throw RaiseValueError(message);
|
||||
inline pybind11::error_already_set raiseValueError(const std::string &message) {
|
||||
return raisePyError(PyExc_ValueError, message.c_str());
|
||||
}
|
||||
|
||||
} // namespace pybind11
|
||||
|
||||
#endif // NPCOMP_PYTHON_NPCOMP_PYBIND_UTILS_H
|
|
@ -1 +0,0 @@
|
|||
add_subdirectory(npcomp-opt)
|
|
@ -1,18 +0,0 @@
|
|||
# npcomp-opt is always linked dynamically as we want to distribute the
|
||||
# binaries with the python packages for hacking/debugging.
|
||||
add_npcomp_executable(npcomp-opt npcomp-opt.cpp)
|
||||
|
||||
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
||||
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
||||
|
||||
target_link_libraries(npcomp-opt PRIVATE
|
||||
MLIROptLib
|
||||
NPCOMPInitAll
|
||||
TorchMLIRInitAll
|
||||
|
||||
# TODO: Remove these in favor of interface deps.
|
||||
${dialect_libs}
|
||||
${conversion_libs}
|
||||
)
|
||||
|
||||
mlir_check_all_link_libraries(npcomp-opt)
|
|
@ -1,103 +0,0 @@
|
|||
//===- npcomp-opt.cpp -------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "mlir/IR/AsmState.h"
|
||||
#include "mlir/IR/Dialect.h"
|
||||
#include "mlir/IR/MLIRContext.h"
|
||||
#include "mlir/InitAllDialects.h"
|
||||
#include "mlir/InitAllPasses.h"
|
||||
#include "mlir/Pass/Pass.h"
|
||||
#include "mlir/Pass/PassManager.h"
|
||||
#include "mlir/Support/FileUtilities.h"
|
||||
#include "mlir/Support/MlirOptMain.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/ToolOutputFile.h"
|
||||
|
||||
#include "npcomp/InitAll.h"
|
||||
#include "torch-mlir/InitAll.h"
|
||||
|
||||
static llvm::cl::opt<std::string> inputFilename(llvm::cl::Positional,
|
||||
llvm::cl::desc("<input file>"),
|
||||
llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<std::string>
|
||||
outputFilename("o", llvm::cl::desc("Output filename"),
|
||||
llvm::cl::value_desc("filename"), llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<bool> splitInputFile(
|
||||
"split-input-file",
|
||||
llvm::cl::desc("Split the input file into pieces and process each "
|
||||
"chunk independently"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verifyDiagnostics(
|
||||
"verify-diagnostics",
|
||||
llvm::cl::desc("Check that emitted diagnostics match "
|
||||
"expected-* lines on the corresponding line"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verifyPasses(
|
||||
"verify-each",
|
||||
llvm::cl::desc("Run the verifier after each transformation pass"),
|
||||
llvm::cl::init(true));
|
||||
|
||||
static llvm::cl::opt<bool> allowUnregisteredDialects(
|
||||
"allow-unregistered-dialect",
|
||||
llvm::cl::desc("Allow operation with no registered dialects"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
mlir::DialectRegistry registry;
|
||||
|
||||
mlir::registerAsmPrinterCLOptions();
|
||||
mlir::registerMLIRContextCLOptions();
|
||||
|
||||
mlir::registerAllDialects(registry);
|
||||
mlir::registerAllPasses();
|
||||
|
||||
mlir::NPCOMP::registerAllDialects(registry);
|
||||
mlir::NPCOMP::registerAllPasses();
|
||||
|
||||
mlir::torch::registerAllDialects(registry);
|
||||
mlir::torch::registerAllPasses();
|
||||
|
||||
llvm::InitLLVM y(argc, argv);
|
||||
|
||||
// Register any pass manager command line options.
|
||||
mlir::registerPassManagerCLOptions();
|
||||
mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run");
|
||||
|
||||
// Parse pass names in main to ensure static initialization completed.
|
||||
llvm::cl::ParseCommandLineOptions(argc, argv,
|
||||
"MLIR modular optimizer driver\n");
|
||||
|
||||
// Set up the input file.
|
||||
std::string errorMessage;
|
||||
auto file = mlir::openInputFile(inputFilename, &errorMessage);
|
||||
if (!file) {
|
||||
llvm::errs() << errorMessage << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto output = mlir::openOutputFile(outputFilename, &errorMessage);
|
||||
if (!output) {
|
||||
llvm::errs() << errorMessage << "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (failed(MlirOptMain(output->os(), std::move(file), passPipeline, registry,
|
||||
splitInputFile, verifyDiagnostics, verifyPasses,
|
||||
allowUnregisteredDialects))) {
|
||||
return 1;
|
||||
}
|
||||
// Keep the output file if the invocation of MlirOptMain was successful.
|
||||
output->keep();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue