blob: 64adb488aee54ecf00e9b8b8515d13ed490001d3 [file] [log] [blame]
Anthony Barbiere8a49832018-01-18 10:04:05 +00001/*
2 * Copyright (c) 2017-2018 ARM Limited.
3 *
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>
32
33namespace arm_compute
34{
35namespace test
36{
37namespace framework
38{
39/** Instrument creating measurements based on the information returned by clGetEventProfilingInfo for each OpenCL kernel executed*/
Anthony Barbier72f4ae52018-11-07 17:33:54 +000040template <bool output_timestamps>
41class SchedulerClock : public Instrument
Anthony Barbiere8a49832018-01-18 10:04:05 +000042{
43public:
Alex Gildayc357c472018-03-21 13:54:09 +000044 /** Construct a Scheduler timer.
45 *
46 * @param[in] scale_factor Measurement scale factor.
47 */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000048 SchedulerClock(ScaleFactor scale_factor);
Alex Gildayc357c472018-03-21 13:54:09 +000049
50 /** Prevent instances of this class from being copy constructed */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000051 SchedulerClock(const SchedulerClock &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000052 /** Prevent instances of this class from being copied */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000053 SchedulerClock &operator=(const SchedulerClock &) = delete;
54 /** Use the default move assignment operator */
55 SchedulerClock &operator=(SchedulerClock &&) = default;
56 /** Use the default move constructor */
57 SchedulerClock(SchedulerClock &&) = default;
58 /** Use the default destructor */
59 ~SchedulerClock() = default;
Alex Gildayc357c472018-03-21 13:54:09 +000060
Anthony Barbiere8a49832018-01-18 10:04:05 +000061 std::string id() const override;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010062 void test_start() override;
Anthony Barbiere8a49832018-01-18 10:04:05 +000063 void start() override;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010064 void test_stop() override;
Anthony Barbiere8a49832018-01-18 10:04:05 +000065 Instrument::MeasurementsMap measurements() const override;
Alex Gildayc357c472018-03-21 13:54:09 +000066
67 /** Kernel information */
Anthony Barbiere8a49832018-01-18 10:04:05 +000068 struct kernel_info
69 {
70 Instrument::MeasurementsMap measurements{}; /**< Time it took the kernel to run */
71 std::string name{}; /**< Kernel name */
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010072 std::string prefix{}; /**< Kernel prefix */
Anthony Barbiere8a49832018-01-18 10:04:05 +000073 };
74
75private:
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010076 std::list<kernel_info> _kernels;
77 IScheduler *_real_scheduler;
78 Scheduler::Type _real_scheduler_type;
79 std::function<decltype(graph::execute_task)> _real_graph_function;
80 ScaleFactor _scale_factor;
81 std::shared_ptr<IScheduler> _interceptor;
Anthony Barbiere8a49832018-01-18 10:04:05 +000082};
Anthony Barbier72f4ae52018-11-07 17:33:54 +000083
84using SchedulerTimer = SchedulerClock<false>;
85using SchedulerTimestamps = SchedulerClock<true>;
86
Anthony Barbiere8a49832018-01-18 10:04:05 +000087} // namespace framework
88} // namespace test
89} // namespace arm_compute
90#endif /* ARM_COMPUTE_TEST_SCHEDULER_TIMER */