To estimate the performance difference between the int8/uint8 matrix multiplications (matmuls) and the float matmuls in the Ethereal repository, we need to analyze the AVX code and the number of cycles required for each operation.
The AVX code for int8/uint8 matmuls is implemented using the _mm256_maddubs_epi16 instruction, which performs 16 unsigned 8-bit integer multiplications and adds the results to 16 signed 16-bit integers. This instruction has a throughput of 1 cycle per operation on modern Intel and AMD CPUs.
On the other hand, the float matmuls are implemented using the _mm256_fmadd_ps instruction, which performs 8 single-precision floating-point multiplications and adds the results to 8 single-precision floating-point numbers. This instruction also has a throughput of 1 cycle per operation on modern Intel and AMD CPUs.
However, there are some key differences between the two instructions:
- The int8/uint8 matmul instruction operates on 16 elements at a time, while the float matmul instruction operates on 8 elements at a time. This means that the int8/uint8 matmul instruction can process twice as many elements per cycle as the float matmul instruction.
- The int8/uint8 matmul instruction uses 8-bit integers, which require less memory bandwidth than the 32-bit floats used in the float matmul instruction. This can result in significant memory bandwidth savings, especially for large matrices.
To estimate the performance difference, let's assume that we are multiplying two matrices with dimensions 1024x1024. The int8/uint8 matmul instruction would require approximately 1024*1024*2 / 16 = 131,072 cycles to complete, assuming a throughput of 1 cycle per operation.
The float matmul instruction, on the other hand, would require approximately 1024*1024*2 / 8 = 262,144 cycles to complete, assuming a throughput of 1 cycle per operation.
Based on these estimates, the int8/uint8 matmul instruction is approximately 2x faster than the float matmul instruction on a per-parameter basis. However, this is a rough estimate and the actual performance difference may vary depending on the specific use case and hardware.
In addition to the instruction-level performance difference, the int8/uint8 matmul instruction also has a significant memory bandwidth advantage. This can result in even larger performance gains in practice, especially for large matrices that do not fit in the cache.
Overall, the int8/uint8 matmuls in the Ethereal repository are likely to be significantly faster than the float matmuls on a per-parameter basis, due to the combination of higher throughput and lower memory bandwidth requirements.