首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用FDO (PGO) + LTO在linux上构建最新的HandBrake?

如何使用FDO (PGO) + LTO在linux上构建最新的HandBrake?
EN

Unix & Linux用户
提问于 2021-06-23 00:56:00
回答 2查看 401关注 0票数 1

将CFLAGS和CXXFLAGS传递给最新版本的HandBrake构建(撰写本文时的版本为1.3.3)将有效,直到您添加了-flto,这将导致失败整个构建。

如何用LTO选项HandBrake -flto和作为一个延伸的目标,以及FDO (反馈导向的优化,也就是FDO,又名PGO)?

HandBrake中的大多数编解码器都是使用“手工编码”程序集开发的,因此许多人断言编译器优化的收益不会太大。我想测试和挑战这个断言!

EN

回答 2

Unix & Linux用户

回答已采纳

发布于 2021-08-01 02:34:35

我重新尝试了最新的标签版本,即GCC-11和CLANG-12中的Handbrake v1.4.0。要获得成功的构建,所需的配置需要稍加更改。例如,GCC-11构建无法成功地构建某些模块,因为它无法在培训后解析配置文件的路径(gcda文件在绝对路径中)。

下面是GCC-11和CLANG-12的训练和FDO配置,分别为v1.4.0和不同于之前的回答过程,即手闸v1.3.3。

GCC-11:

配置和构建GCC-11的命令:

代码语言:javascript
复制
./configure --harden --optimize=speed --enable-fdk-aac --disable-nvenc --build=build-v1.4.0 && cd ./build-v1.4.0 && time make -j$(( $(nproc) + 1 ));

训练/剖析阶段手刹V1.4.0 -> GCC-11 custom.defs文件:

代码语言:javascript
复制
GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic
GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic
X265.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
X265.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
X265_8.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
X265_8.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
X265_10.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
X265_10.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
X265_12.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
X265_12.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBHB.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBHB.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBDAV1D.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBDAV1D.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
GTK.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
GTK.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBDVDREAD.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBDVDREAD.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBDVDNAV.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBDVDNAV.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBBLURAY.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBBLURAY.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
TEST.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
TEST.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
FDKAAC.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
FDKAAC.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
ZIMG.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
ZIMG.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBDAV1D.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto
LIBDAV1D.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-generate -fprofile-update=atomic -flto

FDO级手制动器V1.4.0 -> GCC-11 custom.defs文件:

代码语言:javascript
复制
GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training
GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training
X265.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
X265.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
X265_8.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
X265_8.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
X265_10.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
X265_10.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
X265_12.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
X265_12.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBHB.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBHB.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBDAV1D.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBDAV1D.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
GTK.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
GTK.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBDVDREAD.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBDVDREAD.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBDVDNAV.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBDVDNAV.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBBLURAY.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBBLURAY.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
TEST.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
TEST.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
FDKAAC.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
FDKAAC.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
ZIMG.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
ZIMG.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBDAV1D.GCC.args.O.speed = -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto
LIBDAV1D.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -msse2avx -O3 -pipe -fprofile-use -fprofile-correction -fprofile-partial-training -flto

LLVM-12/clang-12/ldd-12:

Clang做PGO和GCC有点不同。很明显,与GCC和相关的默认工具相比,在使用Clang/LLVM/LLD时,解析模块的绝对路径没有问题。但是,Clang需要一个额外的合并步骤来合并FDO所需的原始配置文件。

因此,有三个步骤:

  1. 培训/概况阶段
  2. 合并原始配置文件数据
  3. FDO阶段

步骤命令的细节。步骤1和步骤3的custom.defs文件分别列在下面的三个步骤之后。本节纯粹是为了说明每个步骤所需的命令,而不是custom.defs。因此,在运行配置和构建逗号之前,您需要确保custom.defs已经就位:

  1. 为LLVM-12/clang-12/ld-12配置和构建命令:
代码语言:javascript
复制
LDFLAGS="-fuse-ld=lld" ./configure --ar /usr/bin/llvm-ar --ranlib /usr/bin/llvm-ranlib --strip /usr/bin/llvm-strip --cc /usr/bin/clang --optimize=speed --enable-fdk-aac --disable-nvenc --build=build-v1.4.0-CLANG && cd ./build-v1.4.0-CLANG && time LDFLAGS="-fuse-ld=lld" make -j$(( $(nproc) + 1 ));

建成后,按照正常情况训练/配置,比如GCC,或者如果你尝试了之前的1.3.3版本的说明。

  1. 在培训/分析之后,合并原始配置文件数据。用构建的正确位置替换和路径。
代码语言:javascript
复制
llvm-profdata merge -output=/handbrake.profdata /default_*.profraw
  1. file,这是与步骤1完全相同的一行命令,差异在custom.defs文件中。
