【发布时间】:2021-12-26 11:53:49
【问题描述】:
我处理的代码中有大量的浮点运算。我们有测试用例记录给定输入的输出,并验证我们不会过多地改变结果。我有它建议我启用 -march native 来提高性能。但是,启用该功能后,我们会遇到测试失败,因为结果发生了变化。由于访问由 -march native 启用的更现代的硬件而将使用的指令是否会减少浮点错误的数量?增加浮点错误量?还是两者兼而有之?融合乘法加法应该减少浮点错误的数量,但这是典型的随时间添加的指令吗?或者是否添加了一些说明,虽然效率更高但准确性更低?
我的目标平台是 x86_64 Linux。根据/proc/cpuinfo的处理器信息为:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 85
model name : Intel(R) Xeon(R) Gold 6152 CPU @ 2.10GHz
stepping : 4
microcode : 0x2006a0a
cpu MHz : 2799.999
cache size : 30976 KB
physical id : 0
siblings : 44
core id : 0
cpu cores : 22
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit
bogomips : 4200.00
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
【问题讨论】:
-
问题可能是未定义的行为。我建议尝试找出由
-march native启用的-mXXX中的哪一个导致了问题。 -
这是一个很好的建议@eerorika。虽然我当然希望它不是 UB(我最近尝试使用 UB san 和 address sanitizer 运行),但查看较小更改的影响可能会对正在发生的事情有所了解。
-
但你不使用
<fenv.h>的东西,对吧? -
注意:FMA 有时是stink。
标签: c++ c floating-point x86-64 precision