AcademySoftwareFoundation / OpenShadingLanguage

Advanced shading language for production GI renderers
BSD 3-Clause "New" or "Revised" License
2.09k stars 357 forks source link

Move qualifying GroupData params onto stack #1710

Closed chellmuth closed 1 year ago

chellmuth commented 1 year ago

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:

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:

linux-foundation-easycla[bot] commented 1 year ago

CLA Signed

The committers listed above are authorized under a signed CLA.

aconty commented 1 year ago

This looks very good to me!

AlexMWells commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

lgritz commented 1 year ago

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