Commit 64f73acd authored by Lenny Wang's avatar Lenny Wang Committed by Michael Niedermayer

cmdutils & opencl: add -opencl_bench option to test and show available OpenCL devices

Reviewed-by: 's avatarWei Gao <highgod0401@gmail.com>
Reviewed-by: 's avatarStefano Sabatini <stefasab@gmail.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 8e702bd3
...@@ -25,6 +25,7 @@ ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF)) ...@@ -25,6 +25,7 @@ ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF))
ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
$(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o)) $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o))
$(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog)-$(CONFIG_OPENCL) += cmdutils_opencl.o))
OBJS-ffmpeg += ffmpeg_opt.o ffmpeg_filter.o OBJS-ffmpeg += ffmpeg_opt.o ffmpeg_filter.o
OBJS-ffmpeg-$(HAVE_VDPAU_X11) += ffmpeg_vdpau.o OBJS-ffmpeg-$(HAVE_VDPAU_X11) += ffmpeg_vdpau.o
......
...@@ -58,10 +58,6 @@ ...@@ -58,10 +58,6 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#endif #endif
#if CONFIG_OPENCL
#include "libavutil/opencl.h"
#endif
static int init_report(const char *env); static int init_report(const char *env);
...@@ -985,26 +981,6 @@ int opt_timelimit(void *optctx, const char *opt, const char *arg) ...@@ -985,26 +981,6 @@ int opt_timelimit(void *optctx, const char *opt, const char *arg)
return 0; return 0;
} }
#if CONFIG_OPENCL
int opt_opencl(void *optctx, const char *opt, const char *arg)
{
char *key, *value;
const char *opts = arg;
int ret = 0;
while (*opts) {
ret = av_opt_get_key_value(&opts, "=", ":", 0, &key, &value);
if (ret < 0)
return ret;
ret = av_opencl_set_option(key, value);
if (ret < 0)
return ret;
if (*opts)
opts++;
}
return ret;
}
#endif
void print_error(const char *filename, int err) void print_error(const char *filename, int err)
{ {
char errbuf[128]; char errbuf[128];
......
...@@ -98,8 +98,12 @@ int opt_max_alloc(void *optctx, const char *opt, const char *arg); ...@@ -98,8 +98,12 @@ int opt_max_alloc(void *optctx, const char *opt, const char *arg);
int opt_codec_debug(void *optctx, const char *opt, const char *arg); int opt_codec_debug(void *optctx, const char *opt, const char *arg);
#if CONFIG_OPENCL
int opt_opencl(void *optctx, const char *opt, const char *arg); int opt_opencl(void *optctx, const char *opt, const char *arg);
int opt_opencl_bench(void *optctx, const char *opt, const char *arg);
#endif
/** /**
* Limit the execution time. * Limit the execution time.
*/ */
......
...@@ -22,5 +22,6 @@ ...@@ -22,5 +22,6 @@
{ "max_alloc" , HAS_ARG, {.func_arg = opt_max_alloc}, "set maximum size of a single allocated block", "bytes" }, { "max_alloc" , HAS_ARG, {.func_arg = opt_max_alloc}, "set maximum size of a single allocated block", "bytes" },
{ "cpuflags" , HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, { "cpuflags" , HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" },
#if CONFIG_OPENCL #if CONFIG_OPENCL
{ "opencl_bench", OPT_EXIT, {.func_arg = opt_opencl_bench}, "run benchmark on all OpenCL devices and show results" },
{ "opencl_options", HAS_ARG, {.func_arg = opt_opencl}, "set OpenCL environment options" }, { "opencl_options", HAS_ARG, {.func_arg = opt_opencl}, "set OpenCL environment options" },
#endif #endif
This diff is collapsed.
...@@ -14,6 +14,8 @@ libavutil: 2012-10-22 ...@@ -14,6 +14,8 @@ libavutil: 2012-10-22
API changes, most recent first: API changes, most recent first:
2013-12-xx - xxxxxxx - lavu 52.57.100 - opencl.h
Add av_opencl_benchmark() function.
2013-11-xx - xxxxxxx - lavu 52.56.100 - ffversion.h 2013-11-xx - xxxxxxx - lavu 52.56.100 - ffversion.h
Moves version.h to libavutil/ffversion.h. Moves version.h to libavutil/ffversion.h.
......
...@@ -250,6 +250,10 @@ Possible flags for this option are: ...@@ -250,6 +250,10 @@ Possible flags for this option are:
@end table @end table
@end table @end table
@item -opencl_bench
Benchmark all available OpenCL devices and show the results. This option
is only available when FFmpeg has been compiled with @code{--enable-opencl}.
@item -opencl_options options (@emph{global}) @item -opencl_options options (@emph{global})
Set OpenCL environment options. This option is only available when Set OpenCL environment options. This option is only available when
FFmpeg has been compiled with @code{--enable-opencl}. FFmpeg has been compiled with @code{--enable-opencl}.
......
...@@ -1051,13 +1051,13 @@ See reference "OpenCL Specification Version: 1.2 chapter 5.6.4". ...@@ -1051,13 +1051,13 @@ See reference "OpenCL Specification Version: 1.2 chapter 5.6.4".
Select the index of the platform to run OpenCL code. Select the index of the platform to run OpenCL code.
The specified index must be one of the indexes in the device list The specified index must be one of the indexes in the device list
which can be obtained with @code{av_opencl_get_device_list()}. which can be obtained with @code{ffmpeg -opencl_bench} or @code{av_opencl_get_device_list()}.
@item device_idx @item device_idx
Select the index of the device used to run OpenCL code. Select the index of the device used to run OpenCL code.
The specifed index must be one of the indexes in the device list which The specifed index must be one of the indexes in the device list which
can be obtained with @code{av_opencl_get_device_list()}. can be obtained with @code{ffmpeg -opencl_bench} or @code{av_opencl_get_device_list()}.
@end table @end table
......
...@@ -761,3 +761,45 @@ int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_n ...@@ -761,3 +761,45 @@ int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_n
} }
return 0; 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;
}
...@@ -310,4 +310,20 @@ void av_opencl_release_kernel(AVOpenCLKernelEnv *env); ...@@ -310,4 +310,20 @@ void av_opencl_release_kernel(AVOpenCLKernelEnv *env);
*/ */
void av_opencl_uninit(void); 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 */ #endif /* LIBAVUTIL_OPENCL_H */
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
*/ */
#define LIBAVUTIL_VERSION_MAJOR 52 #define LIBAVUTIL_VERSION_MAJOR 52
#define LIBAVUTIL_VERSION_MINOR 56 #define LIBAVUTIL_VERSION_MINOR 57
#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment