diff options
author | Lenny Wang <lwanghpc@gmail.com> | 2013-12-08 21:01:00 -0600 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-12-09 21:21:36 +0100 |
commit | 64f73acd1d3853e55a7cd7631987dfd83c4171e7 (patch) | |
tree | cdb797b8e3dbe005c675d6ebab4f45cc94b49efd /libavutil/opencl.c | |
parent | 8e702bd3a8f5a4271590ab5aa38a41087ceaab1b (diff) | |
download | ffmpeg-64f73acd1d3853e55a7cd7631987dfd83c4171e7.tar.gz |
cmdutils & opencl: add -opencl_bench option to test and show available OpenCL devices
Reviewed-by: Wei Gao <highgod0401@gmail.com>
Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/opencl.c')
-rw-r--r-- | libavutil/opencl.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libavutil/opencl.c b/libavutil/opencl.c index 8654c25b90..142c6b0bf2 100644 --- a/libavutil/opencl.c +++ b/libavutil/opencl.c @@ -761,3 +761,45 @@ int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_n } return 0; } + +int64_t av_opencl_benchmark(AVOpenCLDeviceNode *device_node, cl_platform_id platform, + int64_t (*benchmark)(AVOpenCLExternalEnv *ext_opencl_env)) +{ + int64_t ret = 0; + cl_int status; + cl_context_properties cps[3]; + AVOpenCLExternalEnv *ext_opencl_env = NULL; + + ext_opencl_env = av_opencl_alloc_external_env(); + ext_opencl_env->device_id = device_node->device_id; + ext_opencl_env->device_type = device_node->device_type; + av_log(&opencl_ctx, AV_LOG_VERBOSE, "Performing test on OpenCL device %s\n", + device_node->device_name); + + cps[0] = CL_CONTEXT_PLATFORM; + cps[1] = (cl_context_properties)platform; + cps[2] = 0; + ext_opencl_env->context = clCreateContextFromType(cps, ext_opencl_env->device_type, + NULL, NULL, &status); + if (status != CL_SUCCESS || !ext_opencl_env->context) { + ret = AVERROR_EXTERNAL; + goto end; + } + ext_opencl_env->command_queue = clCreateCommandQueue(ext_opencl_env->context, + ext_opencl_env->device_id, 0, &status); + if (status != CL_SUCCESS || !ext_opencl_env->command_queue) { + ret = AVERROR_EXTERNAL; + goto end; + } + ret = benchmark(ext_opencl_env); + if (ret < 0) + av_log(&opencl_ctx, AV_LOG_ERROR, "Benchmark failed with OpenCL device %s\n", + device_node->device_name); +end: + if (ext_opencl_env->command_queue) + clReleaseCommandQueue(ext_opencl_env->command_queue); + if (ext_opencl_env->context) + clReleaseContext(ext_opencl_env->context); + av_opencl_free_external_env(&ext_opencl_env); + return ret; +} |