Project stage 2 Implementation
In this project, we aimed to implement and test AFMV capability in the GCC for AArch64 systems. AFMV allows the compiler to automatically create multiple versions of a function optimized for different processor features, thereby enhancing performance without requiring manual intervention from the developer. To implement and test the AFMV capability, we created a series of test cases that define functions with the target_clones
attribute.
link to github: https://github.com/zijunlii/gcc/tree/master/gcc/testsuite/g%2B%2B.target/aarch64/afmv
Test cases:
1. Test to verify that multiple versions of a simple function foo are created and executed correctly.
#include <stdio.h>
__attribute__((target_clones("default", "sse4.2", "avx2")))
void foo() {
printf("Function foo\n");
}
int main() {
foo();
return 0;
}
2. Test to verify AFMV functionality with different optimization levels, ensuring that the function bar
is optimized and executed correctly.
#include <stdio.h>
__attribute__((target_clones("default", "sse4.2", "avx2")))
void bar() {
printf("Function bar\n");
}
int main() {
bar();
return 0;
}
3. Test to verify that AFMV can be applied to inline functions. The baz function should be multiple
versions created and executed correctly.
#include <stdio.h>
__attribute__((target_clones("default", "sse4.2", "avx2")))
inline void baz() {
printf("Function baz\n");
}
int main() {
baz();
return 0;
}
along with the test file:
# Load the DejaGnu framework
load_lib gcc-dg.exp
# Set the source directory
set srcdir [file dirname [info script]]
# Define the test
dg-init
set testname "afmv_test_1"
set srcfile "${srcdir}/afmv_test_1.c"
dg-runtest $srcfile "-O2 -fdump-tree-all" ""
dg-finish
An Makefile is also setup to run the above tests using DejaGnu:
dg-runtest $(srcdir)/gcc/testsuite/g++.target/aarch64/afmv/*.exp
This project was an excellent opportunity to dive deep into the GCC internals and understand how
AFMV can significantly optimize performance for various architectures. Learning to use DejaGnu for
automated testing was beneficial. It is a powerful tool for running test suites in a consistent and
repeatable manner.
The ability of GCC to automatically generate optimized versions of functions based on different
instruction sets is fascinating. It allows developers to write code without worrying about low-level
optimizations for different hardware. Building GCC from source and configuring it correctly was
challenging. Ensuring all dependencies were met and the build environment was correctly set up
required careful attention.
There are still many advanced features of GCC that I need to explore further. Gaining proficiency in
these areas will require more hands-on experience and study.
Comments
Post a Comment