Skip to content

Add docs tutorial for adding a new ATen operator (MLIR path)#206

Merged
YWHyuk merged 1 commit intoPSAL-POSTECH:masterfrom
MinkyuPark0816:docs/add-aten-op-tutorial
Jan 19, 2026
Merged

Add docs tutorial for adding a new ATen operator (MLIR path)#206
YWHyuk merged 1 commit intoPSAL-POSTECH:masterfrom
MinkyuPark0816:docs/add-aten-op-tutorial

Conversation

@MinkyuPark0816
Copy link
Copy Markdown

No description provided.

@YWHyuk YWHyuk merged commit e402d2d into PSAL-POSTECH:master Jan 19, 2026
@@ -0,0 +1,681 @@
# How to add support for a new ATen Operator in PyTorchSim
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think the template keyword is required in this title

## Overview
PyTorchSim executes PyTorch programs by **lowering ATen operators into MLIR**,
followed by backend-specific code generation and simulation.
This wiki describes contributors through the process of adding support for **new
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

describes -> guides or helps?

PyTorchSim executes PyTorch programs by **lowering ATen operators into MLIR**,
followed by backend-specific code generation and simulation.
This wiki describes contributors through the process of adding support for **new
ATen operators** by defining custom lowerings in PyTorchSim’s MLIR-based
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think template need to be mentioned here



We use a dummy operator, `torch._foobar()`, as a minimal example.
Although `_foobar` has trivial semantics, it still exercises the full
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be helpful to explicitly mention that foobar is an ATen operator. Plus, how about adding a ULR?

## Background

Before diving into the step-by-step implementation, it helps to understand
how an ATen operator flows through PyTorchSim’s MLIR-based pipeline. At a high level, supporting a new ATen operator means intercepting the
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What about adding a figure of the compilation flow for the template kernel?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

intercepting sounds slightly awkward

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it would be good to mention the difference between the ordinary codegen path and the template codegen path


### Lowering stage (`mlir_lowering.py`)

During lowering, a custom function (e.g., `custom_<op>`) is invoked for
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think readers might be confused about what custom_function is and why it suddenly appears here.

Did you mean to explain that custom_function is called during the lowering process because it is registered in the lowering dictionary as {aten._foobar: custom_function}

`aten.<op>`.

The lowering:
- materializes inputs in Inductor IR if necessary,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

?


This is the key hook where new ATen operator support is introduced.

### Scheduling stage (`mlir_scheduling.py`)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Codegen stage?

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