SPO600 Project - Stage 2: Implementation
Stage 2 Summary
This is my summary post for Stage 2 of the Winter 2022 SPO600 Project. To see my Stage 1 post click here. To see the outline for this project click here.
A quick summary of my Stage 1 was I planned to implement SVE2 optimizations in SoX by using autovectorization. In this stage I will be attempting to implement those changes.
Here are some more useful links:
This is my repo where I store the audio files I've made to test SoX. The noChanges folder is for audio files converted before my changes, and the changes folder is for audio files converted after my changes.
This is my repo of SoX, which I'm actively making my changes in.
Step 1: Implementing Changes
First step: implementing those changes. Since I've chosen to do autovectorization this part is honestly a bit quick. I change the CFLAGS variable in SoX's configure script from optimization level 2 to level 3, and add an option to include SVE2 extensions. The original CLFAGS value and the updated one are offered below.
original:
-g -O2 -fstack-protector-strong -Wall -Wmissing-prototypes -Wstrict-prototypes -fopenmp
edited:
-g -O3 -march=armv8-a+sve2 -fstack-protector-strong -Wall -Wmissing-prototypes -Wstrict-prototypes -fopenmp
For these changes I've decided to use O3 for the optimizations, but if I run into any issues I plan to use O2 with ftree-vectorize as a back-up. But so long as O3 does not cause any apparent issues during testing I figured why not. The more optimizations the better I think.
Anyways after this I run the configure script and I have my makefiles all created with the proper control options, and I run make. Once this is done I try to run SoX and thankfully it crashes. Which actually is good news because this likely means my changes were implemented and the autovectorizer did find places to make optimizations, and since I wasn't running the code on a processor that supports SVE2. So for my final change I edit the shell script of SoX and add qemu-aarch64 to the section of the code that actually runs SoX. The section I edited is shown below. This addition is done so the processor can emulate SVE2 functionality.
func_exec_program_core ()
{
if test -n "$lt_option_debug"; then
$ECHO "sox:sox:$LINENO: newargv[0]: $progdir/$program" 1>&2
func_lt_dump_args ${1+"$@"} 1>&2
fi
exec qemu-aarch64 "$progdir/$program" ${1+"$@"}
$ECHO "$0: cannot exec $program $*" 1>&2
exit 1
}
With this I then try running SoX again and good news it works. At least on the surface level. Next step is to verify those changes a bit more thoroughly.
Step 2: Verifying Changes
Now I'd like to preface this section by mentioning that with the new stage 3 requirements, I am a bit confused what to do here, as some of the analysis in Stage 3 does seem to overlap with how I imagined I would verify my changes built correctly. What I've decided is that I'll do some preliminary tests here to make sure SoX is still working as expected and in Stage 3 I'll take a deeper dive into what's happening.
So first of all, the first test already went great. SoX blew up when I wasn't emulating SVE2 and it ran happily when I was. Great news. Next is to try get SoX to actually do something useful. SoX comes with a sample audio file named Monkey.wav, which is a short monkey screech. Before making my changes I converted this file into a couple over audio files, namely: aiff, aif, and aifc. I point out these specifically as these are the files I'm able to actually play on my macbook, along with the original .wav file. With my changes now implemented I decide to convert the wav file again into these formats. I've listened to them all again and there doesn't seem to be any difference between the files from before the changes and after. If you'd like to see for yourself, I've made this git repo, with a folder for files converted with no changes and with changes.
The other test I'm able to do is provided with SoX, and that is a test script called testall.sh. I ran this script before and after making my changes, and after comparing the output from both they're both the same. That output is included below. Consider both outputs were exactly identical I've decided to consider it a success at this stage.
Format: 8svx Options:
Format: aiff Options:
Format: aifc Options:
Format: au Options:
Format: avr Options: -e unsigned-integer
Format: cdr Options:
/home/pzdanko/project/SoX/sox-code/src/.libs/sox WARN formats: cdda can't encode at 8012Hz; using 44100Hz
/home/pzdanko/project/SoX/sox-code/src/.libs/sox WARN formats: cdda can't encode mono; setting channels to 2
Format: cvs Options:
Format: dat Options:
Format: hcom Options: -r 22050
Format: maud Options:
Format: prc Options:
/home/pzdanko/project/SoX/sox-code/src/.libs/sox WARN formats: prc can't encode at 8012Hz; using 8000Hz
Format: prc Options: -e signed-integer
/home/pzdanko/project/SoX/sox-code/src/.libs/sox WARN formats: prc can't encode at 8012Hz; using 8000Hz
/home/pzdanko/project/SoX/sox-code/src/.libs/sox WARN formats: prc can't encode Signed Integer PCM
Format: sf Options:
Format: smp Options:
Format: sndt Options:
Format: txw Options:
/home/pzdanko/project/SoX/sox-code/src/.libs/sox WARN formats: txw can't encode at 8012Hz; using 16666.7Hz
Format: ub Options: -r 8130
/home/pzdanko/project/SoX/sox-code/src/.libs/sox WARN raw: `/tmp/monkey.ub': # channels not specified; trying mono
Format: vms Options:
Format: voc Options:
Format: vox Options: -r 8130
Format: wav Options:
Format: wve Options:
/home/pzdanko/project/SoX/sox-code/src/.libs/sox WARN formats: wve can't encode at 8012Hz; using 8000Hz
The last "test" I'll do here is just to give some extra confirmation that SVE2 optimizations were actually made. To do this I look through the executable files of SoX looking for any instance of whilelo, an SVE2 instruction. some quick checks have me find that I have 376 whilelos in the /.libs/libsox.so.3.0.0 file and 2 in /.libs/sox file. In Stage 3 I'll dive deeper into this but for now all this gives me some good confirmation that my changes have been implemented and SoX is still running as expected.
Step 3: Testing Other Platforms
The last step of this stage is to confirm that the project still runs properly on other platforms. For this I decide to try my changes on the x86_64 platform. Unfortunately, I wasn't able to test my changes on this platform. Before even making my changes to SoX, I tried to get the regular SoX working on x86_64 and ran into some issues. Namely that before running the configure script I'm supposed to run the command autoreconf -i. This gives me an error shown below.
lpc10/Makefile.am:8: error: Libtool library used but 'LIBTOOL' is undefined
lpc10/Makefile.am:8: The usual way to define 'LIBTOOL' is to add 'LT_INIT'
lpc10/Makefile.am:8: to 'configure.ac' and run 'aclocal' and 'autoconf' again.
lpc10/Makefile.am:8: If 'LT_INIT' is in 'configure.ac', make sure
lpc10/Makefile.am:8: its definition is in aclocal's search path.
src/Makefile.am:26: error: Libtool library used but 'LIBTOOL' is undefined
src/Makefile.am:26: The usual way to define 'LIBTOOL' is to add 'LT_INIT'
src/Makefile.am:26: to 'configure.ac' and run 'aclocal' and 'autoconf' again.
src/Makefile.am:26: If 'LT_INIT' is in 'configure.ac', make sure
src/Makefile.am:26: its definition is in aclocal's search path.
autoreconf: automake failed with exit status: 1
I tried editing the configure.ac file to define LIBTOOL but honestly I couldn't get it to work. I wish I could offer more here but I really don't know what else to do for this step.
Comments
Post a Comment