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

Move qualifying GroupData params onto stack #1710

Merged
merged 8 commits into from
Sep 11, 2023

Conversation

chellmuth
Copy link
Collaborator

@chellmuth chellmuth commented Aug 9, 2023

Description

On SPI Arnold, we are seeing GroupData as a bottleneck for GPU performance. Regardless of whether the buffer is backed by local or global memory, it's off-chip and slow to access.

This change moves qualifying parameters out of the GroupData struct and onto the stack. On GPU this makes those parameters more likely to be stored in registers, leading to better performance.

Qualifying parameter details

The qualifying parameters are all the output parameters minus three exceptions.

A typical output parameter's lifetime is scoped to the execution of the instance it is associated with. The parameter is initialized at the beginning of instance execution, accessed during the body of the instance, and after the instance body its final state is broadcast to all its downstream connections. This lifetime makes output parameters a good fit for stack storage.

The three exceptions:

  • output parameters can be connected upstream and written to before instance execution
  • output closures are initialized at the beginning of shader execution
  • output parameters can be renderer outputs and read after instance execution

These are all identifiable at code generation time and can be flagged as disqualifying.

Improvements

On internal scenes, this change improves performance by about 15% on GPU. On CPU there aren't any performance regressions, but we don't see significant gains either. It also improves ptx generation and compilation by about 10%, and slightly lowers our memory footprint due to the GroupData size reduction.

Tests

Exceptions 2 & 3 are covered by existing tests. A new test is added for exception 1, and for the case of successful optimization. This patch was also run through our internal shading testsuite.

Checklist:

  • I have read the contribution guidelines.
  • I have previously submitted a Contributor License Agreement.
  • I have updated the documentation, if applicable.
  • I have ensured that the change is tested somewhere in the testsuite (adding new test cases if necessary).
  • My code follows the prevailing code style of this project.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 9, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@aconty
Copy link
Contributor

aconty commented Aug 10, 2023

This looks very good to me!

@AlexMWells
Copy link
Contributor

As this seems useful change in general, would be good to update batched version to make the same type of change (actually should looks pretty much identical)

@chellmuth
Copy link
Collaborator Author

As this seems useful change in general, would be good to update batched version to make the same type of change (actually should looks pretty much identical)

Yep, happy to port this over.

@chellmuth
Copy link
Collaborator Author

Updated with batched implementation. I'm relying on the Github CI for testing.

@lgritz
Copy link
Collaborator

lgritz commented Aug 23, 2023

Chris, you can build and test batched mode at work. Ask me how tomorrow.

Copy link
Contributor

@AlexMWells AlexMWells left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
@lgritz lgritz merged commit d4faecd into AcademySoftwareFoundation:main Sep 11, 2023
22 of 23 checks passed
Copy link
Collaborator

@lgritz lgritz left a comment

Choose a reason for hiding this comment

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

LGTM

chellmuth pushed a commit to chellmuth/OpenShadingLanguage that referenced this pull request Sep 6, 2024
  * build(deps): Raise minimum CMake dependency from 3.12 to 3.15 (AcademySoftwareFoundation#1724)
  * Change RendererServices::get_texture_handle back to ustring (AcademySoftwareFoundation#1726)
  * The recently added SS::find_symloc can have const args (AcademySoftwareFoundation#1723)
  * perf(gpu): Move qualifying GroupData params onto stack (AcademySoftwareFoundation#1710)
  * OptiX PTX pipeline overhaul (AcademySoftwareFoundation#1680)
  * Fix default fmt logic changing in latest openimageio release (AcademySoftwareFoundation#1725)
  * feat: Add API for building attribute getter free functions. (AcademySoftwareFoundation#1704)
  * fix: Handle mixed string casting that plagues optix codegen (AcademySoftwareFoundation#1718)
  * Rs fmt specification - Journaling Algorithm for error, warning, fprintf (AcademySoftwareFoundation#1702)
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.

4 participants