Author Topic: AVX safe FFmpeg  (Read 2644 times)

Igor

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 9
  • Posts: 34
  • Karma: +8/-0
    • View Profile
AVX safe FFmpeg
« on: February 18, 2021, 02:07:38 pm »
This is a version of ffmpeg compiled with AVX support and correct alignment. When launched with the OS / 4 kernel, it takes advantage of the AVX instructions of modern processors.
http://ru2.halfos.ru/ffmpeg/ffmpeg-4.2.2-os2-avx.zip
« Last Edit: February 18, 2021, 02:22:11 pm by Igor »

Dariusz Piatkowski

  • Hero Member
  • *****
  • Thank You
  • -Given: 15
  • -Receive: 32
  • Posts: 990
  • Karma: +21/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #1 on: February 18, 2021, 03:00:30 pm »
Hi Igor,

Do you have a quick pre-requisites summary?

I ask b/c trying on non OS4 kernel (assuming here that it runs w/o the AVX instructions in such a scenario) shows the following:

Code: [Select]
[G:\test\ffmpeg_avx]ffmpeg
SYS1804: The system cannot find the file VORBIS0.

...so clearly a missing DLL.

Thanks!

Igor

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 9
  • Posts: 34
  • Karma: +8/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #2 on: February 18, 2021, 04:21:16 pm »
Hi Igor,

Do you have a quick pre-requisites summary?

I ask b/c trying on non OS4 kernel (assuming here that it runs w/o the AVX instructions in such a scenario) shows the following:

Code: [Select]
[G:\test\ffmpeg_avx]ffmpeg
SYS1804: The system cannot find the file VORBIS0.

...so clearly a missing DLL.

Thanks!

Hi Dariusz,

Please install libvorbis via ANPM.
You can also use yum, but I don't know what the package is called there. Perhaps the same.

David Graser

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 90
  • Posts: 682
  • Karma: +44/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #3 on: February 18, 2021, 04:45:19 pm »
Need to install OPUS in YUM also.

Dariusz Piatkowski

  • Hero Member
  • *****
  • Thank You
  • -Given: 15
  • -Receive: 32
  • Posts: 990
  • Karma: +21/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #4 on: February 18, 2021, 05:29:00 pm »
Igor,

Hi Igor,

Do you have a quick pre-requisites summary?

I ask b/c trying on non OS4 kernel (assuming here that it runs w/o the AVX instructions in such a scenario) shows the following:

Code: [Select]
[G:\test\ffmpeg_avx]ffmpeg
SYS1804: The system cannot find the file VORBIS0.

...so clearly a missing DLL.

Thanks!

Hi Dariusz,

Please install libvorbis via ANPM.
You can also use yum, but I don't know what the package is called there. Perhaps the same.

You know, I was a little too-quick on the response, should have done my homework and at least ran chkdll32x against the EXE.

So now that I've actually done that, here are the results:

Code: [Select]
[G:\test\ffmpeg_avx]chkdll32x ffmpeg.exe
Loading DLL 'libcx0' --> G:\USR\LIB\LIBCX0.DLL.
Loading DLL 'avdevi58' --> NOT loaded!
Unable to load DLL 'avdevi58'.  DosLoadModule returned: 2
OS/2 reports 'SDL2200' contributed to the failure.
Loading DLL 'avfilt7' --> NOT loaded!
Unable to load DLL 'avfilt7'.  DosLoadModule returned: 2
OS/2 reports 'VORBIS0' contributed to the failure.
Loading DLL 'avform58' --> NOT loaded!
Unable to load DLL 'avform58'.  DosLoadModule returned: 2
OS/2 reports 'VORBIS0' contributed to the failure.
Loading DLL 'avcode58' --> NOT loaded!
Unable to load DLL 'avcode58'.  DosLoadModule returned: 2
OS/2 reports 'VORBIS0' contributed to the failure.
Loading DLL 'avresa4' --> G:\TEST\FFMPEG_AVX\LIB\AVRESA4.DLL.
Loading DLL 'postpr55' --> G:\TEST\FFMPEG_AVX\LIB\POSTPR55.DLL.
Loading DLL 'swresa3' --> G:\TEST\FFMPEG_AVX\LIB\SWRESA3.DLL.
Loading DLL 'swscal5' --> G:\TEST\FFMPEG_AVX\LIB\SWSCAL5.DLL.
Loading DLL 'avutil56' --> G:\TEST\FFMPEG_AVX\LIB\AVUTIL56.DLL.
Loading DLL 'gcc1' --> G:\USR\LIB\GCC1.DLL.
Loading DLL 'libcn0' --> G:\USR\LIB\LIBCN0.DLL.
Loading DLL 'doscalls' --> loaded.

I'll YUM all of these to see which RPM packages they belong to...

Igor

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 9
  • Posts: 34
  • Karma: +8/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #5 on: February 18, 2021, 07:57:22 pm »
Dariusz,

I have installed:
1. SDL2 2.0.12-2
2. libvorbis 1.3.7-2

Possibly needed packages SDL2_*
I also have them installed.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 13
  • -Receive: 226
  • Posts: 3151
  • Karma: +59/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #6 on: February 18, 2021, 08:04:12 pm »
