Commit 9443a2b
Reformulating matrix multiplication scale equation to reduce math ops and improve power and performance. (#6437)
Summary:
This diff simplifies the the matrix multiplication scale equation in q_linear op.
The existing equation in q_linear op is:
```
for i in K / 4
sums[c] = mat1_tex . (qmat2(c) scales[c])
out += sums
```
where c = [0, 4), out, sums, mat1_tex and qmat2 are vectors and scales is a scalar.
The dot product is associative with respect to scalar multiplication as mentioned in https://en.wikipedia.org/wiki/Dot_product ie. (ac1).(bc2) = c1c2(a.b)
Thus, the multiplication can be rearranged as:
```
for i in K / 4
sums[c] = (mat1_tex . qmat2(c)) scales[c]
out += sums
```
Using distributive property of multiplication ie. ab + ac + ad ... = a(b + c+ d...) the code can be further simplified to:
```
for i in K / 4
sums[c] = mat1_tex . qmat2(c)
out += sums
out *= scale
```
This rearrangement significantly reduces redundant multiplications.
Reviewed By: SS-JIA, jorgep31415
Differential Revision: D644794051 parent 4f12131 commit 9443a2b
1 file changed
+6
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | 105 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
114 | 110 | | |
115 | 111 | | |
116 | 112 | | |
117 | 113 | | |
118 | 114 | | |
119 | 115 | | |
120 | 116 | | |
| 117 | + | |
| 118 | + | |
121 | 119 | | |
122 | 120 | | |
123 | 121 | | |
| |||
0 commit comments