代码语言:javascript
复制
LDFLAGS="-fuse-ld=lld" ./configure --ar /usr/bin/llvm-ar --ranlib /usr/bin/llvm-ranlib --strip /usr/bin/llvm-strip --cc /usr/bin/clang --optimize=speed --enable-fdk-aac --disable-nvenc --build=build-v1.4.0-CLANG && cd ./build-v1.4.0-CLANG && time LDFLAGS="-fuse-ld=lld" make -j$(( $(nproc) + 1 ));

训练/剖析阶段手刹V1.4.0 -> LLVM-12/CLANG-12/LLD-12 custom.defs文件:

记住用正确的绝对路径替换<绝对路径到配置文件>

代码语言:javascript
复制
GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic
GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic
X265.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
X265.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
X265_8.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
X265_8.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
X265_10.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
X265_10.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
X265_12.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
X265_12.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBHB.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBHB.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBDAV1D.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBDAV1D.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
GTK.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
GTK.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBDVDREAD.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBDVDREAD.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBDVDNAV.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBDVDNAV.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBBLURAY.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBBLURAY.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
TEST.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
TEST.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
FDKAAC.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
FDKAAC.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
ZIMG.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
ZIMG.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBDAV1D.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin
LIBDAV1D.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-generate=/default_%m.profraw -fprofile-update=atomic -flto=thin

FDO级手制动V1.4.0 -> LLVM-12/CLANG-12/LLD-12 custom.defs文件:

记住用正确的绝对路径替换<绝对路径到合并配置文件>

代码语言:javascript
复制
GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata
GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata
X265.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
X265.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
X265_8.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
X265_8.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
X265_10.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
X265_10.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
X265_12.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
X265_12.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBHB.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBHB.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBDAV1D.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBDAV1D.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
GTK.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
GTK.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBDVDREAD.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBDVDREAD.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBDVDNAV.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBDVDNAV.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBBLURAY.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBBLURAY.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
TEST.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
TEST.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
FDKAAC.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
FDKAAC.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
ZIMG.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
ZIMG.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBDAV1D.GCC.args.O.speed = -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin
LIBDAV1D.GCC.args.extra = -mfpmath=sse -mavx -fstack-protector-strong -D_FORTIFY_SOURCE=2 -march=native -O3 -pipe -fprofile-instr-use=/handbrake.profdata -flto=thin

现在,您可以使用PGO+LTO在GCC或LLVM/CLANG/LLD上构建<#>Handbrake v1.4.0。请随意选择这两种方法中的哪一种会使您的幻想或基准成为您心中的满足!:-)

票数 0
EN

Unix & Linux用户

发布于 2021-06-23 01:24:45

EDIT 01/08/2021.下面的所有操作都是针对Handbrake v1.3.3完成的。请参阅我对Handbrake v1.4.0

我在GitHub上回答了一个类似于我提出的问题的问题,并认为这个问题的答案最好是在stackexchange这里用类似的问题为公众服务,而不是被埋在github发行票里.https://github.com/HandBrake/HandBrake/issues/1072#issuecomment-865630524

而且,观察到的好处也将为那些愿意通过努力并为他们节省大量编码/代码转换时间的人提供服务。他们可以在完成工作后对其进行基准测试,以证明这一断言。

大部分程序是从这里描述的笔记中推导和实验的.https://github.com/griff/HandBrake/blob/master/doc/BUILD-Linux

如上述链接所述,不建议使用CFLAGS/CXXFLAGS指导编译或构建。建议使用内置配置机制设置gcc旗。

<#>怎么做?

手闸只是许多“克罗姆”的前端。要查看每个cont肋骨模块是如何构建的,您可以在生成它们之前,利用构建或目标目录中的每个控件的"make“报告。

要获得构建目录,您需要通过.

代码语言:javascript
复制
$  ./configure --build=build --optimize=speed

如果你没有的话。

MAKE报告

例如,假设您正在一个名为"build“的文件夹中构建HandBrake (类似于上面配置命令中的值),那么:

代码语言:javascript
复制
$  cd ./build
$  make report.help
  AVAILABLE MAKEFILE VARS REPORTS
  ----------------------------------------------------------------
  report.main            global general vars
  report.gcc             global gcc vars (inherited by module GCC)
  report.var             usage: make report.var name=VARNAME
  x265.report            X265-scoped vars
  x265_8.report          X265_8-scoped vars
  x265_10.report         X265_10-scoped vars
  x265_12.report         X265_12-scoped vars
  libdav1d.report        LIBDAV1D-scoped vars
  ffmpeg.report          FFMPEG-scoped vars
  libdvdread.report      LIBDVDREAD-scoped vars
  libdvdnav.report       LIBDVDNAV-scoped vars
  libbluray.report       LIBBLURAY-scoped vars
  nvenc.report           NVENC-scoped vars
  libhb.report           LIBHB-scoped vars
  test.report            TEST-scoped vars
  gtk.report             GTK-scoped vars
  pkg.report             PKG-scoped vars

