From 1af5416917268692fcd4b34b1d7ffebd3a2aea8a Mon Sep 17 00:00:00 2001 From: SiCongLi Date: Wed, 6 Oct 2021 15:25:57 +0100 Subject: Add experimental PostOp interface to ClGemmMatrixMultiplyReshapedKernel Part 1 This interface supports the fusion of multiple elementwise operations Partially resolves: COMPMID-4435 Change-Id: If68dd7dd98dcf239fde7cb1f0a4a6d4d1e899a6f Signed-off-by: SiCongLi Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6483 Tested-by: Arm Jenkins Reviewed-by: Gian Marco Iodice Comments-Addressed: Arm Jenkins --- utils/TypePrinter.h | 163 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 151 insertions(+), 12 deletions(-) (limited to 'utils') diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h index 220c3ac189..64694f0e7c 100644 --- a/utils/TypePrinter.h +++ b/utils/TypePrinter.h @@ -36,12 +36,13 @@ #include "arm_compute/core/Strides.h" #include "arm_compute/core/TensorInfo.h" #include "arm_compute/core/Types.h" +#include "arm_compute/core/experimental/IPostOp.h" #include "arm_compute/runtime/CL/CLTunerTypes.h" #include "arm_compute/runtime/CL/CLTypes.h" #include "arm_compute/runtime/FunctionDescriptors.h" #include "arm_compute/runtime/common/LSTMParams.h" +#include "src/core/experimental/PostOp.h" #include "support/StringSupport.h" - #include #include #include @@ -135,6 +136,133 @@ std::string to_string(const std::vector &args) return str.str(); } +/** @name (EXPERIMENTAL_POST_OPS) + * @{ + */ +/** Formmated output of the @ref experimental::PostOpType type + * + * @param[out] os Output stream. + * @param[in] post_op_type Type to output. + * + * @return Modified output stream. + */ +inline ::std::ostream &operator<<(::std::ostream &os, experimental::PostOpType post_op_type) +{ + os << "type="; + switch(post_op_type) + { + case experimental::PostOpType::Activation: + { + os << "Activation"; + break; + } + case experimental::PostOpType::Eltwise_Add: + { + os << "Eltwise_Add"; + break; + } + default: + { + ARM_COMPUTE_ERROR("Unsupported PostOpType"); + break; + } + } + return os; +} +/** Converts a @ref experimental::PostOpType to string + * + * @param[in] post_op_type PostOpType value to be converted + * + * @return String representing the corresponding PostOpType + */ +inline std::string to_string(experimental::PostOpType post_op_type) +{ + std::stringstream str; + str << post_op_type; + return str.str(); +} +/** Formatted output of the @ref experimental::IPostOp type. + * + * @param[out] os Output stream. + * @param[in] post_op Type to output. + * + * @return Modified output stream. + */ +template +inline ::std::ostream &operator<<(::std::ostream &os, const experimental::IPostOp &post_op) +{ + os << "<"; + os << post_op.type() << ","; + os << "prev_op_arg_pos=" << post_op.prev_dst_pos() << ","; + switch(post_op.type()) + { + case experimental::PostOpType::Activation: + { + const auto _post_op = utils::cast::polymorphic_downcast *>(&post_op); + os << "act_info=" << &(_post_op->_act_info); + break; + } + case experimental::PostOpType::Eltwise_Add: + { + const auto _post_op = utils::cast::polymorphic_downcast *>(&post_op); + os << "convert_policy=" << _post_op->_policy; + break; + } + default: + { + ARM_COMPUTE_ERROR("Unsupported PostOpType"); + break; + } + } + os << ">"; + return os; +} +/** Converts an @ref experimental::IPostOp to string + * + * @param[in] post_op IPostOp value to be converted + * + * @return String representing the corresponding IPostOp + */ +template +inline std::string to_string(const experimental::IPostOp &post_op) +{ + std::stringstream str; + str << post_op; + return str.str(); +} +/** Formatted output of the @ref experimental::PostOpList type. + * + * @param[out] os Output stream. + * @param[in] post_ops Type to output. + * + * @return Modified output stream. + */ +template +inline ::std::ostream &operator<<(::std::ostream &os, const experimental::PostOpList &post_ops) +{ + os << "["; + for(const auto &post_op : post_ops.get_list()) + { + os << *post_op << ","; + } + os << "]"; + return os; +} +/** Converts a @ref experimental::PostOpList to string + * + * @param[in] post_ops PostOpList value to be converted + * + * @return String representing the corresponding PostOpList + */ +template +inline std::string to_string(const experimental::PostOpList &post_ops) +{ + std::stringstream str; + str << post_ops; + return str.str(); +} +/** @} */ // end of group (EXPERIMENTAL_POST_OPS) + /** Formatted output of the Dimensions type. * * @param[out] os Output stream. @@ -244,8 +372,9 @@ inline ::std::ostream &operator<<(::std::ostream &os, const GEMMKernelInfo &gemm os << " fp_mixed_precision= " << gemm_info.fp_mixed_precision; os << " mult_transpose1xW_width= " << gemm_info.mult_transpose1xW_width; os << " mult_interleave4x4_height= " << gemm_info.mult_interleave4x4_height; - os << " a_offset = " << gemm_info.a_offset; - os << " b_offset = " << gemm_info.b_offset; + os << " a_offset= " << gemm_info.a_offset; + os << " b_offset= " << gemm_info.b_offset; + os << "post_ops= " << gemm_info.post_ops; os << ")"; return os; } @@ -487,7 +616,7 @@ inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo: /** Formatted output of the activation function info type. * - * @param[in] info Type to output. + * @param[in] info ActivationLayerInfo to output. * * @return Formatted string. */ @@ -501,25 +630,35 @@ inline std::string to_string(const arm_compute::ActivationLayerInfo &info) return str.str(); } -/** Formatted output of the activation function info type. +/** Formatted output of the activation function info. * - * @param[in] info Type to output. + * @param[out] os Output stream. + * @param[in] info ActivationLayerInfo to output. * * @return Formatted string. */ -inline std::string to_string(const arm_compute::ActivationLayerInfo *info) +inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo *info) { - std::string ret_str = "nullptr"; if(info != nullptr) { - std::stringstream str; if(info->enabled()) { - str << info->activation(); + os << info->activation(); + os << "("; + os << "VAL_A=" << info->a() << ","; + os << "VAL_B=" << info->b(); + os << ")"; + } + else + { + os << "disabled"; } - ret_str = str.str(); } - return ret_str; + else + { + os << "nullptr"; + } + return os; } /** Formatted output of the activation function type. -- cgit v1.2.1