[MLIR] Some numpy operators support by Hardcode84 · Pull Request #192 · IntelPython/numba · GitHub
Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 65 additions & 22 deletions mlir-compiler/mlir-compiler/src/pipelines/plier_to_linalg.cpp
2 changes: 1 addition & 1 deletion mlir-compiler/mlir-compiler/src/pipelines/plier_to_std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ void PlierToStdPass::runOnOperation()

patterns.insert<
plier::CallOpLowering
>(type_converter, context, callLowerer);
>(type_converter, context, std::ref(callLowerer));

mlir::populateStdExpandOpsPatterns(context, patterns);

Expand Down
2 changes: 1 addition & 1 deletion mlir-compiler/plier/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ target_include_directories(${PLIER_LIB} PRIVATE

target_include_directories(${PLIER_LIB} PUBLIC
./include
${PROJECT_BINARY_DIR}/include
${PROJECT_BINARY_DIR}/plier/include
)

add_dependencies(${PLIER_LIB} MLIRPlierOpsIncGen)
4 changes: 2 additions & 2 deletions mlir-compiler/plier/include/plier/PlierOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def GlobalOp : Plier_Op<"global", [NoSideEffect]> {

def BinOp : Plier_Op<"binop", []> {
let arguments = (ins
AnyType:$rhs,
AnyType:$lhs,
AnyType:$rhs,
StrAttr:$op);

let results = (outs AnyType);

let builders = [
OpBuilderDAG<(ins "::mlir::Value":$rhs, "::mlir::Value":$lhs, "::mlir::StringRef ":$op)>
OpBuilderDAG<(ins "::mlir::Value":$lhs, "::mlir::Value":$rhs, "::mlir::StringRef ":$op)>
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace plier
{
struct CallOpLowering : public mlir::OpRewritePattern<plier::PyCallOp>
{
using resolver_t = llvm::function_ref<mlir::LogicalResult(plier::PyCallOp, llvm::StringRef, llvm::ArrayRef<mlir::Value>, llvm::ArrayRef<std::pair<llvm::StringRef, mlir::Value>> , mlir::PatternRewriter&)>;
using resolver_t = std::function<mlir::LogicalResult(plier::PyCallOp, llvm::StringRef, llvm::ArrayRef<mlir::Value>, llvm::ArrayRef<std::pair<llvm::StringRef, mlir::Value>> , mlir::PatternRewriter&)>;

CallOpLowering(mlir::TypeConverter &typeConverter,
mlir::MLIRContext *context,
Expand Down
17 changes: 17 additions & 0 deletions numba/mlir/numpy/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,29 @@ def eltwise(builder, args, body, res_type = None):
return builder.generic(args, init, iterators, maps, body)

@register_func('numpy.add', numpy.add)
@register_func('operator.add')
def add_impl(builder, arg1, arg2):
def body(a, b, c):
return a + b

return eltwise(builder, (arg1, arg2), body)

@register_func('numpy.subtract', numpy.subtract)
@register_func('operator.sub')
def sub_impl(builder, arg1, arg2):
def body(a, b, c):
return a - b

return eltwise(builder, (arg1, arg2), body)

@register_func('numpy.multiply', numpy.multiply)
@register_func('operator.mul')
def mul_impl(builder, arg1, arg2):
def body(a, b, c):
return a * b

return eltwise(builder, (arg1, arg2), body)

@register_func('array.sum')
@register_func('numpy.sum', numpy.sum)
def sum_impl(builder, arg, axis=None):
Expand Down
33 changes: 15 additions & 18 deletions numba/mlir/tests/test_numpy.py