You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mgb-opt.cpp 2.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * \file tools/mlir/mgb-opt/mgb-opt.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied.
  11. */
  12. #include "megbrain/jit/mlir/ir/dialect.h"
  13. #include "megbrain/jit/mlir/ir/passes.h"
  14. #include <llvm/Support/CommandLine.h>
  15. #include <llvm/Support/InitLLVM.h>
  16. #include <llvm/Support/PrettyStackTrace.h>
  17. #include <llvm/Support/SourceMgr.h>
  18. #include <llvm/Support/ToolOutputFile.h>
  19. #include <mlir/Dialect/Affine/IR/AffineOps.h>
  20. #include <mlir/Dialect/LLVMIR/LLVMDialect.h>
  21. #include <mlir/IR/AsmState.h>
  22. #include <mlir/InitAllDialects.h>
  23. #include <mlir/InitAllPasses.h>
  24. #include <mlir/Pass/Pass.h>
  25. #include <mlir/Pass/PassManager.h>
  26. #include <mlir/Support/FileUtilities.h>
  27. #include <mlir/Support/MlirOptMain.h>
  28. using namespace llvm;
  29. using namespace mlir;
  30. //! TODO: Implement a custom MlirOptMain that supports the following flags.
  31. static cl::opt<bool> print_mlir{
  32. "print-mlir",
  33. cl::desc("Prints MLIR IR after translation"),
  34. cl::init(false),
  35. };
  36. static cl::list<std::string> input_values{
  37. "input-value",
  38. cl::desc("Input shapes and optional values"),
  39. cl::ZeroOrMore,
  40. };
  41. static cl::opt<std::string> input_values_file{
  42. "input-value-file",
  43. cl::desc("Provides a file for input shapes and optional values (see "
  44. "ParseToVariantListFromFile in vm_util.h for details)"),
  45. cl::init(""),
  46. };
  47. static cl::opt<bool> run{
  48. "run",
  49. cl::desc("Runs the module (vs. just compiling and verifing)"),
  50. cl::init(true),
  51. };
  52. static cl::list<std::string> run_args{
  53. "run-arg",
  54. cl::desc("Argument passed to the execution flag parser"),
  55. cl::ZeroOrMore,
  56. };
  57. namespace mgb {
  58. namespace jit {
  59. void register_test_mgb_to_affine_lowering_pass();
  60. void register_test_affine_to_llvm_lowering_pass();
  61. } // namespace jit
  62. } // namespace mgb
  63. int main(int argc, char** argv) {
  64. mlir::registerAllPasses();
  65. mlir::DialectRegistry registry;
  66. mlir::registerAllDialects(registry);
  67. registry.insert<mgb::jit::MgbDialect>();
  68. mgb::jit::register_test_mgb_to_affine_lowering_pass();
  69. mgb::jit::register_test_affine_to_llvm_lowering_pass();
  70. return failed(MlirOptMain(argc, argv, "MLIR modular optimizer driver", registry));
  71. }

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台