I use cuvidGetDecoderCaps to check whether my gpu suuport hevc decoding. I noticed that the calling thread needs to be associated with a valid context.
I use cudaSetDevice
to create a primary context, then call cuvidGetDecoderCaps, but still get error 101(cudaErrorInvalidDevice), do I have to call cuCtxCreate to explicitly create the context.
code here:
CheckCudaErrors(cudaSetDevice(0));
CUcontext cuda_context = nullptr;
CheckCudaErrors(cuCtxGetCurrent(&cuda_context));
if (cuda_context == nullptr) {
LOG(ERROR) << "cuda context is nullptr";
return -1;
} else {
LOG(INFO) << "cuda context is not nullptr";
}
CUVIDDECODECAPS decode_caps = {};
decode_caps.eCodecType = cudaVideoCodec_HEVC;
decode_caps.eChromaFormat = cudaVideoChromaFormat_420;
decode_caps.nBitDepthMinus8 = 0;
CheckCudaErrors(cuvidGetDecoderCaps(&decode_caps));
get output:
cuda context is not nullptr
Check failed: err == CUDA_SUCCESS (101 vs. 0) Cuda driver api error = 101(cudaErrorInvalidDevice)
Does anyone know why?