Why CLGEMM(F16) has lower instruction count & higher performance than CLGEMMLowp(8bit)
Hello,
The Mali-T880 is capable of doing 16 x int8 operations per cycle and 8 x FP16 operations per cycle (https://community.arm.com/graphics/b/blog/posts/the-mali-gpu-an-abstract-machine-part-3---the-midgard-shader-core). I ran program using CLGEMMLowp(8bit) and CLGEMM(F16) functions on Mali-T880 GPU. However, Low precision CLGEMMLowp (8bit) has several orders of magnitude lower performance than CLGEMM (F16).
First, I read the "Mali instruction count" register with Arm DS5 streamline and it shows that CLGEMMLowp has 3x more instruction count than CLGEMM! And the CLGEMM has around 9.5 to 10x higher performance than CLGEMMLowp.
I provided below the compute functions for both programs. I ran the matrix size "M=1000, N=1000, K=1000"
CLGEMMLowp: void main_cl_gemm(int argc, const char **argv) {
CLTensor src1, src2, out1;
CLScheduler::get().default_init();
constexpr uint16_t M[] = { 49, 128, 160, 196, 196, 196, 3136, 12544, 1000, 1000, 1000, 1000};
constexpr uint16_t N[] = { 256, 508, 832, 160, 204, 256, 192, 64, 1000, 1000, 1000, 1000};
constexpr uint16_t K[] = { 832, 1, 49, 528, 864, 1152, 576, 147, 1, 10, 100, 1000};
int pointer =0;
if (argc > 1) {
//std::cout << "Argv=" << argv[1] <<"\n";
pointer= atoi(argv[1]);
std::cout << "Argv(int)=" << pointer <<"\n\n";
}
else {
pointer=2;
std:: cout << "Argv(int) Default=" << pointer << "\n\n";
}
const TensorShape src1_shape(K[pointer],M[pointer]);
const TensorShape src2_shape(N[pointer],K[pointer]);
const TensorShape out1_shape(N[pointer],M[pointer]);
src1.allocator()->init(TensorInfo(src1_shape, Format::U8));
src2.allocator()->init(TensorInfo(src2_shape, Format::U8));
out1.allocator()->init(TensorInfo(out1_shape, Format::U8));
// Initialize just the dimensions and format of the temporary and destination images:
CLGEMMLowp gemm;
gemm.configure(&src2, &src1, &out1, 0, 0, 0, 1, 24);
// Now that the padding requirements are known we can allocate the images:
src1.allocator()->allocate();
src2.allocator()->allocate();
out1.allocator()->allocate();
float avg =10;
double totalTime = 0.0;
for ( int i=0; i<avg; i++)
{
double st = time();
gemm.run();
CLScheduler::get().sync();
double totalTemp = (time() - st);
totalTime = totalTime + totalTemp;
}
double tT= totalTime*1000;
tT = tT/avg;
double MACS=M[pointer]*N[pointer]*K[pointer];
double OPS= (MACS/tT)*1000;
double GOPS= OPS/(1000000000);
std::cout << "Matrix size= " << M[pointer] << " * " << N[pointer] << " * " << K[pointer] << "\t" << tT << "ms\t" << "Runtime of " << avg << " runs=" << totalTime << "s\t" << GOPS << "GOPS/s\n\n";
}
CLGEMM: void main_cl_gemm(int argc, const char **argv) {
CLTensor src1, src2, out1;
CLScheduler::get().default_init();
constexpr uint16_t M[] = { 49, 128, 160, 196, 196, 196, 3136, 12544, 1000, 1000, 1000, 1000};
constexpr uint16_t N[] = { 256, 508, 832, 160, 204, 256, 192, 64, 1000, 1000, 1000, 1000};
constexpr uint16_t K[] = { 832, 1, 49, 528, 864, 1152, 576, 147, 1, 10, 100, 1000};
int pointer =0;
if (argc > 1) {
//std::cout << "Argv=" << argv[1] <<"\n";
pointer= atoi(argv[1]);
std::cout << "Argv(int)=" << pointer <<"\n\n";
}
else {
pointer=2;
std:: cout << "Argv(int) Default=" << pointer << "\n\n";
}
const TensorShape src1_shape(K[pointer],M[pointer]);
const TensorShape src2_shape(N[pointer],K[pointer]);
const TensorShape out1_shape(N[pointer],M[pointer]);
src1.allocator()->init(TensorInfo(src1_shape, Format::F16));
src2.allocator()->init(TensorInfo(src2_shape, Format::F16));
out1.allocator()->init(TensorInfo(out1_shape, Format::F16));
// Initialize just the dimensions and format of the temporary and destination images:
CLGEMM gemm;
gemm.configure(&src1, &src2, NULL, &out1, 1.0, 0.0);
// Now that the padding requirements are known we can allocate the images:
src1.allocator()->allocate();
src2.allocator()->allocate();
out1.allocator()->allocate();
float avg =10;
double totalTime = 0.0;
for ( int i=0; i<avg; i++)
{
double st = time();
gemm.run();
CLScheduler::get().sync();
double totalTemp = (time() - st);
totalTime = totalTime + totalTemp;
}
double tT= totalTime*1000;
tT = tT/avg;
double MACS=M[pointer]*N[pointer]*K[pointer];
double OPS= (MACS/tT)*1000;
double GOPS= OPS/(1000000000);
std::cout << "Matrix size= " << M[pointer] << " * " << N[pointer] << " * " << K[pointer] << "\t" << tT << "ms\t" << "Runtime of " << avg << " runs=" << totalTime << "s\t" << GOPS << "GOPS/s\n\n";
}
Hello @atrah22,
We are still investigating to improve the performance of CLGEMMLowp. You notice such a behavior (although 9-10x difference is a bit more than we expect) because GEMMLowp essentially performs the calculations and accumulation in 32-bit integer. Moreover, you have extra instructions for the dequantization and quantization.
Hello @GeorgeARM,
Thankyou for the quick reply. Yes, now I do understand about the higher instruction count.
I did try to omit calling interleave and transpose function and just compute GEMMLowpMatrixMultiplyKernel. In that case the the performance is similar/better to that of CLGEMM. When I do the same with CLGEMM i.e. omit the interleave and transpose function and compute CLGEMMMatrixMultiplyKernel then the overall performance is hardly affected (which should be the case).
But why does interleave and transpose function has so much effect on CLGEMMLowp performance?
Closing as this issue has to do with a very old version of the library. Please try with the newest version and reopen if you still have any questions.