Compute Library
 21.05
OpenCLTimer.h
Go to the documentation of this file.
1 /*
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_OPENCL_TIMER
25 #define ARM_COMPUTE_TEST_OPENCL_TIMER
26 
27 #include "Instrument.h"
28 
29 #ifdef ARM_COMPUTE_CL
31 #endif /* ARM_COMPUTE_CL */
32 
34 
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*/
44 template <bool output_timestamps>
45 class OpenCLClock : public Instrument
46 {
47 public:
48  /** Construct an OpenCL timer.
49  *
50  * @param[in] scale_factor Measurement scale factor.
51  */
52  OpenCLClock(ScaleFactor scale_factor);
53  std::string id() const override;
54  void test_start() override;
55  void start() override;
56  void stop() override;
57  void test_stop() override;
58  MeasurementsMap measurements() const override;
59  MeasurementsMap test_measurements() const override;
60 
61 private:
62 #ifdef ARM_COMPUTE_CL
63  struct kernel_info
64  {
65  ::cl::Event event{}; /**< OpenCL event associated to the kernel enqueue */
66  std::string name{}; /**< OpenCL Kernel name */
67  };
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;
72  bool _timer_enabled;
73 #endif /* ARM_COMPUTE_CL */
74 
75 private:
76  float _scale_factor{};
77 };
78 
81 
82 } // namespace framework
83 } // namespace test
84 } // namespace arm_compute
85 #endif /* ARM_COMPUTE_TEST_OPENCL_TIMER */
void stop() override
Stop measuring.
OpenCLClock(ScaleFactor scale_factor)
Construct an OpenCL timer.
Definition: OpenCLTimer.cpp:56
MeasurementsMap test_measurements() const override
Return the latest test measurements.
void start() override
Start measuring.
Copyright (c) 2017-2021 Arm Limited.
void execute_task(ExecutionTask &task)
Definition: Workload.cpp:41
cl_int clEnqueueNDRangeKernel(cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event)
Definition: OpenCL.cpp:372
const char * name
Interface for classes that can be used to measure performance.
Definition: Instrument.h:50
void test_start() override
Start of the test.
Definition: OpenCLTimer.cpp:90
Wrapper to configure the Khronos OpenCL C++ header.
Instrument creating measurements based on the information returned by clGetEventProfilingInfo for eac...
Definition: OpenCLTimer.h:45
std::string id() const override
Identifier for the instrument.
Definition: OpenCLTimer.cpp:43
std::map< std::string, Measurement > MeasurementsMap
Map of measurements.
Definition: Instrument.h:109
MeasurementsMap measurements() const override
Return the latest measurements.
void test_stop() override
End of the test.