在上面的第一列的每一行中,您将看到每个报表。然后,您可以通过

代码语言:javascript
复制
$  make 

将替换为所需的报表。

需要注意的是,即使在每个报表中,都存在对上述内容的层次结构和继承。

代码语言:javascript
复制
report.gcc

可以作为gcc旗的根。

在我的例子中,我选择使用以前的“速度”来配置构建。

代码语言:javascript
复制
$  ./configure --build=build --optimize=speed

哪个映射到

代码语言:javascript
复制
GCC.args.O.speed

report.gcc

报告中另一个重要的关键是

代码语言:javascript
复制
GCC.args.extra

这基本上“可能”在前者之后附加额外的编译器选项标志。正如gcc所知,如果选项之间有冲突,最后一个选项就会被使用。由于我们无法很容易地判断出许多模块是使用一个还是另一个还是两者,所以我倾向于确保第一个模块中的任何内容,也在后者中。但后者可以包含更多!您可以通过检查报表来查看默认值。

您可以通过创建一个名为"custom.defs“的文本文件配置来覆盖上面的内容(如果您克隆了它,那么handbrake的顶部文件夹就是您基本上执行git拉命令的位置)。

代码语言:javascript
复制
/HandBrake$ ls -h
AUTHORS.markdown  CODE_OF_CONDUCT.md  CONTRIBUTING.md  download  gtk      macosx         pkg              scripts      THANKS.markdown
build             configure           COPYING          gccFDO    libhb    make           preset           SECURITY.md  TRANSLATION.markdown
build2            contrib             custom.defs    graphics  LICENSE  NEWS.markdown  README.markdown  test         win

FDO (又名PGO)

我在我的系统中做了FDO (反馈导向的优化,也就是FDO,PGO - Profile引导的优化),所以我通常首先使用定义为custom.defs

代码语言:javascript
复制
$ cat custom.defs 
GCC.args.O.speed = -march=native -O3 -pipe -fprofile-generate=../gccFDO -fprofile-update=atomic
GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -fprofile-generate=../gccFDO -fprofile-update=atomic

然后运行HandBrake,用不同的编解码器、过滤器和设置对几个视频进行转码;几天后生成配置文件。然后我使用生成的配置文件.

代码语言:javascript
复制
$ cat custom.defs 
GCC.args.O.speed = -march=native -O3 -pipe -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training

在一个全新的构建目录上。对典型目标编码类型进行分析的典型源类型通常是良好的常见可疑因素。我典型的目标类型是带有AAC音频的x265_10bit:

  1. 从x264到x265_10bit
  2. 从x265到x265_10bit
  3. 从各种形式的AC3到您使用的典型AAC
  4. 从各种形式的DTS到您使用的典型的AAC
  5. 你使用的任何典型的预处理、过滤、去噪等。

正如您所能想象的,取决于您的硬件,这可能需要一段时间!我的侧写花了一周时间!

您可以微调每个模块的编译器标志和优化,方法是使用我前面描述的每个模块的报告过程,并通过在custom_defs文件中引用所需的值来重写键,就像上面关于GCC.args.*默认值的示例一样。

要使上述所有操作正常工作,请记住没有导出CFLAGS或CXXFLAGS。您可以通过以下方法检查在bash会话中设置的标志:

代码语言:javascript
复制
$  export -p | grep FLAGS

LTO + FDO:

链接时间优化LTO与FDO是优秀的,因为可以很容易地研究谷歌的许多程序和基准。

不幸的是,当在GCC.args.*中使用-flto或为FFMPEG模块设置LTO时,将失败,整个构建失败。那是布尔型的或。它会失败在其中一个或另一个或两者!

然而,LTO可以添加到所有其他模块!

这是我的custom.defs..。

代码语言:javascript
复制
$ cat custom.defs
GCC.args.O.speed = -march=native -O3 -pipe -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
X265.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
X265.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
X265_8.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
X265_8.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
X265_10.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
X265_10.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
X265_12.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
X265_12.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBHB.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBHB.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBDAV1D.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBDAV1D.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
GTK.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
GTK.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBDVDREAD.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBDVDREAD.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBDVDNAV.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBDVDNAV.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBBLURAY.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
LIBBLURAY.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
TEST.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
TEST.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
NVENC.GCC.args.O.speed = -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training
NVENC.GCC.args.extra = -mfpmath=sse -march=native -O3 -pipe -flto -fprofile-use=../gccFDO -fprofile-correction -fprofile-partial-training

<#>EDIT 01/08/2021.所有这些都是针对手刹v1.3.3完成的。

对于v1.4.0,上面的<#>The进程失败了--请参阅我对v1.4.0的另一个答案。

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/655384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档