Skip to content

Commit

Permalink
Add stub numpy dialect.
Browse files Browse the repository at this point in the history
  • Loading branch information
stellaraccident committed Apr 27, 2020
1 parent ac302ea commit d3b6e17
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 27 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: LLVM
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode

build
build-mlir
install-mlir
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion include/npcomp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Empty file
add_subdirectory(Dialect)
1 change: 1 addition & 0 deletions include/npcomp/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Numpy)
3 changes: 3 additions & 0 deletions include/npcomp/Dialect/Numpy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
24 changes: 24 additions & 0 deletions include/npcomp/Dialect/Numpy/NumpyDialect.h
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions include/npcomp/Dialect/Numpy/NumpyDialect.td
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions include/npcomp/Dialect/Numpy/NumpyOps.h
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions include/npcomp/Dialect/Numpy/NumpyOps.td
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion include/npcomp/Dummy.h

This file was deleted.

8 changes: 1 addition & 7 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
add_llvm_tool(npcomp-dummy-runner
dummy-runner.cpp
)

target_link_libraries(npcomp-dummy-runner PRIVATE
LLVMSupport
)
add_subdirectory(Dialect)
1 change: 1 addition & 0 deletions lib/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Numpy)
12 changes: 12 additions & 0 deletions lib/Dialect/Numpy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions lib/Dialect/Numpy/NumpyDialect.cpp
Original file line number Diff line number Diff line change
@@ -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"
>();
}
21 changes: 21 additions & 0 deletions lib/Dialect/Numpy/NumpyOps.cpp
Original file line number Diff line number Diff line change
@@ -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
12 changes: 0 additions & 12 deletions lib/dummy-runner.cpp

This file was deleted.

6 changes: 5 additions & 1 deletion python/npcomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ target_link_libraries(${extension_target}
PRIVATE
${dialect_libs}
${conversion_libs}

pybind11::module

# Local depends
NPCOMPNumpyDialect

# Upstream depends
LLVMSupport
MLIRAffineToStandard
MLIRAffineTransforms
Expand Down

0 comments on commit d3b6e17

Please sign in to comment.