blob: 9cc0381a9afb5f132cb2db7a9ad56100393932e6 [file] [log] [blame]
Anthony Barbiere8a49832018-01-18 10:04:05 +00001/*
Freddie Liardet59fd7a72021-06-17 13:30:11 +01002 * Copyright (c) 2017-2019,2021 Arm Limited.
Anthony Barbiere8a49832018-01-18 10:04:05 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_TEST_SCHEDULER_TIMER
25#define ARM_COMPUTE_TEST_SCHEDULER_TIMER
26
27#include "Instrument.h"
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010028#include "arm_compute/graph/Workload.h"
Anthony Barbiere8a49832018-01-18 10:04:05 +000029#include "arm_compute/runtime/Scheduler.h"
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010030
Anthony Barbiere8a49832018-01-18 10:04:05 +000031#include <list>
Georgios Pinitas12833d02019-07-25 13:31:10 +010032#include <memory>
33#include <vector>
Anthony Barbiere8a49832018-01-18 10:04:05 +000034
35namespace arm_compute
36{
37namespace test
38{
39namespace framework
40{
Georgios Pinitas12833d02019-07-25 13:31:10 +010041/** Scheduler user interface */
42class ISchedulerUser
43{
44public:
45 /** Default Destructor */
46 virtual ~ISchedulerUser() = default;
47 /** Intercept the scheduler used by
48 *
49 * @param interceptor Intercept the scheduler used by the scheduler user.
50 */
51 virtual void intercept_scheduler(std::unique_ptr<IScheduler> interceptor) = 0;
52 /** Restore the original scheduler */
53 virtual void restore_scheduler() = 0;
54 /** Real scheduler accessor
55 *
56 * @return The real scheduler
57 */
58 virtual IScheduler *scheduler() = 0;
59};
60
Anthony Barbiere8a49832018-01-18 10:04:05 +000061/** Instrument creating measurements based on the information returned by clGetEventProfilingInfo for each OpenCL kernel executed*/
Anthony Barbier72f4ae52018-11-07 17:33:54 +000062template <bool output_timestamps>
63class SchedulerClock : public Instrument
Anthony Barbiere8a49832018-01-18 10:04:05 +000064{
65public:
Freddie Liardet59fd7a72021-06-17 13:30:11 +010066 using LayerData = std::map<std::string, std::string>;
Alex Gildayc357c472018-03-21 13:54:09 +000067 /** Construct a Scheduler timer.
68 *
69 * @param[in] scale_factor Measurement scale factor.
70 */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000071 SchedulerClock(ScaleFactor scale_factor);
Alex Gildayc357c472018-03-21 13:54:09 +000072 /** Prevent instances of this class from being copy constructed */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000073 SchedulerClock(const SchedulerClock &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000074 /** Prevent instances of this class from being copied */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000075 SchedulerClock &operator=(const SchedulerClock &) = delete;
76 /** Use the default move assignment operator */
77 SchedulerClock &operator=(SchedulerClock &&) = default;
78 /** Use the default move constructor */
79 SchedulerClock(SchedulerClock &&) = default;
80 /** Use the default destructor */
81 ~SchedulerClock() = default;
Alex Gildayc357c472018-03-21 13:54:09 +000082
Georgios Pinitas12833d02019-07-25 13:31:10 +010083 // Inherited overridden methods
Anthony Barbiere8a49832018-01-18 10:04:05 +000084 std::string id() const override;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010085 void test_start() override;
Anthony Barbiere8a49832018-01-18 10:04:05 +000086 void start() override;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010087 void test_stop() override;
Anthony Barbiere8a49832018-01-18 10:04:05 +000088 Instrument::MeasurementsMap measurements() const override;
Freddie Liardet59fd7a72021-06-17 13:30:11 +010089 std::string instrument_header() const override;
Alex Gildayc357c472018-03-21 13:54:09 +000090
91 /** Kernel information */
Anthony Barbiere8a49832018-01-18 10:04:05 +000092 struct kernel_info
93 {
94 Instrument::MeasurementsMap measurements{}; /**< Time it took the kernel to run */
95 std::string name{}; /**< Kernel name */
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010096 std::string prefix{}; /**< Kernel prefix */
Anthony Barbiere8a49832018-01-18 10:04:05 +000097 };
98
99private:
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100100 std::list<kernel_info> _kernels;
Freddie Liardet59fd7a72021-06-17 13:30:11 +0100101 std::map<std::string, LayerData> _layer_data_map;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100102 IScheduler *_real_scheduler;
103 Scheduler::Type _real_scheduler_type;
104 std::function<decltype(graph::execute_task)> _real_graph_function;
105 ScaleFactor _scale_factor;
106 std::shared_ptr<IScheduler> _interceptor;
Georgios Pinitas12833d02019-07-25 13:31:10 +0100107 std::vector<ISchedulerUser *> _scheduler_users;
Anthony Barbiere8a49832018-01-18 10:04:05 +0000108};
Anthony Barbier72f4ae52018-11-07 17:33:54 +0000109
110using SchedulerTimer = SchedulerClock<false>;
111using SchedulerTimestamps = SchedulerClock<true>;
112
Anthony Barbiere8a49832018-01-18 10:04:05 +0000113} // namespace framework
114} // namespace test
115} // namespace arm_compute
116#endif /* ARM_COMPUTE_TEST_SCHEDULER_TIMER */