Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6139)

Issue 639042: Review: runtime optimizations, part 2 (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 1 month ago by larrygritz
Modified:
14 years, 1 month ago
Reviewers:
ckulla
CC:
dev-osl_imageworks.com, osl-dev_googlegroups.com
Base URL:
http://openshadinglanguage.googlecode.com/svn/trunk/
Visibility:
Public.

Description

Significant additional work on "runtime code optimization" introduced recently. Quick run-down: * New constant folding for additional ops: neg, aref (was previously commented out due to bugs), compref, strlen, endswith, concat, clamp, sqrt, matrix, transform[nv]. * All previous optimizations had been ones where no *new* constant values were needed (we could do new constant symbols, but only using VALUES that were stored statically or were the defaults of parameters stored in the master). Now we can make up brand new constants with new values, which are stored in the ShadingSystem via the helper class ConstantPool. This allows add, sub, mul, and div where both operands are constant will just turn into a single constant, as well as several of the other new constant folding routines to work. * Refactor to eliminate the if-else-else-else of constant folding routine selection, in favor of a hash map acting as a dispatch table. * Allow "local aliasing" within basic blocks -- previously, "A=const" would remember that A had the constant value (so subsequent C=A*B, say, would treat A as a constant) but only if the statement was in the global scope and A was never subsequently reassigned. Now we can remember that A has that value, but just for the basic block it's in and/or until it's reassigned. This allows lots of additional constant folding. When each basic block is done, its local aliases are forgotten. * Some preliminary groundwork for tracking which params will be used by downstream layers, so I can take advantage of that layer. (Apologies for the incomplete nature of that.) * Add -O0, -O1, -O2 optional flags to "testshade" to specify level of runtime optimization. * New statistics track how many actual instructions we execute over a render, and how much total time we spend doing the runtime optimization. * A couple minor renames and cleanups I promised Chris I'd do in the last review, but somehow botched the checkin and didn't get them all committed. * IMPORTANT bug fix to the last checkin, in constfold_add -- lines 340 and 347 got the argument numbers mixed up, resulting in turning "A = B + 0" into "A=0" rather than "A=B". Oops! So, the net result of all this is summarized by the following stats from a production asset we like to use as a benchmark: optimize=1 5:35 2046 MB peak 1,806,370,431 instructions run optimize=2 4:32 1403 MB peak 1,046,991,997 instructions run As for how we can reduce the number of instructions executed by almost 45% but only reduce runtime by 20%, let's just say there are other bottlenecks in our renderer we're working on and interpreter overhead is obviously not the major (or at least not the sole) bottleneck.

Patch Set 1 #

Total comments: 6
Unified diffs Side-by-side diffs Delta from patch set Stats (+841 lines, -275 lines) Patch
src/include/osl_pvt.h View 4 chunks +6 lines, -2 lines 0 comments Download
src/liboslcomp/oslcomp.cpp View 1 chunk +1 line, -2 lines 0 comments Download
src/liboslexec/constantpool.h View 1 chunk +109 lines, -0 lines 0 comments Download
src/liboslexec/context.cpp View 2 chunks +2 lines, -0 lines 0 comments Download
src/liboslexec/exec.cpp View 4 chunks +4 lines, -3 lines 0 comments Download
src/liboslexec/instance.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/liboslexec/oslexec_pvt.h View 6 chunks +14 lines, -1 line 0 comments Download
src/liboslexec/oslops.h View 1 chunk +15 lines, -0 lines 0 comments Download
src/liboslexec/runtimeoptimize.cpp View 37 chunks +677 lines, -266 lines 6 comments Download
src/liboslexec/shadingsys.cpp View 2 chunks +6 lines, -0 lines 0 comments Download
src/testshade/testshade.cpp View 3 chunks +6 lines, -0 lines 0 comments Download

Messages

Total messages: 5
larrygritz
14 years, 1 month ago (2010-03-22 21:43:44 UTC) #1
larrygritz
So sorry, those stats I mentioned at the end are for optimize = 1 and ...
14 years, 1 month ago (2010-03-22 21:46:14 UTC) #2
ckulla
http://codereview.appspot.com/639042/diff/1/11 File src/liboslexec/runtimeoptimize.cpp (right): http://codereview.appspot.com/639042/diff/1/11#newcode36 src/liboslexec/runtimeoptimize.cpp:36: #include "OpenImageIO/timer.h" Shouldn't this be included with angle brackets? ...
14 years, 1 month ago (2010-03-23 14:54:49 UTC) #3
lg_imageworks.com
On Mar 23, 2010, at 7:54 AM, <ckulla@gmail.com> <ckulla@gmail.com> wrote: > src/liboslexec/runtimeoptimize.cpp:36: #include "OpenImageIO/timer.h" > ...
14 years, 1 month ago (2010-03-23 16:36:50 UTC) #4
ckulla
14 years, 1 month ago (2010-03-23 17:31:44 UTC) #5
Ah I see - that all makes sense.

LGTM!
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b