10000 WIP: linearzer rewrite by Tzvetomir-Kaydjiev · Pull Request #9312 · tinygrad/tinygrad · GitHub
[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: linearzer rewrite #9312

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Tzvetomir-Kaydjiev
Copy link

WIP: Global rewrite of SINK.

This attempts to split the compute graph on multiple scopes before the linearization process starts. I am not sure if this is possible with local changes to the graph, because this scopes can be overlapping for this implementation.

For example the case for TestOps.test_avg_pool3d_failure:

ASSIGN1 -- depends -- > RANGE1, RANGE2
ASSIGN2 -- depends -- > RANGE1
ASSIGN3 -- depends -- > RANGE2

We can try to make with by shoving everything in a nested loop:

Loop RANGE1 {
  Loop RANGE2 {
    ASSIGN1
    ASSIGN2
    ASSIGN3
  }
}

or we can have multiple loops with duplicate operations for RANGE, LOAD ... :

Loop RANGE1 {
  Loop RANGE2 {
    ASSIGN1
  }
}
Loop RANGE1 {
  ASSIGN2
}
Loop RANGE2 {
  ASSIGN3
}

The current implementation tries to do the first variant and fails because can't shove a ASSIGN2 and ASSIGN3 because one must be in the nested loop.

This scratch implementation tries to do the second approach.

Opinion?

@Tzvetomir-Kaydjiev Tzvetomir-Kaydjiev marked this pull request as draft March 1, 2025 11:25
Copy link
Contributor
github-actions bot commented Mar 1, 2025

This branch currently is behind tinygrad/master. The line count difference bot is disabled.

@geohot
Copy link
Collaborator
geohot commented Mar 2, 2025

Can you use rewrite rules? They are a lot easier to reason about than state in Python.

@Tzvetomir-Kaydjiev
Copy link
Author

I added rewrite if VIZ is enabled, also fixed some problems with the new implementation, but I think there are still some problems to fix with the implicit dependencies of the Ops.STORE operations. I can add more more rewrite rules for the final SINK transformation, but the scope generation and scope merger, probably can not be broken down.

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
0