This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Uniform control-flow cycles reported by MALIOC

I have a Unity shader using the multi-compile keyword. I am trying to replace it with a uniform flow-control in order to reduce the number of variants.

I have 4 questions.

Q1: I cannot understand the output of MALIOC (Mali-G71).

Arithmetic Cycles of Fragment shader (in all cases Total Cycles==Shortest Path Cycles==Longest Path Cycles)

- Without the keyword: 7.50

- With the keyword: 7.65

- Uniform flow-control: 7.50 

It seems to me that MALIOC reports the cycles of shader with uniform flow-control by assuming the uniform value, and thus only computes the cycles of a path.

If the instructions of both paths are executed, the cycles should be much longer.

Q2: Is uniform flow-control so terrible as described here ? https://developer.arm.com/documentation/101897/0200/shader-code/uniform-control-flow

Q3: May we assume that the driver optimises the shader on-the-fly based upon the uniform value so that only one branch will be executed (I guess not) ?

Q4: Which GPU counters should I check in Streamline for the potential problems of uniform flow control ? According to my experiment, the "Diverged instructions" are almost none in all cases.

Parents
  • Q1: I cannot understand the output of MALIOC (Mali-G71).

    Based on what you're showing it looks like the compiler is just managing to statically optimize out all runtime control flow. This is possible in some cases of small conditional blocks being entirely replaced with inlined conditional selects. Mali Offline Compiler won't assume any specific uniform value. 

    Q2: Is uniform flow-control so terrible as described here ? 

    On older Mali hardware (Utgard, Midgard architecture), yes. On newer hardware (Bifrost, Valhall architecture) the impact of branchy shader control flow is much lower as long as you don't get divergent control flow.

    Q3: May we assume that the driver optimises the shader on-the-fly based upon the uniform value so that only one branch will be executed?

    There is no compile specialization of binaries based on uniform values, so if you have a uniform branch then the branch will end up in the executed code if the compiler can't completely optimize it out. If all threads branch the same way (no divergence), which should always the case for uniform-controlled branches, then you shouldn't have a major problem.

    Q4: Which GPU counters should I check in Streamline for the potential problems of uniform flow control?

    The "Diverged instruction" counter is the one to use. Uniform-based branches, by definition, cannot be divergent.

    Kind regards, 
    Pete

Reply
  • Q1: I cannot understand the output of MALIOC (Mali-G71).

    Based on what you're showing it looks like the compiler is just managing to statically optimize out all runtime control flow. This is possible in some cases of small conditional blocks being entirely replaced with inlined conditional selects. Mali Offline Compiler won't assume any specific uniform value. 

    Q2: Is uniform flow-control so terrible as described here ? 

    On older Mali hardware (Utgard, Midgard architecture), yes. On newer hardware (Bifrost, Valhall architecture) the impact of branchy shader control flow is much lower as long as you don't get divergent control flow.

    Q3: May we assume that the driver optimises the shader on-the-fly based upon the uniform value so that only one branch will be executed?

    There is no compile specialization of binaries based on uniform values, so if you have a uniform branch then the branch will end up in the executed code if the compiler can't completely optimize it out. If all threads branch the same way (no divergence), which should always the case for uniform-controlled branches, then you shouldn't have a major problem.

    Q4: Which GPU counters should I check in Streamline for the potential problems of uniform flow control?

    The "Diverged instruction" counter is the one to use. Uniform-based branches, by definition, cannot be divergent.

    Kind regards, 
    Pete

Children