This repository contains a series of functions to demonstrate the use of ARM's NEON SIMD instructions for efficiently processing data from a CSV file. The functions include calculations such as averages, vector magnitudes, least-squares fit, and variance.
Math:
Where (x_i) are the elements of the array and (n) is the number of elements.
Description: This function calculates the average of an array of floats (e.g., acceleration values in g). It uses SIMD to process multiple elements at once for efficiency.
Function:
float calculate_average_neon(float *data, int n);
Math:
Where (x), (y), and (z) are the components of the vector.
Description: This function calculates the magnitude of a 3D vector (e.g., acceleration vector composed of x-axis, y-axis, and z-axis values) for each data point. It uses NEON SIMD instructions to calculate the magnitudes for multiple points at once.
Function:
void calculate_magnitudes_neon(float *x, float *y, float *z, float *magnitudes, int n);
Math:
Where (m) is the slope, (b) is the intercept, (x) is the independent variable, and (y) is the dependent variable.
Description: This function calculates the slope and intercept of a linear regression line using the least-squares method. The result is a linear model of the form (y = mx + b). NEON SIMD is used to perform the summations and calculations in parallel for faster performance.
Function:
void calculate_least_squares_neon(float *x, float *y, int n, float *m, float *b);
Math:
Where (x_i) are the elements of the array and (\mu) is the mean of the array.
Description: This function calculates the variance of the data points in the array (e.g., z-axis acceleration in g). It computes how spread out the values are from the mean. SIMD operations are used to calculate the squared differences from the mean for all values at once.
Function:
float calculate_variance_neon(float *data, int n);
The time taken for all calculations is measured using a struct get_wtime
that exists in the code.
double get_wtime(void){
struct timeval t;
gettimeofday(&t, NULL);
return (double)t.tv_sec + (double)t.tv_usec*1.0e-6;
}
This allows for a precise measurement of the time taken for each SIMD-optimized operation, enabling you to compare performance gains when using SIMD.
Make sure you only write code on the file main-program-simd.c
. DO NOT change the scalar one. You need it to check the validity of your results in the SIMD version.
Workshop supervisor will give you a raspberry pi and an IP Address to connect via Secure Shell. In order to establish an SSH connection, run on your terminal:
Credentials are user
and password user
. The X value is dependent on the raspberry that will be assigned to your team.
The project files are in the ~/Desktop/Workshop
of your Raspberry Pi.
(~
: home directory)
cd ~/Desktop/Workshop
- Official Arm Documentation
- Of course, SIMD.info
- AI is your friend. You can use the chatbot of your liking.
In order for a C program to run, the source code needs to be compiled with linked libraries. In order to make the compilation stage easier for the contenstant, we'll use Makefile
.
If you going to compile the code for the first time, make sure you are in the directory that contains the Makefile
. Then run on your terminal:
make
You should see the code getting compiled.
If you are going to compile again, make sure to remove all executables that are already created. To do that, run on your terminal:
make clean
It will remove all binaries from the code folder.
In order to compile one file only, run on your terminal:
make scalar
To compile only the serial version or:
make simd
To compile the SIMD version of the code.
At last, you have to run the serial program and your SIMD solution. Run on your terminal:
./scalar_program
For the scalar/serial program, and:
./simd_program
For the SIMD program that you wrote.
In the terminal, you should see the results and the time taken for execution.
In order to win the prizes as a team, you'll be judged based on the solution you will give. Some of the criteria are:
- The code execution is flawless
- The good use of SIMD Instructions
- The time difference of the scalar and SIMD solution
- The absence of warnings in the compilation phase