2021-10-08 12:44:15 +08:00
|
|
|
cmake_minimum_required(VERSION 3.12)
|
|
|
|
|
|
|
|
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)
|
[torch-mlir earthmoving (1/N)] C/C++ code movement.
This creates the `external/torch-mlir` directory as an
LLVM_EXTERNAL_PROJECTS-compatible project (analogous to
`iree-dialects`) and completes movement/rename of all pure MLIR C/C++
compiler code into there. The next step will be to move all the Python
code / code that links/includes PyTorch C++ code (which currently lives
in `frontends/pytorch`) into a subdirectory here.
I call this "earthmoving" because it is mostly mechanical changes and
renames. As a quick summary (we can change this down the road easily)
- C++ `mlir::NPCOMP::Torch -> mlir::torch::Torch`
- CAPI `npcompTorchListTypeGet -> torchMlirTorchListTypeGet`
- preprocessor `#ifndef NPCOMP_ -> #ifndef TORCHMLIR_`
- CMake `NPCOMPFoo -> TorchMLIRFoo`
The goal of this is to create a standalone project creating a center of
mass for entry into the MLIR ecosystem from PyTorch, suitable in scope
for eventual inclusion/ownership in PyTorch. The idea is that
`external/torch-mlir` will some day be pulled out into its own
repository, and then npcomp will simply pull it in as a submodule.
Layering-wise, what lives in `torch-mlir` lowers code from PyTorch
(currently TorchScript, but TorchFX or pytorch/xla-style tracing are
possible extensions) down to what we have been calling the "Torch
backend contract" which is cleaned up IR (inlining, simplifcation,
conversion to value tensors, ...) entirely in the `torch` dialect. This
is the branching off point for further lowering, of which npcomp takes
one opinion (outside `torch-mlir` of course!), namely the
`TorchConversion` dialect/transforms which lower to IR suitable for IREE
and other linalg-on-tensors based lower-level compilers.
Summary of changes:
- move `{include,lib,test}/Dialect/Torch` into `torch-mlir`
- move relevant parts of CAPI into `torch-mlir`.
- leave a few things related to the `torch-mlir` Python build commented
out, which should be resolved in a subsequent change.
2021-09-10 03:24:10 +08:00
|
|
|
endif()
|
|
|
|
|
2022-01-26 14:16:30 +08:00
|
|
|
if(POLICY CMP0116)
|
|
|
|
cmake_policy(SET CMP0116 OLD)
|
|
|
|
endif()
|
|
|
|
|
2021-10-08 12:44:15 +08:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Project setup and globals
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
2021-10-09 02:28:40 +08:00
|
|
|
project(torch-mlir LANGUAGES CXX C)
|
2021-10-08 12:44:15 +08:00
|
|
|
set(CMAKE_C_STANDARD 11)
|
2022-08-09 11:17:35 +08:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2021-10-08 12:44:15 +08:00
|
|
|
|
2022-02-03 07:01:38 +08:00
|
|
|
macro(torch_mlir_add_llvm_external_project name identifier location)
|
|
|
|
message(STATUS "Adding LLVM external project ${name} (${identifier}) -> ${location}")
|
|
|
|
if(NOT EXISTS "${location}/CMakeLists.txt")
|
|
|
|
message(FATAL_ERROR "External project location ${location} is not valid")
|
|
|
|
endif()
|
|
|
|
list(APPEND LLVM_EXTERNAL_PROJECTS ${name})
|
|
|
|
list(REMOVE_DUPLICATES LLVM_EXTERNAL_PROJECTS)
|
|
|
|
set(LLVM_EXTERNAL_${identifier}_SOURCE_DIR ${location} CACHE STRING "" FORCE)
|
|
|
|
set(LLVM_EXTERNAL_PROJECTS ${LLVM_EXTERNAL_PROJECTS} CACHE STRING "" FORCE)
|
|
|
|
endmacro()
|
|
|
|
|
2022-07-21 07:18:16 +08:00
|
|
|
option(TORCH_MLIR_ENABLE_MHLO "Add mhlo dialect" ON)
|
|
|
|
if(TORCH_MLIR_ENABLE_MHLO)
|
|
|
|
add_definitions(-DTORCH_MLIR_ENABLE_MHLO)
|
|
|
|
endif()
|
|
|
|
|
2022-08-29 10:11:40 +08:00
|
|
|
option(TORCH_MLIR_ENABLE_LTC "Enables LTC backend" OFF)
|
2022-07-30 17:54:40 +08:00
|
|
|
|
2022-08-16 21:30:22 +08:00
|
|
|
if(TORCH_MLIR_ENABLE_LTC)
|
|
|
|
set(ENV{TORCH_MLIR_ENABLE_LTC} 1)
|
2022-09-29 23:43:39 +08:00
|
|
|
message(STATUS "LTC Backend build is enabled")
|
2022-08-16 21:30:22 +08:00
|
|
|
else()
|
|
|
|
set(ENV{TORCH_MLIR_ENABLE_LTC} 0)
|
2022-09-29 23:43:39 +08:00
|
|
|
message(STATUS "LTC Backend build is disabled")
|
2022-08-16 21:30:22 +08:00
|
|
|
endif()
|
|
|
|
|
2022-02-03 07:01:38 +08:00
|
|
|
torch_mlir_add_llvm_external_project(
|
|
|
|
torch-mlir-dialects
|
|
|
|
TORCH_MLIR_DIALECTS
|
2022-03-27 00:12:27 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/externals/llvm-external-projects/torch-mlir-dialects)
|
2022-02-03 07:01:38 +08:00
|
|
|
|
2022-09-26 23:58:05 +08:00
|
|
|
option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF)
|
2022-09-23 10:01:37 +08:00
|
|
|
|
ci: enable ccache on Windows (#1548)
This patch makes a few small, but key, changes to enable ccache on
Windows. First, it replaces the hendrikmuhs/ccache-action action with
command line invocations to the ccache binary, since the action has two
bugs, one of which causes CI to refer to different ccache artifacts
before versus after the build on Windows whereas the other bug can
sometimes cause the action to incorrectly infer that the cache is empty.
Second, this patch slightly alters the cache key, so that our old cache
artifacts, which have grown too big, are eventually discarded in favor
of the new, smaller cache artifacts. Along the way, this patch also
keeps the RollPyTorch's cache artifact separate from the regular build's
cache artifact so as to keep these artifacts small, and also because the
RollPyTorch action is off the critical path for most contributors.
Finally, this patch makes small changes to the CMake file so that on
Windows, the ccache binary is added as a prefix, as recommended on the
[ccache Wiki](https://github.com/ccache/ccache/wiki/MS-Visual-Studio).
2022-11-04 01:17:22 +08:00
|
|
|
# Adjustments to use ccache on Windows
|
|
|
|
if (WIN32)
|
|
|
|
find_program(ccache_exe ccache)
|
|
|
|
if(ccache_exe)
|
|
|
|
file(COPY_FILE ${ccache_exe} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT)
|
|
|
|
set(CMAKE_VS_GLOBALS
|
|
|
|
"CLToolExe=cl.exe"
|
|
|
|
"CLToolPath=${CMAKE_BINARY_DIR}"
|
|
|
|
"TrackFileAccess=false"
|
|
|
|
"UseMultiToolTask=true"
|
|
|
|
"DebugInformationFormat=OldStyle"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2022-09-26 23:58:05 +08:00
|
|
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR TORCH_MLIR_OUT_OF_TREE_BUILD)
|
2022-07-21 07:18:16 +08:00
|
|
|
message(STATUS "Torch-MLIR out-of-tree build.")
|
2021-10-08 12:44:15 +08:00
|
|
|
# Out-of-tree build
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# MLIR/LLVM Configuration
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
find_package(MLIR REQUIRED CONFIG)
|
|
|
|
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
|
|
|
|
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
|
|
|
|
|
|
|
|
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
|
|
|
|
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
|
|
|
|
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
2021-10-22 12:09:00 +08:00
|
|
|
|
2021-10-08 12:44:15 +08:00
|
|
|
# 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")
|
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
|
|
|
|
include(TableGen)
|
|
|
|
include(AddLLVM)
|
|
|
|
include(AddMLIR)
|
|
|
|
include(HandleLLVMOptions)
|
|
|
|
|
|
|
|
# Don't try to compile the python extensions at the moment. We need
|
|
|
|
# to import lots of dependencies from AddMLIRPython to make this work.
|
2021-10-28 08:04:12 +08:00
|
|
|
set(MLIR_ENABLE_BINDINGS_PYTHON 1)
|
|
|
|
option(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER "Enables JIT IR Importer" ON)
|
2021-10-08 12:44:15 +08:00
|
|
|
|
2021-10-09 02:28:40 +08:00
|
|
|
set(TORCH-MLIR_BUILT_STANDALONE 1)
|
2021-10-08 12:44:15 +08:00
|
|
|
set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
|
2022-03-27 00:12:27 +08:00
|
|
|
add_subdirectory(externals/llvm-external-projects/torch-mlir-dialects)
|
2021-10-08 12:44:15 +08:00
|
|
|
else()
|
2022-07-21 07:18:16 +08:00
|
|
|
message(STATUS "Torch-MLIR in-tree build.")
|
2021-10-08 12:44:15 +08:00
|
|
|
# In-tree build with LLVM_EXTERNAL_PROJECTS=torch-mlir
|
2021-10-22 12:09:00 +08:00
|
|
|
|
2021-10-08 12:44:15 +08:00
|
|
|
option(MLIR_ENABLE_BINDINGS_PYTHON "Enables MLIR Python Bindings" OFF)
|
|
|
|
option(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER "Enables JIT IR Importer" ON)
|
|
|
|
|
|
|
|
# TODO: Fix this upstream so that global include directories are not needed.
|
|
|
|
set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir)
|
|
|
|
set(MLIR_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include)
|
|
|
|
set(MLIR_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/mlir/include)
|
|
|
|
set(MLIR_INCLUDE_DIRS "${MLIR_INCLUDE_DIR};${MLIR_GENERATED_INCLUDE_DIR}")
|
2021-10-09 02:28:40 +08:00
|
|
|
endif()
|
[torch-mlir earthmoving (1/N)] C/C++ code movement.
This creates the `external/torch-mlir` directory as an
LLVM_EXTERNAL_PROJECTS-compatible project (analogous to
`iree-dialects`) and completes movement/rename of all pure MLIR C/C++
compiler code into there. The next step will be to move all the Python
code / code that links/includes PyTorch C++ code (which currently lives
in `frontends/pytorch`) into a subdirectory here.
I call this "earthmoving" because it is mostly mechanical changes and
renames. As a quick summary (we can change this down the road easily)
- C++ `mlir::NPCOMP::Torch -> mlir::torch::Torch`
- CAPI `npcompTorchListTypeGet -> torchMlirTorchListTypeGet`
- preprocessor `#ifndef NPCOMP_ -> #ifndef TORCHMLIR_`
- CMake `NPCOMPFoo -> TorchMLIRFoo`
The goal of this is to create a standalone project creating a center of
mass for entry into the MLIR ecosystem from PyTorch, suitable in scope
for eventual inclusion/ownership in PyTorch. The idea is that
`external/torch-mlir` will some day be pulled out into its own
repository, and then npcomp will simply pull it in as a submodule.
Layering-wise, what lives in `torch-mlir` lowers code from PyTorch
(currently TorchScript, but TorchFX or pytorch/xla-style tracing are
possible extensions) down to what we have been calling the "Torch
backend contract" which is cleaned up IR (inlining, simplifcation,
conversion to value tensors, ...) entirely in the `torch` dialect. This
is the branching off point for further lowering, of which npcomp takes
one opinion (outside `torch-mlir` of course!), namely the
`TorchConversion` dialect/transforms which lower to IR suitable for IREE
and other linalg-on-tensors based lower-level compilers.
Summary of changes:
- move `{include,lib,test}/Dialect/Torch` into `torch-mlir`
- move relevant parts of CAPI into `torch-mlir`.
- leave a few things related to the `torch-mlir` Python build commented
out, which should be resolved in a subsequent change.
2021-09-10 03:24:10 +08:00
|
|
|
|
2022-07-21 07:18:16 +08:00
|
|
|
if (TORCH_MLIR_ENABLE_MHLO)
|
|
|
|
set(MHLO_BUILD_EMBEDDED ON)
|
|
|
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/externals/mlir-hlo
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/mlir-hlo
|
|
|
|
EXCLUDE_FROM_ALL)
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/mlir-hlo/include)
|
2022-11-17 06:40:36 +08:00
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/mlir-hlo)
|
2022-07-21 07:18:16 +08:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/mlir-hlo/include)
|
2022-11-17 06:40:36 +08:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/mlir-hlo)
|
2022-07-21 07:18:16 +08:00
|
|
|
endif()
|
|
|
|
|
[torch-mlir earthmoving (1/N)] C/C++ code movement.
This creates the `external/torch-mlir` directory as an
LLVM_EXTERNAL_PROJECTS-compatible project (analogous to
`iree-dialects`) and completes movement/rename of all pure MLIR C/C++
compiler code into there. The next step will be to move all the Python
code / code that links/includes PyTorch C++ code (which currently lives
in `frontends/pytorch`) into a subdirectory here.
I call this "earthmoving" because it is mostly mechanical changes and
renames. As a quick summary (we can change this down the road easily)
- C++ `mlir::NPCOMP::Torch -> mlir::torch::Torch`
- CAPI `npcompTorchListTypeGet -> torchMlirTorchListTypeGet`
- preprocessor `#ifndef NPCOMP_ -> #ifndef TORCHMLIR_`
- CMake `NPCOMPFoo -> TorchMLIRFoo`
The goal of this is to create a standalone project creating a center of
mass for entry into the MLIR ecosystem from PyTorch, suitable in scope
for eventual inclusion/ownership in PyTorch. The idea is that
`external/torch-mlir` will some day be pulled out into its own
repository, and then npcomp will simply pull it in as a submodule.
Layering-wise, what lives in `torch-mlir` lowers code from PyTorch
(currently TorchScript, but TorchFX or pytorch/xla-style tracing are
possible extensions) down to what we have been calling the "Torch
backend contract" which is cleaned up IR (inlining, simplifcation,
conversion to value tensors, ...) entirely in the `torch` dialect. This
is the branching off point for further lowering, of which npcomp takes
one opinion (outside `torch-mlir` of course!), namely the
`TorchConversion` dialect/transforms which lower to IR suitable for IREE
and other linalg-on-tensors based lower-level compilers.
Summary of changes:
- move `{include,lib,test}/Dialect/Torch` into `torch-mlir`
- move relevant parts of CAPI into `torch-mlir`.
- leave a few things related to the `torch-mlir` Python build commented
out, which should be resolved in a subsequent change.
2021-09-10 03:24:10 +08:00
|
|
|
set(TORCH_MLIR_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
|
|
set(TORCH_MLIR_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
message(STATUS "Building torch-mlir project at ${TORCH_MLIR_SOURCE_DIR} (into ${TORCH_MLIR_BINARY_DIR})")
|
|
|
|
|
2021-10-08 12:44:15 +08:00
|
|
|
include_directories(${LLVM_INCLUDE_DIRS})
|
|
|
|
include_directories(${MLIR_INCLUDE_DIRS})
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
|
[torch-mlir earthmoving (1/N)] C/C++ code movement.
This creates the `external/torch-mlir` directory as an
LLVM_EXTERNAL_PROJECTS-compatible project (analogous to
`iree-dialects`) and completes movement/rename of all pure MLIR C/C++
compiler code into there. The next step will be to move all the Python
code / code that links/includes PyTorch C++ code (which currently lives
in `frontends/pytorch`) into a subdirectory here.
I call this "earthmoving" because it is mostly mechanical changes and
renames. As a quick summary (we can change this down the road easily)
- C++ `mlir::NPCOMP::Torch -> mlir::torch::Torch`
- CAPI `npcompTorchListTypeGet -> torchMlirTorchListTypeGet`
- preprocessor `#ifndef NPCOMP_ -> #ifndef TORCHMLIR_`
- CMake `NPCOMPFoo -> TorchMLIRFoo`
The goal of this is to create a standalone project creating a center of
mass for entry into the MLIR ecosystem from PyTorch, suitable in scope
for eventual inclusion/ownership in PyTorch. The idea is that
`external/torch-mlir` will some day be pulled out into its own
repository, and then npcomp will simply pull it in as a submodule.
Layering-wise, what lives in `torch-mlir` lowers code from PyTorch
(currently TorchScript, but TorchFX or pytorch/xla-style tracing are
possible extensions) down to what we have been calling the "Torch
backend contract" which is cleaned up IR (inlining, simplifcation,
conversion to value tensors, ...) entirely in the `torch` dialect. This
is the branching off point for further lowering, of which npcomp takes
one opinion (outside `torch-mlir` of course!), namely the
`TorchConversion` dialect/transforms which lower to IR suitable for IREE
and other linalg-on-tensors based lower-level compilers.
Summary of changes:
- move `{include,lib,test}/Dialect/Torch` into `torch-mlir`
- move relevant parts of CAPI into `torch-mlir`.
- leave a few things related to the `torch-mlir` Python build commented
out, which should be resolved in a subsequent change.
2021-09-10 03:24:10 +08:00
|
|
|
|
|
|
|
function(torch_mlir_target_includes target)
|
|
|
|
set(_dirs
|
2022-04-04 17:37:28 +08:00
|
|
|
$<BUILD_INTERFACE:${MLIR_INCLUDE_DIRS}>
|
[torch-mlir earthmoving (1/N)] C/C++ code movement.
This creates the `external/torch-mlir` directory as an
LLVM_EXTERNAL_PROJECTS-compatible project (analogous to
`iree-dialects`) and completes movement/rename of all pure MLIR C/C++
compiler code into there. The next step will be to move all the Python
code / code that links/includes PyTorch C++ code (which currently lives
in `frontends/pytorch`) into a subdirectory here.
I call this "earthmoving" because it is mostly mechanical changes and
renames. As a quick summary (we can change this down the road easily)
- C++ `mlir::NPCOMP::Torch -> mlir::torch::Torch`
- CAPI `npcompTorchListTypeGet -> torchMlirTorchListTypeGet`
- preprocessor `#ifndef NPCOMP_ -> #ifndef TORCHMLIR_`
- CMake `NPCOMPFoo -> TorchMLIRFoo`
The goal of this is to create a standalone project creating a center of
mass for entry into the MLIR ecosystem from PyTorch, suitable in scope
for eventual inclusion/ownership in PyTorch. The idea is that
`external/torch-mlir` will some day be pulled out into its own
repository, and then npcomp will simply pull it in as a submodule.
Layering-wise, what lives in `torch-mlir` lowers code from PyTorch
(currently TorchScript, but TorchFX or pytorch/xla-style tracing are
possible extensions) down to what we have been calling the "Torch
backend contract" which is cleaned up IR (inlining, simplifcation,
conversion to value tensors, ...) entirely in the `torch` dialect. This
is the branching off point for further lowering, of which npcomp takes
one opinion (outside `torch-mlir` of course!), namely the
`TorchConversion` dialect/transforms which lower to IR suitable for IREE
and other linalg-on-tensors based lower-level compilers.
Summary of changes:
- move `{include,lib,test}/Dialect/Torch` into `torch-mlir`
- move relevant parts of CAPI into `torch-mlir`.
- leave a few things related to the `torch-mlir` Python build commented
out, which should be resolved in a subsequent change.
2021-09-10 03:24:10 +08:00
|
|
|
$<BUILD_INTERFACE:${TORCH_MLIR_SOURCE_DIR}/include>
|
|
|
|
$<BUILD_INTERFACE:${TORCH_MLIR_BINARY_DIR}/include>
|
|
|
|
)
|
|
|
|
# In LLVM parlance, the actual target may just be an interface and may not
|
|
|
|
# be responsible for actually compiling anything. The corresponding obj.
|
|
|
|
# target, when present, is just used for compilation and does not
|
|
|
|
# contribute to the interface properties.
|
|
|
|
# TODO: Normalize this upstream.
|
|
|
|
target_include_directories(${target} PUBLIC ${_dirs})
|
|
|
|
if(TARGET obj.${target})
|
|
|
|
target_include_directories(obj.${target} PRIVATE ${_dirs})
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2022-02-26 06:41:09 +08:00
|
|
|
# Configure CMake.
|
[torch-mlir earthmoving (1/N)] C/C++ code movement.
This creates the `external/torch-mlir` directory as an
LLVM_EXTERNAL_PROJECTS-compatible project (analogous to
`iree-dialects`) and completes movement/rename of all pure MLIR C/C++
compiler code into there. The next step will be to move all the Python
code / code that links/includes PyTorch C++ code (which currently lives
in `frontends/pytorch`) into a subdirectory here.
I call this "earthmoving" because it is mostly mechanical changes and
renames. As a quick summary (we can change this down the road easily)
- C++ `mlir::NPCOMP::Torch -> mlir::torch::Torch`
- CAPI `npcompTorchListTypeGet -> torchMlirTorchListTypeGet`
- preprocessor `#ifndef NPCOMP_ -> #ifndef TORCHMLIR_`
- CMake `NPCOMPFoo -> TorchMLIRFoo`
The goal of this is to create a standalone project creating a center of
mass for entry into the MLIR ecosystem from PyTorch, suitable in scope
for eventual inclusion/ownership in PyTorch. The idea is that
`external/torch-mlir` will some day be pulled out into its own
repository, and then npcomp will simply pull it in as a submodule.
Layering-wise, what lives in `torch-mlir` lowers code from PyTorch
(currently TorchScript, but TorchFX or pytorch/xla-style tracing are
possible extensions) down to what we have been calling the "Torch
backend contract" which is cleaned up IR (inlining, simplifcation,
conversion to value tensors, ...) entirely in the `torch` dialect. This
is the branching off point for further lowering, of which npcomp takes
one opinion (outside `torch-mlir` of course!), namely the
`TorchConversion` dialect/transforms which lower to IR suitable for IREE
and other linalg-on-tensors based lower-level compilers.
Summary of changes:
- move `{include,lib,test}/Dialect/Torch` into `torch-mlir`
- move relevant parts of CAPI into `torch-mlir`.
- leave a few things related to the `torch-mlir` Python build commented
out, which should be resolved in a subsequent change.
2021-09-10 03:24:10 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH ${MLIR_MAIN_SRC_DIR}/cmake/modules)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${LLVM_MAIN_SRC_DIR}/cmake)
|
|
|
|
|
|
|
|
include(TableGen)
|
|
|
|
include(AddLLVM)
|
|
|
|
include(AddMLIR)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Setup python.
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
if(MLIR_ENABLE_BINDINGS_PYTHON)
|
|
|
|
include(MLIRDetectPythonEnv)
|
2021-10-22 12:09:00 +08:00
|
|
|
mlir_configure_python_dev_packages()
|
[torch-mlir earthmoving (1/N)] C/C++ code movement.
This creates the `external/torch-mlir` directory as an
LLVM_EXTERNAL_PROJECTS-compatible project (analogous to
`iree-dialects`) and completes movement/rename of all pure MLIR C/C++
compiler code into there. The next step will be to move all the Python
code / code that links/includes PyTorch C++ code (which currently lives
in `frontends/pytorch`) into a subdirectory here.
I call this "earthmoving" because it is mostly mechanical changes and
renames. As a quick summary (we can change this down the road easily)
- C++ `mlir::NPCOMP::Torch -> mlir::torch::Torch`
- CAPI `npcompTorchListTypeGet -> torchMlirTorchListTypeGet`
- preprocessor `#ifndef NPCOMP_ -> #ifndef TORCHMLIR_`
- CMake `NPCOMPFoo -> TorchMLIRFoo`
The goal of this is to create a standalone project creating a center of
mass for entry into the MLIR ecosystem from PyTorch, suitable in scope
for eventual inclusion/ownership in PyTorch. The idea is that
`external/torch-mlir` will some day be pulled out into its own
repository, and then npcomp will simply pull it in as a submodule.
Layering-wise, what lives in `torch-mlir` lowers code from PyTorch
(currently TorchScript, but TorchFX or pytorch/xla-style tracing are
possible extensions) down to what we have been calling the "Torch
backend contract" which is cleaned up IR (inlining, simplifcation,
conversion to value tensors, ...) entirely in the `torch` dialect. This
is the branching off point for further lowering, of which npcomp takes
one opinion (outside `torch-mlir` of course!), namely the
`TorchConversion` dialect/transforms which lower to IR suitable for IREE
and other linalg-on-tensors based lower-level compilers.
Summary of changes:
- move `{include,lib,test}/Dialect/Torch` into `torch-mlir`
- move relevant parts of CAPI into `torch-mlir`.
- leave a few things related to the `torch-mlir` Python build commented
out, which should be resolved in a subsequent change.
2021-09-10 03:24:10 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
add_subdirectory(include)
|
|
|
|
add_subdirectory(lib)
|
|
|
|
add_subdirectory(tools)
|
|
|
|
|
2021-09-28 02:36:44 +08:00
|
|
|
add_custom_target(check-torch-mlir-all)
|
|
|
|
add_dependencies(check-torch-mlir-all
|
|
|
|
check-torch-mlir
|
2022-02-03 07:01:38 +08:00
|
|
|
check-torch-mlir-dialects
|
2021-09-28 02:36:44 +08:00
|
|
|
)
|
|
|
|
|
[torch-mlir earthmoving (1/N)] C/C++ code movement.
This creates the `external/torch-mlir` directory as an
LLVM_EXTERNAL_PROJECTS-compatible project (analogous to
`iree-dialects`) and completes movement/rename of all pure MLIR C/C++
compiler code into there. The next step will be to move all the Python
code / code that links/includes PyTorch C++ code (which currently lives
in `frontends/pytorch`) into a subdirectory here.
I call this "earthmoving" because it is mostly mechanical changes and
renames. As a quick summary (we can change this down the road easily)
- C++ `mlir::NPCOMP::Torch -> mlir::torch::Torch`
- CAPI `npcompTorchListTypeGet -> torchMlirTorchListTypeGet`
- preprocessor `#ifndef NPCOMP_ -> #ifndef TORCHMLIR_`
- CMake `NPCOMPFoo -> TorchMLIRFoo`
The goal of this is to create a standalone project creating a center of
mass for entry into the MLIR ecosystem from PyTorch, suitable in scope
for eventual inclusion/ownership in PyTorch. The idea is that
`external/torch-mlir` will some day be pulled out into its own
repository, and then npcomp will simply pull it in as a submodule.
Layering-wise, what lives in `torch-mlir` lowers code from PyTorch
(currently TorchScript, but TorchFX or pytorch/xla-style tracing are
possible extensions) down to what we have been calling the "Torch
backend contract" which is cleaned up IR (inlining, simplifcation,
conversion to value tensors, ...) entirely in the `torch` dialect. This
is the branching off point for further lowering, of which npcomp takes
one opinion (outside `torch-mlir` of course!), namely the
`TorchConversion` dialect/transforms which lower to IR suitable for IREE
and other linalg-on-tensors based lower-level compilers.
Summary of changes:
- move `{include,lib,test}/Dialect/Torch` into `torch-mlir`
- move relevant parts of CAPI into `torch-mlir`.
- leave a few things related to the `torch-mlir` Python build commented
out, which should be resolved in a subsequent change.
2021-09-10 03:24:10 +08:00
|
|
|
if(MLIR_ENABLE_BINDINGS_PYTHON)
|
2021-09-21 04:55:36 +08:00
|
|
|
# If parent projects want to configure where to place the python packages,
|
|
|
|
# respect that.
|
2021-09-11 02:44:38 +08:00
|
|
|
if(NOT TORCH_MLIR_PYTHON_PACKAGES_DIR)
|
|
|
|
set(TORCH_MLIR_PYTHON_PACKAGES_DIR "${CMAKE_CURRENT_BINARY_DIR}/python_packages")
|
|
|
|
endif()
|
2021-10-08 12:44:15 +08:00
|
|
|
add_dependencies(check-torch-mlir-all
|
|
|
|
check-torch-mlir-python
|
|
|
|
)
|
2021-09-11 02:44:38 +08:00
|
|
|
add_subdirectory(python)
|
2021-10-08 12:44:15 +08:00
|
|
|
else()
|
|
|
|
add_custom_target(TorchMLIRPythonModules)
|
[torch-mlir earthmoving (1/N)] C/C++ code movement.
This creates the `external/torch-mlir` directory as an
LLVM_EXTERNAL_PROJECTS-compatible project (analogous to
`iree-dialects`) and completes movement/rename of all pure MLIR C/C++
compiler code into there. The next step will be to move all the Python
code / code that links/includes PyTorch C++ code (which currently lives
in `frontends/pytorch`) into a subdirectory here.
I call this "earthmoving" because it is mostly mechanical changes and
renames. As a quick summary (we can change this down the road easily)
- C++ `mlir::NPCOMP::Torch -> mlir::torch::Torch`
- CAPI `npcompTorchListTypeGet -> torchMlirTorchListTypeGet`
- preprocessor `#ifndef NPCOMP_ -> #ifndef TORCHMLIR_`
- CMake `NPCOMPFoo -> TorchMLIRFoo`
The goal of this is to create a standalone project creating a center of
mass for entry into the MLIR ecosystem from PyTorch, suitable in scope
for eventual inclusion/ownership in PyTorch. The idea is that
`external/torch-mlir` will some day be pulled out into its own
repository, and then npcomp will simply pull it in as a submodule.
Layering-wise, what lives in `torch-mlir` lowers code from PyTorch
(currently TorchScript, but TorchFX or pytorch/xla-style tracing are
possible extensions) down to what we have been calling the "Torch
backend contract" which is cleaned up IR (inlining, simplifcation,
conversion to value tensors, ...) entirely in the `torch` dialect. This
is the branching off point for further lowering, of which npcomp takes
one opinion (outside `torch-mlir` of course!), namely the
`TorchConversion` dialect/transforms which lower to IR suitable for IREE
and other linalg-on-tensors based lower-level compilers.
Summary of changes:
- move `{include,lib,test}/Dialect/Torch` into `torch-mlir`
- move relevant parts of CAPI into `torch-mlir`.
- leave a few things related to the `torch-mlir` Python build commented
out, which should be resolved in a subsequent change.
2021-09-10 03:24:10 +08:00
|
|
|
endif()
|
2021-09-11 02:44:38 +08:00
|
|
|
|
|
|
|
add_subdirectory(test)
|