Video Codec SDK 9.0.20 Samples using cuCtxCreate

The samples in Video Codec SDK 9.0.20 use cuCtxCreate.

From https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DRIVER.html

Note that the use of multiple CUcontext s per device within a single process will substantially degrade performance and is strongly discouraged. Instead, it is highly recommended that the implicit one-to-one device-to-context mapping for the process provided by the CUDA Runtime API be used.

From https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__CTX.html#group__CUDA__CTX_1g65dc0012348bc84810e2103a40d8e2cf

Note:
In most cases it is recommended to use cuDevicePrimaryCtxRetain.

Is the Video Codec SDK exempt from this recommendation?

Are you saying it is using multiple CUcontext per device within a single process? I don’t think it is.

  1. The official Nvidia reference entry for cuCtxCreate recommends using cuDevicePrimaryCtxRetain. It does not make clear when to prefer to use cuCtxCreate instead.

  2. A sample for an Nvidia library uses cuCtxCreate. I asked why - in a very simple and direct way : "Is the Video Codec SDK exempt from this recommendation? ".

  3. You respond: "Are you saying it is using multiple CUcontext per device within a single process? I don’t think it is. "

  4. Since it is not a direct answer to a simple direct question, I will interpret it and hope for confirmation that the interpretation is right or for someone to correct it if otherwise.

  5. My interpretation is this:

a) Since it is clear in the samples that only one instance of a context was created, cuCtxCreate can be used to no ill effect.

b) More importantly (in my case, at least), cuDevicePrimaryCtxRetain could also have been used.

c) There is nothing special about the Video Codec SDK. The recommendation to use cuDevicePrimaryCtxRetain applies here as well.

d) In larger applications where different modules are worked on by different people, always use cuDevicePrimaryCtxRetain, even when using the Video Codec SDK, to avoid creating multiple contexts.

e) The Video Codec SDK samples do not exemplify cases where you have to use cuCtxCreate instead of cuDevicePrimaryCtxRetain.

I’m referring to the first sentence from your quote:

"Note that the use of multiple CUcontext s per device within a single process will substantially degrade performance and is strongly discouraged. "

That is a correct statement. It should convey understanding. I don’t think the samples are doing that.

It’s OK to use cuCtxCreate if you create 1 context and stay within that. It’s not necessary to convert to use of the primary context. Many many CUDA driver API applications work this way, and it’s not necessary for them all to be rewritten to use the primary context nor issue “an exemption”.

So I won’t be able to answer your yes/no direct question about whether the sdk samples have an exemption. If you need an answer to that, I won’t be able to provide it.

It seems that the responses I get are only to the first part of any of my posts.

To repeat (paraphrased) the second part of my last post:

Are these assertions correct? If not, can anybody please correct them?

a) Since it is clear in the samples that only one instance of a context was created, cuCtxCreate can be used to no ill effect.

b) More importantly (in my case, at least), cuDevicePrimaryCtxRetain could also have been used.

c) There is nothing special about the Video Codec SDK (in general, not specifically about the samples). The recommendation to use cuDevicePrimaryCtxRetain applies here as well.

d) In larger applications where different modules are worked on by different people, always use cuDevicePrimaryCtxRetain, even when using the Video Codec SDK, to avoid creating multiple contexts.

e) The Video Codec SDK samples do not exemplify cases where you have to use cuCtxCreate instead of cuDevicePrimaryCtxRetain.