blob: 1812272435da3bfbe2e233f30a307c83370065c5 [file] [log] [blame]
Anthony Barbier6e433492017-11-09 15:52:00 +00001/*
Georgios Pinitasb6af4822021-09-14 12:33:34 +01002 * Copyright (c) 2017-2018, 2021 Arm Limited.
Anthony Barbier6e433492017-11-09 15:52:00 +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_OPENCL_TIMER
25#define ARM_COMPUTE_TEST_OPENCL_TIMER
26
27#include "Instrument.h"
28
29#ifdef ARM_COMPUTE_CL
30#include "arm_compute/core/CL/OpenCL.h"
31#endif /* ARM_COMPUTE_CL */
32
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010033#include "arm_compute/graph/Workload.h"
34
Anthony Barbier6e433492017-11-09 15:52:00 +000035#include <list>
36
37namespace arm_compute
38{
39namespace test
40{
41namespace framework
42{
43/** Instrument creating measurements based on the information returned by clGetEventProfilingInfo for each OpenCL kernel executed*/
Anthony Barbier72f4ae52018-11-07 17:33:54 +000044template <bool output_timestamps>
45class OpenCLClock : public Instrument
Anthony Barbier6e433492017-11-09 15:52:00 +000046{
47public:
Alex Gildayc357c472018-03-21 13:54:09 +000048 /** Construct an OpenCL timer.
49 *
50 * @param[in] scale_factor Measurement scale factor.
51 */
Anthony Barbier72f4ae52018-11-07 17:33:54 +000052 OpenCLClock(ScaleFactor scale_factor);
Anthony Barbier6e433492017-11-09 15:52:00 +000053 std::string id() const override;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010054 void test_start() override;
Anthony Barbier6e433492017-11-09 15:52:00 +000055 void start() override;
Anthony Barbierc4835212018-05-16 14:20:04 +010056 void stop() override;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010057 void test_stop() override;
Anthony Barbier6e433492017-11-09 15:52:00 +000058 MeasurementsMap measurements() const override;
Anthony Barbiere7f4a432018-11-09 10:58:40 +000059 MeasurementsMap test_measurements() const override;
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010060
61private:
Anthony Barbier6e433492017-11-09 15:52:00 +000062#ifdef ARM_COMPUTE_CL
63 struct kernel_info
64 {
Anthony Barbier72f4ae52018-11-07 17:33:54 +000065 ::cl::Event event{}; /**< OpenCL event associated to the kernel enqueue */
Anthony Barbier6e433492017-11-09 15:52:00 +000066 std::string name{}; /**< OpenCL Kernel name */
67 };
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +010068 std::list<kernel_info> _kernels;
69 std::function<decltype(clEnqueueNDRangeKernel)> _real_function;
Georgios Pinitasb6af4822021-09-14 12:33:34 +010070#ifdef ARM_COMPUTE_GRAPH_ENABLED
71 std::function<decltype(graph::execute_task)> _real_graph_function;
72#endif /* ARM_COMPUTE_GRAPH_ENABLED */
73 std::string _prefix;
74 bool _timer_enabled;
Anthony Barbier6e433492017-11-09 15:52:00 +000075#endif /* ARM_COMPUTE_CL */
Giorgio Arenace58a9f2017-10-31 17:59:17 +000076
77private:
78 float _scale_factor{};
Anthony Barbier6e433492017-11-09 15:52:00 +000079};
Anthony Barbier72f4ae52018-11-07 17:33:54 +000080
81using OpenCLTimer = OpenCLClock<false>;
82using OpenCLTimestamps = OpenCLClock<true>;
83
Anthony Barbier6e433492017-11-09 15:52:00 +000084} // namespace framework
85} // namespace test
86} // namespace arm_compute
87#endif /* ARM_COMPUTE_TEST_OPENCL_TIMER */