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

Michael Niedermayer michaelni at gmx.at
Fri Mar 29 12:16:42 CET 2013


On Fri, Mar 29, 2013 at 04:15:35PM +0800, Wei Gao wrote:
> 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?

You could implement a mutex with the atomic operations and this
way support more cases. This isnt critical though but if you dont
do it the #ifs should be removed as they are misleading, one would
think that there is some support withput pthreads when actually there
is none currently


> 
> 
> >
> >
> > > +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.

would it be possible to detect that a kernel has been registered after
init and in that case print a warning and redo teh compile ?

Iam asking as currently there is nothing in the API that forbids an
application to register things later

[...]

Thanks

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130329/86d95d59/attachment.asc>


More information about the ffmpeg-devel mailing list