3

I'm playing around with nvidia's unroll loops directive, but haven't seen a way to turn it on selectively.

Lets say I have this...

void testUnroll()
{
    #pragma optionNV(unroll all)
    for (...)
        ...
}

void testNoUnroll()
{
    for (...)
        ...
}

Here, I'm assuming both loops end up being unrolled. To stop this I think the solution will involve resetting the directive after the block I want affected, for example:

    #pragma optionNV(unroll all)
    for (...)
        ...
    #pragma optionNV(unroll default) //??

However I don't know the keyword to reset the unroll behaviour to the initial/default setting. How can this be done? If anyone could also point to some official docs for nvidia's compiler directives that'd be even better.


Currently, it seems only the last #pragma optionNV(unroll *) directive found in the program is used (eg throw one in the last line and it overrides everything above it).

jozxyqk
  • 16,424
  • 12
  • 91
  • 180

2 Answers2

0

According to this post on the NVidia forums, having no keyword afterwards will set it to default behavior:

#pragma unroll 1 will prevent the compiler from ever unrolling a loop.

If no number is specified after #pragma unroll, the loop is completely unrolled if its trip count is constant, otherwise it is not unrolled at all.

I'm not sure if it works on GLSL, but you can maybe try:

#pragma optionNV(unroll)

If anyone tries this, let us know if it works!

ninjagecko
  • 88,546
  • 24
  • 137
  • 145
  • Thanks for the reference. However, default behavior unrolls loops up to a certain threshold (although I'm not sure what this is). The main thing I was getting at is, back in 2013 at least, I couldn't apply the directive to only a certain block of code and not the rest - it was global. Actually I only realized that after posting, hence the update. – jozxyqk Oct 22 '16 at 01:23
0

I don't remember where I found this, but I can confirm that this works on an Nvidia 1070 with the 435 driver on Linux with OpenGL 4.6:

#pragma optionNV(inline 0)

In my case link time is reduced in almost an 20X, and performance drops around 50%, very useful for making small tweaks to shaders in development.

dv1729
  • 987
  • 1
  • 8
  • 25