aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamy Elgammal <ramelg01@e127066.cambridge.arm.com>2021-08-19 22:10:30 +0100
committerramy.elgammal <ramy.elgammal@arm.com>2021-09-01 14:16:20 +0000
commite920d6a62b8d96e08950e81bba769e8674d4921b (patch)
treeda8308b76a424f18c9b6a66ac39e446b21f64a0d
parentb1db6e16b7041af2212884ed8c6b3300a2a6a976 (diff)
downloadComputeLibrary-e920d6a62b8d96e08950e81bba769e8674d4921b.tar.gz
Printing operators parameters, currently for CpuAdd operator only.
Resolves: COMPMID-4718 Change-Id: Id4dd762cd1b759bb814b9d0b1ea0c9ba4dfbae6f Signed-off-by: Ramy Elgammal <ramy.elgammal@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6139 Reviewed-by: Giorgio Arena <giorgio.arena@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--arm_compute/core/utils/logging/Macros.h2
-rw-r--r--src/common/utils/Log.h112
-rw-r--r--src/cpu/operators/CpuAdd.cpp3
-rw-r--r--utils/TypePrinter.h13
4 files changed, 129 insertions, 1 deletions
diff --git a/arm_compute/core/utils/logging/Macros.h b/arm_compute/core/utils/logging/Macros.h
index 4900bf9e6b..0ab17c4464 100644
--- a/arm_compute/core/utils/logging/Macros.h
+++ b/arm_compute/core/utils/logging/Macros.h
@@ -74,7 +74,7 @@ inline std::string signature_name(const std::string &pretty_func)
{ \
size_t size = ::snprintf(nullptr, 0, fmt, __VA_ARGS__) + 1; \
auto char_str = std::make_unique<char[]>(size); \
- ::snprintf(char_str.get(), size, #fmt, __VA_ARGS__); \
+ ::snprintf(char_str.get(), size, fmt, __VA_ARGS__); \
__logger->log(log_level, std::string(char_str.get(), char_str.get() + size - 1)); \
} \
} while(false)
diff --git a/src/common/utils/Log.h b/src/common/utils/Log.h
index cfbc95a627..89e86bf2fc 100644
--- a/src/common/utils/Log.h
+++ b/src/common/utils/Log.h
@@ -26,6 +26,7 @@
#include "arm_compute/core/Error.h"
#include "arm_compute/core/utils/logging/Macros.h"
+#include "utils/TypePrinter.h"
#ifdef ARM_COMPUTE_LOGGING_ENABLED
/** Create a logger
@@ -102,4 +103,115 @@
ARM_COMPUTE_LOG_MSG_WITH_FUNCNAME("ComputeLibrary", arm_compute::logging::LogLevel::INFO, msg); \
} while(false)
+/** Function template specialization for the out of bound element at index = tuple_size
+ *
+ * @param[in,out] data_registry Reference to the input parameters data in a string format
+ * @param[in] in_params_tuple Tuple of different input data types
+ */
+template <std::size_t Index, typename... Tp>
+inline typename std::enable_if<Index == sizeof...(Tp), void>::type
+logParamsImpl(std::vector<std::string> &data_registry, const std::tuple<Tp...> &in_params_tuple)
+{
+ // Because it is out of bound index so do nothing
+ ARM_COMPUTE_UNUSED(data_registry);
+ ARM_COMPUTE_UNUSED(in_params_tuple);
+}
+
+/** Function template to iterate over all input parameters tuple at compile time:
+ *
+ * @param[in,out] data_registry Reference to a vector of input parameters data in a string format
+ * @param[in] in_params_tuple Constant reference to a tuple of different input data types
+ */
+template <std::size_t Index, typename... Tp>
+inline typename std::enable_if < Index<sizeof...(Tp), void>::type
+logParamsImpl(std::vector<std::string> &data_registry, const std::tuple<Tp...> &in_params_tuple)
+{
+ data_registry.push_back(arm_compute::to_string(std::get<Index>(in_params_tuple)));
+ // Unfold the next tuple element
+ logParamsImpl < Index + 1, Tp... > (data_registry, in_params_tuple);
+}
+
+/** Function Template with variable number of inputs to collect all the passed parameters from
+ * the logging macro ARM_COMPUTE_LOG_PARAMS(...)
+ *
+ * @param[in] ...ins The input parameters in the variadic template
+ *
+ * @return vector of the parameters' data in a string format
+ */
+template <typename... Ts>
+const std::vector<std::string> logParams(Ts... ins)
+{
+ std::vector<std::string> data_registry{};
+ std::tuple<Ts...> in_params_tuple(ins...);
+
+ // Start logging the tuple elements, starting from 0 to tuple_size-1
+ logParamsImpl<0>(data_registry, in_params_tuple);
+ return data_registry;
+}
+
+/** Inline function to parse the input parameters string passed from strignizing of the variadic macro input
+ * #__VA_ARGS__.
+ * It is Inline to avoid the redefinition of this function each time this header is included
+ *
+ * @param[in] in_params_str Constant reference to a string consists of the names of the input parameters provided
+ * as:ARM_COMPUTE_LOG_PARAMS(src0, src1) the params_names = "src0, src1"
+ *
+ * @return Vector of strings containing all the names of the input parameters
+ */
+inline const std::vector<std::string> getParamsNames(const std::string &in_params_str)
+{
+ std::stringstream ss(in_params_str);
+
+ // Vector containing all the names of the input parameters
+ std::vector<std::string> names;
+ std::string temp;
+
+ // Usually the input parameters string would be name of parameters separated
+ // by ',' e.g. "src0, src1, policy"
+ while(std::getline(ss, temp, ','))
+ {
+ names.push_back(temp);
+ }
+ for(auto &name : names)
+ {
+ // Totally get rid of white space characters
+ name.erase(std::remove(name.begin(), name.end(), ' '), name.end());
+ }
+ return names;
+}
+
+/** It constructs the log message to be displayed by the logger by writing each parameter name and its
+ * corresponding data info string.
+ *
+ * @param[in] params_names Constant reference to a string consists of the the input parameters' names
+ * provided e.g.: ARM_COMPUTE_LOG_PARAMS(src0, src1) then params_names = "src0, src1"
+ * @param[in] data_registry Constant reference to a registry of all parameters' data in string format,
+ * stringnized by arm_compute::to_string()
+ *
+ * @return Log message string to be displayed
+ */
+inline const std::string constructDataLog(const std::vector<std::string> &params_names,
+ const std::vector<std::string> &data_registry)
+{
+ std::string dataLog = "\n ";
+ ARM_COMPUTE_ERROR_ON(params_names.size() != data_registry.size());
+ for(uint8_t i = 0; i < params_names.size(); ++i)
+ {
+ dataLog += params_names[i] + ": " + data_registry.at(i) + "\n ";
+ }
+
+ return dataLog;
+}
+
+/** Macro for logging input Parameters from any function.
+ * It detects the input parameters names, and their corresponding values before stringizing them using
+ * the overloaded arm_compute::to_string() type printer. Finally, displayed using the printer configured
+ * in the logger.
+ *
+ * @param[in] ... Input parameters
+ */
+#define ARM_COMPUTE_LOG_PARAMS(...) \
+ ARM_COMPUTE_LOG_INFO_WITH_FUNCNAME_ACL(constructDataLog(getParamsNames(#__VA_ARGS__), \
+ logParams(__VA_ARGS__)));
+
#endif /* SRC_COMMON_LOG_H */
diff --git a/src/cpu/operators/CpuAdd.cpp b/src/cpu/operators/CpuAdd.cpp
index 42a7b99ceb..755b1994ae 100644
--- a/src/cpu/operators/CpuAdd.cpp
+++ b/src/cpu/operators/CpuAdd.cpp
@@ -25,12 +25,15 @@
#include "src/cpu/kernels/CpuAddKernel.h"
+#include "src/common/utils/Log.h"
+
namespace arm_compute
{
namespace cpu
{
void CpuAdd::configure(const ITensorInfo *src0, const ITensorInfo *src1, ITensorInfo *dst, ConvertPolicy policy, const ActivationLayerInfo &act_info)
{
+ ARM_COMPUTE_LOG_PARAMS(src0, src1, policy, act_info);
ARM_COMPUTE_UNUSED(act_info);
auto k = std::make_unique<kernels::CpuAddKernel>();
k->configure(src0, src1, dst, policy);
diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h
index 3ccba2c7e9..58ddb3f7bf 100644
--- a/utils/TypePrinter.h
+++ b/utils/TypePrinter.h
@@ -1056,6 +1056,19 @@ inline std::string to_string(const TensorInfo &info)
return str.str();
}
+/** Formatted output of the ITensorInfo* type.
+ *
+ * @param[in] info Type to output.
+ *
+ * @return Formatted string.
+ */
+inline std::string to_string(const ITensorInfo *info)
+{
+ std::stringstream str;
+ str << info;
+ return str.str();
+}
+
/** Formatted output of the Dimensions type.
*
* @param[in] dimensions Type to output.