From 554fa09a0f3d6c9c572634c9d2de9bfb6c3218b0 Mon Sep 17 00:00:00 2001 From: Keith Davis Date: Tue, 20 Jul 2021 11:25:22 +0100 Subject: IVGCVSW-5980 JSON profiling output * Add new ProfilingDetails class to construct operator details string * Add new macro which helps append layer details to ostream * Add ProfilingEnabled to NetworkProperties so that profiling can be realised when loading the network * Add further optional info to WorkloadInfo specific to convolutions * Generalise some JsonPrinter functions into JsonUtils for reusability * Remove explicit enabling of profiling within InferenceModel as it is done when loading network * Add ProfilingDetails macros to ConvolutionWorkloads for validation Signed-off-by: Keith Davis Change-Id: Ie84bc7dc667e72e6bcb635544f9ead7af1765690 --- src/armnn/Profiling.hpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/armnn/Profiling.hpp') diff --git a/src/armnn/Profiling.hpp b/src/armnn/Profiling.hpp index d134425b6c..785f50521e 100644 --- a/src/armnn/Profiling.hpp +++ b/src/armnn/Profiling.hpp @@ -5,6 +5,7 @@ #pragma once #include "ProfilingEvent.hpp" +#include "ProfilingDetails.hpp" #include #include "armnn/IProfiler.hpp" @@ -38,6 +39,14 @@ public: const std::string& name, std::vector&& instruments); + template + void AddLayerDetails(const std::string& label, + const DescriptorType& desc, + const WorkloadInfo& infos) + { + m_ProfilingDetails->AddDetailsToString(label, desc, infos); + } + // Marks the end of a user-defined event. void EndEvent(Event* event); @@ -61,6 +70,8 @@ public: uint32_t GetEventColor(const BackendId& backendId) const; using EventPtr = std::unique_ptr; + using DescPtr = std::unique_ptr; + struct Marker { std::size_t m_Id; @@ -83,6 +94,7 @@ public: std::stack m_Parents; std::vector m_EventSequence; + DescPtr m_ProfilingDetails = std::make_unique(); bool m_ProfilingEnabled; }; @@ -152,8 +164,39 @@ private: IProfiler* m_Profiler; ///< Profiler used }; +// Helper to easily add operator details during profiling. +class ScopedProfilingUpdateDescriptions +{ +public: + template + ScopedProfilingUpdateDescriptions(const std::string& name, const DescriptorType& desc, const WorkloadInfo& infos) + : m_Profiler(ProfilerManager::GetInstance().GetProfiler()) + { + if (m_Profiler && m_Profiler->IsProfilingEnabled()) + { + m_Profiler->AddLayerDetails(name, desc, infos); + } + } + + ~ScopedProfilingUpdateDescriptions() + {} + +private: + + IProfiler* m_Profiler; ///< Profiler used +}; + +template +void IProfiler::AddLayerDetails(const std::string& name, + const DescriptorType& desc, + const WorkloadInfo& infos) +{ + return pProfilerImpl->AddLayerDetails(name, desc, infos); +} + } // namespace armnn +// Event Definitions for profiling #define ARMNN_SCOPED_PROFILING_EVENT_WITH_INSTRUMENTS_UNIQUE_LOC_INNER(lineNumber, backendId, /*name,*/ ...) \ armnn::ScopedProfilingEvent e_ ## lineNumber(backendId, /*name,*/ __VA_ARGS__); @@ -172,3 +215,13 @@ private: #define ARMNN_SCOPED_PROFILING_EVENT(backendId, name) \ ARMNN_SCOPED_PROFILING_EVENT_WITH_INSTRUMENTS(backendId, name, armnn::WallClockTimer()) + +// Workload Description definitons for profiling +#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC_UNIQUE_LOC_INNER(lineNumber, name, desc, infos) \ + armnn::ScopedProfilingUpdateDescriptions e_ ## lineNumber(name, desc, infos); + +#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC_UNIQUE_LOC(lineNumber, name, desc, infos) \ + ARMNN_REPORT_PROFILING_WORKLOAD_DESC_UNIQUE_LOC_INNER(lineNumber, name, desc, infos) + +#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos) \ + ARMNN_REPORT_PROFILING_WORKLOAD_DESC_UNIQUE_LOC(__LINE__, name, desc, infos) -- cgit v1.2.1