GCC Code Coverage Report


Directory: src/
File: src/talp/talp_gpu.c
Date: 2025-11-21 10:34:40
Exec Total Coverage
Lines: 0 39 0.0%
Functions: 0 6 0.0%
Branches: 0 10 0.0%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2025 Barcelona Supercomputing Center */
3 /* */
4 /* This file is part of the DLB library. */
5 /* */
6 /* DLB is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU Lesser General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* DLB is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU Lesser General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU Lesser General Public License */
17 /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18 /*********************************************************************************/
19
20 #include "talp/talp_gpu.h"
21
22 #include "LB_core/spd.h"
23 #include "support/atomic.h"
24 #include "support/dlb_common.h"
25 #include "talp/regions.h"
26 #include "talp/talp.h"
27 #include "talp/talp_types.h"
28
29 static trigger_update_func_t trigger_update_fn = NULL;
30
31 /* Called when regions are stopped and we need to collect GPU measurements */
32 void talp_gpu_sync_measurements(void) {
33 if (trigger_update_fn) trigger_update_fn();
34 }
35
36 /* The following symbols need to be public so that the GPU plugin can call us */
37
38 DLB_EXPORT_SYMBOL
39 void talp_gpu_init(trigger_update_func_t update_fn) {
40
41 spd_enter_dlb(thread_spd);
42 const subprocess_descriptor_t *spd = thread_spd;
43 talp_info_t *talp_info = spd->talp_info;
44 if (talp_info) {
45 /* Set flag */
46 talp_info->flags.have_gpu = true;
47
48 /* Set up callback function to read measurements */
49 trigger_update_fn = update_fn;
50
51 /* Start global region (no-op if already started) */
52 region_start(spd, talp_info->monitor);
53
54 /* Set useful state */
55 talp_sample_t *sample = talp_get_thread_sample(spd);
56 talp_set_sample_state(sample, useful, talp_info->flags.papi);
57 }
58 }
59
60 DLB_EXPORT_SYMBOL
61 void talp_gpu_finalize(void) {
62 talp_gpu_sync_measurements();
63 }
64
65 DLB_EXPORT_SYMBOL
66 void talp_gpu_into_runtime_api(void) {
67
68 spd_enter_dlb(thread_spd);
69 const subprocess_descriptor_t *spd = thread_spd;
70 const talp_info_t *talp_info = spd->talp_info;
71 if (talp_info) {
72 /* Update sample */
73 talp_sample_t *sample = talp_get_thread_sample(spd);
74 talp_update_sample(sample, talp_info->flags.papi, TALP_NO_TIMESTAMP);
75 // or: talp_flush_samples_to_regions(spd);
76
77 /* Into Sync call -> not_useful_gpu */
78 talp_set_sample_state(sample, not_useful_gpu, talp_info->flags.papi);
79 }
80 }
81
82 DLB_EXPORT_SYMBOL
83 void talp_gpu_out_of_runtime_api(void) {
84
85 spd_enter_dlb(thread_spd);
86 const subprocess_descriptor_t *spd = thread_spd;
87 const talp_info_t *talp_info = spd->talp_info;
88 if (talp_info) {
89 /* Update sample */
90 talp_sample_t *sample = talp_get_thread_sample(spd);
91 DLB_ATOMIC_ADD_RLX(&sample->stats.num_gpu_runtime_calls, 1);
92 talp_update_sample(sample, talp_info->flags.papi, TALP_NO_TIMESTAMP);
93 // or: talp_flush_samples_to_regions(spd);
94
95 /* Out of Sync call -> useful */
96 talp_set_sample_state(sample, useful, talp_info->flags.papi);
97 }
98 }
99
100 DLB_EXPORT_SYMBOL
101 void talp_gpu_update_sample(talp_gpu_measurements_t measurements) {
102
103 spd_enter_dlb(thread_spd);
104 const subprocess_descriptor_t *spd = thread_spd;
105 talp_info_t *talp_info = spd->talp_info;
106 if (talp_info) {
107 talp_info->gpu_sample.timers.useful += measurements.useful_time;
108 talp_info->gpu_sample.timers.communication += measurements.communication_time;
109 talp_info->gpu_sample.timers.inactive += measurements.inactive_time;
110 }
111 }
112