bugfix: CLDeconvolutionLayer::validate fails if bias==NULL (#439)
[platform/upstream/armcl.git] / arm_compute / core / NEON / kernels / assembly / profiler.hpp
1 /*
2  * Copyright (c) 2017 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 #pragma once
25
26 #ifdef CYCLE_PROFILING
27
28 #include "../perf.h"
29
30 class profiler {
31 private:
32     static const int maxevents = 10000;
33     unsigned long times[maxevents];
34     unsigned long units[maxevents];
35     int events[maxevents];
36     int currentevent;
37     int countfd;
38
39 public:
40     profiler() {
41         currentevent=0;
42         countfd=open_cycle_counter();
43     }
44
45     ~profiler() {
46         close(countfd);
47         int tots[5];
48         unsigned long counts[5];
49         unsigned long tunits[5];
50         const char * descs[] = { "Prepare A", "Prepare B", "Kernel", "Merge" };
51
52         for (int i=1; i<5; i++) {
53             tots[i] = 0;
54             counts[i] = 0;
55             tunits[i] = 0;
56         }
57
58         printf("Profiled events:\n");
59         for (int i=0; i<currentevent; i++) {
60             tots[events[i]]++;
61             counts[events[i]] += times[i];
62             tunits[events[i]] += units[i];
63         }
64
65         printf("%20s  %9s %9s %9s %12s %9s\n", "", "Events", "Total", "Average", "Bytes/MACs", "Per cycle");
66         for (int i=1; i<5; i++) {
67             printf("%20s: %9d %9ld %9ld %12lu %9.2f\n",descs[i-1],tots[i],counts[i],counts[i]/tots[i],tunits[i],(float)tunits[i]/counts[i]);
68         }
69     }
70
71     template <typename T>
72     void operator() (int i, unsigned long u, T func) {
73         if (currentevent==maxevents) {
74             func();
75         } else {
76             events[currentevent] = i;
77             units[currentevent] = u;
78             start_counter(countfd);
79             func();
80             long long cycs = stop_counter(countfd);
81             times[currentevent++] = cycs;
82         }
83     }
84 };
85
86 #else
87
88 class profiler {
89 public:
90     template <typename T>
91     void operator() (int i, unsigned long u, T func) {
92         func();
93     }
94 };
95
96 #endif
97
98 #define PROFILE_PREPA 1
99 #define PROFILE_PREPB 2
100 #define PROFILE_KERNEL 3
101 #define PROFILE_MERGE 4
102
103