RE-POST March: SPO600 Week 8
This post would be about an introduction on the Auto-FMV project of Software Portability and Optimization (SPO600) class.
AFMV Project
https://toronto.tylers.info/dokuwiki-toronto/doku.php?id=spo600:2024_winter_project (updated 2024-04-17, since the previous wiki no longer worked)
Function Multi-Versioning
#include <stdio.h>
__attribute__((target("default")))
void x() {
printf("Hello, World!\n");
}
__attribute__((target("arch=x86-64-v4)))
void x() {
printf("Hello, World!\n");
}
int main() {
x();
return 0;
}
In multi-versioning, it is possible to have the same function name. However, the attributes would specify when each version is going to be used.
The attributes specify a target which would be the architecture of the machine we want this to run on.
If we don't want to use intrinsic, assembler, or different algorithm then the code can be written as:
#include <stdio.h>
__attribute__((target_clones("default","arch=x86-64-v4")))
int main() {
printf("Hello, World!\n");
}
This would make 2 copies of the function.
It is also possible to just add features instead of a full architecture. Instead of writing arch=x86-64-v4, just add the feature like so: "sse4.2,avx2".
However, in aarch64, is it not possible to "arch=" argument.
Another difference is when adding multiple features, in x86 it is comma-separated. However, in aarch64, a plus sign is used "sve+sve2".
In arrch64, it is possible also manually specify multiple versions of the function by using target_version instead of target_clones.
In addition, when looking at objecdump command, the feature would have the upper letter M before the feature name so that we know that the function is to be mangled.
In this project, we would use this function muti-versioning without changing the source code. We would be only changing the build instructions.
We want to be able to do something like this in either GCC or G++:
gcc -fafmv=sve,sve2 file.c -o file -03
gcc -fno-afmv file.c -o file -03
Comments
Post a Comment