Skip to content
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

Closed
wants to merge 29 commits into from

Conversation

howin98
Copy link
Contributor

@howin98 howin98 commented Apr 23, 2023

No description provided.

howin98 and others added 17 commits April 19, 2023 02:56
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>
@howin98 howin98 marked this pull request as ready for review April 23, 2023 12:58
@github-actions
Copy link
Contributor

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.

@@ -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>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个注释掉的原因是因为神马

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恢复了,这个是之前为了生成中间变量测试用的

Comment on lines 147 to 172
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;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

拆成两个函数吧,然后把放到调用处

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@github-actions
Copy link
Contributor

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(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以加个日志

Copy link
Contributor Author

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放到下面的if的else

Copy link
Contributor Author

@howin98 howin98 Apr 24, 2023

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里面,其实这部分代码还没写好,我才反应过来

@howin98 howin98 closed this Apr 24, 2023
auto-merge was automatically disabled April 24, 2023 08:12

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants