Feature/frontend and passes#328
Conversation
543c497 to
812351d
Compare
|
How is this PR different from #327? |
This PR is a split-out subset of PR #327. The original PR has been divided into three smaller independent PRs: the PyTorch Python frontend integration (this one), interpreter support for executing Python-frontend models, and refactoring of oversize run function. All original functionalities from #327 remain intact across the three split PRs. |
But this one is still too huge. Can we make one PR just touches one pass? |
812351d to
9bd84f5
Compare
tancheng
left a comment
There was a problem hiding this comment.
Can we have a mlir test for this emulation/expansion?
| std::unique_ptr<mlir::Pass> createLowerBuiltinToNeuraPass(); | ||
| std::unique_ptr<mlir::Pass> createLowerAffineToNeuraPass(); | ||
|
|
||
| // Math Expansion Pass. |
There was a problem hiding this comment.
// Math Expansion Pass. -> // Math Emulation Pass.
| std::unique_ptr<mlir::Pass> createLowerAffineToNeuraPass(); | ||
|
|
||
| // Math Expansion Pass. | ||
| std::unique_ptr<mlir::Pass> createExpandMathToArithPass(); |
There was a problem hiding this comment.
createExpandMathToArithPass -> `createEmulateMathWithArithPass
| include "mlir/Pass/PassBase.td" | ||
|
|
||
| //=========================================================// | ||
| // Math Expansion Pass. |
| //=========================================================// | ||
| // Math Expansion Pass. | ||
| //=========================================================// | ||
| def ExpandMathToArith : Pass<"expand-math-to-arith", "ModuleOp"> { |
There was a problem hiding this comment.
Basically, rename Expansion to Emulation. Expand -> Emulate. ExpandMathTo -> EmulateMathWith.
| /** | ||
| * @file ExpandMathToArithPass.cpp | ||
| * @brief Expands math.fpowi and math.tanh into arith/math.exp primitives | ||
| * so they survive pipeline transformations without type mismatches. |
There was a problem hiding this comment.
Why there would be "type mismatches" if we keep fpowi and tanh? Why they are different from other ops?
| * promotes constants (e.g. exponent 3 for x^3) to kernel block arguments. | ||
| * Once promoted, the exponent is no longer a visible constant and can no | ||
| * longer be expanded into a fixed chain of arith.mulf. |
There was a problem hiding this comment.
"can no longer be expanded into a fixed chain of arith.mulf" would this cause any problem?
And what about tanh, any problem (tanh has constant as well?) force us to "expand" it before taskflow-conversion? CC @ShangkunLi
|
Thanks for the cleanup~! Plz update the PR description accordingly. |
aa3b4ac to
4541d16
Compare
4541d16 to
497ad1c
Compare
This PR implements a PyTorch → Neura IR Python frontend compilation pipeline and supporting MLIR pass infrastructure.
Python Frontend (tools/neura-py-frontend/)
neura_pipeline.py: Core compilation pipeline with 4 stages:
Stage 0: PyTorch model → Linalg-on-Tensors IR (via torch-mlir)
Stage 1: Linalg → Affine IR (manual unrolling + canonicalization)
Stage 2: Affine → Taskflow → Neura IR
Stage 3: Neura IR → Optimisation + Codegen
neura-py-frontend.sh: One-click shell wrapper with conda env activation
environment.yml: Conda environment spec (torch 2.5.1 + torch-mlir)
README.md: Full usage documentation
CMakeLists.txt: Optional build integration
New Passes
ExpandMathToArith: Expands math.exp and related ops to arith primitives, ensuring full downstream Neura coverage
StripTaskflowTask: Removes taskflow.task wrappers to produce clean Neura IR for testing and dataflow conversion
Dialect Extensions
New ops: neura.exp, neura.rsqrt, neura.fcmp
ArithToNeuraPass extended with support for the new ops and dynamic shapes
Test Infrastructure (test/Conversion/python2neura/)
9 PyTorch model definitions: matmul / MLP / residual block / conv2d+relu+pool / transformer attention / transformer block / GELU+LayerNorm
generate_mlir.py: Automated lit-testable MLIR generation with DATAFLOW_IR FileCheck
test_models.py: End-to-end pipeline verification (IR generation)