CS110 Lab 11

Computer Architecture I @ ShanghaiTech University
Download the starter code here

Introduction to SIMD

SIMD makes a program faster by executing the same instruction on multiple data at the same time. In this lab, we will use Intel Intrinsics to implement simple programs.

Part 1: Vector addition

In this part, you will implement a vector addition program using SIMD. Please "translate" naive_add() to simd_add().
You may use the following intrinsics, search in the Intel Intrinsics Guide: Try to tell the difference of the following "load" intrisics:

Part 2: Matrix multiplication

In this part, you will implement a matrix multiplication program using SIMD. Please "translate" naive_matmul() to simd_matmul().
You may use the following intrinsics: Explain why this makes the program faster.

Part 3: Loop unrolling

Read Wikipedia and try to understand the concept of loop unrolling: Implement loop_unroll_matmul() and loop_unroll_simd_matmul(), explain the performance boost they brought.

Part 4: Compiler optimization

Run make test, explain why -O3 makes the program much faster.
For checkup: Put this piece of code into godbolt.org , compile them with a risc-v compiler, and tell the difference between -O0 and -O3.
int a = 0;

void modify(int j) {
    a += j;
}


int main() {
    for (int i = 0; i < 1000; i++) {
        a += 1;
    }

    for (int i = 0; i < 1000; i++) {
        a += i;
    }

    return a;
}