Skip to content

Feature/frontend and passes#328

Open
itemkelvin wants to merge 1 commit into
mainfrom
feature/frontend-and-passes
Open

Feature/frontend and passes#328
itemkelvin wants to merge 1 commit into
mainfrom
feature/frontend-and-passes

Conversation

@itemkelvin

Copy link
Copy Markdown
Collaborator

This PR implements a PyTorch → Neura IR Python frontend compilation pipeline and supporting MLIR pass infrastructure.

  1. 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

  2. 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

  3. Dialect Extensions
    New ops: neura.exp, neura.rsqrt, neura.fcmp
    ArithToNeuraPass extended with support for the new ops and dynamic shapes

  4. 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)

@itemkelvin itemkelvin force-pushed the feature/frontend-and-passes branch 2 times, most recently from 543c497 to 812351d Compare June 15, 2026 15:33
@tancheng

Copy link
Copy Markdown
Contributor

How is this PR different from #327?

@itemkelvin

Copy link
Copy Markdown
Collaborator Author

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.

@tancheng

Copy link
Copy Markdown
Contributor

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?

@itemkelvin itemkelvin force-pushed the feature/frontend-and-passes branch from 812351d to 9bd84f5 Compare June 16, 2026 12:19

@tancheng tancheng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we have a mlir test for this emulation/expansion?

Comment thread include/Conversion/ConversionPasses.h Outdated
std::unique_ptr<mlir::Pass> createLowerBuiltinToNeuraPass();
std::unique_ptr<mlir::Pass> createLowerAffineToNeuraPass();

// Math Expansion Pass.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

// Math Expansion Pass. -> // Math Emulation Pass.

Comment thread include/Conversion/ConversionPasses.h Outdated
std::unique_ptr<mlir::Pass> createLowerAffineToNeuraPass();

// Math Expansion Pass.
std::unique_ptr<mlir::Pass> createExpandMathToArithPass();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

createExpandMathToArithPass -> `createEmulateMathWithArithPass

Comment thread include/Conversion/ConversionPasses.td Outdated
include "mlir/Pass/PassBase.td"

//=========================================================//
// Math Expansion Pass.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expansion -> Emulation

Comment thread include/Conversion/ConversionPasses.td Outdated
//=========================================================//
// Math Expansion Pass.
//=========================================================//
def ExpandMathToArith : Pass<"expand-math-to-arith", "ModuleOp"> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why there would be "type mismatches" if we keep fpowi and tanh? Why they are different from other ops?

Comment on lines +8 to +10
* 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"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

@tancheng

Copy link
Copy Markdown
Contributor

Thanks for the cleanup~! Plz update the PR description accordingly.

@itemkelvin itemkelvin force-pushed the feature/frontend-and-passes branch 4 times, most recently from aa3b4ac to 4541d16 Compare June 16, 2026 18:15
@itemkelvin itemkelvin force-pushed the feature/frontend-and-passes branch from 4541d16 to 497ad1c Compare June 16, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants