GCC Code Coverage Report


Directory: src/
File: src/talp/talp_gpu.c
Date: 2026-03-27 16:05:46
Exec Total Coverage
Lines: 5 56 8.9%
Functions: 1 6 16.7%
Branches: 1 20 5.0%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2026 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 "apis/dlb_errors.h"
23 #include "LB_core/spd.h"
24 #include "support/atomic.h"
25 #include "support/debug.h"
26 #include "support/dlb_common.h"
27 #include "talp/backend.h"
28 #include "talp/backend_manager.h"
29 #include "talp/regions.h"
30 #include "talp/talp.h"
31 #include "talp/talp_output.h"
32 #include "talp/talp_types.h"
33
34
35 static const backend_api_t *gpu_backend_api = NULL;
36 static gpu_measurements_t gpu_sample = {0};
37
38 // Called from talp core
39 15 int talp_gpu_init(const subprocess_descriptor_t *spd) {
40
41 15 gpu_backend_api = talp_backend_manager_load_gpu_backend(spd->options.talp_gpu_backend);
42
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (gpu_backend_api == NULL) {
43 15 debug_warning("GPU backend could not be loaded");
44 15 return DLB_ERR_UNKNOWN;
45 }
46
47 int error;
48
49 /* If GPU component is not explicitly set, probe plugin first */
50 if (!(spd->options.talp & TALP_COMPONENT_GPU)) {
51 error = gpu_backend_api->probe();
52 if (error == DLB_BACKEND_ERROR) {
53 debug_warning("HWC backend probe failed");
54 return DLB_ERR_UNKNOWN;
55 }
56 }
57
58 error = gpu_backend_api->init(&core_api);
59 if (error == DLB_BACKEND_ERROR) {
60 debug_warning("GPU backend could not be initialized");
61 return DLB_ERR_UNKNOWN;
62 }
63
64 error = gpu_backend_api->start();
65 if (error == DLB_BACKEND_ERROR) {
66 debug_warning("GPU backend could not be started");
67 gpu_backend_api->finalize();
68 return DLB_ERR_UNKNOWN;
69 }
70
71 if (gpu_backend_api->capabilities.gpu_amd) {
72 talp_output_record_gpu_vendor(GPU_VENDOR_AMD);
73 } else if (gpu_backend_api->capabilities.gpu_nvidia) {
74 talp_output_record_gpu_vendor(GPU_VENDOR_NVIDIA);
75 }
76
77 return DLB_SUCCESS;
78 }
79
80
81 // Called from talp core
82 void talp_gpu_finalize(void) {
83
84 if (gpu_backend_api != NULL) {
85
86 gpu_backend_api->stop();
87 gpu_backend_api->flush();
88 gpu_backend_api->finalize();
89
90 talp_backend_manager_unload_gpu_backend();
91 gpu_backend_api = NULL;
92 }
93 }
94
95
96 // Called from GPU backend plugin: CPU enters GPU runtime
97 void talp_gpu_enter_runtime(void) {
98
99 spd_enter_dlb(thread_spd);
100 const subprocess_descriptor_t *spd = thread_spd;
101 const talp_info_t *talp_info = spd->talp_info;
102 if (talp_info) {
103 /* Update sample */
104 talp_sample_t *sample = talp_get_thread_sample(spd);
105 talp_update_sample(spd, sample, TALP_NO_TIMESTAMP);
106 // or: talp_flush_samples_to_regions(spd);
107
108 /* Into Sync call -> not_useful_gpu */
109 talp_set_sample_state(spd, sample, TALP_STATE_NOT_USEFUL_GPU);
110 }
111 }
112
113
114 // Called from GPU backend plugin: CPU exits GPU runtime
115 void talp_gpu_exit_runtime(void) {
116
117 spd_enter_dlb(thread_spd);
118 const subprocess_descriptor_t *spd = thread_spd;
119 const talp_info_t *talp_info = spd->talp_info;
120 if (talp_info) {
121 /* Update sample */
122 talp_sample_t *sample = talp_get_thread_sample(spd);
123 DLB_ATOMIC_ADD_RLX(&sample->stats.num_gpu_runtime_calls, 1);
124 talp_update_sample(spd, sample, TALP_NO_TIMESTAMP);
125 // or: talp_flush_samples_to_regions(spd);
126
127 /* Out of Sync call -> useful */
128 talp_set_sample_state(spd, sample, TALP_STATE_USEFUL);
129 }
130 }
131
132
133 // Called from GPU backend plugin: flush GPU data
134 void talp_gpu_submit(const gpu_measurements_t *measurements) {
135
136 gpu_sample.useful_time += measurements->useful_time;
137 gpu_sample.communication_time += measurements->communication_time;
138 gpu_sample.inactive_time += measurements->inactive_time;
139 }
140
141 // called from core
142 void talp_gpu_collect(gpu_measurements_t *out) {
143
144 // flush GPU, may cause callback to talp_gpu_submit
145 gpu_backend_api->flush();
146
147 *out = gpu_sample;
148 gpu_sample = (const gpu_measurements_t){0};
149 }
150