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

Add lazytrace option to avoid combinatoric optixTrace inlining #1815

Merged
merged 2 commits into from
May 9, 2024

Conversation

chellmuth
Copy link
Collaborator

OptiX inlines all calls to optixTrace at module compilation time. Due to OSL's lazy layer evaluation, if layer A calls layer B M times, and layer B calls layer C N times, that can lead to M*N inlines of optixTrace if layer C contains a trace operation.

In practice we've observed single trace ops being inlined hundreds of times, leading to minutes-long shader compilations.

This patch adds a new option, lazytrace, to run layers with trace ops unconditionally at the start of shader evaluation. This costs some potential performance in cases where the trace layer would never be evaluated, but removes all the compilation penalties that the inlining was presenting.

Tests

Added a new test, lazytrace, that checks via printf to make sure the non-lazy execution ordering rules were correctly followed when lazytrace=0.

Checklist:

  • I have read the contribution guidelines.
  • 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. If I haven't
    already run clang-format v17 before submitting, I definitely will look at
    the CI test that runs clang-format and fix anything that it highlights as
    being nonconforming.

OptiX inlines all calls to optixTrace at module compilation time. Due to OSL's
lazy layer evaluation, if layer A calls layer B M times, and layer B calls
layer C N times, that can lead to M*N inlines of optixTrace if layer C contains
a trace operation.

In practice we've observed single trace ops being inlined hundreds of times,
leading to minutes-long shader compilations.

This patch adds a new option, lazytrace, to run layers with trace ops
unconditionally at the start of shader evaluation. This costs some potential
performance in cases where the trace layer would never be evaluated, but
removes all the compilation penalties that the inlining was presenting.

Signed-off-by: Chris Hellmuth <[email protected]>
// but it will prevent optixTrace calls from being repeatedly
// inlined when lazytrace=0.
if (!group()[con.srclayer]->run_lazily())
continue;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the only part of the PR that affects the status quo lazytrace=1 path. I could narrow it to only execute when lazytrace=0, but it seems better to always skip the run-layer check on unconditionally-executed layers.

Signed-off-by: Chris Hellmuth <[email protected]>
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

@lgritz lgritz merged commit 056ba18 into AcademySoftwareFoundation:main May 9, 2024
25 checks passed
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.

2 participants