[FFmpeg-devel] [PATCH 1/2] libavutil/libavfilter: opencl wrapper based on comments on 20130328

Wei Gao highgod0401 at gmail.com
Fri Mar 29 09:15:35 CET 2013


Hi,

Thanks for your reply, some questions and explanations

Thanks
Best regards


2013/3/29 Michael Niedermayer <michaelni at gmx.at>

> On Thu, Mar 28, 2013 at 08:57:44PM +0800, Wei Gao wrote:
> >
>
> >  configure          |    4
> >  libavutil/Makefile |    3
> >  libavutil/opencl.c |  658
> +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  libavutil/opencl.h |  198 +++++++++++++++
> >  4 files changed, 863 insertions(+)
> > b6faea13ffbbe062ca802507e91e2da2c4e5e5ef
>  0001-opencl-wrapper-based-on-comments-on-20130328.patch
> > From 38aa9bb65c63d44cd1586383f37197bee93c61ab Mon Sep 17 00:00:00 2001
> > From: highgod0401 <highgod0401 at gmail.com>
> > Date: Thu, 28 Mar 2013 20:42:21 +0800
> > Subject: [PATCH 1/2] opencl wrapper based on comments on 20130328
> >
>
> > +#include "opencl.h"
> > +#include "avstring.h"
> > +#include "log.h"
> > +#include "avassert.h"
> > +
> > +
> > +#if !HAVE_MEMORYBARRIER && !HAVE_SYNC_VAL_COMPARE_AND_SWAP &&
> !HAVE_MACHINE_RW_BARRIER
> > +#if HAVE_PTHREADS
> > +
> > +#include <pthread.h>
> > +static pthread_mutex_t atomic_opencl_lock = PTHREAD_MUTEX_INITIALIZER;
> > +
> > +#define LOCK_OPENCL pthread_mutex_lock(&atomic_opencl_lock);
> > +#define UNLOCK_OPENCL pthread_mutex_unlock(&atomic_opencl_lock);
> > +
> > +#elif !HAVE_THREADS
> > +#define LOCK_OPENCL
> > +#define UNLOCK_OPENCL
> > +#endif
> > +#else
> > +#define LOCK_OPENCL
> > +#define UNLOCK_OPENCL
> > +#endif
>
> the #ifs are quite misleading as pthreads are a strict dependancy
> currently


 I reference the atomic.c code, should I add any other operation?


>
>
> > +int av_opencl_init(AVDictionary *options, AVOpenCLExternalInfo
> *ext_opencl_info)
> > +{
> > +    int ret = 0;
> > +    LOCK_OPENCL
> > +    if (!gpu_env.opencl_is_inited) {
> > +        /*initialize devices, context, command_queue*/
> > +        AVDictionaryEntry *opt_entry = av_dict_get(options,
> "build_option", NULL, 0);
> > +        ret = init_opencl_env(&gpu_env, ext_opencl_info);
> > +        if (ret < 0)
> > +            goto end;
> > +        /*initialize program, kernel_name, kernel_count*/
> > +        ret = compile_kernel_file(&gpu_env, opt_entry->value);
> > +        if (ret < 0)
> > +            goto end;
> > +        av_assert1(gpu_env.kernel_count > 0);
> > +        gpu_env.opencl_is_inited = 1;
> > +    }
> > +end:
> > +    UNLOCK_OPENCL
> > +    return ret;
> > +}
>
> Registration of things like codecs formats and filters is not
> guranteed to end before the first are opened and used.
> The API makes no such gurantees and user applications can easily
> register all codecs and start decoding and only later register
> all avfilters and build a filter graph.
> User applications can also register their own codecs
>
> The code does not look like it would work if any registration would
> happen after the first use
>
this function is to implement two functions, one is init OpenCL
environment, the second is to compile kernel code using GPU. about the
first on, initial once should be enough because all kernels should run in
the same environment. about the second,the kernels should be compiled
before run, it is not a good way when some kernels are runing while others
are being compiled. Also the method we will implement later that load a
binary file to avoid compiling every time also require all the kernels
should be compiled before running.

User also can use av_opencl_register_kernel_code to register their own
kernels then call av_opencl_init to initial opencl and compile the kernel.


> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Concerning the gods, I have no means of knowing whether they exist or not
> or of what sort they may be, because of the obscurity of the subject, and
> the brevity of human life -- Protagoras
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>


More information about the ffmpeg-devel mailing list