Selective nvidia #pragma optionNV(unroll all)

2019-05-11 18:36发布

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).

1条回答
地球回转人心会变
2楼-- · 2019-05-11 19:12

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!

查看更多
登录 后发表回答