aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorLenny Wang <lwanghpc@gmail.com>2013-12-08 21:01:00 -0600
committerMichael Niedermayer <michaelni@gmx.at>2013-12-09 21:21:36 +0100
commit64f73acd1d3853e55a7cd7631987dfd83c4171e7 (patch)
treecdb797b8e3dbe005c675d6ebab4f45cc94b49efd /libavutil
parent8e702bd3a8f5a4271590ab5aa38a41087ceaab1b (diff)
downloadffmpeg-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')
-rw-r--r--libavutil/opencl.c42
-rw-r--r--libavutil/opencl.h16
-rw-r--r--libavutil/version.h2
3 files changed, 59 insertions, 1 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;
+}
diff --git a/libavutil/opencl.h b/libavutil/opencl.h
index e4ecbf812c..cf0abd7975 100644
--- a/libavutil/opencl.h
+++ b/libavutil/opencl.h
@@ -310,4 +310,20 @@ void av_opencl_release_kernel(AVOpenCLKernelEnv *env);
*/
void av_opencl_uninit(void);
+/**
+ * Benchmark an OpenCL device with a user defined callback function. This function
+ * sets up an external OpenCL environment including context and command queue on
+ * the device then tears it down in the end. The callback function should perform
+ * the rest of the work.
+ *
+ * @param device pointer to the OpenCL device to be used
+ * @param platform cl_platform_id handle to which the device belongs to
+ * @param benchmark callback function to perform the benchmark, return a
+ * negative value in case of failure
+ * @return the score passed from the callback function, a negative error code in case
+ * of failure
+ */
+int64_t av_opencl_benchmark(AVOpenCLDeviceNode *device, cl_platform_id platform,
+ int64_t (*benchmark)(AVOpenCLExternalEnv *ext_opencl_env));
+
#endif /* LIBAVUTIL_OPENCL_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 3c0461b262..b1a9afa842 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,7 +75,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 56
+#define LIBAVUTIL_VERSION_MINOR 57
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \