Skip to content

Commit 57b56b5

Browse files
author
Treece Burgess
committed
Cuda/NVML Components: Check for variation of shared objects e.g. libcudart.so, libcudart.so.1 or libcudart (catch all).
1 parent 7d80985 commit 57b56b5

File tree

5 files changed

+305
-157
lines changed

5 files changed

+305
-157
lines changed

src/components/cuda/cupti_profiler.c

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -290,51 +290,41 @@ static int unload_cupti_perf_sym(void)
290290
}
291291

292292
/**@class load_nvpw_sym
293-
* @brief Search for libnvperf_host.so. Order of search is outlined below.
293+
* @brief Search for a variation of the shared object libnvperf_host.
294+
* Order of search is outlined below.
294295
*
295296
* 1. If a user sets PAPI_CUDA_PERFWORKS, this will take precedent over
296297
* the options listed below to be searched.
297-
* 2. If we fail to collect libnvperf_host.so from PAPI_CUDA_PERFWORKS or it is not set,
298-
* we will search the path defined with PAPI_CUDA_ROOT; as this is supposed to always be set.
299-
* 3. If we fail to collect libnvperf_host.so from steps 1 and 2, then we will search the linux
300-
* default directories listed by /etc/ld.so.conf. As a note, updating the LD_LIBRARY_PATH is
301-
* advised for this option.
302-
* 4. We use dlopen to search for libnvperf_host.so.
303-
* If this fails, then we failed to find libnvperf_host.so.
298+
* 2. If we fail to collect a variation of the shared object libnvperf_host from
299+
* PAPI_CUDA_PERFWORKS or it is not set, we will search the path defined with PAPI_CUDA_ROOT;
300+
* as this is supposed to always be set.
301+
* 3. If we fail to collect a variation of the shared object libnvperf_host from steps 1 and 2,
302+
* then we will search the linux default directories listed by /etc/ld.so.conf. As a note,
303+
* updating the LD_LIBRARY_PATH is advised for this option.
304+
* 4. We use dlopen to search for a variation of the shared object libnvperf_host.
305+
* If this fails, then we failed to find a variation of the shared object libnvperf_host.
304306
*/
305307
static int load_nvpw_sym(void)
306308
{
307-
COMPDBG("Entering.\n");
308-
char dlname[] = "libnvperf_host.so";
309-
char lookup_path[PATH_MAX];
309+
int soNamesToSearchCount = 3;
310+
const char *soNamesToSearchFor[] = {"libnvperf_host.so", "libnvperf_host.so.1", "libnvperf_host"};
310311

311-
/* search PAPI_CUDA_PERFWORKS for libnvperf_host.so (takes precedent over PAPI_CUDA_ROOT) */
312+
// If a user set PAPI_CUDA_PERFWORKS with a path, then search it for the shared object (takes precedent over PAPI_CUDA_ROOT)
312313
char *papi_cuda_perfworks = getenv("PAPI_CUDA_PERFWORKS");
313314
if (papi_cuda_perfworks) {
314-
sprintf(lookup_path, "%s/%s", papi_cuda_perfworks, dlname);
315-
dl_nvpw = dlopen(lookup_path, RTLD_NOW | RTLD_GLOBAL);
315+
dl_nvpw = search_and_load_shared_objects(papi_cuda_perfworks, NULL, soNamesToSearchFor, soNamesToSearchCount);
316316
}
317317

318-
const char *standard_paths[] = {
319-
"%s/extras/CUPTI/lib64/%s",
320-
"%s/lib64/%s",
321-
NULL,
322-
};
323-
324-
/* search PAPI_CUDA_ROOT for libnvperf_host.so */
318+
char *soMainName = "libnvperf_host";
319+
// If a user set PAPI_CUDA_ROOT with a path and we did not already find the shared object, then search it for the shared object
325320
char *papi_cuda_root = getenv("PAPI_CUDA_ROOT");
326321
if (papi_cuda_root && !dl_nvpw) {
327-
dl_nvpw = cuptic_load_dynamic_syms(papi_cuda_root, dlname, standard_paths);
328-
}
329-
330-
/* search linux default directories for libnvperf_host.so */
331-
if (linked_cudart_path && !dl_nvpw) {
332-
dl_nvpw = cuptic_load_dynamic_syms(linked_cudart_path, dlname, standard_paths);
322+
dl_nvpw = search_and_load_shared_objects(papi_cuda_root, soMainName, soNamesToSearchFor, soNamesToSearchCount);
333323
}
334324

335-
/* last ditch effort to find libcupti.so */
325+
// Last ditch effort to find a variation of libnvperf_host, see dlopen manpages for how search occurs
336326
if (!dl_nvpw) {
337-
dl_nvpw = dlopen(dlname, RTLD_NOW | RTLD_GLOBAL);
327+
dl_nvpw = search_and_load_from_system_paths(soNamesToSearchFor, soNamesToSearchCount);
338328
if (!dl_nvpw) {
339329
ERRDBG("Loading libnvperf_host.so failed.\n");
340330
goto fn_fail;

0 commit comments

Comments
 (0)