Calculating mipmap lod

In a piece of shading code I wish to know the mipmap level being sampled from a texture.
At my disposal I have a dPdx and dPdy. To determine the mipmap level I could sample from a texture with a unique colour at each mipmap level.
However, this would come at the cost of another texture sample and I’d like to know if a manual calculation would be possible and faster.
Is there any documentation on how rtTex2DGrad determines the final mipmap level sampled?

I’m working with OptiX 3.9.1 and CUDA 7.5.

Suppose you did find a way to predict the mip level. Would you use that information to do your own custom texture filtering or for some other purpose? Are you perhaps trying to load textures dynamically? I’m curious about the high level goal, if you don’t mind sharing. Maybe there’s another way to accomplish it. Feel free to email one of us or optix-help.