From b46702118eddcfec11487be8dd23234066642d62 Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Fri, 18 May 2018 16:55:39 +0100 Subject: COMPMID-1181: Support for tracing configuration This patch adds support for tracing function and kernel configuration arguments. The trace is printed to stdout. To enable tracing run the script: scripts/enable_tracing.py and recompile the library with tracing=1. Change-Id: If6626785e263d9023899b20e175a53652d70a605 Signed-off-by: morgolock Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2712 Tested-by: Arm Jenkins Reviewed-by: Sang-Hoon Park Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- Android.bp | 5 + SConscript | 6 + SConstruct | 1 + arm_compute/core/TracePoint.h | 134 +++++++++++++++++++ scripts/clang_tidy_rules.py | 5 +- scripts/enable_tracing.py | 137 ++++++++++++++++++++ src/core/CL/CLTracePoint.cpp | 85 ++++++++++++ src/core/NEON/NETracePoint.cpp | 53 ++++++++ src/core/TracePoint.cpp | 285 +++++++++++++++++++++++++++++++++++++++++ src/runtime/CL/TracePoint.cpp | 41 ++++++ src/runtime/TracePoint.cpp | 49 +++++++ utils/TypePrinter.h | 8 +- 12 files changed, 807 insertions(+), 2 deletions(-) create mode 100644 arm_compute/core/TracePoint.h create mode 100755 scripts/enable_tracing.py create mode 100644 src/core/CL/CLTracePoint.cpp create mode 100644 src/core/NEON/NETracePoint.cpp create mode 100644 src/core/TracePoint.cpp create mode 100644 src/runtime/CL/TracePoint.cpp create mode 100644 src/runtime/TracePoint.cpp diff --git a/Android.bp b/Android.bp index 799398558..6acc1a71e 100644 --- a/Android.bp +++ b/Android.bp @@ -54,6 +54,7 @@ cc_library_static { "src/core/CL/CLCoreRuntimeContext.cpp", "src/core/CL/CLHelpers.cpp", "src/core/CL/CLKernelLibrary.cpp", + "src/core/CL/CLTracePoint.cpp", "src/core/CL/ICLDistribution1D.cpp", "src/core/CL/ICLHOG.cpp", "src/core/CL/ICLKernel.cpp", @@ -228,6 +229,7 @@ cc_library_static { "src/core/IKernel.cpp", "src/core/ITensor.cpp", "src/core/MultiImageInfo.cpp", + "src/core/NEON/NETracePoint.cpp", "src/core/NEON/kernels/NEAbsoluteDifferenceKernel.cpp", "src/core/NEON/kernels/NEAccumulateKernel.cpp", "src/core/NEON/kernels/NEActivationLayerKernel.cpp", @@ -402,6 +404,7 @@ cc_library_static { "src/core/Rounding.cpp", "src/core/SubTensorInfo.cpp", "src/core/TensorInfo.cpp", + "src/core/TracePoint.cpp", "src/core/Utils.cpp", "src/core/Validate.cpp", "src/core/Version.cpp", @@ -435,6 +438,7 @@ cc_library_static { "src/runtime/CL/CLTensorAllocator.cpp", "src/runtime/CL/CLTuner.cpp", "src/runtime/CL/ICLSimpleFunction.cpp", + "src/runtime/CL/TracePoint.cpp", "src/runtime/CL/functions/CLAbsoluteDifference.cpp", "src/runtime/CL/functions/CLAccumulate.cpp", "src/runtime/CL/functions/CLActivationLayer.cpp", @@ -734,6 +738,7 @@ cc_library_static { "src/runtime/SubTensor.cpp", "src/runtime/Tensor.cpp", "src/runtime/TensorAllocator.cpp", + "src/runtime/TracePoint.cpp", "src/runtime/Utils.cpp", "utils/CommonGraphOptions.cpp", "utils/GraphUtils.cpp", diff --git a/SConscript b/SConscript index 66dfff451..f3ae8c3c8 100644 --- a/SConscript +++ b/SConscript @@ -247,6 +247,12 @@ if env['gles_compute']: runtime_files += Glob('src/runtime/GLES_COMPUTE/functions/*.cpp') graph_files += Glob('src/graph/backends/GLES/*.cpp') +if env['tracing']: + arm_compute_env.Append(CPPDEFINES = ['ARM_COMPUTE_TRACING_ENABLED']) +else: + # Remove TracePoint files if tracing is disabled: + core_files = [ f for f in core_files if not "TracePoint" in str(f)] + runtime_files = [ f for f in runtime_files if not "TracePoint" in str(f)] bootcode_o = [] if env['os'] == 'bare_metal': diff --git a/SConstruct b/SConstruct index 0076a365e..09df1937a 100644 --- a/SConstruct +++ b/SConstruct @@ -55,6 +55,7 @@ vars.AddVariables( BoolVariable("gles_compute", "Enable OpenGL ES Compute Shader support", False), BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True), BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False), + BoolVariable("tracing", "Enable runtime tracing", False), BoolVariable("openmp", "Enable OpenMP backend", False), BoolVariable("cppthreads", "Enable C++11 threads backend", True), PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), diff --git a/arm_compute/core/TracePoint.h b/arm_compute/core/TracePoint.h new file mode 100644 index 000000000..6951d6d5e --- /dev/null +++ b/arm_compute/core/TracePoint.h @@ -0,0 +1,134 @@ +/* + * 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 ARM_COMPUTE_TRACEPOINT_H +#define ARM_COMPUTE_TRACEPOINT_H + +#include +#include +#include + +namespace arm_compute +{ +#ifdef ARM_COMPUTE_TRACING_ENABLED +#define CREATE_TRACEPOINT(...) TracePoint __tp(__VA_ARGS__) + +/** Class used to dump configuration values in functions and kernels */ +class TracePoint final +{ +public: + /** Layer types */ + enum class Layer + { + CORE, + RUNTIME + }; + /** struct describing the arguments for a tracepoint */ + struct Args final + { + std::vector args{}; + }; + /** Constructor + * + * @param[in] source type of layer for the tracepoint + * @param[in] class_name the name of the class creating the tracepoint + * @param[in] object a pointer to the actual object owning the tracepoint + * @param[in] args a struct describing all the arguments used in the call to the configure() method + * + */ + TracePoint(Layer source, const std::string &class_name, void *object, Args &&args); + /** Destructor */ + ~TracePoint(); + +private: + static int g_depth; /**< current depth */ + int _depth; /**< tracepoint depth */ +}; + +/** Operator to write an argument to a @ref TracePoint + * + * @param[in] tp Tracepoint to be used for writing + * @param[in] arg Argument to be written in the tracepoint + * + * @return A referece to the updated tracepoint + */ +template +TracePoint::Args &&operator<<(typename std::enable_if < !std::is_pointer::value, TracePoint::Args >::type &&tp, const T &arg); +template +TracePoint::Args &&operator<<(TracePoint::Args &&tp, const T *arg); + +#define CONST_REF_CLASS(type) \ + template <> \ + TracePoint::Args &&operator<<(TracePoint::Args &&tp, const type &arg) \ + { \ + ARM_COMPUTE_UNUSED(tp); \ + tp.args.push_back(#type "(" + to_string(arg) + ")"); \ + return std::move(tp); \ + } + +#define CONST_PTR_ADDRESS(type) \ + template <> \ + TracePoint::Args &&operator<<(TracePoint::Args &&tp, const type *arg) \ + { \ + ARM_COMPUTE_UNUSED(tp); \ + tp.args.push_back(#type "*(" + to_ptr_string(arg) + ")"); \ + return std::move(tp); \ + } +#define CONST_PTR_CLASS(type) \ + template <> \ + TracePoint::Args &&operator<<(TracePoint::Args &&tp, const type *arg) \ + { \ + ARM_COMPUTE_UNUSED(tp); \ + if(arg) \ + tp.args.push_back(#type "(" + to_string(*arg) + ")"); \ + else \ + tp.args.push_back(#type "( nullptr )"); \ + return std::move(tp); \ + } + +#define CONST_REF_SIMPLE(type) \ + template <> \ + TracePoint::Args &&operator<<(TracePoint::Args &&tp, const type &arg) \ + { \ + ARM_COMPUTE_UNUSED(tp); \ + tp.args.push_back(#type "(" + support::cpp11::to_string(arg) + ")"); \ + return std::move(tp); \ + } + +#define TRACE_TO_STRING(type) \ + std::string to_string(const type &arg) \ + { \ + ARM_COMPUTE_UNUSED(arg); \ + return ""; \ + } +#else /* ARM_COMPUTE_TRACING_ENABLED */ +#define CREATE_TRACEPOINT(...) +#define CONST_REF_CLASS(type) +#define CONST_PTR_ADDRESS(type) +#define CONST_PTR_CLASS(type) +#define CONST_REF_SIMPLE(type) +#define TRACE_TO_STRING(type) +#endif /* ARM_COMPUTE_TRACING_ENABLED */ +} //namespace arm_compute + +#endif /* ARM_COMPUTE_TRACEPOINT_H */ diff --git a/scripts/clang_tidy_rules.py b/scripts/clang_tidy_rules.py index 99bc5a63c..8d448ad92 100755 --- a/scripts/clang_tidy_rules.py +++ b/scripts/clang_tidy_rules.py @@ -28,7 +28,10 @@ def filter_files( list_files ): if os.path.splitext(f)[1] != ".cpp": continue # Skip OMPScheduler as it causes problems in clang - if "OMPScheduler.cpp" in f: + if (("OMPScheduler.cpp" in f) or + ("CLTracePoint.cpp" in f) or + ("NETracePoint.cpp" in f) or + ("TracePoint.cpp" in f)): continue to_check.append(f) return to_check diff --git a/scripts/enable_tracing.py b/scripts/enable_tracing.py new file mode 100755 index 000000000..3379e532f --- /dev/null +++ b/scripts/enable_tracing.py @@ -0,0 +1,137 @@ +# +# 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. +# +# +#!/usr/bin/env python +import re +import os +import sys +import argparse +import fnmatch +import logging + +import json +import glob + +logger = logging.getLogger("acl_tracing") + +# Returns the files matching the given pattern +def find(path, pattern): + matches = [] + for root, dirnames, filenames, in os.walk(path): + for filename in fnmatch.filter(filenames, pattern): + matches.append(os.path.join(root,filename)) + return matches + +# Returns the class name (Core or Runtime) and arguments of the given function +def get_class_and_args(function): + decl = " ".join(function_signature) + m = re.match("void ([^:]+)::configure\(([^)]*)\)", decl) + if m: + assert m, "Can't parse '%s'" % line + class_name = m.group(1) + args = m.group(2) + #Remove comments: + args = re.sub("\/\*.*?\*\/","",args) + #Remove templates + args = re.sub("<.*?>","",args) + logger.debug(args) + arg_names = [] + for arg in args.split(","): + m = re.match(".*?([^ &*]+)$", arg.strip()) + arg_names.append(m.group(1)) + logger.debug(" %s" % m.group(1)) + return (class_name, arg_names) + else: + return ('','') + +# Adds the tracepoints to the source file for the given function +def do_insert_tracing(source, function, fd): + logger.debug("Full signature = %s" % " ".join(function_signature)) + class_name, arg_names = get_class_and_args(function) + if len(arg_names): + assert len(arg_names), "No argument to configure for %s ?" % class_name + spaces = re.match("([ ]*)void", function[0]).group(1) + fd.write("%s CREATE_TRACEPOINT(%s, \"%s\", this, TracePoint::Args()" % (spaces, source, class_name)) + for arg in arg_names: + fd.write("<<%s" % arg) + fd.write(");\n") + else: + print('Failed to get class name in %s ' % " ".join(function_signature)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description="Post process JSON benchmark files", + ) + + parser.add_argument("-D", "--debug", action='store_true', help="Enable script debugging output") + args = parser.parse_args() + logging_level = logging.INFO + if args.debug: + logging_level = logging.DEBUG + logging.basicConfig(level=logging_level) + logger.debug("Arguments passed: %s" % str(args.__dict__)) + for f in find("src","*.cpp"): + logger.debug(f) + fd = open(f,'r+') + lines = fd.readlines() + contains_configure = False + for line in lines: + if re.search(r"void.*::configure\(",line): + contains_configure = True + break + if not contains_configure: + continue + fd.seek(0) + fd.truncate() + function_signature = None + insert_tracing = False + start = True + for line in lines: + write = True + if start: + if not (line.startswith("/*") or line.startswith(" *") or line.startswith("#") or len(line.strip()) == 0): + start = False + fd.write("#include \"arm_compute/core/TracePoint.h\"\n") + elif not function_signature: + if re.search(r"void.*::configure\(",line): + function_signature = [ line.rstrip() ] + else: + if re.search("[ ]*{$", line): + insert_tracing = True + else: + function_signature.append(line.rstrip()) + if write: + fd.write(line) + if insert_tracing: + if "/core/" in f: + source = "TracePoint::Layer::CORE" + elif "/runtime/" in f: + source = "TracePoint::Layer::RUNTIME" + else: + assert "Can't find layer for file %s" %f + do_insert_tracing(source, function_signature, fd) + insert_tracing = False + function_signature = None diff --git a/src/core/CL/CLTracePoint.cpp b/src/core/CL/CLTracePoint.cpp new file mode 100644 index 000000000..b459cfbf3 --- /dev/null +++ b/src/core/CL/CLTracePoint.cpp @@ -0,0 +1,85 @@ +/* + * 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 "arm_compute/core/TracePoint.h" + +#include "arm_compute/core/CL/ICLArray.h" +#include "arm_compute/core/CL/ICLDistribution1D.h" +#include "arm_compute/core/CL/ICLHOG.h" +#include "arm_compute/core/CL/ICLLut.h" +#include "arm_compute/core/CL/ICLMultiHOG.h" +#include "arm_compute/core/CL/ICLMultiImage.h" +#include "arm_compute/core/CL/ICLTensor.h" +#include "arm_compute/core/CL/kernels/CLLKTrackerKernel.h" +#include "utils/TypePrinter.h" + +#include + +namespace arm_compute +{ +std::string to_string(const ICLTensor &arg) +{ + std::stringstream str; + str << "TensorInfo(" << *arg.info() << ")"; + return str.str(); +} + +template <> +TracePoint::Args &&operator<<(TracePoint::Args &&tp, const ICLTensor *arg) +{ + tp.args.push_back("ICLTensor(" + to_string_if_not_null(arg) + ")"); + return std::move(tp); +} + +TRACE_TO_STRING(std::vector) +TRACE_TO_STRING(ICLMultiImage) +TRACE_TO_STRING(ICLDetectionWindowArray) +TRACE_TO_STRING(ICLKeyPointArray) +TRACE_TO_STRING(ICLLKInternalKeypointArray) +TRACE_TO_STRING(ICLCoefficientTableArray) +TRACE_TO_STRING(ICLCoordinates2DArray) +TRACE_TO_STRING(ICLOldValArray) +TRACE_TO_STRING(cl::Buffer) +TRACE_TO_STRING(ICLDistribution1D) +TRACE_TO_STRING(ICLMultiHOG) +TRACE_TO_STRING(ICLHOG) +TRACE_TO_STRING(ICLLut) +TRACE_TO_STRING(ICLSize2DArray) +TRACE_TO_STRING(std::vector) + +CONST_PTR_CLASS(std::vector) +CONST_PTR_CLASS(ICLMultiImage) +CONST_PTR_CLASS(ICLDetectionWindowArray) +CONST_PTR_CLASS(ICLKeyPointArray) +CONST_PTR_CLASS(ICLLKInternalKeypointArray) +CONST_PTR_CLASS(ICLCoefficientTableArray) +CONST_PTR_CLASS(ICLCoordinates2DArray) +CONST_PTR_CLASS(ICLOldValArray) +CONST_PTR_CLASS(cl::Buffer) +CONST_PTR_CLASS(ICLDistribution1D) +CONST_PTR_CLASS(ICLMultiHOG) +CONST_PTR_CLASS(ICLHOG) +CONST_PTR_CLASS(ICLLut) +CONST_PTR_CLASS(ICLSize2DArray) +CONST_PTR_CLASS(std::vector) +} // namespace arm_compute diff --git a/src/core/NEON/NETracePoint.cpp b/src/core/NEON/NETracePoint.cpp new file mode 100644 index 000000000..298c6f410 --- /dev/null +++ b/src/core/NEON/NETracePoint.cpp @@ -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. + */ +#include "arm_compute/core/TracePoint.h" + +#include "arm_compute/core/NEON/kernels/NELKTrackerKernel.h" +#include "arm_compute/core/NEON/kernels/assembly/INEGEMMWrapperKernel.h" +#include "arm_compute/core/NEON/kernels/convolution/common/convolution.hpp" +#include "utils/TypePrinter.h" + +#include + +namespace arm_compute +{ +std::string to_string(const PaddingType &arg) +{ + return ((arg == PADDING_SAME) ? "PADDING_SAME" : "PADDING_VALID"); +} + +TRACE_TO_STRING(INELKInternalKeypointArray) +TRACE_TO_STRING(std::unique_ptr) + +CONST_PTR_CLASS(INELKInternalKeypointArray) +CONST_PTR_CLASS(std::unique_ptr) + +template <> +TracePoint::Args &&operator<<(TracePoint::Args &&tp, const PaddingType &arg) +{ + tp.args.push_back("PaddingType(" + to_string(arg) + ")"); + return std::move(tp); +} + +} // namespace arm_compute diff --git a/src/core/TracePoint.cpp b/src/core/TracePoint.cpp new file mode 100644 index 000000000..b5c18186b --- /dev/null +++ b/src/core/TracePoint.cpp @@ -0,0 +1,285 @@ +/* + * 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 "arm_compute/core/TracePoint.h" + +#include "arm_compute/core/HOGInfo.h" +#include "arm_compute/core/IArray.h" +#include "arm_compute/core/IDistribution1D.h" +#include "arm_compute/core/IHOG.h" +#include "arm_compute/core/ILut.h" +#include "arm_compute/core/IMultiHOG.h" +#include "arm_compute/core/IMultiImage.h" +#include "arm_compute/core/IPyramid.h" +#include "arm_compute/core/ITensor.h" +#include "arm_compute/core/KernelDescriptors.h" +#include "arm_compute/core/NEON/kernels/assembly/arm_gemm.hpp" +#include "arm_compute/core/PixelValue.h" +#include "arm_compute/core/Window.h" +#include "arm_compute/runtime/FunctionDescriptors.h" +#include "arm_compute/runtime/IWeightsManager.h" +#include "arm_compute/runtime/MemoryGroup.h" +#include "utils/TypePrinter.h" + +#include +#include + +namespace arm_compute +{ +#ifndef DOXYGEN_SKIP_THIS +int TracePoint::g_depth = 0; + +TracePoint::TracePoint(Layer layer, const std::string &class_name, void *object, Args &&args) + : _depth(++g_depth) +{ + ARM_COMPUTE_UNUSED(layer, object, args); + const std::string indentation = " "; + std::string prefix = ""; + for(int i = 0; i < _depth; ++i) + { + prefix += indentation; + prefix += indentation; + } + printf("%s%s::configure(", prefix.c_str(), class_name.c_str()); + for(auto &arg : args.args) + { + printf("\n%s%s%s", prefix.c_str(), indentation.c_str(), arg.c_str()); + } + printf("\n%s)\n", prefix.c_str()); +} + +TracePoint::~TracePoint() +{ + --g_depth; +} + +std::string to_string(const arm_gemm::Activation &arg) +{ + switch(arg.type) + { + case arm_gemm::Activation::Type::None: + return "None"; + case arm_gemm::Activation::Type::ReLU: + return "ReLU"; + case arm_gemm::Activation::Type::BoundedReLU: + return "BoundedReLU"; + default: + ARM_COMPUTE_ERROR("Not supported"); + return "Uknown"; + }; +} + +std::string to_string(const arm_gemm::GemmArgs &arg) +{ + std::stringstream str; + for(size_t k = 0; k < arg._ci->get_cpu_num(); ++k) + { + str << "[CPUCore " << k << "]" << to_string(arg._ci->get_cpu_model(0)) << " "; + } + str << "Msize= " << arg._Msize << " "; + str << "Nsize= " << arg._Nsize << " "; + str << "Ksize= " << arg._Ksize << " "; + str << "nbatches= " << arg._nbatches << " "; + str << "nmulti= " << arg._nmulti << " "; + str << "trA= " << arg._trA << " "; + str << "trB= " << arg._trB << " "; + str << "Activation= " << to_string(arg._act) << " "; + str << "maxthreads= " << arg._maxthreads << " "; + str << "pretransposed_hint= " << arg._pretransposed_hint << " "; + return str.str(); +} + +std::string to_string(const ITensor &arg) +{ + std::stringstream str; + str << "TensorInfo(" << *arg.info() << ")"; + return str.str(); +} + +std::string to_ptr_string(const void *arg) +{ + std::stringstream ss; + ss << arg; + return ss.str(); +} + +TRACE_TO_STRING(ThresholdType) +TRACE_TO_STRING(IDetectionWindowArray) +TRACE_TO_STRING(ICoordinates2DArray) +TRACE_TO_STRING(IMultiImage) +using pair_uint = std::pair; +TRACE_TO_STRING(pair_uint) +TRACE_TO_STRING(IKeyPointArray) +TRACE_TO_STRING(IDistribution1D) +TRACE_TO_STRING(IHOG) +TRACE_TO_STRING(ILut) +TRACE_TO_STRING(IPyramid) +TRACE_TO_STRING(IMultiHOG) +TRACE_TO_STRING(ISize2DArray) +TRACE_TO_STRING(MemoryGroup) +TRACE_TO_STRING(BoxNMSLimitInfo) +TRACE_TO_STRING(DepthwiseConvolutionReshapeInfo) +TRACE_TO_STRING(DWCWeightsKernelInfo) +TRACE_TO_STRING(DWCKernelInfo) +TRACE_TO_STRING(GEMMLHSMatrixInfo) +TRACE_TO_STRING(GEMMRHSMatrixInfo) +TRACE_TO_STRING(GEMMKernelInfo) +TRACE_TO_STRING(InstanceNormalizationLayerKernelInfo) +TRACE_TO_STRING(SoftmaxKernelInfo) +TRACE_TO_STRING(FuseBatchNormalizationType) +TRACE_TO_STRING(DirectConvolutionLayerOutputStageKernelInfo) +TRACE_TO_STRING(FFTScaleKernelInfo) +TRACE_TO_STRING(GEMMLowpOutputStageInfo) +TRACE_TO_STRING(FFT1DInfo) +TRACE_TO_STRING(FFT2DInfo) +TRACE_TO_STRING(FFTDigitReverseKernelInfo) +TRACE_TO_STRING(FFTRadixStageKernelInfo) +TRACE_TO_STRING(IWeightsManager) +TRACE_TO_STRING(Coordinates2D) +TRACE_TO_STRING(ITensorInfo) +TRACE_TO_STRING(InternalKeypoint) +TRACE_TO_STRING(arm_gemm::Nothing) +TRACE_TO_STRING(PixelValue) +TRACE_TO_STRING(std::allocator) +using array_f32 = std::array; +TRACE_TO_STRING(array_f32) + +CONST_REF_CLASS(arm_gemm::GemmArgs) +CONST_REF_CLASS(arm_gemm::Nothing) +CONST_REF_CLASS(arm_gemm::Activation) +CONST_REF_CLASS(DirectConvolutionLayerOutputStageKernelInfo) +CONST_REF_CLASS(GEMMLowpOutputStageInfo) +CONST_REF_CLASS(DWCWeightsKernelInfo) +CONST_REF_CLASS(DWCKernelInfo) +CONST_REF_CLASS(DepthwiseConvolutionReshapeInfo) +CONST_REF_CLASS(GEMMLHSMatrixInfo) +CONST_REF_CLASS(GEMMRHSMatrixInfo) +CONST_REF_CLASS(GEMMKernelInfo) +CONST_REF_CLASS(InstanceNormalizationLayerKernelInfo) +CONST_REF_CLASS(SoftmaxKernelInfo) +CONST_REF_CLASS(PaddingMode) +CONST_REF_CLASS(Coordinates) +CONST_REF_CLASS(FFT1DInfo) +CONST_REF_CLASS(FFT2DInfo) +CONST_REF_CLASS(FFTDigitReverseKernelInfo) +CONST_REF_CLASS(FFTRadixStageKernelInfo) +CONST_REF_CLASS(FFTScaleKernelInfo) +CONST_REF_CLASS(MemoryGroup) +CONST_REF_CLASS(IWeightsManager) +CONST_REF_CLASS(ActivationLayerInfo) +CONST_REF_CLASS(PoolingLayerInfo) +CONST_REF_CLASS(PadStrideInfo) +CONST_REF_CLASS(NormalizationLayerInfo) +CONST_REF_CLASS(Size2D) +CONST_REF_CLASS(WeightsInfo) +CONST_REF_CLASS(GEMMInfo) +CONST_REF_CLASS(GEMMReshapeInfo) +CONST_REF_CLASS(Window) +CONST_REF_CLASS(BorderSize) +CONST_REF_CLASS(BorderMode) +CONST_REF_CLASS(PhaseType) +CONST_REF_CLASS(MagnitudeType) +CONST_REF_CLASS(Termination) +CONST_REF_CLASS(ReductionOperation) +CONST_REF_CLASS(InterpolationPolicy) +CONST_REF_CLASS(SamplingPolicy) +CONST_REF_CLASS(DataType) +CONST_REF_CLASS(DataLayout) +CONST_REF_CLASS(Channel) +CONST_REF_CLASS(ConvertPolicy) +CONST_REF_CLASS(TensorShape) +CONST_REF_CLASS(PixelValue) +CONST_REF_CLASS(Strides) +CONST_REF_CLASS(WinogradInfo) +CONST_REF_CLASS(RoundingPolicy) +CONST_REF_CLASS(MatrixPattern) +CONST_REF_CLASS(NonLinearFilterFunction) +CONST_REF_CLASS(ThresholdType) +CONST_REF_CLASS(ROIPoolingLayerInfo) +CONST_REF_CLASS(BoundingBoxTransformInfo) +CONST_REF_CLASS(ComparisonOperation) +CONST_REF_CLASS(ArithmeticOperation) +CONST_REF_CLASS(BoxNMSLimitInfo) +CONST_REF_CLASS(FuseBatchNormalizationType) +CONST_REF_CLASS(ElementWiseUnary) +CONST_REF_CLASS(ComputeAnchorsInfo) +CONST_REF_CLASS(PriorBoxLayerInfo) +CONST_REF_CLASS(DetectionOutputLayerInfo) +CONST_REF_CLASS(Coordinates2D) +CONST_REF_CLASS(std::vector) +CONST_REF_CLASS(std::vector) +CONST_REF_CLASS(std::vector) +CONST_REF_CLASS(pair_uint) +CONST_REF_CLASS(array_f32) + +CONST_PTR_CLASS(ITensor) +CONST_PTR_CLASS(ITensorInfo) +CONST_PTR_CLASS(IWeightsManager) +CONST_PTR_CLASS(InternalKeypoint) +CONST_PTR_CLASS(IDetectionWindowArray) +CONST_PTR_CLASS(ICoordinates2DArray) +CONST_PTR_CLASS(IMultiImage) +CONST_PTR_CLASS(Window) +CONST_PTR_CLASS(IKeyPointArray) +CONST_PTR_CLASS(HOGInfo) +CONST_PTR_CLASS(IDistribution1D) +CONST_PTR_CLASS(IHOG) +CONST_PTR_CLASS(ILut) +CONST_PTR_CLASS(IPyramid) +CONST_PTR_CLASS(IMultiHOG) +CONST_PTR_CLASS(ISize2DArray) +CONST_PTR_CLASS(std::allocator) +CONST_PTR_CLASS(std::vector) + +CONST_REF_SIMPLE(bool) +CONST_REF_SIMPLE(uint64_t) +CONST_REF_SIMPLE(int64_t) +CONST_REF_SIMPLE(uint32_t) +CONST_REF_SIMPLE(int32_t) +CONST_REF_SIMPLE(int16_t) +CONST_REF_SIMPLE(float) + +CONST_PTR_ADDRESS(float) +CONST_PTR_ADDRESS(uint8_t) +CONST_PTR_ADDRESS(void) +CONST_PTR_ADDRESS(short) +CONST_PTR_ADDRESS(int) +CONST_PTR_ADDRESS(uint64_t) +CONST_PTR_ADDRESS(uint32_t) +CONST_PTR_ADDRESS(uint16_t) + +template <> +TracePoint::Args &&operator<<(TracePoint::Args &&tp, const uint16_t &arg) +{ + tp.args.push_back("uint16_t(" + support::cpp11::to_string(arg) + ")"); + return std::move(tp); +} + +template <> +TracePoint::Args &&operator<<(TracePoint::Args &&tp, const uint8_t &arg) +{ + tp.args.push_back("uint8_t(" + support::cpp11::to_string(arg) + ")"); + return std::move(tp); +} +#endif /* DOXYGEN_SKIP_THIS */ +} // namespace arm_compute diff --git a/src/runtime/CL/TracePoint.cpp b/src/runtime/CL/TracePoint.cpp new file mode 100644 index 000000000..97029f532 --- /dev/null +++ b/src/runtime/CL/TracePoint.cpp @@ -0,0 +1,41 @@ +/* + * 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 "arm_compute/core/TracePoint.h" +#include "arm_compute/runtime/CL/CLArray.h" +#include "arm_compute/runtime/CL/CLPyramid.h" +#include "arm_compute/runtime/CL/functions/CLLSTMLayer.h" +#include "utils/TypePrinter.h" + +#include +#include + +namespace arm_compute +{ +TRACE_TO_STRING(CLPyramid) +TRACE_TO_STRING(LSTMParams) +TRACE_TO_STRING(CLCoordinates2DArray) +CONST_PTR_CLASS(CLPyramid) +CONST_PTR_CLASS(LSTMParams) +CONST_PTR_CLASS(CLCoordinates2DArray) +} // namespace arm_compute diff --git a/src/runtime/TracePoint.cpp b/src/runtime/TracePoint.cpp new file mode 100644 index 000000000..817d63bdf --- /dev/null +++ b/src/runtime/TracePoint.cpp @@ -0,0 +1,49 @@ +/* + * 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 "arm_compute/core/TracePoint.h" +#include +#include + +#include "arm_compute/core/NEON/kernels/assembly/arm_gemm.hpp" +#include "arm_compute/runtime/Array.h" +#include "arm_compute/runtime/Pyramid.h" +#include "arm_compute/runtime/common/LSTMParams.h" +#include "utils/TypePrinter.h" + +namespace arm_compute +{ +TRACE_TO_STRING(KeyPointArray) +TRACE_TO_STRING(Pyramid) +TRACE_TO_STRING(LSTMParams) +TRACE_TO_STRING(FullyConnectedLayerInfo) +TRACE_TO_STRING(arm_gemm::Requantize32) + +CONST_PTR_CLASS(KeyPointArray) +CONST_PTR_CLASS(Pyramid) +CONST_PTR_CLASS(LSTMParams) +CONST_PTR_CLASS(DetectionPostProcessLayerInfo) +CONST_PTR_CLASS(FullyConnectedLayerInfo) +CONST_PTR_CLASS(GenerateProposalsInfo) +CONST_PTR_CLASS(arm_gemm::Requantize32) +} // namespace arm_compute diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h index 79ec367a5..b62bd69a8 100644 --- a/utils/TypePrinter.h +++ b/utils/TypePrinter.h @@ -59,6 +59,7 @@ std::string to_string_if_not_null(T *arg) return to_string(*arg); } } + /** Formatted output of the Dimensions type. * * @param[out] os Output stream. @@ -1091,7 +1092,12 @@ inline ::std::ostream &operator<<(::std::ostream &os, const GEMMInfo &info) os << "{is_a_reshaped=" << info.is_a_reshaped() << ","; os << "is_b_reshaped=" << info.is_b_reshaped() << ","; os << "reshape_b_only_on_first_run=" << info.reshape_b_only_on_first_run() << ","; - os << "}"; + os << "depth_output_gemm3d=" << info.depth_output_gemm3d() << ","; + os << "reinterpret_input_as_3d=" << info.reinterpret_input_as_3d() << ","; + os << "retain_internal_weights=" << info.retain_internal_weights() << ","; + os << "fp_mixed_precision=" << info.fp_mixed_precision() << ","; + os << "broadcast_bias=" << info.broadcast_bias() << ","; + os << "pretranpose_B=" << info.pretranpose_B() << ","; return os; } -- cgit v1.2.3