11---
22title : Vanilla matrix multiplication
3- weight : 5
3+ weight : 6
44
55# ## FIXED, DO NOT MODIFY
66layout : learningpathall
77---
88
9- ## Vanilla matrix multiplication
10-
119In this section, you will learn about an example of standard matrix multiplication in C.
1210
13- ### Algorithm description
11+ ## Vanilla matrix multiplication algorithm
1412
1513The vanilla matrix multiplication operation takes two input matrices, A [ Ar
1614rows x Ac columns] and B [ Br rows x Bc columns] , to produce an output matrix C
@@ -22,7 +20,6 @@ element in the B column then summing all these products, as Figure 2 shows.
2220
2321This implies that the A, B, and C matrices have some constraints on their
2422dimensions:
25-
2623- A's number of columns must match B's number of rows: Ac == Br.
2724- C has the dimensions Cr == Ar and Cc == Bc.
2825
@@ -31,22 +28,21 @@ properties and use, by reading this [Wikipedia
3128article on Matrix Multiplication] ( https://en.wikipedia.org/wiki/Matrix_multiplication ) .
3229
3330In this Learning Path, you will see the following variable names:
34-
35- - `` matLeft `` corresponds to the left-hand side argument of the matrix
31+ - ` matLeft ` corresponds to the left-hand side argument of the matrix
3632 multiplication.
37- - `` matRight ` ` corresponds to the right-hand side of the matrix multiplication.
38- - `` M `` is `` matLeft ` ` number of rows.
39- - `` K `` is `` matLeft `` number of columns (and `` matRight ` ` number of rows).
40- - `` N `` is `` matRight ` ` number of columns.
41- - `` matResult ` ` corresponds to the result of the matrix multiplication, with
42- `` M `` rows and `` N ` ` columns.
33+ - ` matRight ` corresponds to the right-hand side of the matrix multiplication.
34+ - ` M ` is ` matLeft ` number of rows.
35+ - ` K ` is ` matLeft ` number of columns (and ` matRight ` number of rows).
36+ - ` N ` is ` matRight ` number of columns.
37+ - ` matResult ` corresponds to the result of the matrix multiplication, with
38+ ` M ` rows and ` N ` columns.
4339
44- ### C implementation
40+ ## C implementation
4541
4642A literal implementation of the textbook matrix multiplication algorithm, as
47- described above, can be found in file `` matmul_vanilla.c ` ` :
43+ described above, can be found in file ` matmul_vanilla.c ` :
4844
49- ``` C
45+ ``` C { line_numbers="true" }
5046void matmul (uint64_t M, uint64_t K, uint64_t N,
5147 const float * restrict matLeft, const float * restrict matRight,
5248 float * restrict matResult) {
@@ -65,16 +61,16 @@ void matmul(uint64_t M, uint64_t K, uint64_t N,
6561```
6662
6763In this Learning Path, the matrices are laid out in memory as contiguous
68- sequences of elements, in [Row-Major
69- Order](https://en.wikipedia.org/wiki/Row-_and_column-major_order). The
70- ``matmul`` function performs the algorithm described above.
71-
72- The pointers to ``matLeft``, ``matRight`` and ``matResult`` have been annotated as
73- ``restrict``, which informs the compiler that the memory areas designated by
74- those pointers do not alias. This means that they do not overlap in any way, so that the
75- compiler does not need to insert extra instructions to deal with these cases.
76- The pointers to ``matLeft`` and ``matRight`` are marked as ``const`` as neither of these two matrices are modified by `` matmul` `.
77-
78- You now have a reference standard matrix multiplication function. You will use it later
79- on in this Learning Path to ensure that the assembly version and the intrinsics
80- version of the multiplication algorithm do not contain errors.
64+ sequences of elements, in [Row-Major Order](https://en.wikipedia.org/wiki/Row-_and_column-major_order).
65+ The `matmul` function performs the algorithm described above.
66+
67+ The pointers to `matLeft`, `matRight` and `matResult` have been annotated
68+ as `restrict`, which informs the compiler that the memory areas designated by
69+ those pointers do not alias. This means that they do not overlap in any way, so
70+ that the compiler does not need to insert extra instructions to deal with these
71+ cases. The pointers to `matLeft` and `matRight` are marked as `const` as
72+ neither of these two matrices are modified by `matmul`.
73+
74+ You now have a reference standard matrix multiplication function. You will use
75+ it later on in this Learning Path to ensure that the assembly version and the
76+ intrinsics version of the multiplication algorithm do not contain errors.
0 commit comments