-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CodeGen]Support Ahead Compilation in MLIR JIT #10182
Conversation
Signed-off-by: daquexian <daquexian566@gmail.com> Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org> Co-authored-by: WangXingyu <1908865287@qq.com> Co-authored-by: daquexian <daquexian566@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Peihong Liu <mosout@qq.com> Co-authored-by: zhao di <54237695+Alokia@users.noreply.github.com> Co-authored-by: Juncheng <liujuncheng1022@gmail.com> Co-authored-by: Wang Yi <53533850+marigoold@users.noreply.github.com> Co-authored-by: Xiaoyu Xu <xiaoyulink@gmail.com>
Code got formatted by CI. Please request CI again if you still want to have this PR merged. If the PR is from a forked repo, please download the patch files from the GitHub Actions web page and apply them locally. |
oneflow/ir/lib/OneFlow/Passes.cpp
Outdated
@@ -1024,8 +1024,9 @@ void AddLowerToLinalgMemRefPasses(PassManager& pm) { | |||
tosa::createTosaMakeBroadcastablePass()); // tosa-make-broadcastable | |||
pm.addPass(createCSEPass()); // cse | |||
pm.addNestedPass<func::FuncOp>(tosa::createTosaToLinalg()); // tosa-to-linalg-on-tensors | |||
pm.addNestedPass<func::FuncOp>( | |||
createLinalgElementwiseOpFusionPass()); // linalg-fuse-elementwise-ops | |||
// pm.addNestedPass<func::FuncOp>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个注释掉的原因是因为神马
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
恢复了,这个是之前为了生成中间变量测试用的
std::string convertFuncToByte(func::FuncOp& func, const StringAttr& device_tag, | ||
bool compile_to_llvm) { | ||
mlir::DialectRegistry registry; | ||
registry | ||
.insert<mlir::oneflow::OneFlowDialect, mlir::func::FuncDialect, mlir::memref::MemRefDialect, | ||
mlir::tosa::TosaDialect, mlir::linalg::LinalgDialect, mlir::tensor::TensorDialect>(); | ||
mlir::MLIRContext mlir_ctx(registry); | ||
|
||
std::string mlir; | ||
llvm::raw_string_ostream os_mlir(mlir); | ||
mlir::writeBytecodeToFile(func, os_mlir); | ||
if (!compile_to_llvm) return mlir; | ||
|
||
mlir::OwningOpRef<mlir::ModuleOp> module = | ||
::mlir::parseSourceString<mlir::ModuleOp>(mlir, &mlir_ctx); | ||
mlir::registerLLVMDialectTranslation(registry); | ||
if (::oneflow::ParseBooleanFromEnv("ONEFLOW_MLIR_STDOUT", false)) { func->print(llvm::outs()); } | ||
getLowerFunction(device_tag)(&mlir_ctx, *module); | ||
if (::oneflow::ParseBooleanFromEnv("ONEFLOW_MLIR_STDOUT", false)) { func->print(llvm::outs()); } | ||
(*module)->setAttr(jit::RAW_GRAPH, StringAttr::get(&mlir_ctx, mlir)); | ||
|
||
std::string byte; | ||
llvm::raw_string_ostream os_byte(byte); | ||
mlir::writeBytecodeToFile(*module, os_byte); | ||
return byte; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
拆成两个函数吧,然后把放到调用处
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
CI failed when running job: Build cpu. PR label automerge has been removed |
mlir::LogicalResult matchAndRewrite(func::FuncOp op, | ||
mlir::PatternRewriter& rewriter) const override { | ||
auto [is_legal, list] = getAllocInfoList(op); | ||
if (!is_legal) { return failure(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以加个日志
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有点问题,需要后面用one shot buffize和一些其他的操作处理一下,我这里写一个TODO
std::string mlir; | ||
llvm::raw_string_ostream os_mlir(mlir); | ||
function->print(os_mlir); | ||
std::string byte = convertFuncToByte(function); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放到下面的if的else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个pr有问题,我想把这个pr的改动移动到tmp buffer里面,但是不小心把tmp buffer移动到了这个pr里面,其实这部分代码还没写好,我才反应过来
Pull request was closed
No description provided.