这是indexloc提供的服务,不要输入任何密码
Skip to content

Add subgroups feature #4963

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

Merged
merged 22 commits into from
Jan 16, 2025
Merged

Add subgroups feature #4963

merged 22 commits into from
Jan 16, 2025

Conversation

alan-baker
Copy link
Contributor

@alan-baker alan-baker commented Nov 8, 2024

  • API
    • new feature: subgroups
    • new properties for adapter info:
      • minSubgroupSize subgroupMinSize
      • maxSubgroupSize subgroupMaxSize
  • WGSL
    • new built-in values
      • subgroup_invocation_id
      • subgroup_size
    • subgroup and quad built-in functions
    • new uniformity diagnostic subgroup_uniformity

Missing subgroup_branching diagnostic and uniformity updates.


edited to match final naming: 'minSubgroupSize' was changed to 'subgroupMinSize', 'maxSubgroupSize' was changed to 'subgroupMaxSize'

* API
  * new feature: subgroups
  * new properties for adapter info:
    * minSubgroupSize
    * maxSubgroupSize
* WGSL
  * new built-in values
    * subgroup_invocation_id
    * subgroup_size
  * subgroup and quad built-in functions
  * new uniformity diagnostic subgroup_uniformity
@alan-baker alan-baker added this to the Milestone 1 milestone Nov 8, 2024
Copy link
Contributor

github-actions bot commented Nov 8, 2024

Previews, as seen when this build job started (f950527):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt

Copy link
Contributor

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

Main question is whether we want a new GPUAdapterProperties object or not

@dneto0 dneto0 self-requested a review November 8, 2024 20:04
Copy link
Contributor

@Kangz Kangz left a comment

Choose a reason for hiding this comment

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

Looks great! Added a bunch of comments but they are relatively minor.

Copy link
Contributor

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

No further comments on the API side

* move minSubgroupSize and maxSubgroupSize into GPUAdapterInfo
  * provide default values
* Fix link to wgsl spec
* Fix uniformity rules in wgsl related to parameters they are required
  to be uniform
Copy link
Contributor

@dneto0 dneto0 left a comment

Choose a reason for hiding this comment

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

WGSL side looking very good. Thanks!

alan-baker and others added 4 commits November 15, 2024 09:41
Co-authored-by: Kai Ninomiya <kainino@chromium.org>
* Mention subgroup_size is uniform in compute shaders in the uniformity
  analysis description of built-in values
* Updates to the subgroups section
* Fix typos and links
@kainino0x kainino0x added wgsl WebGPU Shading Language Issues api WebGPU API labels Nov 18, 2024
* add notes about uniform control flow scope
* add prefix to inclusive and exclusive subgroup op descriptions
@alan-baker alan-baker changed the title WIP: Add subgroups feature Add subgroups feature Dec 4, 2024
mwyrzykowski
mwyrzykowski previously approved these changes Dec 6, 2024
Copy link

@mwyrzykowski mwyrzykowski left a comment

Choose a reason for hiding this comment

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

Looks good!

@mwyrzykowski mwyrzykowski dismissed their stale review December 6, 2024 18:27

Want to ask a question

* Add extra spec cross-links for subgroups
@kdashg
Copy link
Contributor

kdashg commented Dec 10, 2024

WGSL 2024-12-10 Minutes
  • (touch-base, status updates)
  • JB: Some review. Some question of properties into their own interface. Min size and max size are not limits; don’t work as limits. Comment on another issue “separate out properties as their own thing when we need them”.
  • JB: Is there a concept of a subgroup index, as a subset of a workgroup.
  • AB: There is but not in every API.
  • AB: There is no reliable mapping between linear invocation Index in a compute shader, and subgroup index.
  • JB: So no reliable chunking of local IDs into subgroups.
  • JB: When someone uses this API they have to write as if an invocation’s subgroup members might be anywhere in the workgroup.
  • AB: There’s nothing you can rely on in all cases. If you have a linear workgroup you do tend to see linear subgroup in an obvious way. Difficulty comes when you have multidimensional workgroups.
  • AB: D3D doesn’t have a subgroup ID. You have to write code to avoid assuming the association.
  • JB: I can’t figure out how to use this. I can use ballot or sum. But what elements am I even operating on. There are no guarantees.
  • AB: A lot of operations are reductions, and you don’t need to know the relative order of things because you reduce all the way down. The CTS tests go out of their way to avoid the assumptions. It often generates its own subgroup ID specific to the execution. E.g. use a broadcast of the invocation index of the first element in the subgroup. So everyone in the subgroup shares some arbitrary value.
  • JB: And you use the index that you place the subgroup results. And you accept the possibility it’s not 100% dense.
  • AB: Most of the time you want to resolve results from the whole workgroup, and so it ends up dense. You can reconstruct where each invocation was placed.
  • JB: CTS is one thing, but doesn’t have to produce a result an ordinary program might want to do.
  • AB: Think of [atomic?] decimated compaction. Use two passes. First pass decides who needs to write, then you use atomics and reductions to calculate the index into which subgroup leads write.
  • JB: I wonder if there are techniques like you describe that are ubiquitous that are so valuable such that we supply them as recommended primitives to give people a foothold.
  • AB: Maybe. It came up in internal discussion to add language features that add polyfills over the enable-extension baseline feature.
  • JB: I put other comments on the PR, don’t need to talk about it here.
  • MW: do we need some kind of barrier functions for subgroups? OR do implementations insert the barriers.
  • AB: There are no new barriers because there no “subgroup memory” memory locations to protect. So you reuse the existing barriers to order memory accesses. In Vulkan the subgroup-execution-scope barriers are non-uniform, which is tricky ot think about. So you end up trying to ensure subgroup reconvergence, then use a workgroup barrier.
  • MW: Sounds good.
  • Reviews and iteration will continue.

@alan-baker alan-baker requested a review from jimblandy December 18, 2024 16:13
aarongable pushed a commit to chromium/chromium that referenced this pull request Jan 11, 2025
This CL adds the subgroupMinSize and subgroupMaxSize properties to
GPUAdapterInfo behind the experimental WebGPUSubgroupsFeatures blink
runtime feature.

Spec PR: gpuweb/gpuweb#4963

Change-Id: I4f9edbd6482a0f7a1f98086bcba1205b5e24ceea
Bug: 354751907
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6162500
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Fr <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/main@{#1405153}
Copy link
Contributor

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

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

This looks good to me. I have some editorial comments, but nothing blocking.

Comment on lines +18942 to +18943
Returns the maximum value of `e` among all [=subgroups/active=] invocations in the [=subgroup=].
</table>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this discuss subnormal and NaN behavior, the way the description of max does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed this as #5044

alan-baker and others added 2 commits January 16, 2025 10:12
Co-authored-by: Jim Blandy <jimb@red-bean.com>
Co-authored-by: Jim Blandy <jimb@red-bean.com>
@alan-baker alan-baker merged commit bb105af into main Jan 16, 2025
4 checks passed
aarongable pushed a commit to chromium/chromium that referenced this pull request Jan 22, 2025
Spec PR: gpuweb/gpuweb#4963

Bug: 354751907
Change-Id: If5823c0ff95b4de72d0f95e1a5cd1cd92e3b5459
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6163583
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
Commit-Queue: Fr <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/main@{#1409490}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api WebGPU API wgsl WebGPU Shading Language Issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants