The build process is done on a machine with AVX2. When I run my application on a machine without AVX2 it crashes in silk_inner_product_FLP_avx2 with "trap invalid opcode".
This lets me presume that AVX2 runtime detection does not work properly.
Designs
Child items
...
Show closed items
Linked items
0
Link issues together to show that they're related.
Learn more.
#0 0x000055beca8b72dc in silk_inner_product_FLP_avx2 (data1=0x7f156a7f4ca0, data2=0x7f156a7f4ca0, dataSize=384)
at silk/float/x86/inner_product_FLP_avx2.c:50
Running sde it seems to work as expected:
./../../sde-external-9.38.0-2024-04-18-lin/sde64 -ivb -- ./test_opus_encode
...
./../../sde-external-9.38.0-2024-04-18-lin/sde64 -- ./test_opus_encode
Testing libopus 1.5.2-11-g2554a89e encoder. Random seed: 269938783 (80D8)
Running simple tests for bugs that have been fixed previously
silk_inner_product_FLP_avx2
silk_inner_product_FLP_avx2
silk_inner_product_FLP_avx2
silk_inner_product_FLP_avx2
I wonder if this might be a problem related to live migration. Otherwise, QEMU lets you choose a custom CPU feature set if desired, and I'm not really sure how that interacts with CPUID testing.
So do I get it right, that it seems that the run-time detection detects AVX2 because the cpuid reports so, because the cpu model indeed supports avx2. But finally the QEMU-Virtualization does not support avx2 execution, right?
If so, should the opus runtime check be improved to honor lscpu feature flags or is the cloud-hoster not playing by the rules?
I have certainly run into issues before with QEMU and confusion between the host and the emulation target's capabilities. cpu_features also uses CPUID, though. The only thing I can think of that it does differently is that it also checks to see if the OS saves YMM registers (which was not possible to do in an OS-agnostic way before AVX). libopus currently does not do that.
Are you able to confirm that this is the difference on your system? I.e., can you look at the value of have_xcr0 and os_preserves->avx_registers determined in ParseCpuId()?
Hi, I've hit this bug as well trying to run a VM with qemu. Here's the stacktrace I get:
Core was generated by `/usr/bin/qemu-system-x86_64 -name guest=windows11,debug-threads=on -S -object {'.Program terminated with signal SIGILL, Illegal instruction.Downloading source file /usr/src/debug/opus/build/../opus-1.5.2/celt/x86/pitch_avx.c#0 0x00006aa8348196ff in celt_pitch_xcorr_avx2 (arch=<optimized out>, max_pitch=<optimized out>, len=<optimized out>, xcorr=<optimized out>, _y=<optimized out>, _x=<optimized out>) at ../opus-1.5.2/celt/x86/pitch_avx.c:9797 xcorr[i] = celt_inner_prod(_x, _y+i, len, arch);[Current thread is 1 (Thread 0x6aa838aed380 (LWP 23910))](gdb) bt#0 0x00006aa8348196ff in celt_pitch_xcorr_avx2 (arch=<optimized out>, max_pitch=<optimized out>, len=<optimized out>, xcorr=<optimized out>, _y=<optimized out>, _x=<optimized out>) at ../opus-1.5.2/celt/x86/pitch_avx.c:97#1 celt_pitch_xcorr_avx2 (_x=0x7cb19e86abf0, _y=<optimized out>, xcorr=0x7cb19e86aba0, len=748, max_pitch=5, arch=<optimized out>) at ../opus-1.5.2/celt/x86/pitch_avx.c:86#2 0x00006aa8348627a7 in _celt_autocorr.isra.0 (x=x@entry=0x7cb19e86abf0, ac=ac@entry=0x7cb19e86aba0, window=window@entry=0x0, overlap=overlap@entry=0, lag=lag@entry=4, n=n@entry=752, arch=<optimized out>) at ../opus-1.5.2/celt/celt_lpc.c:333#3 0x00006aa834823298 in pitch_downsample (x=x@entry=0x7cb19e86fc90, x_lp=x_lp@entry=0x7cb19e86abf0, len=len@entry=1504, C=C@entry=2, arch=<optimized out>) at ../opus-1.5.2/celt/pitch.c:184#4 0x00006aa83482b5e0 in run_prefilter (analysis=<optimized out>, nbAvailableBytes=<optimized out>, enabled=<optimized out>, qgain=<synthetic pointer>, gain=<synthetic pointer>, pitch=<synthetic pointer>, prefilter_tapset=<optimized out>, N=<optimized out>, CC=<optimized out>, prefilter_mem=<optimized out>, in=<optimized out>, st=<optimized out>) at ../opus-1.5.2/celt/celt_encoder.c:1221#5 celt_encode_with_ec (st=<optimized out>, pcm=<optimized out>, frame_size=<optimized out>, compressed=<optimized out>, nbCompressedBytes=<optimized out>, enc=<optimized out>) at ../opus-1.5.2/celt/celt_encoder.c:1694#6 0x00006aa8348106ab in opus_encode_frame_native (st=st@entry=0x366b4d64030, pcm=pcm@entry=0x7cb19e876f30, frame_size=frame_size@entry=480, data=<optimized out>, data@entry=0x366b43923e0 "\364\377\376", max_data_bytes=max_data_bytes@entry=480, float_api=float_api@entry=0, first_frame=<optimized out>, dred_bitrate_bps=<optimized out>, analysis_info=<optimized out>, is_silence=<optimized out>, redundancy=<optimized out>, celt_to_silk=<optimized out>, prefill=<optimized out>, equiv_rate=<optimized out>, to_celt=<optimized out>) at ../opus-1.5.2/src/opus_encoder.c:2299#7 0x00006aa83481471f in opus_encode_native (st=0x366b4d64030, pcm=<optimized out>, frame_size=<optimized out>, data=<optimized out>, out_data_bytes=<optimized out>, lsb_depth=<optimized out>, lsb_depth@entry=16, analysis_pcm=<optimized out>, analysis_size=<optimized out>, c1=<optimized out>, c2=<optimized out>, analysis_channels=<optimized out>, downmix=<optimized out>, float_api=<optimized out>) at ../opus-1.5.2/src/opus_encoder.c:1682#8 0x00006aa834815931 in opus_encode (st=<optimized out>, pcm=<optimized out>, analysis_frame_size=480, data=<optimized out>, max_data_bytes=<optimized out>) at ../opus-1.5.2/src/opus_encoder.c:2517#9 0x00006aa834e90c9b in snd_codec_encode_opus (out_size=<synthetic pointer>, out_ptr=0x366b43923e0 "\364\377\376", in_size=1920, in_ptr=0x366b439572c "", codec=<optimized out>) at ../spice-0.15.2/subprojects/spice-common/common/snd_codec.c:108#10 snd_codec_encode (out_size=<synthetic pointer>, out_ptr=0x366b43923e0 "\364\377\376", in_size=1920, in_ptr=0x366b439572c "", codec=<optimized out>) at ../spice-0.15.2/subprojects/spice-common/common/snd_codec.c:244#11 snd_playback_send_write (playback_client=0x366b4391bc0) at ../spice-0.15.2/server/sound.cpp:591#12 PlaybackChannelClient::send_item (this=0x366b4391bc0, item=<optimized out>) at ../spice-0.15.2/server/sound.cpp:658#13 0x00006aa834e76d6a in RedChannelClient::send_any_item (item=0x366b4391be0,--Type <RET> for more, q to quit, c to continue without paging--c this=0x366b4391bc0) at ../spice-0.15.2/server/red-channel-client.cpp:513#14 RedChannelClient::push (this=0x366b4391bc0) at ../spice-0.15.2/server/red-channel-client.cpp:1164#15 0x00006aa834e9051d in RedChannelClient::pipe_add_push (item=..., this=<optimized out>) at ../spice-0.15.2/server/red-channel-client.cpp:1398#16 snd_send (client=0x366b4391bc0) at ../spice-0.15.2/server/sound.cpp:636#17 0x00006aa8384a5395 in line_out_put_buffer () at ../qemu-9.1.0/audio/spiceaudio.c:160#18 0x0000036682a9bda9 in audio_pcm_hw_run_out () at ../qemu-9.1.0/audio/audio.c:1117#19 audio_run_out () at ../qemu-9.1.0/audio/audio.c:1226#20 0x0000036682a9c55d in audio_run () at ../qemu-9.1.0/audio/audio.c:1388#21 audio_timer () at ../qemu-9.1.0/audio/audio.c:855#22 0x0000036682f1566b in timerlist_run_timers () at ../qemu-9.1.0/util/qemu-timer.c:576#23 0x0000036682f15800 in timerlist_run_timers () at ../qemu-9.1.0/util/qemu-timer.c:509#24 qemu_clock_run_timers () at ../qemu-9.1.0/util/qemu-timer.c:590#25 qemu_clock_run_all_timers () at ../qemu-9.1.0/util/qemu-timer.c:677#26 0x0000036682f15aa3 in main_loop_wait () at ../qemu-9.1.0/util/main-loop.c:600#27 0x0000036682e3f327 in qemu_main_loop () at ../qemu-9.1.0/system/runstate.c:826#28 qemu_default_main () at ../qemu-9.1.0/system/main.c:37#29 0x00006aa8393fae08 in __libc_start_call_main (main=main@entry=0x3668283ab90 <main>, argc=argc@entry=139, argv=argv@entry=0x7cb19e8782e8) at ../sysdeps/nptl/libc_start_call_main.h:58#30 0x00006aa8393faecc in __libc_start_main_impl (main=0x3668283ab90 <main>, argc=139, argv=0x7cb19e8782e8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7cb19e8782d8) at ../csu/libc-start.c:360#31 0x000003668283dc35 in _start ()
This is not the first time I report such an issue, AVX detection is hard to get right. I use a hardened kernel which disables it to mitigate a security vulnerability in my CPU, even though it is supported.
You can take a look at this orc MR which fixed the issue some time ago.
In case that matters:
$ pacman -Qi opusName : opusVersion : 1.5.2-1Description : Totally open, royalty-free, highly versatile audio codecArchitecture : x86_64URL : https://www.opus-codec.org/Licenses : BSD-3-ClauseGroups : NoneProvides : libopus.so=0-64Depends On : glibcOptional Deps : NoneRequired By : chromium ffmpeg gst-plugins-base libsndfile pipewire-audio spice spice-gtk wireshark-cliOptional For : NoneConflicts With : NoneReplaces : NoneInstalled Size : 5.30 MiBPackager : Jan Alexander Steffens (heftig) <heftig@archlinux.org>Build Date : Wed 17 Apr 2024 02:57:01 AM CESTInstall Date : Tue 30 Apr 2024 12:15:16 AM CESTInstall Reason : Installed as a dependency for another packageInstall Script : NoValidated By : Signature