diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..9b3aa8b72 --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: LLVM diff --git a/.gitignore b/.gitignore index 572cb1a71..46b0a397e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.vscode + build build-mlir install-mlir diff --git a/CMakeLists.txt b/CMakeLists.txt index 35a60efe1..c9a3f44b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,8 +35,8 @@ link_directories(${LLVM_BUILD_LIBRARY_DIR}) add_definitions(${LLVM_DEFINITIONS}) # MLIR npcomp project. -set(MLIR_NPCOMP_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # --src-root -set(MLIR_NPCOMP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) # --includedir +#set(MLIR_NPCOMP_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # --src-root +#set(MLIR_NPCOMP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) # --includedir set(MLIR_NPCOMP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(MLIR_NPCOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) @@ -51,9 +51,9 @@ message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") # TODO(laurenzo): What is the right way to get include directories for # cross project dependencies? -include_directories(${MLIR_NPCOMP_INCLUDE_DIR}) -include_directories(${CMAKE_SOURCE_DIR}/../mlir/include) -include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) +#include_directories(${MLIR_NPCOMP_INCLUDE_DIR}) +#include_directories(${CMAKE_SOURCE_DIR}/../mlir/include) +#include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) add_subdirectory(include/npcomp) add_subdirectory(lib) diff --git a/include/npcomp/CMakeLists.txt b/include/npcomp/CMakeLists.txt index 932b79829..0ca0f41c5 100644 --- a/include/npcomp/CMakeLists.txt +++ b/include/npcomp/CMakeLists.txt @@ -1 +1 @@ -# Empty file +add_subdirectory(Dialect) diff --git a/include/npcomp/Dialect/CMakeLists.txt b/include/npcomp/Dialect/CMakeLists.txt new file mode 100644 index 000000000..0323a7a11 --- /dev/null +++ b/include/npcomp/Dialect/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Numpy) diff --git a/include/npcomp/Dialect/Numpy/CMakeLists.txt b/include/npcomp/Dialect/Numpy/CMakeLists.txt new file mode 100644 index 000000000..6d0442e79 --- /dev/null +++ b/include/npcomp/Dialect/Numpy/CMakeLists.txt @@ -0,0 +1,3 @@ +add_mlir_dialect(NumpyOps numpy) +add_mlir_doc(NumpyDialect -gen-dialect-doc NumpyDialect Numpy/) +add_mlir_doc(NumpyOps -gen-op-doc NumpyOps Numpy/) diff --git a/include/npcomp/Dialect/Numpy/NumpyDialect.h b/include/npcomp/Dialect/Numpy/NumpyDialect.h new file mode 100644 index 000000000..24b1f3840 --- /dev/null +++ b/include/npcomp/Dialect/Numpy/NumpyDialect.h @@ -0,0 +1,24 @@ +//===- NumpyDialect.h - Core numpy dialect ----------------------*- 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_DIALECT_NUMPY_NUMPY_DIALECT_H +#define NPCOMP_DIALECT_NUMPY_NUMPY_DIALECT_H + +#include "mlir/IR/Dialect.h" + +namespace mlir { +namespace npcomp { +namespace NUMPY { + +#include "npcomp/Dialect/Numpy/NumpyOpsDialect.h.inc" + +} // namespace NUMPY +} // namespace npcomp +} // namespace mlir + +#endif // NPCOMP_DIALECT_NUMPY_NUMPY_DIALECT_H diff --git a/include/npcomp/Dialect/Numpy/NumpyDialect.td b/include/npcomp/Dialect/Numpy/NumpyDialect.td new file mode 100644 index 000000000..afcb96e58 --- /dev/null +++ b/include/npcomp/Dialect/Numpy/NumpyDialect.td @@ -0,0 +1,26 @@ +//===- NumpyDialect.td - Core numpy dialect ----------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef NPCOMP_DIALECT_NUMPY_NUMPY_DIALECT +#define NPCOMP_DIALECT_NUMPY_NUMPY_DIALECT + +include "mlir/IR/OpBase.td" + +def Numpy_Dialect : Dialect { + let name = "numpy"; + let summary = "Core numpy dialect"; + let description = [{ + Dialect of types and core numpy ops and abstractions. + }]; + let cppNamespace = "NUMPY"; +} + +class Numpy_Op traits = []> : + Op; + +#endif // NPCOMP_DIALECT_NUMPY_NUMPY_DIALECT diff --git a/include/npcomp/Dialect/Numpy/NumpyOps.h b/include/npcomp/Dialect/Numpy/NumpyOps.h new file mode 100644 index 000000000..c6f066189 --- /dev/null +++ b/include/npcomp/Dialect/Numpy/NumpyOps.h @@ -0,0 +1,27 @@ +//===- NumpyOps.h - Core numpy dialect ops ----------------------*- 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_DIALECT_NUMPY_NUMPY_OPS_H +#define NPCOMP_DIALECT_NUMPY_NUMPY_OPS_H + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" +#include "mlir/Interfaces/SideEffects.h" + +namespace mlir { +namespace npcomp { +namespace NUMPY { + +#define GET_OP_CLASSES +#include "npcomp/Dialect/Numpy/NumpyOps.h.inc" + +} // namespace NUMPY +} // namespace npcomp +} // namespace mlir + +#endif // NPCOMP_DIALECT_NUMPY_NUMPY_OPS_H diff --git a/include/npcomp/Dialect/Numpy/NumpyOps.td b/include/npcomp/Dialect/Numpy/NumpyOps.td new file mode 100644 index 000000000..f75f7d1e4 --- /dev/null +++ b/include/npcomp/Dialect/Numpy/NumpyOps.td @@ -0,0 +1,30 @@ +//===- NumpyOps.td - Core numpy dialect ops ----------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef NPCOMP_DIALECT_NUMPY_NUMPY_OPS +#define NPCOMP_DIALECT_NUMPY_NUMPY_OPS + +include "NumpyDialect.td" +include "mlir/Interfaces/SideEffects.td" + +def Numpy_FooOp : Numpy_Op<"foo", [NoSideEffect, + SameOperandsAndResultType]> { + let summary = "Temp op"; + let description = [{ + Temp op + }]; + + let arguments = (ins I32:$input); + let results = (outs I32:$res); + + let assemblyFormat = [{ + $input attr-dict `:` type($input) + }]; +} + +#endif // NPCOMP_DIALECT_NUMPY_NUMPY_OPS diff --git a/include/npcomp/Dummy.h b/include/npcomp/Dummy.h deleted file mode 100644 index fab17ac78..000000000 --- a/include/npcomp/Dummy.h +++ /dev/null @@ -1 +0,0 @@ -// Empty file diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 1171e2f25..0ca0f41c5 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,7 +1 @@ -add_llvm_tool(npcomp-dummy-runner - dummy-runner.cpp -) - -target_link_libraries(npcomp-dummy-runner PRIVATE - LLVMSupport -) +add_subdirectory(Dialect) diff --git a/lib/Dialect/CMakeLists.txt b/lib/Dialect/CMakeLists.txt new file mode 100644 index 000000000..0323a7a11 --- /dev/null +++ b/lib/Dialect/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Numpy) diff --git a/lib/Dialect/Numpy/CMakeLists.txt b/lib/Dialect/Numpy/CMakeLists.txt new file mode 100644 index 000000000..2d9fe793b --- /dev/null +++ b/lib/Dialect/Numpy/CMakeLists.txt @@ -0,0 +1,12 @@ +add_mlir_dialect_library(NPCOMPNumpyDialect + NumpyDialect.cpp + NumpyOps.cpp + + ADDITIONAL_HEADER_DIRS + ${PROJECT_SOURCE_DIR}/include/npcomp/Dialect/Numpy + + DEPENDS + MLIRNumpyOpsIncGen +) + +target_link_libraries(NPCOMPNumpyDialect PUBLIC MLIRIR) diff --git a/lib/Dialect/Numpy/NumpyDialect.cpp b/lib/Dialect/Numpy/NumpyDialect.cpp new file mode 100644 index 000000000..5c21c7be6 --- /dev/null +++ b/lib/Dialect/Numpy/NumpyDialect.cpp @@ -0,0 +1,21 @@ +//===- NumpyDialect.cpp - Core numpy dialect --------------------*- 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/Dialect/Numpy/NumpyDialect.h" +#include "npcomp/Dialect/Numpy/NumpyOps.h" + +using namespace mlir; +using namespace mlir::npcomp::NUMPY; + +NumpyDialect::NumpyDialect(MLIRContext *context) + : Dialect(getDialectNamespace(), context) { + addOperations< +#define GET_OP_LIST +#include "npcomp/Dialect/Numpy/NumpyOps.cpp.inc" + >(); +} diff --git a/lib/Dialect/Numpy/NumpyOps.cpp b/lib/Dialect/Numpy/NumpyOps.cpp new file mode 100644 index 000000000..af04ace20 --- /dev/null +++ b/lib/Dialect/Numpy/NumpyOps.cpp @@ -0,0 +1,21 @@ +//===- NumpyOps.cpp - Core numpy dialect ops --------------------*- 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/Dialect/Numpy/NumpyOps.h" +#include "mlir/IR/OpImplementation.h" +#include "npcomp/Dialect/Numpy/NumpyDialect.h" + +namespace mlir { +namespace npcomp { +namespace numpy { + +#include "npcomp/Dialect/Numpy/NumpyOps.cpp.inc" + +} // namespace numpy +} // namespace npcomp +} // namespace mlir diff --git a/lib/dummy-runner.cpp b/lib/dummy-runner.cpp deleted file mode 100644 index 8501dba73..000000000 --- a/lib/dummy-runner.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "llvm/Support/InitLLVM.h" -#include "llvm/Support/CommandLine.h" -#include "npcomp/Dummy.h" - -using namespace llvm; - -int main(int argc, char** argv) { - InitLLVM y(argc, argv); - cl::ParseCommandLineOptions(argc, argv, "Dummy program\n"); - llvm::outs() << "Hello world!\n"; - return 0; -} diff --git a/python/npcomp/CMakeLists.txt b/python/npcomp/CMakeLists.txt index e61f27651..0b36d9545 100644 --- a/python/npcomp/CMakeLists.txt +++ b/python/npcomp/CMakeLists.txt @@ -65,8 +65,12 @@ target_link_libraries(${extension_target} PRIVATE ${dialect_libs} ${conversion_libs} - pybind11::module + + # Local depends + NPCOMPNumpyDialect + + # Upstream depends LLVMSupport MLIRAffineToStandard MLIRAffineTransforms