PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
kernels_trace.h
Go to the documentation of this file.
1/**
2 *
3 * @file kernels_trace.h
4 *
5 * Wrappers to trace kernels.
6 *
7 * @copyright 2004-2025 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 * Univ. Bordeaux. All rights reserved.
9 *
10 * @version 6.4.0
11 * @author Gregoire Pichon
12 * @author Mathieu Faverge
13 * @author Tony Delarue
14 * @author Alycia Lisito
15 * @date 2024-07-05
16 *
17 * @addtogroup eztrace_dev
18 * @{
19 *
20 **/
21#ifndef _kernels_trace_h_
22#define _kernels_trace_h_
23
24#include "common.h"
25#include "flops.h"
26#include "kernels_enums.h"
27
28/**
29 * @brief Global array to store the number of flops executed per kernel
30 */
31extern volatile double kernels_flops[PastixKernelLvl1Nbr];
32
33/**
34 * @brief Lock to accumulate flops
35 */
36extern pastix_atomic_lock_t lock_flops;
37
38/**
39 * @brief Overall number of flops
40 */
41extern double overall_flops[3];
42
43#if defined(PASTIX_GENERATE_MODEL)
44
45/**
46 * @brief Structure to store information linked to a kernel in order to generate
47 * the cost model
48 */
49typedef struct pastix_model_entry_s {
50 pastix_ktype_t ktype; /**< The type of the kernel */
51 int m; /**< The first diemension of the kernel */
52 int n; /**< The second dimension of the kernel if present, 0 otherwise */
53 int k; /**< The third dimension of the kernel, 0 otherwise */
54 double time; /**< The time spent in the kernel (s) */
55} pastix_model_entry_t;
56
57extern pastix_model_entry_t *model_entries; /**< Array to all entries */
58extern volatile int32_t model_entries_nbr; /**< Index of the last entry in the array */
59extern int32_t model_size; /**< Size of the model_entries array */
60
61#endif
62
63void kernelsTraceInit( const pastix_data_t *pastix_data,
64 pastix_trace_t trace );
65void kernelsTraceFinalize( const pastix_data_t *pastix_data );
66void kernelsTraceStop( void );
67void kernelsTraceStart( void );
68
69/**
70 *******************************************************************************
71 *
72 * @brief Start the trace of a single kernel
73 *
74 *******************************************************************************
75 *
76 * @param[in] ktype
77 * Type of the kernel starting that need to be traced.
78 * With EZTrace mode, this call is empty if the environment variable
79 * PASTIX_EZTRACE_LEVEL is different from 1.
80 *
81 *******************************************************************************
82 *
83 * @return the starting time if PASTIX_GENERATE_MODEL is enabled, 0. otherwise.
84 *
85 *******************************************************************************/
86static inline double
88{
89 double time = 0.;
90
91#if defined(PASTIX_WITH_EZTRACE)
92
93 if (pastix_eztrace_level == 1) {
94 EZTRACE_EVENT_PACKED_0( KERNELS_LVL1_CODE(ktype) );
95 }
96
97#endif
98
99#if defined(PASTIX_GENERATE_MODEL)
100
101 time = clockGet();
102
103#endif
104
105 (void)ktype;
106 return time;
107}
108
109/**
110 *******************************************************************************
111 *
112 * @brief Stop the trace of a single kernel
113 *
114 *******************************************************************************
115 *
116 * @param[in] ktype
117 * Type of the kernel starting that need to be traced.
118 * With EZTrace mode, this call is empty if the environment variable
119 * PASTIX_EZTRACE_LEVEL is different from 1.
120 *
121 * @param[in] m
122 * The m parameter of the kernel (used by xxTRF, TRSM, and GEMM)
123 *
124 * @param[in] n
125 * The n parameter of the kernel (used by TRSM, and GEMM)
126 *
127 * @param[in] k
128 * The k parameter of the kernel (used by GEMM)
129 *
130 * @param[in] flops
131 * The number of flops of the kernel
132 *
133 * @param[in] starttime
134 * The stating time of the kernel. Used only if PASTIX_GENERATE_MODEL
135 * is enabled.
136 *
137 *******************************************************************************/
138static inline void
139kernel_trace_stop( int8_t inlast, pastix_ktype_t ktype, int m, int n, int k, double flops, double starttime )
140{
141
142#if defined(PASTIX_WITH_EZTRACE)
143
144 if (pastix_eztrace_level == 1) {
145 EZTRACE_EVENT_PACKED_1( KERNELS_CODE( PastixKernelStop ), flops );
146 }
147
148#endif
149
150#if defined(PASTIX_GENERATE_MODEL)
151
152 {
153 double time = clockGet() - starttime;
154 int32_t index = pastix_atomic_inc_32b( &model_entries_nbr );
155
156 if ( index < model_size ) {
157 model_entries[index].ktype = ktype;
158 model_entries[index].m = m;
159 model_entries[index].n = n;
160 model_entries[index].k = k;
161 model_entries[index].time = time;
162 }
163 else {
164 fprintf(stderr, "WARNING: too many kernels to log %d\n", index);
165 }
166 }
167
168#endif
169
170 pastix_atomic_lock( &lock_flops );
171 overall_flops[inlast] += flops;
172 pastix_atomic_unlock( &lock_flops );
173
174 (void)ktype;
175 (void)m;
176 (void)n;
177 (void)k;
178 (void)flops;
179 (void)starttime;
180 return;
181}
182
183/**
184 * @}
185 */
186#endif /* _kernels_trace_h_ */
enum pastix_ktype_e pastix_ktype_t
List of the Level 1 events that may be traced in PaStiX.
static void kernel_trace_stop(int8_t inlast, pastix_ktype_t ktype, int m, int n, int k, double flops, double starttime)
Stop the trace of a single kernel.
double overall_flops[3]
Overall number of flops.
static double kernel_trace_start(pastix_ktype_t ktype)
Start the trace of a single kernel.
void kernelsTraceStart(void)
Resumes the trace module.
pastix_atomic_lock_t lock_flops
Lock to accumulate flops.
#define PastixKernelStop
Main stop enum event for all the events in traces.
void kernelsTraceFinalize(const pastix_data_t *pastix_data)
Stops the trace module.
volatile double kernels_flops[PastixKernelLvl1Nbr]
Global array to store the number of flops executed per kernel.
void kernelsTraceStop(void)
Pauses the trace module.
void kernelsTraceInit(const pastix_data_t *pastix_data, pastix_trace_t trace)
Starts the trace module.
enum pastix_trace_e pastix_trace_t
Steps to trace.
Main PaStiX data structure.
Definition pastixdata.h:68