blob: aa948d32a6ddfcd1b68b5a3326a15d9f2989bad3 [file] [log] [blame]
Anthony Barbiere8a49832018-01-18 10:04:05 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2019 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:
Alex Gildayc357c472018-03-21 13:54:09 +000066 /** Construct a Scheduler timer.
67 *
68 * @param[in] scale_factor Measurement scale factor.
69 */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000070 SchedulerClock(ScaleFactor scale_factor);
Alex Gildayc357c472018-03-21 13:54:09 +000071 /** Prevent instances of this class from being copy constructed */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000072 SchedulerClock(const SchedulerClock &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000073 /** Prevent instances of this class from being copied */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000074 SchedulerClock &operator=(const SchedulerClock &) = delete;
75 /** Use the default move assignment operator */
76 SchedulerClock &operator=(SchedulerClock &&) = default;
77 /** Use the default move constructor */
78 SchedulerClock(SchedulerClock &&) = default;
79 /** Use the default destructor */
80 ~SchedulerClock() = default;
Alex Gildayc357c472018-03-21 13:54:09 +000081
Georgios Pinitas12833d02019-07-25 13:31:10 +010082 // Inherited overridden methods
Anthony Barbiere8a49832018-01-18 10:04:05 +000083 std::string id() const override;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010084 void test_start() override;
Anthony Barbiere8a49832018-01-18 10:04:05 +000085 void start() override;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010086 void test_stop() override;
Anthony Barbiere8a49832018-01-18 10:04:05 +000087 Instrument::MeasurementsMap measurements() const override;
Alex Gildayc357c472018-03-21 13:54:09 +000088
89 /** Kernel information */
Anthony Barbiere8a49832018-01-18 10:04:05 +000090 struct kernel_info
91 {
92 Instrument::MeasurementsMap measurements{}; /**< Time it took the kernel to run */
93 std::string name{}; /**< Kernel name */
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010094 std::string prefix{}; /**< Kernel prefix */
Anthony Barbiere8a49832018-01-18 10:04:05 +000095 };
96
97private:
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010098 std::list<kernel_info> _kernels;
99 IScheduler *_real_scheduler;
100 Scheduler::Type _real_scheduler_type;
101 std::function<decltype(graph::execute_task)> _real_graph_function;
102 ScaleFactor _scale_factor;
103 std::shared_ptr<IScheduler> _interceptor;
Georgios Pinitas12833d02019-07-25 13:31:10 +0100104 std::vector<ISchedulerUser *> _scheduler_users;
Anthony Barbiere8a49832018-01-18 10:04:05 +0000105};
Anthony Barbier72f4ae52018-11-07 17:33:54 +0000106
107using SchedulerTimer = SchedulerClock<false>;
108using SchedulerTimestamps = SchedulerClock<true>;
109
Anthony Barbiere8a49832018-01-18 10:04:05 +0000110} // namespace framework
111} // namespace test
112} // namespace arm_compute
113#endif /* ARM_COMPUTE_TEST_SCHEDULER_TIMER */