From f3f9acf112e657860a65a0de6f3e23688d38b947 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Mon, 22 Mar 2021 19:16:09 +0800 Subject: [PATCH] fix(tree): fix copybara GitOrigin-RevId: 404721996238ac842fba118f3920713b38600b5b --- .../test/unit/utils/test_network_node.py | 13 +++ src/serialization/impl/extern_c_opr.cpp | 7 +- tools/mlir/mgb-file-check/CMakeLists.txt | 8 ++ tools/mlir/mgb-file-check/mgb-file-check.sh | 3 + tools/mlir/mgb-opt/CMakeLists.txt | 23 +++++ tools/mlir/mgb-opt/mgb-opt.cpp | 85 +++++++++++++++++++ 6 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 tools/mlir/mgb-file-check/CMakeLists.txt create mode 100755 tools/mlir/mgb-file-check/mgb-file-check.sh create mode 100644 tools/mlir/mgb-opt/CMakeLists.txt create mode 100644 tools/mlir/mgb-opt/mgb-opt.cpp diff --git a/imperative/python/test/unit/utils/test_network_node.py b/imperative/python/test/unit/utils/test_network_node.py index d293c3c47..d72491048 100644 --- a/imperative/python/test/unit/utils/test_network_node.py +++ b/imperative/python/test/unit/utils/test_network_node.py @@ -466,6 +466,19 @@ def test_topk(): check_pygraph_dump(fwd, [x], [top, indices]) +def test_nvof(): + if not is_cuda_available(): + return + src_shape = (4, 5, 224, 224, 4) + src = np.random.randint(0, 255, src_shape).astype("uint8") + src = Tensor(src) + + @trace(symbolic=True, capture_as_const=True) + def fwd(src): + return F.nn.nvof(src, precision=1) + + result = fwd(src) + check_pygraph_dump(fwd, [src], [result]) def test_random(): diff --git a/src/serialization/impl/extern_c_opr.cpp b/src/serialization/impl/extern_c_opr.cpp index 080b023eb..1dcc8b8cf 100644 --- a/src/serialization/impl/extern_c_opr.cpp +++ b/src/serialization/impl/extern_c_opr.cpp @@ -290,11 +290,8 @@ ExternCOprRunner::ExternCOprRunner(std::string& name, m_dump_name{name}, m_param{nullptr} { mgb_assert(m_desc->size == sizeof(MGBOprDesc), - "invalid MGBOprDesc size: expect=%zu got=%u, may caused by " - "extern_c_opr.h mismatch, please confirm that the " - "extern_c_opr.h used when compiling the loader is consistent " - "with the runtime caller build used", - sizeof(MGBOprDesc), m_desc->size); + "invalid MGBOprDesc size: expect=%zu got=%u", sizeof(MGBOprDesc), + m_desc->size); for (auto i : inputs) { add_input({i}); } diff --git a/tools/mlir/mgb-file-check/CMakeLists.txt b/tools/mlir/mgb-file-check/CMakeLists.txt new file mode 100644 index 000000000..f13106701 --- /dev/null +++ b/tools/mlir/mgb-file-check/CMakeLists.txt @@ -0,0 +1,8 @@ +add_custom_command( + OUTPUT link_sh + COMMAND ${CMAKE_COMMAND} -E create_symlink + ${PROJECT_SOURCE_DIR}/tools/mlir/mgb-file-check/mgb-file-check.sh + ${PROJECT_BINARY_DIR}/tools/mlir/mgb-file-check/mgb-file-check +) + +add_custom_target(mgb-file-check DEPENDS link_sh) \ No newline at end of file diff --git a/tools/mlir/mgb-file-check/mgb-file-check.sh b/tools/mlir/mgb-file-check/mgb-file-check.sh new file mode 100755 index 000000000..8d68908dd --- /dev/null +++ b/tools/mlir/mgb-file-check/mgb-file-check.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e + +FileCheck --enable-var-scope --dump-input=fail "$@" diff --git a/tools/mlir/mgb-opt/CMakeLists.txt b/tools/mlir/mgb-opt/CMakeLists.txt new file mode 100644 index 000000000..26f1a873e --- /dev/null +++ b/tools/mlir/mgb-opt/CMakeLists.txt @@ -0,0 +1,23 @@ +get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) +get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) +set(LIBS + ${dialect_libs} + ${conversion_libs} + LLVMSupport + MLIROptLib + MLIRIR + MLIRPass + MLIRSupport + ) +add_executable(mgb-opt mgb-opt.cpp) + +target_include_directories( + mgb-opt + PRIVATE ${MLIR_LLVM_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/src/jit/include + ${PROJECT_BINARY_DIR}/src/jit/include) + +add_dependencies(mgb-opt mgb_dialect) + +target_link_libraries(mgb-opt PRIVATE ${LIBS} megbrain megdnn ${MGE_CUDA_LIBS}) + +llvm_update_compile_flags(mgb-opt) diff --git a/tools/mlir/mgb-opt/mgb-opt.cpp b/tools/mlir/mgb-opt/mgb-opt.cpp new file mode 100644 index 000000000..14b8dde7d --- /dev/null +++ b/tools/mlir/mgb-opt/mgb-opt.cpp @@ -0,0 +1,85 @@ +/** + * \file tools/mlir/mgb-opt/mgb-opt.cpp + * MegEngine is Licensed under the Apache License, Version 2.0 (the "License") + * + * Copyright (c) 2014-2021 Megvii Inc. All rights reserved. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + */ + +#include "megbrain/jit/mlir/ir/dialect.h" +#include "megbrain/jit/mlir/ir/passes.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace llvm; +using namespace mlir; + +//! TODO: Implement a custom MlirOptMain that supports the following flags. +static cl::opt print_mlir{ + "print-mlir", + cl::desc("Prints MLIR IR after translation"), + cl::init(false), +}; + +static cl::list input_values{ + "input-value", + cl::desc("Input shapes and optional values"), + cl::ZeroOrMore, +}; + +static cl::opt input_values_file{ + "input-value-file", + cl::desc("Provides a file for input shapes and optional values (see " + "ParseToVariantListFromFile in vm_util.h for details)"), + cl::init(""), +}; + +static cl::opt run{ + "run", + cl::desc("Runs the module (vs. just compiling and verifing)"), + cl::init(true), +}; + +static cl::list run_args{ + "run-arg", + cl::desc("Argument passed to the execution flag parser"), + cl::ZeroOrMore, +}; + +namespace mgb { +namespace jit { +void register_test_mgb_to_affine_lowering_pass(); +void register_test_affine_to_llvm_lowering_pass(); +} // namespace jit +} // namespace mgb + +int main(int argc, char** argv) { + mlir::registerAllPasses(); + + mlir::DialectRegistry registry; + mlir::registerAllDialects(registry); + registry.insert(); + + mgb::jit::register_test_mgb_to_affine_lowering_pass(); + mgb::jit::register_test_affine_to_llvm_lowering_pass(); + + return failed(MlirOptMain(argc, argv, "MLIR modular optimizer driver", registry)); +} -- GitLab