Skip to content

Add support for inductively defined functions#8878

Draft
stevenraphael wants to merge 23 commits into
halide:mainfrom
stevenraphael:inductive2
Draft

Add support for inductively defined functions#8878
stevenraphael wants to merge 23 commits into
halide:mainfrom
stevenraphael:inductive2

Conversation

@stevenraphael
Copy link
Copy Markdown
Contributor

@stevenraphael stevenraphael commented Nov 24, 2025

Following substantial discussion with Andrew Adams and Alex Reinking, I have implemented a first draft of their idea of inductively defined functions. A full description is in src/Inductive.h. This pull includes correctness and error tests. Please suggest any additional changes I need to make. The basic idea is to have pure functions that are defined with self-references, e.g. f(x) = select(x <= 0, input(0), input(x) + f(x - 1)), which allows for optimizations that are currently impossible to do with reduction domains.

@stevenraphael stevenraphael changed the title Inductive2 Inductive functions Nov 24, 2025
@stevenraphael stevenraphael changed the title Inductive functions Add support for inductively defined functions Nov 24, 2025
@zvookin
Copy link
Copy Markdown
Member

zvookin commented Nov 24, 2025

Given the constraints on the definition, I'm wondering if this should be its own syntax. E.g. f(x) = inductive(cond, expr1, expr2) Could also try to put it all in the construction, similar to how RDom is done, but given the arguments need to be specified, function definition syntax seems better.

Main goal is to avoid confusion around the lack of generality in the definition. If it is envisioned that this will become more general, the current design might be the right way to go. (And by confusion, I mean that this makes it look like normal programming language recursion expectations are supported.)

@abadams
Copy link
Copy Markdown
Member

abadams commented Nov 24, 2025

The goal is definitely to become more general over time. The thinking was that if we fail to solve for a base case, we could tell the user to write things in a particular form that is known to work, but first we'd try to handle any recursive RHS.

@alexreinking
Copy link
Copy Markdown
Member

We are likely to merge #8877 before this, so consider using the new APIs to simplify visitors/mutators here. I see two here: RecursiveHelper in is_inductive, and maybe BaseCaseSolver as it has just one visit overload.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 65.14523% with 84 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@7e2ecf2). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/Function.cpp 69.38% 19 Missing and 11 partials ⚠️
src/IROperator.cpp 35.13% 11 Missing and 13 partials ⚠️
src/Inductive.cpp 77.77% 9 Missing and 5 partials ⚠️
src/Func.cpp 54.54% 1 Missing and 4 partials ⚠️
src/IRPrinter.cpp 0.00% 4 Missing and 1 partial ⚠️
src/Schedule.h 0.00% 2 Missing ⚠️
src/Type.h 50.00% 2 Missing ⚠️
src/BoundsInference.cpp 87.50% 0 Missing and 1 partial ⚠️
src/ScheduleFunctions.cpp 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8878   +/-   ##
=======================================
  Coverage        ?   69.24%           
=======================================
  Files           ?      255           
  Lines           ?    78436           
  Branches        ?    18782           
=======================================
  Hits            ?    54316           
  Misses          ?    18532           
  Partials        ?     5588           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

4 participants