From 701312720c8967f39ba42d7e7c6ddf9a87a8e20c Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Wed, 5 Aug 2020 23:27:48 -0700 Subject: [PATCH] Add CMake files and lit configurations, enough for `ninja check-mlir-hlo` to pass on all the tests PiperOrigin-RevId: 325172984 --- CMakeLists.txt | 94 +++++++++++ include/mlir-hlo/CMakeLists.txt | 16 ++ include/mlir-hlo/Dialect/CMakeLists.txt | 16 ++ include/mlir-hlo/Dialect/mhlo/CMakeLists.txt | 17 ++ .../mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt | 31 ++++ .../Dialect/mhlo/transforms/CMakeLists.txt | 23 +++ lib/CMakeLists.txt | 17 ++ lib/Dialect/CMakeLists.txt | 16 ++ lib/Dialect/mhlo/CMakeLists.txt | 17 ++ lib/Dialect/mhlo/IR/CMakeLists.txt | 82 +++++++++ lib/Dialect/mhlo/transforms/CMakeLists.txt | 155 ++++++++++++++++++ lib/utils/CMakeLists.txt | 25 +++ tests/CMakeLists.txt | 36 ++++ tests/lit.cfg.py | 82 +++++++++ tests/lit.site.cfg.py.in | 50 ++++++ tools/CMakeLists.txt | 16 ++ tools/mlir-hlo-opt/CMakeLists.txt | 32 ++++ 17 files changed, 725 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 include/mlir-hlo/CMakeLists.txt create mode 100644 include/mlir-hlo/Dialect/CMakeLists.txt create mode 100644 include/mlir-hlo/Dialect/mhlo/CMakeLists.txt create mode 100644 include/mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt create mode 100644 include/mlir-hlo/Dialect/mhlo/transforms/CMakeLists.txt create mode 100644 lib/CMakeLists.txt create mode 100644 lib/Dialect/CMakeLists.txt create mode 100644 lib/Dialect/mhlo/CMakeLists.txt create mode 100644 lib/Dialect/mhlo/IR/CMakeLists.txt create mode 100644 lib/Dialect/mhlo/transforms/CMakeLists.txt create mode 100644 lib/utils/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/lit.cfg.py create mode 100644 tests/lit.site.cfg.py.in create mode 100644 tools/CMakeLists.txt create mode 100644 tools/mlir-hlo-opt/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c4e2ea1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,94 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +cmake_minimum_required(VERSION 3.13.4) + +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() + +#------------------------------------------------------------------------------- +# Project setup and globals +#------------------------------------------------------------------------------- + +project(mlir-hlo LANGUAGES CXX C) +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 14) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") + +#------------------------------------------------------------------------------- +# Options and settings +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# MSVC defaults +#------------------------------------------------------------------------------- + +if(MSVC) + add_compile_options( + $<$:/MD> + $<$:/MD> + $<$:/MD> + ) +endif() + +#------------------------------------------------------------------------------- +# MLIR/LLVM Configuration +#------------------------------------------------------------------------------- + +find_package(MLIR REQUIRED CONFIG) +message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") +message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") +list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") +list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") + +if(LLVM_ENABLE_ZLIB) + find_package(ZLIB) +endif() + +include(TableGen) +include(AddLLVM) +include(AddMLIR) +include(HandleLLVMOptions) +include_directories(${LLVM_INCLUDE_DIRS}) +include_directories(${MLIR_INCLUDE_DIRS}) +include_directories(${PROJECT_SOURCE_DIR}/include) +include_directories(${PROJECT_BINARY_DIR}/include) +include_directories(${PROJECT_BINARY_DIR}/) +link_directories(${LLVM_BUILD_LIBRARY_DIR}) +add_definitions(${LLVM_DEFINITIONS}) + +#------------------------------------------------------------------------------- +# Directory setup +#------------------------------------------------------------------------------- + +set(MLIR_HLO_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(MLIR_HLO_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) + +add_custom_target(check-mlir-hlo) + +add_subdirectory(include/mlir-hlo) +add_subdirectory(lib) +add_subdirectory(tools) +add_subdirectory(tests) diff --git a/include/mlir-hlo/CMakeLists.txt b/include/mlir-hlo/CMakeLists.txt new file mode 100644 index 0000000..92759d7 --- /dev/null +++ b/include/mlir-hlo/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +add_subdirectory(Dialect) diff --git a/include/mlir-hlo/Dialect/CMakeLists.txt b/include/mlir-hlo/Dialect/CMakeLists.txt new file mode 100644 index 0000000..5ee1a19 --- /dev/null +++ b/include/mlir-hlo/Dialect/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +add_subdirectory(mhlo) diff --git a/include/mlir-hlo/Dialect/mhlo/CMakeLists.txt b/include/mlir-hlo/Dialect/mhlo/CMakeLists.txt new file mode 100644 index 0000000..e138afa --- /dev/null +++ b/include/mlir-hlo/Dialect/mhlo/CMakeLists.txt @@ -0,0 +1,17 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +add_subdirectory(IR) +add_subdirectory(transforms) diff --git a/include/mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt b/include/mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt new file mode 100644 index 0000000..09bdca8 --- /dev/null +++ b/include/mlir-hlo/Dialect/mhlo/IR/CMakeLists.txt @@ -0,0 +1,31 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +# Need a separate function because of the .cc vs .cpp used in the one provided by MLIR +function(add_mlir_hlo_dialect dialect dialect_namespace) + set(LLVM_TARGET_DEFINITIONS ${dialect}.td) + mlir_tablegen(${dialect}.h.inc -gen-op-decls) + mlir_tablegen(${dialect}.cc.inc -gen-op-defs) + mlir_tablegen(${dialect}_structs.h.inc -gen-struct-attr-decls) + mlir_tablegen(${dialect}_structs.cc.inc -gen-struct-attr-defs) + add_public_tablegen_target(MLIR${dialect}IncGen) + add_dependencies(mlir-headers MLIR${dialect}IncGen) +endfunction() + +add_mlir_hlo_dialect(chlo_ops chlo) +add_mlir_hlo_dialect(hlo_ops mhlo) +add_mlir_hlo_dialect(lhlo_ops lmhlo) + +add_mlir_interface(infer_fusibility_op_interface) diff --git a/include/mlir-hlo/Dialect/mhlo/transforms/CMakeLists.txt b/include/mlir-hlo/Dialect/mhlo/transforms/CMakeLists.txt new file mode 100644 index 0000000..6fbc530 --- /dev/null +++ b/include/mlir-hlo/Dialect/mhlo/transforms/CMakeLists.txt @@ -0,0 +1,23 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# + +set(LLVM_TARGET_DEFINITIONS mhlo_passes.td) +mlir_tablegen(mhlo_passes.h.inc -gen-pass-decls) +add_public_tablegen_target(MLIRMhloPassIncGen) + +set(LLVM_TARGET_DEFINITIONS lmhlo_passes.td) +mlir_tablegen(lmhlo_passes.h.inc -gen-pass-decls) +add_public_tablegen_target(MLIRLmhloPassIncGen) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..ec65a5e --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,17 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +add_subdirectory(Dialect) +add_subdirectory(utils) diff --git a/lib/Dialect/CMakeLists.txt b/lib/Dialect/CMakeLists.txt new file mode 100644 index 0000000..5ee1a19 --- /dev/null +++ b/lib/Dialect/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +add_subdirectory(mhlo) diff --git a/lib/Dialect/mhlo/CMakeLists.txt b/lib/Dialect/mhlo/CMakeLists.txt new file mode 100644 index 0000000..e138afa --- /dev/null +++ b/lib/Dialect/mhlo/CMakeLists.txt @@ -0,0 +1,17 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +add_subdirectory(IR) +add_subdirectory(transforms) diff --git a/lib/Dialect/mhlo/IR/CMakeLists.txt b/lib/Dialect/mhlo/IR/CMakeLists.txt new file mode 100644 index 0000000..d7bb505 --- /dev/null +++ b/lib/Dialect/mhlo/IR/CMakeLists.txt @@ -0,0 +1,82 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +include_directories(BEFORE + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}) + +set(LLVM_TARGET_DEFINITIONS hlo_patterns.td) +mlir_tablegen(hlo_patterns.cc.inc -gen-rewriters) +add_public_tablegen_target(MLIRMhloRewriterIncGen) + +set(LLVM_TARGET_DEFINITIONS mhlo_canonicalize.td) +mlir_tablegen(mhlo_canonicalize.inc -gen-rewriters) +add_public_tablegen_target(MLIRMhloCanonicalizeIncGen) + +add_mlir_dialect_library(ChloDialect + chlo_ops.cc + + DEPENDS + MLIRchlo_opsIncGen +) +target_link_libraries(ChloDialect PUBLIC MLIRIR) + +add_mlir_library(MhloInferFusibilityOpInterface + infer_fusibility_op_interface.cc + + DEPENDS + MLIRinfer_fusibility_op_interfaceIncGen +) + + +add_mlir_dialect_library(MhloDialect + hlo_ops.cc + + DEPENDS + MLIRhlo_opsIncGen + MLIRMhloCanonicalizeIncGen + MLIRMhloRewriterIncGen + MLIRinfer_fusibility_op_interfaceIncGen +) +target_link_libraries(MhloDialect + PUBLIC + MLIRIR + MhloInferFusibilityOpInterface + MLIRMhloUtils +) + + +add_mlir_dialect_library(LmhloDialect + lhlo_ops.cc + + DEPENDS + MLIRlhlo_opsIncGen +) +target_link_libraries(LmhloDialect PUBLIC MLIRIR) + + +add_mlir_dialect_library(MhloRegisterDialects + init.cc +DEPENDS + MLIRchlo_opsIncGen + MLIRhlo_opsIncGen + MLIRlhlo_opsIncGen +) +target_link_libraries(MhloRegisterDialects + PUBLIC + ChloDialect + MhloDialect + LmhloDialect +) diff --git a/lib/Dialect/mhlo/transforms/CMakeLists.txt b/lib/Dialect/mhlo/transforms/CMakeLists.txt new file mode 100644 index 0000000..bb9f98d --- /dev/null +++ b/lib/Dialect/mhlo/transforms/CMakeLists.txt @@ -0,0 +1,155 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +include_directories(BEFORE + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}) + +set(LLVM_TARGET_DEFINITIONS lower_complex_patterns.td) +mlir_tablegen(generated_lower_complex.inc -gen-rewriters) +add_public_tablegen_target(MLIRMhloLowerComplexIncGen) + +set(LLVM_TARGET_DEFINITIONS legalize_to_standard_patterns.td) +mlir_tablegen(generated_legalize_to_standard.inc -gen-rewriters) +add_public_tablegen_target(MLIRMhloLegalizeToStandardIncGen) + + +add_mlir_library(ChloPasses + chlo_legalize_to_hlo.cc + chlo_legalize_to_hlo_pass.cc + + DEPENDS + MLIRhlo_opsIncGen + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + ChloDialect + MLIRIR + MLIRPass +) + +add_mlir_library(MhloPasses + legalize_gather_to_torch_index_select.cc + legalize_tanh_to_approximation.cc + lower_complex.cc + lower_complex_patterns.td + lower_general_dot.cc + materialize_broadcasts.cc + materialize_broadcasts_pass.cc + mhlo_fusion.cc + optimize_mhlo.cc + optimize_mhlo_pass.cc + sink_constants_to_control_flow.cc + test_infer_shaped_type_pass.cc + transform_unranked_hlo.cc + unfuse_batch_norm.cc + unfuse_batch_norm_pass.cc + + DEPENDS + MLIRhlo_opsIncGen + MLIRMhloLowerComplexIncGen + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + MLIRIR + MLIRMhloUtils + MLIRPass + MLIRTransformUtils +) + +add_mlir_library(MhloToLhloConversion + hlo_legalize_to_lhlo.cc + + DEPENDS + MLIRhlo_opsIncGen + MLIRlhlo_opsIncGen + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + MhloDialect + LmhloDialect + MLIRIR + MLIRPass +) + +add_mlir_library(MhloToStandard + legalize_control_flow.cc + legalize_to_standard.cc + + DEPENDS + MLIRhlo_opsIncGen + MLIRlhlo_opsIncGen + MLIRMhloLegalizeToStandardIncGen + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + MLIRIR + MLIRPass +) + +add_mlir_library(MhloLhloToLinalg + legalize_to_linalg.cc + + DEPENDS + MLIRhlo_opsIncGen + MLIRlhlo_opsIncGen + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + MhloDialect + MLIRIR + MLIRPass +) + +add_mlir_library(LmhloPasses + lhlo_copy_removal.cc + lhlo_fuse_linalg.cc + lhlo_legalize_to_affine.cc + lhlo_legalize_to_gpu.cc + lhlo_legalize_to_llvm.cc + lhlo_legalize_to_llvm_pass.cc + lhlo_legalize_to_parallel_loops.cc + + DEPENDS + MLIRlhlo_opsIncGen + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + LmhloDialect + MLIRIR + MLIRPass +) + +add_library(AllMhloPasses INTERFACE) +target_link_libraries(AllMhloPasses INTERFACE + ChloPasses + MhloPasses + MhloToLhloConversion + MhloToStandard + MhloLhloToLinalg + LmhloPasses +) diff --git a/lib/utils/CMakeLists.txt b/lib/utils/CMakeLists.txt new file mode 100644 index 0000000..17e86f1 --- /dev/null +++ b/lib/utils/CMakeLists.txt @@ -0,0 +1,25 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# + +add_mlir_library(MLIRMhloUtils + broadcast_utils.cc + convert_op_folder.cc + cycle_detector.cc + hlo_utils.cc + + LINK_LIBS PUBLIC + MLIRSupport + ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..36a7eec --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,36 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +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(MLIR_HLO_TEST_DEPENDS + FileCheck count not + mlir-hlo-opt +) + +add_lit_testsuite(check-mlir-hlo-lit "Running the mlir-hlo regression tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${MLIR_HLO_TEST_DEPENDS} + ) +set_target_properties(check-mlir-hlo-lit PROPERTIES FOLDER "Tests") + +add_lit_testsuites(MLIR_HLO_OPT ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${MLIR_HLO_TEST_DEPENDS}) + +add_dependencies(check-mlir-hlo check-mlir-hlo-lit) diff --git a/tests/lit.cfg.py b/tests/lit.cfg.py new file mode 100644 index 0000000..f81d47a --- /dev/null +++ b/tests/lit.cfg.py @@ -0,0 +1,82 @@ +"""Lit configuration to drive test in this repo.""" +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# 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. + +# -*- Python -*- +# pylint: disable=undefined-variable + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os + +import lit.formats +from lit.llvm import llvm_config +from lit.llvm.subst import ToolSubst +import lit.util + +# Configuration file for the 'lit' test runner. + +# name: The name of this test suite. +config.name = 'MLIR_HLO_OPT' + +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', '.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.mlir_hlo_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' +] + +# 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.mlir_hlo_obj_root, 'test') +config.mlir_hlo_tools_dir = os.path.join(config.mlir_hlo_obj_root, 'tools') + +# Tweak the PATH to include the tools dir. +llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True) + +tool_dirs = [ + os.path.join(config.mlir_hlo_tools_dir, 'mlir-hlo-opt'), + config.llvm_tools_dir, +] +tools = [ + 'mlir-hlo-opt', + 'mlir-cpu-runner', + ToolSubst( + '%mlir_runner_utils_dir', + config.mlir_runner_utils_dir, + unresolved='ignore'), +] + +llvm_config.add_tool_substitutions(tools, tool_dirs) diff --git a/tests/lit.site.cfg.py.in b/tests/lit.site.cfg.py.in new file mode 100644 index 0000000..17b99e9 --- /dev/null +++ b/tests/lit.site.cfg.py.in @@ -0,0 +1,50 @@ +@LIT_SITE_CFG_IN_HEADER@ + +import sys + +config.host_triple = "@LLVM_HOST_TRIPLE@" +config.target_triple = "@TARGET_TRIPLE@" +config.llvm_src_root = "@LLVM_SOURCE_DIR@" +config.llvm_obj_root = "@LLVM_BINARY_DIR@" +config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" +config.llvm_lib_dir = "@LLVM_LIBRARY_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 = "@PYTHON_EXECUTABLE@" +config.gold_executable = "@GOLD_EXECUTABLE@" +config.ld64_executable = "@LD64_EXECUTABLE@" +config.enable_shared = @ENABLE_SHARED@ +config.enable_assertions = @ENABLE_ASSERTIONS@ +config.targets_to_build = "@TARGETS_TO_BUILD@" +config.native_target = "@LLVM_NATIVE_ARCH@" +config.llvm_bindings = "@LLVM_BINDINGS@".split(' ') +config.host_os = "@HOST_OS@" +config.host_cc = "@HOST_CC@" +config.host_cxx = "@HOST_CXX@" +# Note: ldflags can contain double-quoted paths, so must use single quotes here. +config.host_ldflags = '@HOST_LDFLAGS@' +config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" +config.llvm_host_triple = '@LLVM_HOST_TRIPLE@' +config.host_arch = "@HOST_ARCH@" +config.mlir_hlo_src_root = "@CMAKE_SOURCE_DIR@" +config.mlir_hlo_obj_root = "@CMAKE_BINARY_DIR@" +config.mlir_runner_utils_dir = os.path.join(config.llvm_obj_root, "lib") + +# Support substitution of the tools_dir with user parameters. This is +# used when we can't determine the tool dir at configuration time. +try: + config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params + config.llvm_shlib_dir = config.llvm_shlib_dir % lit_config.params +except KeyError: + e = sys.exc_info()[1] + key, = e.args + lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) + + +import lit.llvm +lit.llvm.initialize(lit_config, config) + +# Let the main config do the real work. +lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/tests/lit.cfg.py") diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 0000000..0f3d1c8 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +add_subdirectory(mlir-hlo-opt) diff --git a/tools/mlir-hlo-opt/CMakeLists.txt b/tools/mlir-hlo-opt/CMakeLists.txt new file mode 100644 index 0000000..754469a --- /dev/null +++ b/tools/mlir-hlo-opt/CMakeLists.txt @@ -0,0 +1,32 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# 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 +# +# https://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. +# +get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) +get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) +set(LIBS + ${dialect_libs} + ${conversion_libs} + MLIROptLib + + MhloRegisterDialects + AllMhloPasses + ) +add_llvm_executable(mlir-hlo-opt mlir-hlo-opt.cpp + DEPENDS + MLIRLmhloPassIncGen + MLIRMhloPassIncGen +) +llvm_update_compile_flags(mlir-hlo-opt) +target_link_libraries(mlir-hlo-opt PRIVATE ${LIBS})