source: soft/giet_vm/applications/rosenfeld/include/clock.h @ 822

Last change on this file since 822 was 822, checked in by meunier, 8 years ago

In rosenfeld:

  • Updated nrio0, nrio1, nrio2, nrio1f, nrio2f, nrio1x, nrbool1, nrbool2 and nralloc1 in the nrc2 lib in order to use macro-typed functions
  • Updated the simulation script to include performance evaluation with random images, and a script to generate graphs
  • Updated the clock.h to use 64-bit integers, which potentially breaks the printing on the giet
File size: 13.4 KB
Line 
1
2#ifndef _CLOCK_H_
3#define _CLOCK_H_
4
5#include <stdint.h>
6
7#include "nrc_os_config.h"
8#if TARGET_OS == LINUX
9    #include <sys/time.h>
10#endif
11
12/**
13 * The macros should be called in the following order:
14 * - CLOCK_DEC;
15 * - CLOCK_INIT(num_threads, num_steps);
16 * - CLOCK_APP_START;
17 * - CLOCK_APP_CREATE;
18 * - CLOCK_THREAD_START(thread_id);
19 * - CLOCK_THREAD_COMPUTE_START(thread_id;
20 * - CLOCK_THREAD_START_STEP(thread_id, step_id)
21 * - CLOCK_THREAD_END_STEP(thread_id, step_id)
22 * - (repeat num_steps times)
23 * - CLOCK_THREAD_COMPUTE_END(thread_id);
24 * - CLOCK_THREAD_END(thread_id)
25 * - CLOCK_APP_JOIN;
26 * - CLOCK_APP_END;
27 * - CLOCK_FINALIZE(num_threads);
28 * - PRINT_CLOCK;
29 * - CLOCK_FREE;
30 */
31
32
33static void local_sort_asc(uint64_t tab[], int32_t size) {
34    int32_t tmp;
35    int32_t i, j;
36    for (i = 0; i < size; i++) {
37        uint64_t min = tab[i];
38        int32_t jmin = i;
39        for (j = i + 1; j < size; j++) {
40            if (tab[j] < min) {
41                jmin = j;
42                min = tab[j];
43            }
44        }
45        tmp = tab[i];
46        tab[i] = min;
47        tab[jmin] = tmp;
48    }
49}
50
51
52
53#define CLOCK_DEC uint64_t app_start;                   \
54                  uint64_t app_end;                     \
55                  uint64_t app_create;                  \
56                  uint64_t app_join;                    \
57                  uint64_t * thread_start;              \
58                  uint64_t * thread_end;                \
59                  uint64_t * thread_compute_start;      \
60                  uint64_t * thread_compute_end;        \
61                  int32_t step_number;                  \
62                  int32_t clock_thread_num;             \
63                  uint64_t ** thread_start_step;        \
64                  uint64_t ** thread_end_step;          \
65                  uint64_t global_thread_start;         \
66                  uint64_t global_thread_end;           \
67                  uint64_t global_thread_compute_start; \
68                  uint64_t global_thread_compute_end;   \
69                  uint64_t * global_thread_start_step;  \
70                  uint64_t * global_thread_end_step;
71
72#if TARGET_OS == GIETVM
73    #define CLOCK(x)  ({ x = giet_proctime(); })
74#elif TARGET_OS == LINUX
75    #define CLOCK(x)  ({                      \
76            struct timeval full_time;         \
77            gettimeofday(&full_time, NULL);   \
78            x = (uint64_t) ((full_time.tv_usec + full_time.tv_sec * 1000000)); \
79            })
80#endif
81
82// x = number of threads, y = number of steps
83#define CLOCK_INIT(x, y) ({                                                         \
84    clock_thread_num = (x);                                                         \
85    step_number = (y);                                                              \
86    global_thread_start = 0xFFFFFFFFFFFFFFFFLLU;                                    \
87    global_thread_end = 0;                                                          \
88    global_thread_compute_start = 0xFFFFFFFFFFFFFFFFLLU;                            \
89    global_thread_compute_end = 0;                                                  \
90    if ((x) > 0) {                                                                  \
91        thread_start = (uint64_t *) malloc(sizeof(uint64_t) * (x));                 \
92        thread_end = (uint64_t *) malloc(sizeof(uint64_t) * (x));                   \
93        thread_compute_start = (uint64_t *) malloc(sizeof(uint64_t) * (x));         \
94        thread_compute_end = (uint64_t *) malloc(sizeof(uint64_t) * (x));           \
95        if ((y) > 0) {                                                              \
96            global_thread_start_step = (uint64_t *) malloc(sizeof(uint64_t) * (y)); \
97            global_thread_end_step = (uint64_t *) malloc(sizeof(uint64_t) * (y));   \
98            thread_start_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));     \
99            thread_end_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));       \
100            for (int32_t j = 0; j < (y); j++) {                                     \
101                global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLU;                 \
102                global_thread_end_step[j] = 0;                                      \
103                thread_start_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x)); \
104                thread_end_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x));   \
105            }                                                                       \
106        }                                                                           \
107    }                                                                               \
108})
109
110
111#define CLOCK_APP_START               ({ CLOCK(app_start); })
112#define CLOCK_APP_END                 ({ CLOCK(app_end); })
113#define CLOCK_APP_CREATE              ({ CLOCK(app_create); })
114#define CLOCK_APP_JOIN                ({ CLOCK(app_join); })
115#define CLOCK_THREAD_START(x)         ({ CLOCK(thread_start[x]); })
116#define CLOCK_THREAD_END(x)           ({ CLOCK(thread_end[x]); })
117#define CLOCK_THREAD_COMPUTE_START(x) ({ CLOCK(thread_compute_start[x]); })
118#define CLOCK_THREAD_COMPUTE_END(x)   ({ CLOCK(thread_compute_end[x]); })
119#define CLOCK_THREAD_START_STEP(x, y) ({ CLOCK(thread_start_step[y][x]); })
120#define CLOCK_THREAD_END_STEP(x, y)   ({ CLOCK(thread_end_step[y][x]); })
121
122
123#define CLOCK_FINALIZE ({                                                \
124    for (int32_t i = 0; i < clock_thread_num; i++) {                     \
125        if (thread_start[i] < global_thread_start) {                     \
126            global_thread_start = thread_start[i];                       \
127        }                                                                \
128        if (thread_compute_start[i] < global_thread_compute_start) {     \
129            global_thread_compute_start = thread_compute_start[i];       \
130        }                                                                \
131        if (thread_end[i] > global_thread_end) {                         \
132            global_thread_end = thread_end[i];                           \
133        }                                                                \
134        if (thread_compute_end[i] > global_thread_compute_end) {         \
135            global_thread_compute_end = thread_compute_end[i];           \
136        }                                                                \
137        for (int32_t j = 0; j < step_number; j++) {                      \
138            if (thread_start_step[j][i] < global_thread_start_step[j]) { \
139                global_thread_start_step[j] = thread_start_step[j][i];   \
140            }                                                            \
141            if (thread_end_step[j][i] > global_thread_end_step[j]) {     \
142                global_thread_end_step[j] = thread_end_step[j][i];       \
143            }                                                            \
144        }                                                                \
145    }                                                                    \
146})
147
148#define PRINT_CLOCK ({                                                                                                         \
149    MCA_VERBOSE1(printf("Timestamps:\n"));                                                                                     \
150    MCA_VERBOSE1(printf("[APP_START]            : %llu\n", app_start));                                                        \
151    MCA_VERBOSE1(printf("[APP_CREATE]           : %llu\n", app_create));                                                       \
152    MCA_VERBOSE1(printf("[THREAD_START]         : %llu\n", global_thread_start));                                              \
153    MCA_VERBOSE1(printf("[THREAD_COMPUTE_START] : %llu\n", global_thread_compute_start));                                      \
154    for (int32_t j = 0; j < step_number; j++) {                                                                                \
155        MCA_VERBOSE1(printf("[THREAD_START_STEP_%d]  : %llu\n", j, global_thread_start_step[j]));                              \
156        MCA_VERBOSE1(printf("[THREAD_END_STEP_%d]    : %llu\n", j, global_thread_end_step[j]));                                \
157    }                                                                                                                          \
158    MCA_VERBOSE1(printf("[THREAD_COMPUTE_END]   : %llu\n", global_thread_compute_end));                                        \
159    MCA_VERBOSE1(printf("[THREAD_END]           : %llu\n", global_thread_end));                                                \
160    MCA_VERBOSE1(printf("[APP_JOIN]             : %llu\n", app_join));                                                         \
161    MCA_VERBOSE1(printf("[APP_END]              : %llu\n", app_end));                                                          \
162    MCA_VERBOSE1(printf("Durations (in cycles):\n"));                                                                          \
163    MCA_VERBOSE1(printf("[TOTAL]                : %llu\n", app_end - app_start));                                              \
164    MCA_VERBOSE1(printf("[THREAD]               : %llu\n", app_join - app_create));                                            \
165    MCA_VERBOSE1(printf("[PARALLEL]             : %llu\n", global_thread_end - global_thread_start));                          \
166    MCA_VERBOSE1(printf("[PARALLEL_COMPUTE]     : %llu\n", global_thread_compute_end - global_thread_compute_start));          \
167    for (int32_t j = 0; j < step_number; j++) {                                                                                \
168        MCA_VERBOSE1(printf("[THREAD_STEP_%d]        : %llu\n", j, global_thread_end_step[j] - global_thread_start_step[j]));  \
169    }                                                                                                                          \
170    MCA_VERBOSE1(printf("\n"));                                                                                                \
171    MCA_VERBOSE1(printf("*** All threads times output in a gnuplot data-style ***\n"));                                        \
172    local_sort_asc(thread_start, clock_thread_num);                                                                            \
173    local_sort_asc(thread_compute_start, clock_thread_num);                                                                    \
174    local_sort_asc(thread_compute_end, clock_thread_num);                                                                      \
175    local_sort_asc(thread_end, clock_thread_num);                                                                              \
176    for (int32_t j = 0; j < step_number; j++) {                                                                                \
177        local_sort_asc(thread_start_step[j], clock_thread_num);                                                                \
178        local_sort_asc(thread_end_step[j], clock_thread_num);                                                                  \
179    }                                                                                                                          \
180    MCA_VERBOSE1(printf("# cycle     thread_id\n"));                                                                           \
181    for (int32_t i = 0; i < clock_thread_num; i++) {                                                                           \
182        MCA_VERBOSE1(printf("%llu\t%d\n", thread_start[i], i));                                                                \
183        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_start[i], i));                                                        \
184        for (int32_t j = 0; j < step_number; j++) {                                                                            \
185            MCA_VERBOSE1(printf("%llu\t%d\n", thread_start_step[j][i], i));                                                    \
186            MCA_VERBOSE1(printf("%llu\t%d\n", thread_end_step[j][i], i));                                                      \
187        }                                                                                                                      \
188        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_end[i], i));                                                          \
189        MCA_VERBOSE1(printf("%llu\t%d\n", thread_end[i], i));                                                                  \
190    }                                                                                                                          \
191})
192
193               
194
195
196
197
198#define CLOCK_FREE ({                                   \
199    if (clock_thread_num > 0) {                         \
200        free(thread_start);                             \
201        free(thread_end);                               \
202        free(thread_compute_start);                     \
203        free(thread_compute_end);                       \
204        if (step_number > 0) {                          \
205            free(global_thread_start_step);             \
206            free(global_thread_end_step);               \
207            for (int32_t j = 0; j < step_number; j++) { \
208                free(thread_start_step[j]);             \
209                free(thread_end_step[j]);               \
210            }                                           \
211            free(thread_start_step);                    \
212            free(thread_end_step);                      \
213        }                                               \
214    }                                                   \
215})
216
217
218
219
220#endif
221
Note: See TracBrowser for help on using the repository browser.