Skip to content

[Core] Add four concrete layout categories - #1292

Open
sjfeng1999 wants to merge 5 commits into
mainfrom
pr/feat-core-categories
Open

sjfeng1999 wants to merge 5 commits into
mainfrom
pr/feat-core-categories

Conversation

@sjfeng1999

Copy link
Copy Markdown
Collaborator

The algebra is written once over a category; a category decides what a leaf is and how each leaf operation evaluates. This adds four:

  • Trait: static type inference. A leaf is only its property: a static value, ratio or basis, or a dynamic integer's width, divisibility and fast-divmod flag. Fly infers result types with it and keeps them in attributes.
  • EmitOp: IR emission. A dynamic leaf is bound to an SSA value; each operation computes its Trait result first and emits arith ops only for a dynamic one. It also defines the LLVM representation of a value (get_llvm_type, build/bind/collect) and of the fast-divmod handle, with EmitHooks for dialect pointers and divisions.
  • Runtime: a concrete int64 next to the Trait property. The parity tests print it and the EmitOp tests execute against it. Test only.
  • Symbol: a symbolic expression next to the Trait property, to check the expressions the algebra builds. Test only.

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

The algebra is written once over a category; a category decides what a leaf
is and how each leaf operation evaluates. This adds four:

- Trait: static type inference. A leaf is only its property: a static value,
  ratio or basis, or a dynamic integer's width, divisibility and fast-divmod
  flag. Fly infers result types with it and keeps them in attributes.
- EmitOp: IR emission. A dynamic leaf is bound to an SSA value; each operation
  computes its Trait result first and emits arith ops only for a dynamic one.
  It also defines the LLVM representation of a value (get_llvm_type,
  build/bind/collect) and of the fast-divmod handle, with EmitHooks for
  dialect pointers and divisions.
- Runtime: a concrete int64 next to the Trait property. The parity tests print
  it and the EmitOp tests execute against it. Test only.
- Symbol: a symbolic expression next to the Trait property, to check the
  expressions the algebra builds. Test only.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@sjfeng1999
sjfeng1999 requested review from coderfeli and xudoyuan and a balanced review from Copilot October 14, 2026 10:24

Copilot AI 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.

🟡 Changes recommended

The new test target fails with GCC, and LLVM binding and symbolic round-trip correctness defects remain.

5 open findings
What changed in this PR

Adds Trait, EmitOp, Runtime, and Symbol evaluation categories to the Core layout algebra, with LLVM emission support and extensive parity tests.

Changes:

  • Implements category-independent traversal, inference, symbolic evaluation, runtime evaluation, and LLVM binding.
  • Refines layout, tuple, pointer, swizzle, and tiled-operation behavior.
  • Adds Core C++ tests and integrates them into wheel CI.
