Add stub numpy dialect.

pull/1/head
Stella Laurenzo 2020-04-26 17:20:58 -07:00
parent ac302ea916
commit d3b6e1767a
18 changed files with 181 additions and 27 deletions

1
.clang-format 100644
View File

@ -0,0 +1 @@
BasedOnStyle: LLVM

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.vscode
build build
build-mlir build-mlir
install-mlir install-mlir

View File

@ -35,8 +35,8 @@ link_directories(${LLVM_BUILD_LIBRARY_DIR})
add_definitions(${LLVM_DEFINITIONS}) add_definitions(${LLVM_DEFINITIONS})
# MLIR npcomp project. # MLIR npcomp project.
set(MLIR_NPCOMP_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # --src-root #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_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) # --includedir
set(MLIR_NPCOMP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(MLIR_NPCOMP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(MLIR_NPCOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_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 # TODO(laurenzo): What is the right way to get include directories for
# cross project dependencies? # cross project dependencies?
include_directories(${MLIR_NPCOMP_INCLUDE_DIR}) #include_directories(${MLIR_NPCOMP_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/../mlir/include) #include_directories(${CMAKE_SOURCE_DIR}/../mlir/include)
include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) #include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
add_subdirectory(include/npcomp) add_subdirectory(include/npcomp)
add_subdirectory(lib) add_subdirectory(lib)

View File

@ -1 +1 @@
# Empty file add_subdirectory(Dialect)

View File

@ -0,0 +1 @@
add_subdirectory(Numpy)

View File

@ -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/)

View File

@ -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

View File

@ -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<string mnemonic, list<OpTrait> traits = []> :
Op<Numpy_Dialect, mnemonic, traits>;
#endif // NPCOMP_DIALECT_NUMPY_NUMPY_DIALECT

View File

@ -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

View File

@ -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

View File

@ -1 +0,0 @@
// Empty file

View File

@ -1,7 +1 @@
add_llvm_tool(npcomp-dummy-runner add_subdirectory(Dialect)
dummy-runner.cpp
)
target_link_libraries(npcomp-dummy-runner PRIVATE
LLVMSupport
)

View File

@ -0,0 +1 @@
add_subdirectory(Numpy)

View File

@ -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)

View File

@ -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"
>();
}

View File

@ -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

View File

@ -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;
}

View File

@ -65,8 +65,12 @@ target_link_libraries(${extension_target}
PRIVATE PRIVATE
${dialect_libs} ${dialect_libs}
${conversion_libs} ${conversion_libs}
pybind11::module pybind11::module
# Local depends
NPCOMPNumpyDialect
# Upstream depends
LLVMSupport LLVMSupport
MLIRAffineToStandard MLIRAffineToStandard
MLIRAffineTransforms MLIRAffineTransforms