You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improving 4bit quant mat mul performance by shifting position of -8 operation. (#15436)
Summary:
This diff introduces performance improvements in the 4-bit quant matrix multiplication operation by adjusting the position of the -8 operation. Resulting in overall reduction in math operation performed during shader runtime.
The thinking here is as follows:
* The 4 bit integer weights are unsigned ranging from 0 - 15, and thus to get unsigned number 8 is subtracted from the input.
* Assume WS[] is array of signed weights, M[] is matrix, S is the sum
The main loop essentially performs:
S += ( WS[i] - 8 ) * M[i], for i = [0, N)
* This equation can rewritten as:
S += WS[i] * M[i] - 8 * M[i], for i = [0, N)
* 8 * M[i] need not be performed in the main loop.
Also 8 * M[i], for i = [0, N)
Can be substituted with A += M[i], for i = [0, N)
and A *= 8
Thus, splitting parts of this equation results in a significant reduction in math ops while producing the same result.
Reviewed By: SS-JIA
Differential Revision: D85721578
0 commit comments