diff options
author | highgod0401 <highgod0401@gmail.com> | 2013-04-05 12:22:07 +0800 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-04-05 20:47:21 +0200 |
commit | 99186f1fd2ad8e60ec18a14f51967c404089aeb5 (patch) | |
tree | 49715b4936b4a8c6f3c575c61969c59c7057a274 /libavutil/opencl.c | |
parent | 9a8f1e729588435a1129d6b77e8dcdd1b2745ec6 (diff) | |
download | ffmpeg-99186f1fd2ad8e60ec18a14f51967c404089aeb5.tar.gz |
fix bug of finding CPU device
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/opencl.c')
-rw-r--r-- | libavutil/opencl.c | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/libavutil/opencl.c b/libavutil/opencl.c index c6d555c3a5..d0f75b90ca 100644 --- a/libavutil/opencl.c +++ b/libavutil/opencl.c @@ -91,6 +91,9 @@ static OpenclUtils openclutils = {&openclutils_class}; static GPUEnv gpu_env; +static const cl_device_type device_type[] = {CL_DEVICE_TYPE_GPU, CL_DEVICE_TYPE_CPU, CL_DEVICE_TYPE_DEFAULT}; + + typedef struct { int err_code; const char *err_str; @@ -276,8 +279,8 @@ static int init_opencl_env(GPUEnv *gpu_env, AVOpenCLExternalEnv *ext_opencl_env) cl_platform_id *platform_ids = NULL; cl_context_properties cps[3]; char platform_name[100]; - int i, ret = 0; - cl_device_type device_type[] = {CL_DEVICE_TYPE_GPU, CL_DEVICE_TYPE_CPU, CL_DEVICE_TYPE_DEFAULT}; + int i, j, ret = 0; + if (ext_opencl_env) { if (gpu_env->is_user_created) return 0; @@ -328,22 +331,10 @@ static int init_opencl_env(GPUEnv *gpu_env, AVOpenCLExternalEnv *ext_opencl_env) goto end; } gpu_env->platform_id = platform_ids[i]; - status = clGetDeviceIDs(gpu_env->platform_id, CL_DEVICE_TYPE_GPU, - 0, NULL, &num_devices); - if (status != CL_SUCCESS) { - av_log(&openclutils, AV_LOG_ERROR, "Could not get OpenCL device number:%s\n", opencl_errstr(status)); - ret = AVERROR_EXTERNAL; - goto end; - } - if (num_devices == 0) { - //find CPU device - status = clGetDeviceIDs(gpu_env->platform_id, CL_DEVICE_TYPE_CPU, - 0, NULL, &num_devices); - } - if (status != CL_SUCCESS) { - av_log(&openclutils, AV_LOG_ERROR, "Could not get OpenCL device ids: %s\n", opencl_errstr(status)); - ret = AVERROR(EINVAL); - goto end; + for (j = 0; j < FF_ARRAY_ELEMS(device_type); j++) { + status = clGetDeviceIDs(gpu_env->platform_id, device_type[j], 0, NULL, &num_devices); + if (status == CL_SUCCESS) + break; } if (num_devices) break; @@ -352,8 +343,15 @@ static int init_opencl_env(GPUEnv *gpu_env, AVOpenCLExternalEnv *ext_opencl_env) ret = AVERROR_EXTERNAL; goto end; } + if (i >= num_platforms - 1) { + if (status != CL_SUCCESS) { + av_log(&openclutils, AV_LOG_ERROR, + "Could not get OpenCL device ids: %s\n", opencl_errstr(status)); + ret = AVERROR(EINVAL); + goto end; + } + } i++; - } } if (!gpu_env->platform_id) { @@ -378,22 +376,16 @@ static int init_opencl_env(GPUEnv *gpu_env, AVOpenCLExternalEnv *ext_opencl_env) cps[2] = 0; /* Check for GPU. */ - for (i = 0; i < sizeof(device_type); i++) { + for (i = 0; i < FF_ARRAY_ELEMS(device_type); i++) { gpu_env->device_type = device_type[i]; gpu_env->context = clCreateContextFromType(cps, gpu_env->device_type, NULL, NULL, &status); - if (status != CL_SUCCESS) { - av_log(&openclutils, AV_LOG_ERROR, - "Could not get OpenCL context from device type: %s\n", opencl_errstr(status)); - ret = AVERROR_EXTERNAL; - goto end; - } - if (gpu_env->context) + if (status == CL_SUCCESS) break; } if (!gpu_env->context) { av_log(&openclutils, AV_LOG_ERROR, - "Could not get OpenCL context from device type\n"); + "Could not get OpenCL context from device type: %s\n", opencl_errstr(status)); ret = AVERROR_EXTERNAL; goto end; } |