From 491f30c0fff416007d97f4a5a043923861ef7b64 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Mon, 2 Nov 2020 15:43:57 +0000 Subject: COMPMID-3939: Update GEMM heuristic Mali-G77 - Update heuristic for GEMM reshaped RHS only - Fix left-over block size in CLGEMMMatrixMultiplyReshapedOlyRHSKernel Change-Id: I34c738821ed2e4a537da4a15058eec164cb6b61f Signed-off-by: Gian Marco Iodice Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4305 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- .../CL/gemm/CLGEMMKernelSelectionValhall.cpp | 136 ++++++++++++++++++++- 1 file changed, 130 insertions(+), 6 deletions(-) (limited to 'src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.cpp') diff --git a/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.cpp b/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.cpp index acae0e7565..da41859b87 100644 --- a/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.cpp +++ b/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.cpp @@ -46,8 +46,8 @@ CLGEMMKernelType CLGEMMKernelSelectionValhall::select_kernel(const CLGEMMKernelS using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMKernelSelectionValhall::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - // Configurations for Valhall architectures - static std::map gemm_configs = + // Default configurations for Valhall architectures + static std::map gemm_default_configs = { { DataType::F32, &CLGEMMKernelSelectionValhall::default_f32 }, { DataType::F16, &CLGEMMKernelSelectionValhall::default_f16 }, @@ -57,14 +57,34 @@ CLGEMMKernelType CLGEMMKernelSelectionValhall::select_kernel(const CLGEMMKernelS { DataType::QSYMM8_PER_CHANNEL, &CLGEMMKernelSelectionValhall::default_q8 } }; + // Mali-G77 configurations + static std::map gemm_g77_configs = + { + { DataType::F32, &CLGEMMKernelSelectionValhall::default_f32 }, + { DataType::F16, &CLGEMMKernelSelectionValhall::g77_f16 }, + { DataType::QASYMM8, &CLGEMMKernelSelectionValhall::default_q8 }, + { DataType::QASYMM8_SIGNED, &CLGEMMKernelSelectionValhall::default_q8 }, + { DataType::QSYMM8, &CLGEMMKernelSelectionValhall::default_q8 }, + { DataType::QSYMM8_PER_CHANNEL, &CLGEMMKernelSelectionValhall::default_q8 } + }; + const DataType data_type = params.data_type; - if(gemm_configs.find(data_type) != gemm_configs.end()) + switch(_target) { - return (this->*gemm_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant); + case GPUTarget::G77: + if(gemm_g77_configs.find(data_type) != gemm_g77_configs.end()) + { + return (this->*gemm_g77_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant); + } + ARM_COMPUTE_ERROR("Not supported data type"); + default: + if(gemm_default_configs.find(data_type) != gemm_default_configs.end()) + { + return (this->*gemm_default_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant); + } + ARM_COMPUTE_ERROR("Not supported data type"); } - - ARM_COMPUTE_ERROR("Not supported data type"); } CLGEMMKernelType CLGEMMKernelSelectionValhall::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) @@ -81,6 +101,110 @@ CLGEMMKernelType CLGEMMKernelSelectionValhall::default_f16(unsigned int m, unsig return is_rhs_constant ? CLGEMMKernelType::RESHAPED_ONLY_RHS : CLGEMMKernelType::NATIVE_V1; } +CLGEMMKernelType CLGEMMKernelSelectionValhall::g77_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + if (!is_rhs_constant) + { + return CLGEMMKernelType::NATIVE_V1; + } + + if (m == 1) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + + const float r_mn = static_cast(m) / static_cast(n); + const float r_mk = static_cast(m) / static_cast(k); + const float r_nk = static_cast(n) / static_cast(k); + const float workload = (static_cast(m) * static_cast(n) * static_cast(b)) / 20.0f; + + if(r_mk <= 0.6817956566810608) + { + if(workload <= 801.6000061035156) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(r_mn <= 0.0839829258620739) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(r_mk <= 0.24917218834161758) + { + return CLGEMMKernelType::RESHAPED; + } + else + { + if(workload <= 2551.75) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(workload <= 5061.574951171875) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + } + } + } + } + else + { + if(r_mk <= 4.849947690963745) + { + if(workload <= 17618.4501953125) + { + if(workload <= 5224.699951171875) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(r_nk <= 0.7933054566383362) + { + return CLGEMMKernelType::RESHAPED; + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } + } + else + { + if(workload <= 20275.2001953125) + { + return CLGEMMKernelType::RESHAPED; + } + else + { + if(r_mk <= 3.07421875) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + } + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } +} + CLGEMMKernelType CLGEMMKernelSelectionValhall::default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) { ARM_COMPUTE_UNUSED(m, n, k, b); -- cgit v1.2.1