[FFmpeg-devel] [RFC] mem: facilitate imports into GPU memory space.

Gwenole Beauchesne gb.devel at gmail.com
Sun Oct 25 19:22:54 CET 2015


2015-10-25 14:47 GMT+01:00 wm4 <nfxjfg at googlemail.com>:
> On Sun, 25 Oct 2015 14:28:06 +0100
> Nicolas George <george at nsup.org> wrote:
>> Le quartidi 4 brumaire, an CCXXIV, Gwenole Beauchesne a écrit :
>> > Allow for av_malloc() to allocate memory that could be mapped into
>> > the GPU address space. This requires allocations on page boundaries.
>> > On the video memory buffers side, this requires minimal alignment of
>> > strides to 64 bytes.
>> >
>> > Option 1: use heuristics in av_malloc()
>> > - break down into mem, frame, and avcodec changes.
>> Heuristics are fragile, and the result would probably be many false
>> positive, wasting quite a lot of memory.
>> > Option 2: use a finer decision model
>> > - mem: add av_malloc_aligned()
>> > - buffer: add av_buffer_alloc2() with align and/or flags
>> > - frame/avcodec: use new APIs
>> I would go for flags all the way: with an explicit align value, people will
>> hardcode a random value based on whichever example they looked at, and it
>> will break when CPUs are upgraded to a larger value.
>> The API should probably include some kind of "av_foobar_get_align_flags()"
>> for each foobar domain where alignment can become visible to the
>> application.
> Well, in this case, I expect vaapi code to do the allocations, and
> it'll use the page size for it (as this is what the hardware apparently
> requires).
> People who don't know what they're doing can keep using av_malloc.


However, the idea within libavcodec and libavfilter is to allocate the
video buffers with such requirements. Use-cases are for video
encoding, or video processing. It is possible to map user allocated
memory, but they need to respect the constraints of (i) being page
aligned, and (ii) stride aligned to 512 bits. For OpenCL, that's about
SVM / allocating from "hostptr", and in vaapi realm, that's creating a
VA surface with userptr backing store. This avoids an extra copy or
color conversion (internal format is NV12 tiled).

Gwenole Beauchesne
Intel Corporation SAS / 2 rue de Paris, 92196 Meudon Cedex, France
Registration Number (RCS): Nanterre B 302 456 199

More information about the ffmpeg-devel mailing list