File Description
CMakeLists.txt Enables optional Core tests.
lib/​CMakeLists.txt Adds the Core library directory.
lib/​Core/​CMakeLists.txt Defines FlyCore.
lib/​Core/​Trait.cpp Implements Trait inference.
lib/​Core/​EmitOp.cpp Implements MLIR emission.
lib/​Core/​Testing/​CMakeLists.txt Defines test-only categories.
lib/​Core/​Testing/​Runtime.cpp Implements concrete evaluation.
lib/​Core/​Testing/​Symbol.cpp Implements symbolic expressions.
include/​flydsl/​Core/​Category.def Centralizes category operations.
include/​flydsl/​Core/​Trait.hpp Declares Trait values.
include/​flydsl/​Core/​EmitOp.hpp Declares emission and LLVM binding APIs.
include/​flydsl/​Core/​Runtime.hpp Declares runtime values.
include/​flydsl/​Core/​Symbol.hpp Declares symbolic values.
include/​flydsl/​Core/​Visitor.hpp Adds generic value traversal.
include/​flydsl/​Core/​Algebra/​Config.hpp Extends operations and errors.
include/​flydsl/​Core/​Algebra/​Leaf.hpp Generalizes fast-divmod queries.
include/​flydsl/​Core/​Algebra/​Parse.hpp Adds leaf suffix parsing.
include/​flydsl/​Core/​Algebra/​IntTuple.hpp Separates tuple operation provenance.
include/​flydsl/​Core/​Algebra/​IntTupleAlgorithms.hpp Adds tuple-preserving repetition.
include/​flydsl/​Core/​Algebra/​Layout.hpp Adds explicit indexing and regrouping.
include/​flydsl/​Core/​Algebra/​ComposedLayout.hpp Adds explicit composed indexing.
include/​flydsl/​Core/​Algebra/​Pointer.hpp Adds generic pointer helpers.
include/​flydsl/​Core/​Algebra/​Swizzle.hpp Uses logical right shift.
include/​flydsl/​Core/​Algebra/​Tensor.hpp Updates partition regrouping.
include/​flydsl/​Core/​Algebra/​TiledCopy.hpp Renames thread-index access.
include/​flydsl/​Core/​Algebra/​TiledMma.hpp Renames thread-coordinate access.
tests/​core/​CMakeLists.txt Configures Core test targets.
tests/​core/​common.hpp Adds shared Runtime fixtures.
tests/​core/​TraitTest.cpp Tests Trait semantics.
tests/​core/​EmitOpTest.cpp Tests emitted operations and bindings.
tests/​core/​LeafTest.cpp Tests scalar algebra.
tests/​core/​IntTupleTest.cpp Tests tuple algorithms.
tests/​core/​LayoutTest.cpp Tests layout algebra.
tests/​core/​TileTest.cpp Tests tile operations.
tests/​core/​ComposedLayoutTest.cpp Tests composed layouts.
tests/​core/​SwizzleTest.cpp Tests swizzle behavior.
tests/​core/​PointerTest.cpp Tests pointer offsets.
tests/​core/​TensorTest.cpp Tests tensor slicing and partitioning.
tests/​core/​TiledCopyTest.cpp Tests tiled-copy layouts.
tests/​core/​TiledMMATest.cpp Tests tiled-MMA layouts.
tests/​core/​SymbolTest.cpp Tests symbolic expressions.
scripts/​run_core_tests.sh Builds and runs Core tests.
scripts/​build_llvm.sh Installs LLVM GoogleTest support.
scripts/​build_ci_wheels.sh Runs Core tests during wheel CI.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread include/flydsl/Core/EmitOp.hpp
Comment thread tests/core/CMakeLists.txt Outdated
Comment thread include/flydsl/Core/EmitOp.hpp Outdated
Comment thread lib/Core/Testing/Symbol.cpp
Comment thread lib/Core/Testing/Symbol.cpp
sjfeng1999 and others added 3 commits October 14, 2026 11:37
- tests/core: use -g1 for the light debug info; GCC, which the wheel CI
  builds with, rejects the Clang-only -gline-tables-only.
- EmitOp: bind checks a pointer binding as the bound pointer holds it, so a
  value of another MLIRContext fails instead of binding an invalid pointer.
- EmitOp: get_llvm_type and build_llvm_value reject a bare leaf as the root,
  which they lowered inconsistently; a leaf lowers as a tuple of it.
- Symbol: comparisons print parenthesized inside arithmetic, and a minus
  before a digit parses as part of the literal, so printed expressions with
  comparisons or negative constants parse back to the same expression.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The wheel CI builds with GCC 9 (gcc-toolset-9), which ignores a default
template argument that a later redeclaration adds. Most Core templates are
declared ahead of their definitions with the defaults only on the definition,
so GCC 9 could deduce none of their enable_if parameters and every Core test
failed to compile (make_tuple, make_layout, the tuple operators, ...).

Move each such default to the first declaration and drop it from the
definition, as the standard asks; the tuple operators generated by
FLYDSL_CORE_ARITH_TUPLE_OPERATOR are all declared ahead for that. GCC 9, GCC 13
and Clang build and pass the Core tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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