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

Reduce cost of bounds checks in transforms #43

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kornelski
Copy link
Contributor

@kornelski kornelski commented Feb 11, 2025

According to llvm-mca estimate, the 4x3 transform function

before:

uOps Per Cycle: 2.70
IPC: 1.97
Block RThroughput: 159.3

after:

uOps Per Cycle: 3.48
IPC: 2.69
Block RThroughput: 279.8

@kornelski kornelski force-pushed the clut-opt branch 4 times, most recently from b8d408f to 7585ddd Compare February 11, 2025 13:09
@@ -159,7 +159,7 @@ impl ModularTransform for XYZtoLAB {

struct ClutOnly {
clut: Box<[f32]>,
grid_size: u16,
grid_size: u8,
Copy link
Collaborator

@jrmuizel jrmuizel Feb 12, 2025

Choose a reason for hiding this comment

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

Was the motivation for this? Avoiding the casts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the natural size for it, as read from the input.

I hoped it would also explain to LLVM that grid_size.pow(4) can't overflow, but unfortunately that didn't have any effect.

@jrmuizel
Copy link
Collaborator

Is this code showing up in profiles for you? It should only be used when building a lookup table during transform creation. The actual color transformation should be using a fast path.

@jrmuizel
Copy link
Collaborator

The first 3 commits are queued for landing. https://bugzilla.mozilla.org/show_bug.cgi?id=1947889

The other 3 seem ok but I'd like to understand the motivation a little better before landing them.

@kornelski
Copy link
Contributor Author

Yes, on small images (<640px) the time to build the lookup table takes more time than the transformation itself. Reduction in bounds checks also made the code a bit smaller.

@jrmuizel
Copy link
Collaborator

I've landed the grid size patch. The other two commits cause:

---- gtest::gtest::v4_output stdout ----
thread 'gtest::gtest::v4_output' panicked at src/chain.rs:1109:5:
assertion failed: false

when running cargo test --all-features

@jrmuizel
Copy link
Collaborator

I'll make it so that it runs tests in github actions when I get a chance.

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