Hi ocanela,
Depending on your data dynamic range, you may use downscaling before the multiplication and upscaling after the multiplication. The smaller is the number the greater is the resolution.
If you cannot do so, you can use a linear combination. Suppose that I am multiplying two matrices of 2x2. Let’s compute one of the coefficients of the result matrix:
c11 = a11*b11 + a12*b21
Let’s suppose that B = U + V, and C = P + Q. You can do, for example:
P = A * U
Q = A * V
C = P + Q
Numerically, suppose that a11 = 5, a12 = 3, b11 = 5.1, b21 = 3.2
. We can set u11 = 5, v11=0.1, u21=3, v21=0.2
, such that b11 = 5.1 = u11 + v11 = 5 + 0.1
, and so on:
Our desired result:
c11 = a11*b11 + a12*b21 = 5 * 5.1 + 3 * 3.2 = 35.1
Now, with the decomposition:
p11 = a11*u11 + a12*u21 = 5 * 5 + 3 * 3 = 34
q11 = a11*v11 + a12*v21 = 5 * 0.1 + 3 * 0.2 = 1.1
Thus,
c11 = p11 + q11 = 34 + 1.1 = 35.1
You can play some Math tricks like scaling with this linear decomposition to achieve your goal.
Hope this helps.
Regards,
Leon
Just as an appendix:
About your initial approach about using two half precision matrices, you have to consider that a floating point number is no more than the following product:
a = 1.f * (2^( e - 2^(bit{E-1} - 1) ) )
where f
is the mantissa represented in fixed-point numbers, or the same to f = m/2^(bit{M}
, m is the value of the mantissa, and M is the number of bits used to represent the mantissa, e is the value of the exponent and E is the number of bits used to represent the exponent.
The only path that I see so far is to approximate somehow