Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 Arm Limited. |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 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_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 Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 33 | #include "arm_compute/graph/Workload.h" |
| 34 | |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 35 | #include <list> |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace framework |
| 42 | { |
| 43 | /** Instrument creating measurements based on the information returned by clGetEventProfilingInfo for each OpenCL kernel executed*/ |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 44 | template <bool output_timestamps> |
| 45 | class OpenCLClock : public Instrument |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 46 | { |
| 47 | public: |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 48 | /** Construct an OpenCL timer. |
| 49 | * |
| 50 | * @param[in] scale_factor Measurement scale factor. |
| 51 | */ |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 52 | OpenCLClock(ScaleFactor scale_factor); |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 53 | std::string id() const override; |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 54 | void test_start() override; |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 55 | void start() override; |
Anthony Barbier | c483521 | 2018-05-16 14:20:04 +0100 | [diff] [blame] | 56 | void stop() override; |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 57 | void test_stop() override; |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 58 | MeasurementsMap measurements() const override; |
Anthony Barbier | e7f4a43 | 2018-11-09 10:58:40 +0000 | [diff] [blame] | 59 | MeasurementsMap test_measurements() const override; |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 60 | |
| 61 | private: |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 62 | #ifdef ARM_COMPUTE_CL |
| 63 | struct kernel_info |
| 64 | { |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 65 | ::cl::Event event{}; /**< OpenCL event associated to the kernel enqueue */ |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 66 | std::string name{}; /**< OpenCL Kernel name */ |
| 67 | }; |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 68 | std::list<kernel_info> _kernels; |
| 69 | std::function<decltype(clEnqueueNDRangeKernel)> _real_function; |
| 70 | std::function<decltype(graph::execute_task)> _real_graph_function; |
| 71 | std::string _prefix; |
Anthony Barbier | c483521 | 2018-05-16 14:20:04 +0100 | [diff] [blame] | 72 | bool _timer_enabled; |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 73 | #endif /* ARM_COMPUTE_CL */ |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 74 | |
| 75 | private: |
| 76 | float _scale_factor{}; |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 77 | }; |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 78 | |
| 79 | using OpenCLTimer = OpenCLClock<false>; |
| 80 | using OpenCLTimestamps = OpenCLClock<true>; |
| 81 | |
Anthony Barbier | 6e43349 | 2017-11-09 15:52:00 +0000 | [diff] [blame] | 82 | } // namespace framework |
| 83 | } // namespace test |
| 84 | } // namespace arm_compute |
| 85 | #endif /* ARM_COMPUTE_TEST_OPENCL_TIMER */ |