Skip to content

Add GEN_INDEX pointwise op#359

Open
rsuderman wants to merge 4 commits intoiree-org:mainfrom
rsuderman:pointwise_gen_idx
Open

Add GEN_INDEX pointwise op#359
rsuderman wants to merge 4 commits intoiree-org:mainfrom
rsuderman:pointwise_gen_idx

Conversation

@rsuderman
Copy link
Copy Markdown
Contributor

Emits the output as a linalg.generic that materializes the iteration index along a configurable axis (via PointwiseAttr::setGenIdxAxis). The generic is bridged back to torch via torch_c.from_builtin_tensor so the result feeds the standard output permute.

Also adds buildBuiltinTensorTypeStr / getSignlessElementTypeAsm / getIdentityAffineMapAsm / getIteratorTypesAsm helpers and relaxes the lit-test MLIR indentation check to allow nested region bodies.

Emits the output as a linalg.generic that materializes the iteration index
along a configurable axis (via PointwiseAttr::setGenIdxAxis). The generic
is bridged back to torch via torch_c.from_builtin_tensor so the result
feeds the standard output permute.

Also adds buildBuiltinTensorTypeStr / getSignlessElementTypeAsm /
getIdentityAffineMapAsm / getIteratorTypesAsm helpers and relaxes the
lit-test MLIR indentation check to allow nested region bodies.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Rob Suderman <rob.suderman@gmail.com>
Comment thread include/fusilli/support/asm_emitter.h Outdated
@sjain-stanford sjain-stanford requested a review from IanWood1 April 20, 2026 20:30
Comment thread include/fusilli/support/asm_emitter.h
Comment thread include/fusilli/support/asm_emitter.h
Comment thread tests/pointwise_utils.h
{PointwiseAttr::Mode::FLOOR, 1},
{PointwiseAttr::Mode::GELU_APPROX_TANH_FWD, 1},
{PointwiseAttr::Mode::GELU_FWD, 1},
{PointwiseAttr::Mode::GEN_INDEX, 1},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a bit strange that it takes an input that it never uses. Is this just for shape inference?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct — IN_0 is only used for shape inference. The Graph::pointwise single-operand overload (graph.h:937) feeds the input's shape through inferPropertiesNode so the OUT_0 dims/strides can be derived without having to set them explicitly. This matches cuDNN's Graph API shape for GEN_INDEX (it takes an input tensor whose shape drives the output shape). The emitted linalg.generic doesn't consume IN_0's values.

Comment thread include/fusilli/support/asm_emitter.h Outdated
Comment thread include/fusilli/support/asm_emitter.h Outdated
Comment thread include/fusilli/support/asm_emitter.h Outdated
Comment thread include/fusilli/support/asm_emitter.h Outdated
Comment thread include/fusilli/support/asm_emitter.h Outdated
Comment thread include/fusilli/support/asm_emitter.h Outdated
- Move getSignlessElementTypeAsm to types.h, alongside new isFloatDataType /
  isIntegerDataType helpers driven by a new per-DataType Category column in
  FUSILLI_FORALL_DATA_TYPES. Covers every float dtype (including FP8E5M2) and
  replaces the bug-prone substr("i") check.
- Use interleave() in getIdentityAffineMapAsm / getIteratorTypesAsm.
- Enforce axis range and dtype correctness in PointwiseNode::postValidateNode
  for GEN_INDEX; keep the emitter asserts as safety nets.
- Add unit tests for the new MLIR / dtype helpers.
- Add an int-dtype lit test variant for GEN_INDEX.
- Fold the dedicated pointwise_gen_index sample into pointwise_unary_ops so
  the op is exercised with the other unary pointwise ops.

Signed-off-by: Rob Suderman <rob.suderman@gmail.com>
@rsuderman rsuderman requested a review from IanWood1 April 21, 2026 19:45
Copy link
Copy Markdown
Member

@sjain-stanford sjain-stanford left a comment

Choose a reason for hiding this comment

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

I gave it a cursory look but would like to do another closer review later today or Thursday.

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.

3 participants