Here's the xqs files for it. The *_g.exe files aren't needed, they should have been the unstripped versions with debug data but seem the same as the *.exe versions.
Dmitriy looked at why -fno-common works here, https://github.com/bitwiseworks/gcc-os2/issues/11#issuecomment-759738933 along with the following comments.
Only needed SDL2 2.0.12-2 here, already had libvorbis. The other SDL2 files will be handy for other projects.
Edit: fix zip name

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 2
  • -Receive: 78
  • Posts: 834
  • Karma: +25/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #7 on: February 19, 2021, 01:05:26 pm »
Hi Ivan,

can you confirm that this AVX enabled version will ONLY EVER run on the OS/4 kernel ?

As far as I know, it requires OS support to save and restore the full 256 bit registers on a task switch and I seem to remember that the standard OS/2 kernel only supports SSE, that is, save and restore of only the 128 bit registers.
By the way, does anyone know if the 128 bits that SSE uses are only the lower 128 bits of the 256 bit registers or are these completely distinct register sets (one complete register set for SSE and an additional register set for AVX) ?

Or do I miss something altogether ?

OS4User

  • Sr. Member
  • ****
  • Thank You
  • -Given: 97
  • -Receive: 16
  • Posts: 306
  • Karma: +9/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #8 on: February 19, 2021, 01:32:20 pm »
can you confirm that this AVX enabled version will ONLY EVER run on the OS/4 kernel ?

The R3 code should ask if the operating system supports AVX.  If yes - R3 may decides to use AVX code.  I mean, that correctly  compiled and linked dll  will work  on OS/2 and OS/4 as well.

In OS/4  dll will use AVX code, on OS/2 will NOT use AVX code.

Issue happened because     OS/4 supports AVX  and reports about it to R3 apps,  but FFmpeg libs were generated wrongly  and  cannot use their own AVX code (wrong data alignment).

Of course it does not affect pure OS/2 system - R3 apps   do not see AVX support from OS  and even do try   to use AVX code.

AFAIK,  Igor somehow  generated  dlls  with proper alignments -  so they can use  their AVX code,  but it does not affect OS/2 system at all.
« Last Edit: February 19, 2021, 04:27:42 pm by OS4User »

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 2
  • -Receive: 78
  • Posts: 834
  • Karma: +25/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #9 on: February 19, 2021, 04:13:55 pm »
I was aware of the fact that an application can check via CPUID instruction if the CPU supports AVX.
I was not aware of the fact that an application can check that the OS actually supports to save and restore the AVX register set (even though I remember that the OS is specifically required to set some flag in some register in order to indicate that it supports AVX save/restore registers).
Maybe I will have to look into the Intel / AMD specs ...

Igor

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 9
  • Posts: 34
  • Karma: +8/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #10 on: February 19, 2021, 04:24:59 pm »
Dll kit to support streaming video Seamonkey and Firefox for OS / 4 kernel. Disabled AVX support. Failed to get this set of commands to work with the "-fno-common" key.
http://ru2.halfos.ru/ffmpeg/ffmpeg-os2-2.8.17-dll-noavx.zip

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 13
  • -Receive: 226
  • Posts: 3151
  • Karma: +59/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #11 on: February 19, 2021, 05:50:28 pm »
Dll kit to support streaming video Seamonkey and Firefox for OS / 4 kernel. Disabled AVX support. Failed to get this set of commands to work with the "-fno-common" key.
http://ru2.halfos.ru/ffmpeg/ffmpeg-os2-2.8.17-dll-noavx.zip

You might want to try linking with wl.exe (wlink) as it seems to me the linker handles larger alignment. The -fno-common is kind of a hack.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 13
  • -Receive: 226
  • Posts: 3151
  • Karma: +59/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #12 on: February 19, 2021, 06:06:51 pm »
can you confirm that this AVX enabled version will ONLY EVER run on the OS/4 kernel ?

This FFmpeg plays videos fine on my system, CPU supports AVX, OS/2 kernel which doesn't.
Quote

As far as I know, it requires OS support to save and restore the full 256 bit registers on a task switch and I seem to remember that the standard OS/2 kernel only supports SSE, that is, save and restore of only the 128 bit registers.
By the way, does anyone know if the 128 bits that SSE uses are only the lower 128 bits of the 256 bit registers or are these completely distinct register sets (one complete register set for SSE and an additional register set for AVX) ?

Or do I miss something altogether ?

They're the same registers, just renamed and larger. SSE still uses the lower half.
Good code is supposed to check for operating system support and only use AVX if supported. I have a faint memory that SSE was similar as Win95 and such didn't support saving the registers

OS4User

  • Sr. Member
  • ****
  • Thank You
  • -Given: 97
  • -Receive: 16
  • Posts: 306
  • Karma: +9/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #13 on: February 19, 2021, 07:45:28 pm »
You might want to try linking with wl.exe (wlink) as it seems to me the linker handles larger alignment

Unfortunately, wlink/wl  does not have an option/command to set  "between parts alignment"  within object.

Igor

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 9
  • Posts: 34
  • Karma: +8/-0
    • View Profile
Re: AVX safe FFmpeg
« Reply #14 on: February 19, 2021, 08:06:29 pm »
This FFmpeg plays videos fine on my system, CPU supports AVX, OS/2 kernel which doesn't.
Yes of course. So everything will be, if the kernel does not support AVX, then this code is not included and another algorithm works that does not require special alignment.
But if the kernel supports AVX (this is an OS4 kernel), then the AVX code branch will turn on and a trap will appear.
If you disable AVX support during compilation, then the code will work on both the standard kernel and OS4.