mirror of https://github.com/llvm/torch-mlir
Enable pt1 build.
parent
45c6ee1090
commit
823e051344
|
@ -1,3 +1,7 @@
|
|||
#-------------------------------------------------------------------------------
|
||||
# Project setup and globals
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
if(POLICY CMP0068)
|
||||
|
@ -17,25 +21,10 @@ if(POLICY CMP0116)
|
|||
cmake_policy(SET CMP0116 OLD)
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Project setup and globals
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
project(torch-mlir LANGUAGES CXX C)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
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()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Project options
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -50,13 +39,31 @@ if(TORCH_MLIR_ENABLE_STABLEHLO)
|
|||
add_definitions(-DTORCH_MLIR_ENABLE_STABLEHLO)
|
||||
endif()
|
||||
|
||||
# torch_mlir_add_llvm_external_project(
|
||||
# torch-mlir-dialects
|
||||
# TORCH_MLIR_DIALECTS
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/externals/llvm-external-projects/torch-mlir-dialects)
|
||||
|
||||
option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF)
|
||||
|
||||
# PT1 options.
|
||||
option(TORCH_MLIR_ENABLE_PROJECT_PT1 "Enables the PyTorch1 project under projects/pt1" OFF)
|
||||
# TODO: Rename/scope these. They use historic names for now to ease migration
|
||||
# burden.
|
||||
option(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER "Enables JIT IR Importer" ON)
|
||||
option(TORCH_MLIR_ENABLE_LTC "Enables LTC backend" OFF)
|
||||
option(TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS "Build Torch dialect MLIR Python bindings but neither JIT IR Importer nor LTC backend" OFF)
|
||||
if(TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS)
|
||||
set(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER OFF)
|
||||
set(TORCH_MLIR_ENABLE_LTC OFF)
|
||||
endif()
|
||||
# Force enable the PT1 project if either the JIT_IR_IMPORTER or LTC is enabled.
|
||||
if(NOT TORCH_MLIR_ENABLE_PROJECT_PT1)
|
||||
if(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER OR TORCH_MLIR_ENABLE_LTC)
|
||||
message(STATUS "Enabling projects/pt1 because features requiring it are enabled")
|
||||
set(TORCH_MLIR_ENABLE_PROJECT_PT1 ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Configure out-of-tree vs in-tree build
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR TORCH_MLIR_OUT_OF_TREE_BUILD)
|
||||
message(STATUS "Torch-MLIR out-of-tree build.")
|
||||
# Out-of-tree build
|
||||
|
@ -170,11 +177,6 @@ if(MLIR_ENABLE_BINDINGS_PYTHON)
|
|||
if(NOT TORCH_MLIR_PYTHON_PACKAGES_DIR)
|
||||
set(TORCH_MLIR_PYTHON_PACKAGES_DIR "${CMAKE_CURRENT_BINARY_DIR}/python_packages")
|
||||
endif()
|
||||
#add_subdirectory(python)
|
||||
# TODO: Remove
|
||||
add_custom_target(TorchMLIRPythonModules)
|
||||
else()
|
||||
add_custom_target(TorchMLIRPythonModules)
|
||||
endif()
|
||||
|
||||
add_subdirectory(test)
|
||||
|
@ -225,3 +227,11 @@ if (TORCH_MLIR_ENABLE_STABLEHLO)
|
|||
EXCLUDE_FROM_ALL)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo)
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Sub-projects
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if(TORCH_MLIR_ENABLE_PROJECT_PT1)
|
||||
add_subdirectory(projects/pt1)
|
||||
endif()
|
||||
|
|
|
@ -1,53 +1,4 @@
|
|||
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)
|
||||
endif()
|
||||
|
||||
if(POLICY CMP0116)
|
||||
cmake_policy(SET CMP0116 OLD)
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Project setup and globals
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
project(torch-mlir LANGUAGES CXX C)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
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()
|
||||
|
||||
option(TORCH_MLIR_ENABLE_STABLEHLO "Add stablehlo dialect" ON)
|
||||
if(TORCH_MLIR_ENABLE_STABLEHLO)
|
||||
add_definitions(-DTORCH_MLIR_ENABLE_STABLEHLO)
|
||||
endif()
|
||||
|
||||
option(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER "Enables JIT IR Importer" ON)
|
||||
option(TORCH_MLIR_ENABLE_LTC "Enables LTC backend" OFF)
|
||||
option(TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS "Build Torch dialect MLIR Python bindings but neither JIT IR Importer nor LTC backend" OFF)
|
||||
if(TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS)
|
||||
set(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER OFF)
|
||||
set(TORCH_MLIR_ENABLE_LTC OFF)
|
||||
endif()
|
||||
message(STATUS "Building PyTorch1 compatibility project")
|
||||
|
||||
if(TORCH_MLIR_ENABLE_LTC)
|
||||
set(ENV{TORCH_MLIR_ENABLE_LTC} 1)
|
||||
|
@ -57,132 +8,16 @@ else()
|
|||
message(STATUS "LTC Backend build is disabled")
|
||||
endif()
|
||||
|
||||
torch_mlir_add_llvm_external_project(
|
||||
torch-mlir-dialects
|
||||
TORCH_MLIR_DIALECTS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/externals/llvm-external-projects/torch-mlir-dialects)
|
||||
|
||||
option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR TORCH_MLIR_OUT_OF_TREE_BUILD)
|
||||
message(STATUS "Torch-MLIR out-of-tree build.")
|
||||
# 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)
|
||||
|
||||
# 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.
|
||||
set(MLIR_ENABLE_BINDINGS_PYTHON 1)
|
||||
|
||||
set(TORCH-MLIR_BUILT_STANDALONE 1)
|
||||
set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
|
||||
add_subdirectory(externals/llvm-external-projects/torch-mlir-dialects)
|
||||
else()
|
||||
message(STATUS "Torch-MLIR in-tree build.")
|
||||
# In-tree build with LLVM_EXTERNAL_PROJECTS=torch-mlir
|
||||
|
||||
option(MLIR_ENABLE_BINDINGS_PYTHON "Enables MLIR Python Bindings" OFF)
|
||||
|
||||
# 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}")
|
||||
endif()
|
||||
|
||||
if (TORCH_MLIR_ENABLE_STABLEHLO)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo)
|
||||
endif()
|
||||
|
||||
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})")
|
||||
|
||||
include_directories(${LLVM_INCLUDE_DIRS})
|
||||
include_directories(${MLIR_INCLUDE_DIRS})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||
|
||||
function(torch_mlir_target_includes target)
|
||||
set(_dirs
|
||||
$<BUILD_INTERFACE:${MLIR_INCLUDE_DIRS}>
|
||||
$<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()
|
||||
|
||||
# Configure CMake.
|
||||
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)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/python/torch_mlir/cmake/modules")
|
||||
|
||||
################################################################################
|
||||
# Setup python.
|
||||
################################################################################
|
||||
|
||||
if(MLIR_ENABLE_BINDINGS_PYTHON)
|
||||
include(MLIRDetectPythonEnv)
|
||||
mlir_configure_python_dev_packages()
|
||||
endif()
|
||||
|
||||
add_subdirectory(include)
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(tools)
|
||||
|
||||
add_custom_target(check-torch-mlir-all)
|
||||
add_dependencies(check-torch-mlir-all
|
||||
check-torch-mlir
|
||||
check-torch-mlir-dialects
|
||||
check-torch-mlir-capi
|
||||
)
|
||||
|
||||
if(MLIR_ENABLE_BINDINGS_PYTHON)
|
||||
# If parent projects want to configure where to place the python packages,
|
||||
# respect that.
|
||||
if(NOT TORCH_MLIR_PYTHON_PACKAGES_DIR)
|
||||
set(TORCH_MLIR_PYTHON_PACKAGES_DIR "${CMAKE_CURRENT_BINARY_DIR}/python_packages")
|
||||
endif()
|
||||
add_dependencies(check-torch-mlir-all
|
||||
check-torch-mlir-python
|
||||
check-torch-mlir-pt1
|
||||
)
|
||||
add_subdirectory(python)
|
||||
else()
|
||||
|
@ -190,50 +25,3 @@ else()
|
|||
endif()
|
||||
|
||||
add_subdirectory(test)
|
||||
|
||||
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
||||
install(DIRECTORY include/torch-mlir include/torch-mlir-c
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
COMPONENT torch-mlir-headers
|
||||
FILES_MATCHING
|
||||
PATTERN "*.def"
|
||||
PATTERN "*.h"
|
||||
PATTERN "*.inc"
|
||||
PATTERN "*.td"
|
||||
PATTERN "LICENSE.TXT"
|
||||
)
|
||||
|
||||
install(DIRECTORY ${TORCH_MLIR_BINARY_DIR}/include/torch-mlir
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
COMPONENT torch-mlir-headers
|
||||
FILES_MATCHING
|
||||
PATTERN "*.def"
|
||||
PATTERN "*.h"
|
||||
PATTERN "*.gen"
|
||||
PATTERN "*.inc"
|
||||
PATTERN "*.td"
|
||||
PATTERN "CMakeFiles" EXCLUDE
|
||||
PATTERN "config.h" EXCLUDE
|
||||
)
|
||||
|
||||
if (NOT LLVM_ENABLE_IDE)
|
||||
add_llvm_install_targets(install-torch-mlir-headers
|
||||
DEPENDS torch-mlir-headers
|
||||
COMPONENT torch-mlir-headers)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Important: If loading StableHLO in this fashion, it must come last,
|
||||
# after all of our libraries and test targets have been defined.
|
||||
# It seems that they both abuse upstream CMake macros that accumulate
|
||||
# properties.
|
||||
# Getting this wrong results in building large parts of the stablehlo
|
||||
# project that we don't actually depend on. Further some of those parts
|
||||
# do not even compile on all platforms.
|
||||
if (TORCH_MLIR_ENABLE_STABLEHLO)
|
||||
set(STABLEHLO_BUILD_EMBEDDED ON)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo
|
||||
${CMAKE_CURRENT_BINARY_DIR}/stablehlo
|
||||
EXCLUDE_FROM_ALL)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo)
|
||||
endif()
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# Setup PyTorch
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules")
|
||||
include(TorchMLIRPyTorch)
|
||||
TorchMLIRProbeForPyTorchInstall()
|
||||
find_package(Torch 1.8 REQUIRED)
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
# Setup PyTorch/LTC
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/python/torch_mlir/cmake/modules")
|
||||
include(TorchMLIRPyTorch)
|
||||
|
||||
TorchMLIRProbeForPyTorchInstall()
|
||||
if(TORCH_MLIR_USE_INSTALLED_PYTORCH)
|
||||
TorchMLIRConfigurePyTorch()
|
||||
else()
|
||||
set(Torch_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../libtorch/share/cmake/Torch")
|
||||
# Assume it is a sibling to the overall project.
|
||||
set(Torch_DIR "${PROJECT_SOURCE_DIR}/../libtorch/share/cmake/Torch")
|
||||
message(STATUS "Attempting to locate libtorch as a sibling to the project: ${Torch_DIR}")
|
||||
endif()
|
||||
|
||||
find_package(Torch 1.11 REQUIRED)
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
# Setup PyTorch
|
||||
###########################################################################
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/python/torch_mlir/cmake/modules")
|
||||
include(TorchMLIRPyTorch)
|
||||
|
||||
TorchMLIRProbeForPyTorchInstall()
|
||||
if(TORCH_MLIR_USE_INSTALLED_PYTORCH)
|
||||
TorchMLIRConfigurePyTorch()
|
||||
else()
|
||||
set(Torch_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../libtorch/share/cmake/Torch")
|
||||
# Assume it is a sibling to the overall project.
|
||||
set(Torch_DIR "${PROJECT_SOURCE_DIR}/../libtorch/share/cmake/Torch")
|
||||
message(STATUS "Attempting to locate libtorch as a sibling to the project: ${Torch_DIR}")
|
||||
endif()
|
||||
|
||||
find_package(Torch 1.11 REQUIRED)
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
# Setup PyTorch
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/python/torch_mlir/cmake/modules")
|
||||
include(TorchMLIRPyTorch)
|
||||
|
||||
TorchMLIRProbeForPyTorchInstall()
|
||||
if(TORCH_MLIR_USE_INSTALLED_PYTORCH)
|
||||
TorchMLIRConfigurePyTorch()
|
||||
else()
|
||||
set(Torch_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../libtorch/share/cmake/Torch")
|
||||
else()
|
||||
# Assume it is a sibling to the overall project.
|
||||
set(Torch_DIR "${PROJECT_SOURCE_DIR}/../libtorch/share/cmake/Torch")
|
||||
message(STATUS "Attempting to locate libtorch as a sibling to the project: ${Torch_DIR}")
|
||||
endif()
|
||||
|
||||
find_package(Torch 1.11 REQUIRED)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
llvm_canonicalize_cmake_booleans(
|
||||
MLIR_ENABLE_BINDINGS_PYTHON
|
||||
TORCH_MLIR_ENABLE_JIT_IR_IMPORTER
|
||||
)
|
||||
|
||||
configure_lit_site_cfg(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
|
||||
MAIN_CONFIG
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
|
||||
)
|
||||
|
||||
set(TORCH_MLIR_TEST_DEPENDS
|
||||
FileCheck count not
|
||||
TorchMLIRPythonModules
|
||||
torch-mlir-opt
|
||||
torch-mlir-capi-torch-test
|
||||
)
|
||||
|
||||
add_lit_testsuite(check-torch-mlir-pt1 "Running the torch-mlir PT1 regression tests"
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS ${TORCH_MLIR_TEST_DEPENDS}
|
||||
)
|
||||
set_target_properties(check-torch-mlir-pt1 PROPERTIES FOLDER "Tests")
|
||||
|
||||
add_lit_testsuites(TORCH_MLIR ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${TORCH_MLIR_TEST_DEPENDS})
|
|
@ -0,0 +1,80 @@
|
|||
# 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
|
||||
# Also available under a BSD-style license. See LICENSE.
|
||||
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
import lit.formats
|
||||
import lit.util
|
||||
|
||||
from lit.llvm import llvm_config
|
||||
from lit.llvm.subst import ToolSubst
|
||||
from lit.llvm.subst import FindTool
|
||||
|
||||
# Configuration file for the 'lit' test runner.
|
||||
|
||||
# name: The name of this test suite.
|
||||
config.name = 'TORCH_MLIR'
|
||||
|
||||
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
|
||||
|
||||
# suffixes: A list of file extensions to treat as test files.
|
||||
config.suffixes = ['.mlir', '.py']
|
||||
|
||||
# test_source_root: The root path where tests are located.
|
||||
config.test_source_root = os.path.dirname(__file__)
|
||||
|
||||
# test_exec_root: The root path where tests should be run.
|
||||
config.test_exec_root = os.path.join(config.torch_mlir_obj_root, 'test')
|
||||
|
||||
config.substitutions.append(('%PATH%', config.environment['PATH']))
|
||||
config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
|
||||
|
||||
llvm_config.with_system_environment(['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP'])
|
||||
|
||||
#llvm_config.use_default_substitutions()
|
||||
|
||||
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
|
||||
# subdirectories contain auxiliary inputs for various tests in their parent
|
||||
# directories.
|
||||
config.excludes = [
|
||||
'Inputs', 'Examples', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt',
|
||||
'lit.cfg.py', 'lit.site.cfg.py'
|
||||
]
|
||||
|
||||
# test_source_root: The root path where tests are located.
|
||||
config.test_source_root = os.path.dirname(__file__)
|
||||
|
||||
# test_exec_root: The root path where tests should be run.
|
||||
config.test_exec_root = os.path.join(config.torch_mlir_obj_root, 'test')
|
||||
config.standalone_tools_dir = os.path.join(config.torch_mlir_obj_root, 'bin')
|
||||
|
||||
# Tweak the PATH to include the tools dir.
|
||||
llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
|
||||
# Tweak the PATH to include the binary build dir, in order to pick up CAPI tests during out-of-tree.
|
||||
llvm_config.with_environment('PATH', os.path.join(config.llvm_build_dir, 'bin'), append_path=True)
|
||||
|
||||
# On Windows the path to python could contains spaces in which case it needs to
|
||||
# be provided in quotes. This is the equivalent of how %python is setup in
|
||||
# llvm/utils/lit/lit/llvm/config.py.
|
||||
if "Windows" in config.host_os:
|
||||
config.python_executable = '"%s"' % (config.python_executable)
|
||||
|
||||
tool_dirs = [config.standalone_tools_dir, config.llvm_tools_dir, config.torch_mlir_obj_root]
|
||||
tools = [
|
||||
'torch-mlir-opt',
|
||||
ToolSubst('%PYTHON', config.python_executable, unresolved='ignore'),
|
||||
]
|
||||
|
||||
llvm_config.add_tool_substitutions(tools, tool_dirs)
|
||||
|
||||
if config.enable_bindings_python:
|
||||
llvm_config.with_environment('PYTHONPATH', [
|
||||
os.path.join(config.torch_mlir_python_packages_dir, 'torch_mlir'),
|
||||
],
|
||||
append_path=True)
|
|
@ -0,0 +1,25 @@
|
|||
@LIT_SITE_CFG_IN_HEADER@
|
||||
|
||||
import sys
|
||||
|
||||
config.enable_bindings_python = @MLIR_ENABLE_BINDINGS_PYTHON@
|
||||
config.torch_mlir_obj_root = "@TORCH_MLIR_BINARY_DIR@"
|
||||
config.torch_mlir_python_packages_dir = "@TORCH_MLIR_PYTHON_PACKAGES_DIR@"
|
||||
config.host_os = "@HOST_OS@"
|
||||
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
|
||||
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
|
||||
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
|
||||
config.llvm_build_dir = "@CMAKE_BINARY_DIR@"
|
||||
config.llvm_lib_dir = "@LLVM_LIBS_DIR@"
|
||||
config.llvm_shlib_dir = "@SHLIBDIR@"
|
||||
config.llvm_shlib_ext = "@SHLIBEXT@"
|
||||
config.llvm_exe_ext = "@EXEEXT@"
|
||||
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
|
||||
config.python_executable = "@Python3_EXECUTABLE@"
|
||||
config.enable_jit_ir_importer = @TORCH_MLIR_ENABLE_JIT_IR_IMPORTER@
|
||||
|
||||
import lit.llvm
|
||||
lit.llvm.initialize(lit_config, config)
|
||||
|
||||
# Let the main config do the real work.
|
||||
lit_config.load_config(config, "@TORCH_MLIR_SOURCE_DIR@/projects/pt1/test/lit.cfg.py")
|
|
@ -2,11 +2,12 @@
|
|||
set -euo pipefail
|
||||
|
||||
src_dir="$(realpath "$(dirname "$0")"/..)"
|
||||
project_dir="$src_dir/../.."
|
||||
|
||||
cd "$src_dir"
|
||||
|
||||
# Ensure PYTHONPATH is set for export to child processes, even if empty.
|
||||
export PYTHONPATH=${PYTHONPATH-}
|
||||
source .env
|
||||
source $project_dir/.env
|
||||
|
||||
python -m e2e_testing.main "$@"
|
||||
|
|
Loading…
Reference in New Issue