From 59fd7a722e5bc7e85309d6200bc37a772721a719 Mon Sep 17 00:00:00 2001 From: Freddie Liardet Date: Thu, 17 Jun 2021 13:30:11 +0100 Subject: Add layer data to JSON output Add layer data information to SchedulerTimer JSON output. Resolves: COMPMID-4423 Change-Id: Ife78dee8afc0910cf47b135bc6809cc170ec4ed3 Signed-off-by: Freddie Liardet Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5923 Reviewed-by: Georgios Pinitas Comments-Addressed: Georgios Pinitas Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- tests/framework/instruments/Instrument.h | 11 +++++- tests/framework/instruments/Measurement.h | 10 ++--- tests/framework/instruments/SchedulerTimer.cpp | 52 +++++++++++++++++++++++--- tests/framework/instruments/SchedulerTimer.h | 5 ++- 4 files changed, 66 insertions(+), 12 deletions(-) (limited to 'tests/framework/instruments') diff --git a/tests/framework/instruments/Instrument.h b/tests/framework/instruments/Instrument.h index 3ea15825ad..1770a492ac 100644 --- a/tests/framework/instruments/Instrument.h +++ b/tests/framework/instruments/Instrument.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Arm Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -117,6 +117,15 @@ public: return MeasurementsMap(); } + /** Return JSON formatted instrument header string. + * + * @return JSON formatted string + */ + virtual std::string instrument_header() const + { + return std::string{}; + } + /** Return the latest test measurements. * * @return the latest test measurements. diff --git a/tests/framework/instruments/Measurement.h b/tests/framework/instruments/Measurement.h index af272a9945..2ec68d424b 100644 --- a/tests/framework/instruments/Measurement.h +++ b/tests/framework/instruments/Measurement.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 Arm Limited. + * Copyright (c) 2017-2018,2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -209,10 +209,10 @@ struct Measurement /** Stored value */ union - { - double floating_point; - long long int integer; - } v; + { + double floating_point; + long long int integer; + } v; bool is_floating_point; /**< Is the stored value floating point or integer ? */ }; diff --git a/tests/framework/instruments/SchedulerTimer.cpp b/tests/framework/instruments/SchedulerTimer.cpp index c31cd42d19..35f960d368 100644 --- a/tests/framework/instruments/SchedulerTimer.cpp +++ b/tests/framework/instruments/SchedulerTimer.cpp @@ -26,6 +26,7 @@ #include "Instruments.h" #include "WallClockTimer.h" #include "arm_compute/core/CPP/ICPPKernel.h" +#include "arm_compute/graph/DataLayerVisitor.h" #include "arm_compute/graph/INode.h" #include "support/Cast.h" @@ -53,8 +54,10 @@ class Interceptor final : public IScheduler { public: /** Default constructor. */ - Interceptor(std::list::kernel_info> &kernels, IScheduler &real_scheduler, ScaleFactor scale_factor) - : _kernels(kernels), _real_scheduler(real_scheduler), _timer(scale_factor), _prefix() + Interceptor(std::list::kernel_info> &kernels, + std::map &layers, IScheduler &real_scheduler, + ScaleFactor scale_factor) + : _kernels(kernels), _layer_data_map(layers), _real_scheduler(real_scheduler), _timer(scale_factor), _prefix() { } @@ -126,6 +129,7 @@ protected: private: std::list::kernel_info> &_kernels; + std::map &_layer_data_map; IScheduler &_real_scheduler; WallClock _timer; std::string _prefix; @@ -133,7 +137,8 @@ private: template SchedulerClock::SchedulerClock(ScaleFactor scale_factor) - : _kernels(), _real_scheduler(nullptr), _real_scheduler_type(), _real_graph_function(nullptr), _scale_factor(scale_factor), _interceptor(nullptr), _scheduler_users() + : _kernels(), _layer_data_map(), _real_scheduler(nullptr), _real_scheduler_type(), _real_graph_function(nullptr), + _scale_factor(scale_factor), _interceptor(nullptr), _scheduler_users() { if(instruments_info != nullptr) { @@ -156,6 +161,13 @@ void SchedulerClock::test_start() if(task.node != nullptr && !task.node->name().empty()) { scheduler->set_prefix(task.node->name() + "/"); + + if(_layer_data_map.find(task.node->name()) == _layer_data_map.end()) + { + arm_compute::graph::DataLayerVisitor dlv = {}; + task.node->accept(dlv); + _layer_data_map[task.node->name()] = dlv.layer_data(); + } } else { @@ -177,7 +189,7 @@ void SchedulerClock::test_start() if(_real_scheduler_type != Scheduler::Type::CUSTOM) { _real_scheduler = &Scheduler::get(); - _interceptor = std::make_shared>(_kernels, *_real_scheduler, _scale_factor); + _interceptor = std::make_shared>(_kernels, _layer_data_map, *_real_scheduler, _scale_factor); Scheduler::set(std::static_pointer_cast(_interceptor)); graph::TaskExecutor::get().execute_function = task_interceptor; @@ -188,7 +200,7 @@ void SchedulerClock::test_start() { if(user != nullptr && user->scheduler() != nullptr) { - user->intercept_scheduler(std::make_unique>(_kernels, *user->scheduler(), _scale_factor)); + user->intercept_scheduler(std::make_unique>(_kernels, _layer_data_map, *user->scheduler(), _scale_factor)); } }); } @@ -257,6 +269,36 @@ Instrument::MeasurementsMap SchedulerClock::measurements() co return measurements; } +template +std::string SchedulerClock::instrument_header() const +{ + std::string output{""}; + output += R"("layer_data" : {)"; + for(auto i_it = _layer_data_map.cbegin(), i_end = _layer_data_map.cend(); i_it != i_end; ++i_it) + { + output += "\"" + i_it->first + "\" : {"; + if(i_it->second.size() != 0) + { + // Print for each entry in layer + for(auto entry_it = i_it->second.cbegin(), entry_end = i_it->second.cend(); entry_it != entry_end; ++entry_it) + { + output += "\"" + entry_it->first + "\" : \"" + entry_it->second + "\""; + if(std::next(entry_it) != entry_end) + { + output += ","; + } + } + } + output += "}"; + if(std::next(i_it) != i_end) + { + output += ","; + } + } + output += "}"; + return output; +} + } // namespace framework } // namespace test } // namespace arm_compute diff --git a/tests/framework/instruments/SchedulerTimer.h b/tests/framework/instruments/SchedulerTimer.h index aa948d32a6..9cc0381a9a 100644 --- a/tests/framework/instruments/SchedulerTimer.h +++ b/tests/framework/instruments/SchedulerTimer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Arm Limited. + * Copyright (c) 2017-2019,2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -63,6 +63,7 @@ template class SchedulerClock : public Instrument { public: + using LayerData = std::map; /** Construct a Scheduler timer. * * @param[in] scale_factor Measurement scale factor. @@ -85,6 +86,7 @@ public: void start() override; void test_stop() override; Instrument::MeasurementsMap measurements() const override; + std::string instrument_header() const override; /** Kernel information */ struct kernel_info @@ -96,6 +98,7 @@ public: private: std::list _kernels; + std::map _layer_data_map; IScheduler *_real_scheduler; Scheduler::Type _real_scheduler_type; std::function _real_graph_function; -- cgit v1.2.1