Skip to content

[ROCm] opportunistic fastatomics for ReduceAdd operations for MI300 GPUs - #146264

Closed
pragupta wants to merge 21 commits into
pytorch:mainfrom
pragupta:pg-scatter-add-dup-fix
Closed

pragupta wants to merge 21 commits into
pytorch:mainfrom
pragupta:pg-scatter-add-dup-fix

Conversation

@pragupta

@pragupta pragupta commented Feb 2, 2025 •

Copy link
Copy Markdown
Collaborator

In this approach, we are catching any lane within a wave that is doing fastatomics to the same destination address and computing the sum on the CU. This is leading to 3x improvement in scatter_add performance and 2x improvement in index_select.

scatter_add performance on MI300x:

dtype Baseline (before optimizations) opportunistic fastatomics
f32 1.389425039 0.430447996
fp16 2.195472956 0.779729486
bf16 2.194051027 0.784599513

Using the following reproducer

import torch
import triton


def main():
    dtype = torch.float32
    dim = 1305301
    a = torch.rand(100, device="cuda", dtype=dtype)
    index = torch.randint(0, 100, (dim,), device="cuda")
    src = torch.rand(dim, device="cuda", dtype=dtype)

    print("=" * 20)
    print(
        triton.testing.do_bench(
            lambda: a.scatter_add(0, index, src),
            return_mode="median",
        )
    )
    print("=" * 20)

if __name__ == "__main__":
    main()

co-authored by: @amd-hhashemi

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @dllehr-amd @jataylo @hongxiayang @naromero77amd @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov

@pytorch-bot

pytorch-bot Bot commented Feb 2, 2025 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/146264

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 392bd26 with merge base bb11122 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label Feb 2, 2025
@pruthvistony pruthvistony added the topic: not user facing topic category label Feb 3, 2025
@pragupta

pragupta commented Feb 3, 2025

Copy link
Copy Markdown
Collaborator Author

@pytorchbot label "topic: not user facing"

@pruthvistony pruthvistony added the ciflow/periodic Trigger jobs ran periodically on master (periodic.yml) on the PR label Feb 4, 2025
@pragupta
pragupta force-pushed the pg-scatter-add-dup-fix branch from cdd2d28 to 3614776 Compare February 4, 2025 20:50
@pragupta pragupta changed the title [ROCm] scatter_add: opportunistic fastatomics [ROCm] opportunistic fastatomics for ReduceAdd operations Feb 5, 2025
@pragupta
pragupta force-pushed the pg-scatter-add-dup-fix branch 2 times, most recently from 845eea9 to b134bfa Compare February 7, 2025 16:13
@jithunnair-amd jithunnair-amd changed the title [ROCm] opportunistic fastatomics for ReduceAdd operations [ROCm] opportunistic fastatomics for ReduceAdd operations for MI300 GPUs Feb 7, 2025
@jithunnair-amd jithunnair-amd added the ciflow/unstable Run all experimental or flaky jobs on PyTorch unstable workflow label Feb 7, 2025
@pytorch-bot

pytorch-bot Bot commented Feb 7, 2025

Copy link
Copy Markdown

To add the ciflow label ciflow/unstable please first approve the workflows that are awaiting approval (scroll to the bottom of this page).

This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. Please ping one of the reviewers if you do not have access to approve and run workflows.

@pytorch-bot pytorch-bot Bot removed the ciflow/unstable Run all experimental or flaky jobs on PyTorch unstable workflow label Feb 7, 2025
@jithunnair-amd jithunnair-amd added the ciflow/unstable Run all experimental or flaky jobs on PyTorch unstable workflow label Feb 7, 2025
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@mxz297 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@pragupta

Copy link
Copy Markdown
Collaborator Author

@pytorchbot add label "keep-going"

@pytorch-bot

pytorch-bot Bot commented Feb 12, 2025

Copy link
Copy Markdown

❌ 🤖 pytorchbot command failed:

@pytorchbot: error: argument command: invalid choice: 'add' (choose from 'merge', 'revert', 'rebase', 'label', 'drci', 'cherry-pick', 'close')

usage: @pytorchbot [-h] {merge,revert,rebase,label,drci,cherry-pick,close} ...

Try @pytorchbot --help for more info.

@pragupta

Copy link
Copy Markdown
Collaborator Author

@pytorchbot --help

@pytorch-bot

pytorch-bot Bot commented Feb 12, 2025

Copy link
Copy Markdown

PyTorchBot Help

usage: @pytorchbot [-h] {merge,revert,rebase,label,drci,cherry-pick,close} ...

In order to invoke the bot on your PR, include a line that starts with
@pytorchbot anywhere in a comment. That line will form the command; no
multi-line commands are allowed. Some commands may be used on issues as specified below.

Example:
    Some extra context, blah blah, wow this PR looks awesome

    @pytorchbot merge

optional arguments:
  -h, --help            Show this help message and exit.

command:
  {merge,revert,rebase,label,drci,cherry-pick,close}
    merge               Merge a PR
    revert              Revert a PR
    rebase              Rebase a PR
    label               Add label to a PR
    drci                Update Dr. CI
    cherry-pick         Cherry pick a PR onto a release branch
    close               Close a PR

Merge

usage: @pytorchbot merge [-f MESSAGE | -i] [-ic] [-r [{viable/strict,main}]]

