Skip to content

impr: Utilize subgroups in MNIST Inference when possible #986

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

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

Conversation

reczkok
Copy link
Contributor

@reczkok reczkok commented Mar 4, 2025

Requires chrome 134

EDIT: It is now available by default in chrome and pretty fast. Those are the measured times but I would't take them at face value - some query sets for subgroup version resulted in 0ns inference time which probably means it's below the precision of timestamp queries.

No Subgroups Subgroups
Measured Time No Subgroups Subgroups

EDIT2: Since we now enable timing utilities in TypeGPU timing could become the default in this example

Copy link

github-actions bot commented Mar 4, 2025

pkg.pr.new

packages

pnpm i https://pkg.pr.new/software-mansion/TypeGPU/typegpu@986
pnpm i https://pkg.pr.new/software-mansion/TypeGPU/typegpu@b7d4c5809428f9c01d781055e3110e00ca480a54

benchmark
view benchmark

commit
view commit

@reczkok reczkok force-pushed the impr/mnist-subgroups branch from 22344d7 to 8c78130 Compare March 10, 2025 12:26
@reczkok reczkok requested a review from Copilot March 27, 2025 13:51
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request improves the MNIST inference example by leveraging GPU subgroup operations when available, which should enhance performance.

  • The initialization code now detects subgroup support using navigator.gpu.
  • A new subgroup compute shader is introduced alongside a fallback shader for devices that do not support subgroups.
  • The compute pipeline dynamically selects the appropriate shader based on the detected capabilities.
Comments suppressed due to low confidence (2)

apps/typegpu-docs/src/content/examples/algorithms/mnist-inference/index.ts:23

  • [nitpick] Consider renaming 'fallbackShader' to something like 'nonSubgroupShader' to more explicitly indicate its purpose.
const fallbackShader = `

apps/typegpu-docs/src/content/examples/algorithms/mnist-inference/index.ts:66

  • The workgroup size of 64 is assumed to be divisible by the subgroup size (ssize). Consider adding a static assertion or additional documentation to ensure this invariant holds on all target devices.
var<workgroup> subgroupSums: array<f32, 64 / 4>;

@reczkok reczkok force-pushed the impr/mnist-subgroups branch from 8c78130 to 6e41c18 Compare June 5, 2025 17:17
@reczkok reczkok force-pushed the impr/mnist-subgroups branch from 6e41c18 to 3f8d212 Compare June 17, 2025 16:06
@reczkok reczkok requested a review from iwoplaza June 23, 2025 09:02
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.

1 participant