Skip to main content

Project Stage 1

Photo by SpaceX on Unsplash

Hello! This is my SPO 600 blog, and this post will be long – sorry. The goal is to pick one project that is CPU intensive, written in C or C++, and experiment different compiler options and present the results. That’s why it will be long – lots of data to show.

I choose the AWK project (https://github.com/onetrueawk/awk). It is a handy tool to process files. Parse, sort, and filter are some trivial operations that are CPU intensive. To make it harder, I created a huge XML file to parse it and count the tags.

I've described the machines in my last post, if you miss it, here it is.

I also created a script to run and collect the data. I planned to run each candidate 10 times, but a few attempts didn’t receive any data. So, I decided to nest the loop in a way that even if someone kills my process, the data could be used. Guess what? It happened!

To produce the candidates, I just changed the CFLAGS inside the makefile and ran the make command. I took care to clean everything between the compilations. Here is the list of the candidates:

awkO0 – CFLAGS = -O0 – optimization for compilation time (default)
awkO1 – CFLAGS = -O1 – optimization for code size and execution time
awkO2 – CFLAGS = -O2 – optimization more for code size and execution time
awkO3 – CFLAGS = -O3 – optimization more for code size and execution time
awkOs – CFLAGS = -Os – optimization for code size

Overall, the awkO3 performed better on all machines – except on Ccharlie. The awkO0 and awkOs are 60% and 15% slower than the optimum.  In the Arch64 architecture, the awk01, awk02 and awkO3 performed somewhat the same. However, in the x86_64 architecture, the optimization gain is evident between them. Maybe there is room to improve the Arch64 compiler flags -O1, -O2 and -O3.

Here is the complete data. The time axis is in seconds. See you next post.











Comments

Popular posts from this blog

SIMD - Single Instruction Multiple Data

Photo by  Vladimir Patkachakov  on  Unsplash Hi! Today’s lecture, we learned SIMD - Single Instruction Multiple Data. This is a great tool to process data in a bulk fashion. So, instead of doing one by one, based on the variable size, we can do 16, 8, 4 or 2 at the time. This technique is called auto-vectorization resources, and it falls into the category of machine instruction optimization that I mentioned in my last post. If the machine is SIMD enabled, the compiler can use it when translating a sum loop, for example. If we are summing 8 bits numbers, using SIMD, it will be 16 times faster. However, the compiler can figure that it is not safe to use SIMD due to overlapping or non-aligned data. In fact, the compiler will not apply SIMD in most cases, so we need to get our hands dirty and inject some assembly. I’ll show you how to do it in a second. Here are the lanes of the 128-bit AArch64 Advanced SIMD: 16 x 8 bits 8 x 16 bits 4 x 32 bits 2 x 64 bits 1 x ...

Project Stage 3

Photo by  NASA  on  Unsplash Hello! In this post, I’ll make a list of optimization opportunities that I identified on the AWK project based on what I’ve learned in the SPO600 classes. There are two types of optimizations: portable and platform-specific. Portable optimizations are the ones that work everywhere, like better algorithms and implementations, and also compiler building flags. Platform-specific, on the other hand, works only for a targeted architecture. Like the SIMD instructions available only on Arch64 and many others specific for x86_64. It is possible to “force” the usage of such instructions according to the targeted hardware. We can do that on compilation time, and also on run-time. Now that we know our options, let’s dig in. According to my previous post , the functions nematch and readrec are the hotspots. Here is the command line used to run the awk: ./awk 'BEGIN {FS = "<|:|=";} {if ($8 == "DDD>") a ++;} END {print "cou...

Two-digit Numeric Display

Photo by  Nick Hillier  on  Unsplash Hi! I'm continuing my blog about my SPO classes. After a brief introduction in Assembly, we are good to hit Lab3. Our instructor kindly let us choose one project out of five. And of course, we decided to go with the easiest! We had to do a two-digit numeric display where the numbers are incremented or decremented by pressing plus and minus key in the keyboard. Soon the challenges were reviled as we dive into how to code it. Should we treat every digit separated or together? How to print them into the display? After a moment of reflection, we decided to handle the digits independently to facilitate the printing display. Also, we had to add a bit-map representation of the numbers because the 6502 chip doesn’t know any font. In this post, I’ll show you the code with the logic to increment and decrement without displaying anything. You can monitor the address $13 and $14 to make sure that it is working. Le...