From a085a0c91c5b3061e616fa810d81be5798b240d8 Mon Sep 17 00:00:00 2001 From: SiCong Li Date: Wed, 2 Dec 2020 14:54:34 +0000 Subject: Rename the files and classes required by the OpenCL GEMM heuristic All existing kernel type selection heuristics CLGEMMKernelSelection are renamed to CLGEMMDefaultType All existing kernel configuration heuristics CLGEMMKernelConfiguration are renamed to CLGEMMDefaultConfig This refactoring is required to make room for tuner-based heuristics Resolves COMPMID-3842 Change-Id: I2c9f1029ad67f1e2808c79871698fc4486d45306 Signed-off-by: SiCong Li Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4639 Tested-by: Arm Jenkins Reviewed-by: Manuel Bottini Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.cpp | 587 +++++++++++++++++++++ src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.h | 58 ++ src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.cpp | 94 ++++ src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.h | 53 ++ src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.cpp | 222 ++++++++ src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.h | 54 ++ src/runtime/CL/gemm/CLGEMMKernelSelection.h | 12 +- .../CL/gemm/CLGEMMKernelSelectionBifrost.cpp | 587 --------------------- src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.h | 58 -- .../CL/gemm/CLGEMMKernelSelectionMidgard.cpp | 94 ---- src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.h | 53 -- .../CL/gemm/CLGEMMKernelSelectionValhall.cpp | 222 -------- src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.h | 54 -- 13 files changed, 1074 insertions(+), 1074 deletions(-) create mode 100644 src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.cpp create mode 100644 src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.h create mode 100644 src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.cpp create mode 100644 src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.h create mode 100644 src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.cpp create mode 100644 src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.h delete mode 100644 src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.cpp delete mode 100644 src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.h delete mode 100644 src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.cpp delete mode 100644 src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.h delete mode 100644 src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.cpp delete mode 100644 src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.h (limited to 'src/runtime/CL/gemm') diff --git a/src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.cpp b/src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.cpp new file mode 100644 index 0000000000..5ac25a9a20 --- /dev/null +++ b/src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.cpp @@ -0,0 +1,587 @@ +/* + * Copyright (c) 2020 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.h" + +#include "arm_compute/core/CL/CLHelpers.h" +#include "arm_compute/core/CL/CLKernelLibrary.h" +#include "src/core/CL/gemm/CLGEMMHelpers.h" + +#include +#include + +namespace arm_compute +{ +namespace cl_gemm +{ +CLGEMMDefaultTypeBifrost::CLGEMMDefaultTypeBifrost(GPUTarget gpu) + : ICLGEMMKernelSelection(gpu) +{ +} + +CLGEMMKernelType CLGEMMDefaultTypeBifrost::select_kernel(const CLGEMMKernelSelectionParams ¶ms) +{ + // _target could be used in the future to have a dedicated heuristic for each GPU IP + ARM_COMPUTE_UNUSED(_target); + + using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMDefaultTypeBifrost::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + + // Default configurations for Bifrost architectures + static std::map gemm_default_configs = + { + { DataType::F32, &CLGEMMDefaultTypeBifrost::default_f32 }, + { DataType::F16, &CLGEMMDefaultTypeBifrost::default_f16 }, + { DataType::QASYMM8, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QSYMM8, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeBifrost::default_q8 } + }; + + // Mali-G71 configurations + static std::map gemm_g71_configs = + { + { DataType::F32, &CLGEMMDefaultTypeBifrost::default_f32 }, + { DataType::F16, &CLGEMMDefaultTypeBifrost::g71_f16 }, + { DataType::QASYMM8, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QSYMM8, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeBifrost::default_q8 } + }; + + // Mali-G52 configurations + static std::map gemm_g52_configs = + { + { DataType::F32, &CLGEMMDefaultTypeBifrost::g52_f32 }, + { DataType::F16, &CLGEMMDefaultTypeBifrost::g52_f16 }, + { DataType::QASYMM8, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QSYMM8, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeBifrost::default_q8 } + }; + + // Mali-G76 configurations + static std::map gemm_g76_configs = + { + { DataType::F32, &CLGEMMDefaultTypeBifrost::g76_f32 }, + { DataType::F16, &CLGEMMDefaultTypeBifrost::g76_f16 }, + { DataType::QASYMM8, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QSYMM8, &CLGEMMDefaultTypeBifrost::default_q8 }, + { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeBifrost::default_q8 } + }; + + const DataType data_type = params.data_type; + + switch(_target) + { + case GPUTarget::G71: + if(gemm_g71_configs.find(data_type) != gemm_g71_configs.end()) + { + return (this->*gemm_g71_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant); + } + ARM_COMPUTE_ERROR("Not supported data type"); + case GPUTarget::G76: + if(gemm_g76_configs.find(data_type) != gemm_g76_configs.end()) + { + return (this->*gemm_g76_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant); + } + ARM_COMPUTE_ERROR("Not supported data type"); + case GPUTarget::G52: + if(gemm_g52_configs.find(data_type) != gemm_g52_configs.end()) + { + return (this->*gemm_g52_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"); + } +} + +CLGEMMKernelType CLGEMMDefaultTypeBifrost::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(b); + + CLGEMMKernelType gemm_type = CLGEMMKernelType::NATIVE_V1; + + if(is_rhs_constant) + { + if((m > 1) && (n < 16)) + { + gemm_type = CLGEMMKernelType::RESHAPED_V1; + } + else if(m == 1) + { + gemm_type = CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if((k > 256) && (m > 4)) + { + constexpr float alpha = 3.2f; + constexpr float fact0 = 1.51f; + constexpr float fact1 = 1.66f; + constexpr float ops = 12.0f; + const float scale = k > 1024 ? 1.07f : 1.0f; + gemm_type = (alpha + ((n * fact0) / ops) < ((fact1 * n * scale) / ops)) ? CLGEMMKernelType::RESHAPED_V1 : CLGEMMKernelType::NATIVE_V1; + } + else + { + gemm_type = CLGEMMKernelType::NATIVE_V1; + } + } + + const auto workload = static_cast((m * n) / 20.0f); + + gemm_type = ((workload > 1600.0f) && (gemm_type == CLGEMMKernelType::RESHAPED_V1)) ? CLGEMMKernelType::RESHAPED : gemm_type; + } + + return gemm_type; +} + +CLGEMMKernelType CLGEMMDefaultTypeBifrost::default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(n, k, b); + + if(is_rhs_constant) + { + if(m == 1) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + return CLGEMMKernelType::NATIVE_V1; + } +} + +CLGEMMKernelType CLGEMMDefaultTypeBifrost::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); + + if(is_rhs_constant) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::NATIVE; + } +} + +CLGEMMKernelType CLGEMMDefaultTypeBifrost::g76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(b); + + if(!is_rhs_constant) + { + return CLGEMMKernelType::NATIVE_V1; + } + if(m == 1) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + if(k <= 496) + { + if(n <= 544) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + if(k <= 588) + { + if(k <= 552) + { + if(m <= 148) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(m <= 278) + { + return CLGEMMKernelType::RESHAPED; + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } +} + +CLGEMMKernelType CLGEMMDefaultTypeBifrost::g52_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(b); + + 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 r_mnk = static_cast(m) / (static_cast(n) * static_cast(k)); + + if(r_mn <= 1.5469f) + { + if(r_mk <= 0.8766f) + { + if(r_mk <= 0.0211f) + { + if(r_mnk <= 77.5833f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + if(r_nk <= 0.0832f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + } + else + { + if(r_mnk <= 193.0000f) + { + if(r_mn <= 0.9948f) + { + if(r_mk <= 2.5453f) + { + return CLGEMMKernelType::RESHAPED; + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + } + else + { + if(r_mn <= 17.7370f) + { + if(r_mnk <= 1391.2875f) + { + if(r_mk <= 2.9724f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(r_mnk <= 470.0000f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + } + else + { + if(r_nk <= 0.1381f) + { + if(r_mnk <= 9040.5000f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + if(r_mn <= 5.6790f) + { + return CLGEMMKernelType::RESHAPED; + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } + } + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } +} + +CLGEMMKernelType CLGEMMDefaultTypeBifrost::g76_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(b); + + 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_nk = static_cast(n) / static_cast(k); + + if(k <= 212) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(r_nk <= 0.4990234375f) + { + if(k <= 1392) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(m <= 325) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + } + else + { + if(k <= 471) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(r_mn <= 0.04475911520421505f) + { + return CLGEMMKernelType::RESHAPED; + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } + } + } +} + +CLGEMMKernelType CLGEMMDefaultTypeBifrost::g52_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; + } + + if(n <= 127.0000f) + { + if(n <= 63.5000f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(m <= 3616.0000f) + { + if(b <= 18.5000f) + { + if(m <= 2970.5000f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(k <= 104.0000f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + } + else + { + if(m <= 12.5000f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + if(k <= 104.0000f) + { + if(b <= 18.5000f) + { + if(m <= 490.0000f) + { + if(n <= 272.0000f) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + if(m <= 226.0000f) + { + if(n <= 140.0000f) + { + if(m <= 179.5000f) + { + return CLGEMMKernelType::RESHAPED; + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + } + } +} + +CLGEMMKernelType CLGEMMDefaultTypeBifrost::g71_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(b); + + if(is_rhs_constant) + { + if(m == 1) + { + if(n > k) + { + return CLGEMMKernelType::NATIVE_V1; + } + else + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + } + else + { + return CLGEMMKernelType::RESHAPED; + } + } + else + { + return CLGEMMKernelType::NATIVE_V1; + } +} +} // namespace cl_gemm +} // namespace arm_compute diff --git a/src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.h b/src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.h new file mode 100644 index 0000000000..0cbab35c2e --- /dev/null +++ b/src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef SRC_CLGEMMDEFAULTTYPEBIFROST_H +#define SRC_CLGEMMDEFAULTTYPEBIFROST_H + +#include "arm_compute/runtime/CL/ICLGEMMKernelSelection.h" + +namespace arm_compute +{ +namespace cl_gemm +{ +/** Bifrost based OpenCL GEMMKernel selection */ +class CLGEMMDefaultTypeBifrost final : public ICLGEMMKernelSelection +{ +public: + /** Constructor + * + * @param[in] gpu GPU target + */ + CLGEMMDefaultTypeBifrost(GPUTarget gpu); + + // Inherited overridden method + CLGEMMKernelType select_kernel(const CLGEMMKernelSelectionParams ¶ms) override; + +private: + CLGEMMKernelType g52_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType g76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType g76_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType g52_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType g71_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); +}; +} // namespace cl_gemm +} // namespace arm_compute +#endif /* SRC_CLGEMMDEFAULTTYPEBIFROST_H */ diff --git a/src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.cpp b/src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.cpp new file mode 100644 index 0000000000..88b6060e12 --- /dev/null +++ b/src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2020 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.h" + +#include "arm_compute/core/CL/CLHelpers.h" +#include "arm_compute/core/CL/CLKernelLibrary.h" +#include "arm_compute/core/GPUTarget.h" +#include "src/core/CL/gemm/CLGEMMHelpers.h" + +#include +#include + +namespace arm_compute +{ +namespace cl_gemm +{ +CLGEMMDefaultTypeMidgard::CLGEMMDefaultTypeMidgard(GPUTarget gpu) + : ICLGEMMKernelSelection(gpu) +{ +} + +CLGEMMKernelType CLGEMMDefaultTypeMidgard::select_kernel(const CLGEMMKernelSelectionParams ¶ms) +{ + // _target could be used in the future to have a dedicated heuristic for each GPU IP + ARM_COMPUTE_UNUSED(_target); + + using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMDefaultTypeMidgard::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + + // Configurations for Midgard architectures + static std::map gemm_configs = + { + { DataType::F32, &CLGEMMDefaultTypeMidgard::default_f32 }, + { DataType::F16, &CLGEMMDefaultTypeMidgard::default_f16 }, + { DataType::QASYMM8, &CLGEMMDefaultTypeMidgard::default_q8 }, + { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeMidgard::default_q8 }, + { DataType::QSYMM8, &CLGEMMDefaultTypeMidgard::default_q8 }, + { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeMidgard::default_q8 } + }; + + const DataType data_type = params.data_type; + + if(gemm_configs.find(data_type) != gemm_configs.end()) + { + return (this->*gemm_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant); + } + + ARM_COMPUTE_ERROR("Not supported data type"); +} + +CLGEMMKernelType CLGEMMDefaultTypeMidgard::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(n, k, b); + + // We reshape the matrices only if we do not have the vector-by-matrix case and we reshape the matrix B only once + return ((m != 1) && is_rhs_constant) ? CLGEMMKernelType::RESHAPED_V1 : CLGEMMKernelType::NATIVE_V1; +} + +CLGEMMKernelType CLGEMMDefaultTypeMidgard::default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(n, k, b); + + // We reshape the matrices only if we do not have the vector-by-matrix case and we reshape the matrix B only once + return ((m != 1) && is_rhs_constant) ? CLGEMMKernelType::RESHAPED_V1 : CLGEMMKernelType::NATIVE_V1; +} + +CLGEMMKernelType CLGEMMDefaultTypeMidgard::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, is_rhs_constant); + + return CLGEMMKernelType::NATIVE; +} +} // namespace cl_gemm +} // namespace arm_compute diff --git a/src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.h b/src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.h new file mode 100644 index 0000000000..241072fd58 --- /dev/null +++ b/src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef SRC_CLGEMMDefaultTypeMidgard_H +#define SRC_CLGEMMDefaultTypeMidgard_H + +#include "arm_compute/runtime/CL/ICLGEMMKernelSelection.h" + +namespace arm_compute +{ +namespace cl_gemm +{ +/** Midgard based OpenCL GEMMKernel selection */ +class CLGEMMDefaultTypeMidgard final : public ICLGEMMKernelSelection +{ +public: + /** Constructor + * + * @param[in] gpu GPU target + */ + CLGEMMDefaultTypeMidgard(GPUTarget gpu); + + // Inherited overridden method + CLGEMMKernelType select_kernel(const CLGEMMKernelSelectionParams ¶ms) override; + +private: + CLGEMMKernelType default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); +}; +} // namespace cl_gemm +} // namespace arm_compute +#endif /* SRC_CLGEMMDefaultTypeMidgard_H */ diff --git a/src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.cpp b/src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.cpp new file mode 100644 index 0000000000..ad74368889 --- /dev/null +++ b/src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.cpp @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2020 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.h" + +#include "arm_compute/core/CL/CLHelpers.h" +#include "arm_compute/core/CL/CLKernelLibrary.h" +#include "src/core/CL/gemm/CLGEMMHelpers.h" + +#include +#include + +namespace arm_compute +{ +namespace cl_gemm +{ +CLGEMMDefaultTypeValhall::CLGEMMDefaultTypeValhall(GPUTarget gpu) + : ICLGEMMKernelSelection(gpu) +{ +} + +CLGEMMKernelType CLGEMMDefaultTypeValhall::select_kernel(const CLGEMMKernelSelectionParams ¶ms) +{ + // _target could be used in the future to have a dedicated heuristic for each GPU IP + ARM_COMPUTE_UNUSED(_target); + + using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMDefaultTypeValhall::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + + // Default configurations for Valhall architectures + static std::map gemm_default_configs = + { + { DataType::F32, &CLGEMMDefaultTypeValhall::default_f32 }, + { DataType::F16, &CLGEMMDefaultTypeValhall::default_f16 }, + { DataType::QASYMM8, &CLGEMMDefaultTypeValhall::default_q8 }, + { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeValhall::default_q8 }, + { DataType::QSYMM8, &CLGEMMDefaultTypeValhall::default_q8 }, + { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeValhall::default_q8 } + }; + + // Mali-G77 configurations + static std::map gemm_g77_configs = + { + { DataType::F32, &CLGEMMDefaultTypeValhall::default_f32 }, + { DataType::F16, &CLGEMMDefaultTypeValhall::g77_f16 }, + { DataType::QASYMM8, &CLGEMMDefaultTypeValhall::default_q8 }, + { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeValhall::default_q8 }, + { DataType::QSYMM8, &CLGEMMDefaultTypeValhall::default_q8 }, + { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeValhall::default_q8 } + }; + + const DataType data_type = params.data_type; + + switch(_target) + { + 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"); + } +} + +CLGEMMKernelType CLGEMMDefaultTypeValhall::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(m, n, k, b); + + return is_rhs_constant ? CLGEMMKernelType::RESHAPED_ONLY_RHS : CLGEMMKernelType::NATIVE_V1; +} + +CLGEMMKernelType CLGEMMDefaultTypeValhall::default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) +{ + ARM_COMPUTE_UNUSED(m, n, k, b); + + return is_rhs_constant ? CLGEMMKernelType::RESHAPED_ONLY_RHS : CLGEMMKernelType::NATIVE_V1; +} + +CLGEMMKernelType CLGEMMDefaultTypeValhall::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 CLGEMMDefaultTypeValhall::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); + + if(is_rhs_constant) + { + return CLGEMMKernelType::RESHAPED_ONLY_RHS; + } + else + { + return CLGEMMKernelType::NATIVE; + } +} +} // namespace cl_gemm +} // namespace arm_compute diff --git a/src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.h b/src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.h new file mode 100644 index 0000000000..2fae838cc3 --- /dev/null +++ b/src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef SRC_CLGEMMDEFAULTTYPEVALHALL_H +#define SRC_CLGEMMDEFAULTTYPEVALHALL_H + +#include "arm_compute/runtime/CL/ICLGEMMKernelSelection.h" + +namespace arm_compute +{ +namespace cl_gemm +{ +/** Valhall based OpenCL GEMMKernel selection */ +class CLGEMMDefaultTypeValhall final : public ICLGEMMKernelSelection +{ +public: + /** Constructor + * + * @param[in] gpu GPU target + */ + CLGEMMDefaultTypeValhall(GPUTarget gpu); + + // Inherited overridden method + CLGEMMKernelType select_kernel(const CLGEMMKernelSelectionParams ¶ms) override; + +private: + CLGEMMKernelType default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); + CLGEMMKernelType g77_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); +}; +} // namespace cl_gemm +} // namespace arm_compute +#endif /* SRC_CLGEMMDEFAULTTYPEVALHALL_H */ diff --git a/src/runtime/CL/gemm/CLGEMMKernelSelection.h b/src/runtime/CL/gemm/CLGEMMKernelSelection.h index 69f8349d27..6189a324cf 100644 --- a/src/runtime/CL/gemm/CLGEMMKernelSelection.h +++ b/src/runtime/CL/gemm/CLGEMMKernelSelection.h @@ -25,9 +25,9 @@ #define SRC_CLGEMMKERNELSELECTION_H #include "arm_compute/runtime/CL/ICLGEMMKernelSelection.h" -#include "src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.h" -#include "src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.h" -#include "src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.h" +#include "src/runtime/CL/gemm/CLGEMMDefaultTypeBifrost.h" +#include "src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.h" +#include "src/runtime/CL/gemm/CLGEMMDefaultTypeValhall.h" namespace arm_compute { @@ -48,11 +48,11 @@ public: switch(get_arch_from_target(gpu)) { case GPUTarget::MIDGARD: - return std::make_unique(gpu); + return std::make_unique(gpu); case GPUTarget::BIFROST: - return std::make_unique(gpu); + return std::make_unique(gpu); case GPUTarget::VALHALL: - return std::make_unique(gpu); + return std::make_unique(gpu); default: ARM_COMPUTE_ERROR("Not supported GPU target"); } diff --git a/src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.cpp b/src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.cpp deleted file mode 100644 index 0bda38e5e9..0000000000 --- a/src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.cpp +++ /dev/null @@ -1,587 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.h" - -#include "arm_compute/core/CL/CLHelpers.h" -#include "arm_compute/core/CL/CLKernelLibrary.h" -#include "src/core/CL/gemm/CLGEMMHelpers.h" - -#include -#include - -namespace arm_compute -{ -namespace cl_gemm -{ -CLGEMMKernelSelectionBifrost::CLGEMMKernelSelectionBifrost(GPUTarget gpu) - : ICLGEMMKernelSelection(gpu) -{ -} - -CLGEMMKernelType CLGEMMKernelSelectionBifrost::select_kernel(const CLGEMMKernelSelectionParams ¶ms) -{ - // _target could be used in the future to have a dedicated heuristic for each GPU IP - ARM_COMPUTE_UNUSED(_target); - - using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMKernelSelectionBifrost::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - - // Default configurations for Bifrost architectures - static std::map gemm_default_configs = - { - { DataType::F32, &CLGEMMKernelSelectionBifrost::default_f32 }, - { DataType::F16, &CLGEMMKernelSelectionBifrost::default_f16 }, - { DataType::QASYMM8, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QASYMM8_SIGNED, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QSYMM8, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QSYMM8_PER_CHANNEL, &CLGEMMKernelSelectionBifrost::default_q8 } - }; - - // Mali-G71 configurations - static std::map gemm_g71_configs = - { - { DataType::F32, &CLGEMMKernelSelectionBifrost::default_f32 }, - { DataType::F16, &CLGEMMKernelSelectionBifrost::g71_f16 }, - { DataType::QASYMM8, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QASYMM8_SIGNED, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QSYMM8, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QSYMM8_PER_CHANNEL, &CLGEMMKernelSelectionBifrost::default_q8 } - }; - - // Mali-G52 configurations - static std::map gemm_g52_configs = - { - { DataType::F32, &CLGEMMKernelSelectionBifrost::g52_f32 }, - { DataType::F16, &CLGEMMKernelSelectionBifrost::g52_f16 }, - { DataType::QASYMM8, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QASYMM8_SIGNED, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QSYMM8, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QSYMM8_PER_CHANNEL, &CLGEMMKernelSelectionBifrost::default_q8 } - }; - - // Mali-G76 configurations - static std::map gemm_g76_configs = - { - { DataType::F32, &CLGEMMKernelSelectionBifrost::g76_f32 }, - { DataType::F16, &CLGEMMKernelSelectionBifrost::g76_f16 }, - { DataType::QASYMM8, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QASYMM8_SIGNED, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QSYMM8, &CLGEMMKernelSelectionBifrost::default_q8 }, - { DataType::QSYMM8_PER_CHANNEL, &CLGEMMKernelSelectionBifrost::default_q8 } - }; - - const DataType data_type = params.data_type; - - switch(_target) - { - case GPUTarget::G71: - if(gemm_g71_configs.find(data_type) != gemm_g71_configs.end()) - { - return (this->*gemm_g71_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant); - } - ARM_COMPUTE_ERROR("Not supported data type"); - case GPUTarget::G76: - if(gemm_g76_configs.find(data_type) != gemm_g76_configs.end()) - { - return (this->*gemm_g76_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant); - } - ARM_COMPUTE_ERROR("Not supported data type"); - case GPUTarget::G52: - if(gemm_g52_configs.find(data_type) != gemm_g52_configs.end()) - { - return (this->*gemm_g52_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"); - } -} - -CLGEMMKernelType CLGEMMKernelSelectionBifrost::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(b); - - CLGEMMKernelType gemm_type = CLGEMMKernelType::NATIVE_V1; - - if(is_rhs_constant) - { - if((m > 1) && (n < 16)) - { - gemm_type = CLGEMMKernelType::RESHAPED_V1; - } - else if(m == 1) - { - gemm_type = CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - if((k > 256) && (m > 4)) - { - constexpr float alpha = 3.2f; - constexpr float fact0 = 1.51f; - constexpr float fact1 = 1.66f; - constexpr float ops = 12.0f; - const float scale = k > 1024 ? 1.07f : 1.0f; - gemm_type = (alpha + ((n * fact0) / ops) < ((fact1 * n * scale) / ops)) ? CLGEMMKernelType::RESHAPED_V1 : CLGEMMKernelType::NATIVE_V1; - } - else - { - gemm_type = CLGEMMKernelType::NATIVE_V1; - } - } - - const auto workload = static_cast((m * n) / 20.0f); - - gemm_type = ((workload > 1600.0f) && (gemm_type == CLGEMMKernelType::RESHAPED_V1)) ? CLGEMMKernelType::RESHAPED : gemm_type; - } - - return gemm_type; -} - -CLGEMMKernelType CLGEMMKernelSelectionBifrost::default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(n, k, b); - - if(is_rhs_constant) - { - if(m == 1) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - return CLGEMMKernelType::NATIVE_V1; - } -} - -CLGEMMKernelType CLGEMMKernelSelectionBifrost::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); - - if(is_rhs_constant) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::NATIVE; - } -} - -CLGEMMKernelType CLGEMMKernelSelectionBifrost::g76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(b); - - if(!is_rhs_constant) - { - return CLGEMMKernelType::NATIVE_V1; - } - if(m == 1) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - if(k <= 496) - { - if(n <= 544) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - if(k <= 588) - { - if(k <= 552) - { - if(m <= 148) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - if(m <= 278) - { - return CLGEMMKernelType::RESHAPED; - } - else - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - } - } - else - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } -} - -CLGEMMKernelType CLGEMMKernelSelectionBifrost::g52_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(b); - - 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 r_mnk = static_cast(m) / (static_cast(n) * static_cast(k)); - - if(r_mn <= 1.5469f) - { - if(r_mk <= 0.8766f) - { - if(r_mk <= 0.0211f) - { - if(r_mnk <= 77.5833f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - if(r_nk <= 0.0832f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - } - else - { - if(r_mnk <= 193.0000f) - { - if(r_mn <= 0.9948f) - { - if(r_mk <= 2.5453f) - { - return CLGEMMKernelType::RESHAPED; - } - else - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - } - else - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - } - else - { - if(r_mn <= 17.7370f) - { - if(r_mnk <= 1391.2875f) - { - if(r_mk <= 2.9724f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - if(r_mnk <= 470.0000f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - } - else - { - if(r_nk <= 0.1381f) - { - if(r_mnk <= 9040.5000f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - if(r_mn <= 5.6790f) - { - return CLGEMMKernelType::RESHAPED; - } - else - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - } - } - } - else - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - } -} - -CLGEMMKernelType CLGEMMKernelSelectionBifrost::g76_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(b); - - 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_nk = static_cast(n) / static_cast(k); - - if(k <= 212) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - if(r_nk <= 0.4990234375f) - { - if(k <= 1392) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - if(m <= 325) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - } - else - { - if(k <= 471) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - if(r_mn <= 0.04475911520421505f) - { - return CLGEMMKernelType::RESHAPED; - } - else - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - } - } - } -} - -CLGEMMKernelType CLGEMMKernelSelectionBifrost::g52_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; - } - - if(n <= 127.0000f) - { - if(n <= 63.5000f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - if(m <= 3616.0000f) - { - if(b <= 18.5000f) - { - if(m <= 2970.5000f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - if(k <= 104.0000f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - } - else - { - if(m <= 12.5000f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - if(k <= 104.0000f) - { - if(b <= 18.5000f) - { - if(m <= 490.0000f) - { - if(n <= 272.0000f) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - if(m <= 226.0000f) - { - if(n <= 140.0000f) - { - if(m <= 179.5000f) - { - return CLGEMMKernelType::RESHAPED; - } - else - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - } - } -} - -CLGEMMKernelType CLGEMMKernelSelectionBifrost::g71_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(b); - - if(is_rhs_constant) - { - if(m == 1) - { - if(n > k) - { - return CLGEMMKernelType::NATIVE_V1; - } - else - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - } - else - { - return CLGEMMKernelType::RESHAPED; - } - } - else - { - return CLGEMMKernelType::NATIVE_V1; - } -} -} // namespace cl_gemm -} // namespace arm_compute diff --git a/src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.h b/src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.h deleted file mode 100644 index 6831a12aec..0000000000 --- a/src/runtime/CL/gemm/CLGEMMKernelSelectionBifrost.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef SRC_CLGEMMKERNELSELECTIONBIFROST_H -#define SRC_CLGEMMKERNELSELECTIONBIFROST_H - -#include "arm_compute/runtime/CL/ICLGEMMKernelSelection.h" - -namespace arm_compute -{ -namespace cl_gemm -{ -/** Bifrost based OpenCL GEMMKernel selection */ -class CLGEMMKernelSelectionBifrost final : public ICLGEMMKernelSelection -{ -public: - /** Constructor - * - * @param[in] gpu GPU target - */ - CLGEMMKernelSelectionBifrost(GPUTarget gpu); - - // Inherited overridden method - CLGEMMKernelType select_kernel(const CLGEMMKernelSelectionParams ¶ms) override; - -private: - CLGEMMKernelType g52_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType g76_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType g76_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType g52_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType g71_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); -}; -} // namespace cl_gemm -} // namespace arm_compute -#endif /* SRC_CLGEMMKERNELSELECTIONBIFROST_H */ diff --git a/src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.cpp b/src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.cpp deleted file mode 100644 index d172a827b5..0000000000 --- a/src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.h" - -#include "arm_compute/core/CL/CLHelpers.h" -#include "arm_compute/core/CL/CLKernelLibrary.h" -#include "arm_compute/core/GPUTarget.h" -#include "src/core/CL/gemm/CLGEMMHelpers.h" - -#include -#include - -namespace arm_compute -{ -namespace cl_gemm -{ -CLGEMMKernelSelectionMidgard::CLGEMMKernelSelectionMidgard(GPUTarget gpu) - : ICLGEMMKernelSelection(gpu) -{ -} - -CLGEMMKernelType CLGEMMKernelSelectionMidgard::select_kernel(const CLGEMMKernelSelectionParams ¶ms) -{ - // _target could be used in the future to have a dedicated heuristic for each GPU IP - ARM_COMPUTE_UNUSED(_target); - - using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMKernelSelectionMidgard::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - - // Configurations for Midgard architectures - static std::map gemm_configs = - { - { DataType::F32, &CLGEMMKernelSelectionMidgard::default_f32 }, - { DataType::F16, &CLGEMMKernelSelectionMidgard::default_f16 }, - { DataType::QASYMM8, &CLGEMMKernelSelectionMidgard::default_q8 }, - { DataType::QASYMM8_SIGNED, &CLGEMMKernelSelectionMidgard::default_q8 }, - { DataType::QSYMM8, &CLGEMMKernelSelectionMidgard::default_q8 }, - { DataType::QSYMM8_PER_CHANNEL, &CLGEMMKernelSelectionMidgard::default_q8 } - }; - - const DataType data_type = params.data_type; - - if(gemm_configs.find(data_type) != gemm_configs.end()) - { - return (this->*gemm_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant); - } - - ARM_COMPUTE_ERROR("Not supported data type"); -} - -CLGEMMKernelType CLGEMMKernelSelectionMidgard::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(n, k, b); - - // We reshape the matrices only if we do not have the vector-by-matrix case and we reshape the matrix B only once - return ((m != 1) && is_rhs_constant) ? CLGEMMKernelType::RESHAPED_V1 : CLGEMMKernelType::NATIVE_V1; -} - -CLGEMMKernelType CLGEMMKernelSelectionMidgard::default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(n, k, b); - - // We reshape the matrices only if we do not have the vector-by-matrix case and we reshape the matrix B only once - return ((m != 1) && is_rhs_constant) ? CLGEMMKernelType::RESHAPED_V1 : CLGEMMKernelType::NATIVE_V1; -} - -CLGEMMKernelType CLGEMMKernelSelectionMidgard::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, is_rhs_constant); - - return CLGEMMKernelType::NATIVE; -} -} // namespace cl_gemm -} // namespace arm_compute diff --git a/src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.h b/src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.h deleted file mode 100644 index 3f6003f7dc..0000000000 --- a/src/runtime/CL/gemm/CLGEMMKernelSelectionMidgard.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef SRC_CLGEMMKERNELSELECTIONMIDGARD_H -#define SRC_CLGEMMKERNELSELECTIONMIDGARD_H - -#include "arm_compute/runtime/CL/ICLGEMMKernelSelection.h" - -namespace arm_compute -{ -namespace cl_gemm -{ -/** Midgard based OpenCL GEMMKernel selection */ -class CLGEMMKernelSelectionMidgard final : public ICLGEMMKernelSelection -{ -public: - /** Constructor - * - * @param[in] gpu GPU target - */ - CLGEMMKernelSelectionMidgard(GPUTarget gpu); - - // Inherited overridden method - CLGEMMKernelType select_kernel(const CLGEMMKernelSelectionParams ¶ms) override; - -private: - CLGEMMKernelType default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); -}; -} // namespace cl_gemm -} // namespace arm_compute -#endif /* SRC_CLGEMMKERNELSELECTIONMIDGARD_H */ diff --git a/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.cpp b/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.cpp deleted file mode 100644 index da41859b87..0000000000 --- a/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.h" - -#include "arm_compute/core/CL/CLHelpers.h" -#include "arm_compute/core/CL/CLKernelLibrary.h" -#include "src/core/CL/gemm/CLGEMMHelpers.h" - -#include -#include - -namespace arm_compute -{ -namespace cl_gemm -{ -CLGEMMKernelSelectionValhall::CLGEMMKernelSelectionValhall(GPUTarget gpu) - : ICLGEMMKernelSelection(gpu) -{ -} - -CLGEMMKernelType CLGEMMKernelSelectionValhall::select_kernel(const CLGEMMKernelSelectionParams ¶ms) -{ - // _target could be used in the future to have a dedicated heuristic for each GPU IP - ARM_COMPUTE_UNUSED(_target); - - using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMKernelSelectionValhall::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - - // Default configurations for Valhall architectures - static std::map gemm_default_configs = - { - { DataType::F32, &CLGEMMKernelSelectionValhall::default_f32 }, - { DataType::F16, &CLGEMMKernelSelectionValhall::default_f16 }, - { DataType::QASYMM8, &CLGEMMKernelSelectionValhall::default_q8 }, - { DataType::QASYMM8_SIGNED, &CLGEMMKernelSelectionValhall::default_q8 }, - { DataType::QSYMM8, &CLGEMMKernelSelectionValhall::default_q8 }, - { 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; - - switch(_target) - { - 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"); - } -} - -CLGEMMKernelType CLGEMMKernelSelectionValhall::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(m, n, k, b); - - return is_rhs_constant ? CLGEMMKernelType::RESHAPED_ONLY_RHS : CLGEMMKernelType::NATIVE_V1; -} - -CLGEMMKernelType CLGEMMKernelSelectionValhall::default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant) -{ - ARM_COMPUTE_UNUSED(m, n, k, b); - - 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); - - if(is_rhs_constant) - { - return CLGEMMKernelType::RESHAPED_ONLY_RHS; - } - else - { - return CLGEMMKernelType::NATIVE; - } -} -} // namespace cl_gemm -} // namespace arm_compute diff --git a/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.h b/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.h deleted file mode 100644 index 82e46f694e..0000000000 --- a/src/runtime/CL/gemm/CLGEMMKernelSelectionValhall.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef SRC_CLGEMMKERNELSELECTIONVALHALL_H -#define SRC_CLGEMMKERNELSELECTIONVALHALL_H - -#include "arm_compute/runtime/CL/ICLGEMMKernelSelection.h" - -namespace arm_compute -{ -namespace cl_gemm -{ -/** Valhall based OpenCL GEMMKernel selection */ -class CLGEMMKernelSelectionValhall final : public ICLGEMMKernelSelection -{ -public: - /** Constructor - * - * @param[in] gpu GPU target - */ - CLGEMMKernelSelectionValhall(GPUTarget gpu); - - // Inherited overridden method - CLGEMMKernelType select_kernel(const CLGEMMKernelSelectionParams ¶ms) override; - -private: - CLGEMMKernelType default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); - CLGEMMKernelType g77_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant); -}; -} // namespace cl_gemm -} // namespace arm_compute -#endif /* SRC_CLGEMMKERNELSELECTIONVALHALL_H */ -- cgit v1.2.1