int cuda_init(ENGINE * engine) { if (!quiet && verbose) fprintf(stdout, "initializing engine\n"); int verbosity=OUTPUT_NORMAL; if (quiet==1) verbosity=OUTPUT_QUIET; if(verbose) verbosity=OUTPUT_VERBOSE; cuda_device_init(&num_multiprocessors,buffer_size,verbosity,&host_data,&device_data_in,&device_data_out); initialized=1; return 1; }
static int cuda_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags) { AVCUDADeviceContext *hwctx = ctx->hwctx; CudaFunctions *cu; CUdevice cu_device; CUcontext dummy; CUresult err; int device_idx = 0; if (device) device_idx = strtol(device, NULL, 0); if (cuda_device_init(ctx) < 0) goto error; cu = hwctx->internal->cuda_dl; err = cu->cuInit(0); if (err != CUDA_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Could not initialize the CUDA driver API\n"); goto error; } err = cu->cuDeviceGet(&cu_device, device_idx); if (err != CUDA_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Could not get the device number %d\n", device_idx); goto error; } err = cu->cuCtxCreate(&hwctx->cuda_ctx, CU_CTX_SCHED_BLOCKING_SYNC, cu_device); if (err != CUDA_SUCCESS) { av_log(ctx, AV_LOG_ERROR, "Error creating a CUDA context\n"); goto error; } cu->cuCtxPopCurrent(&dummy); hwctx->internal->is_allocated = 1; return 0; error: cuda_device_uninit(ctx); return AVERROR_UNKNOWN; }