Merge an accepted PR, subject to the rules in .github/merge_rules.json.
By default, this will wait for all required checks (lint, pull) to succeed before merging.

optional arguments:
  -f MESSAGE, --force MESSAGE
                        Merge without checking anything. This requires a reason for auditting purpose, for example:
                        @pytorchbot merge -f 'Minor update to fix lint. Expecting all PR tests to pass'
                        
                        Please use `-f` as last resort, prefer `--ignore-current` to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.
  -i, --ignore-current  Merge while ignoring the currently failing jobs.  Behaves like -f if there are no pending jobs.
  -ic                   Old flag for --ignore-current. Deprecated in favor of -i.
  -r [{viable/strict,main}], --rebase [{viable/strict,main}]
                        Rebase the PR to re run checks before merging.  Accepts viable/strict or main as branch options and will default to viable/strict if not specified.

Revert

usage: @pytorchbot revert -m MESSAGE -c
                          {nosignal,ignoredsignal,landrace,weird,ghfirst}

Revert a merged PR. This requires that you are a Meta employee.

Example:
  @pytorchbot revert -m="This is breaking tests on trunk. hud.pytorch.org/" -c=nosignal

optional arguments:
  -m MESSAGE, --message MESSAGE
                        The reason you are reverting, will be put in the commit message. Must be longer than 3 words.
  -c {nosignal,ignoredsignal,landrace,weird,ghfirst}, --classification {nosignal,ignoredsignal,landrace,weird,ghfirst}
                        A machine-friendly classification of the revert reason.

Rebase

usage: @pytorchbot rebase [-s | -b BRANCH]

Rebase a PR. Rebasing defaults to the stable viable/strict branch of pytorch.
Repeat contributor may use this command to rebase their PR.

optional arguments:
  -s, --stable          [DEPRECATED] Rebase onto viable/strict
  -b BRANCH, --branch BRANCH
                        Branch you would like to rebase to

Label

usage: @pytorchbot label labels [labels ...]

Adds label to a PR or Issue [Can be used on Issues]

positional arguments:
  labels  Labels to add to given Pull Request or Issue [Can be used on Issues]

Dr CI

usage: @pytorchbot drci 

Update Dr. CI. Updates the Dr. CI comment on the PR in case it's gotten out of sync with actual CI results.

cherry-pick

usage: @pytorchbot cherry-pick --onto ONTO [--fixes FIXES] -c
                               {regression,critical,fixnewfeature,docs,release}

Cherry pick a pull request onto a release branch for inclusion in a release

optional arguments:
  --onto ONTO           Branch you would like to cherry pick onto (Example: release/2.1)
  --fixes FIXES         Link to the issue that your PR fixes (Example: https://github.com/pytorch/pytorch/issues/110666)
  -c {regression,critical,fixnewfeature,docs,release}, --classification {regression,critical,fixnewfeature,docs,release}
                        A machine-friendly classification of the cherry-pick reason.

Close

usage: @pytorchbot close

Close a PR [Can be used on issues]

@pragupta

Copy link
Copy Markdown
Collaborator Author

@pytorchbot label "keep-going"

@pytorch-bot pytorch-bot Bot added the keep-going Don't stop on first failure, keep running tests until the end label Feb 12, 2025
@pragupta

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased pg-scatter-add-dup-fix onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout pg-scatter-add-dup-fix && git pull --rebase)

@pragupta
pragupta force-pushed the pg-scatter-add-dup-fix branch from bde074b to 9405e2f Compare February 18, 2025 01:06
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@mxz297 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@mxz297 mxz297 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BF16 regression is resolved and confirmed FP32 gain. Thanks!

@mxz297

mxz297 commented Apr 17, 2025

Copy link
Copy Markdown
Contributor

@jeffdaily there seems to be some mi300 test failures for the PR. Do you know if these failures are pre-existing?

@amd-hhashemi

amd-hhashemi commented Apr 17, 2025 via email

Copy link
Copy Markdown
Contributor

return any(arch in effective_arch for arch in arch_list)

def CDNA3OrLater():
return evaluate_gfx_arch_within(["gfx940", "gfx941", "gfx942", "gfx950"])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove gfx940", "gfx941" as we don't support these anymore

@jeffdaily

Copy link
Copy Markdown
Collaborator

There are a lot of failures on the HUD at the moment, so hard to say if these mi300 failures are new. But given the test names like

test/test_ops.py::TestCommonCUDA::test_dtypes_scatter_reduce_mean_cuda

it would seem this PR is causing some failures on mi300.

CC @pragupta

@linux-foundation-easycla

linux-foundation-easycla Bot commented Apr 21, 2025 •

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@mxz297 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@mxz297 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@mxz297

mxz297 commented Apr 22, 2025

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@mxz297

mxz297 commented Apr 22, 2025

Copy link
Copy Markdown
Contributor

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: pull / linux-jammy-py3.9-gcc11 / test (docs_test, 1, 1, ephemeral.linux.2xlarge)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor-rocm Trigger "inductor" config CI on ROCm ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/trunk Trigger trunk jobs on your pull request keep-going Don't stop on first failure, keep running tests until the end Merged module: inductor module: rocm AMD GPU support for Pytorch open source rocm This tag is for PRs from ROCm team topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.