src/components/rocm/linux-rocm.c
/*
 * Link the necessary ROCM libraries to use the rocm component.  If any of them can not be found, then
 * the ROCM component will just be disabled.  This is done at runtime so that a version of PAPI built
 * with the ROCM component can be installed and used on systems which have the ROCM libraries installed
 * and on systems where these libraries are not installed.
 */
Link the necessary ROCM libraries to use the rocm component.  If any of them can not be found, then
the ROCM component will just be disabled.  This is done at runtime so that a version of PAPI built
with the ROCM component can be installed and used on systems which have the ROCM libraries installed
and on systems where these libraries are not installed.
Link the necessary ROCM libraries to use the rocm component . If any of them can not be found then the ROCM component will just be disabled . This is done at runtime so that a version of PAPI built with the ROCM component can be installed and used on systems which have the ROCM libraries installed and on systems where these libraries are not installed .
static int _rocm_linkRocmLibraries(void)
{
    ROCMDBG("Entering _rocm_linkRocmLibraries\n");
    char path_name[1024];
    if(_dl_non_dynamic_init != NULL) {
        strncpy(_rocm_vector.cmp_info.disabled_reason, "The ROCM component does not support statically linking to libc.", PAPI_MAX_STR_LEN);
        return PAPI_ENOSUPP;
    }
    char *rocm_root = getenv("PAPI_ROCM_ROOT");
    dl1 = NULL;                                                 
    if (strlen(rocm_hsa) > 0) {                             
        dl1 = dlopen(rocm_hsa, RTLD_NOW | RTLD_GLOBAL);     
        if (dl1 == NULL) {
            snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "PAPI_ROCM_HSA override '%s' given in Rules.rocm not found.", rocm_hsa);
            return(PAPI_ENOSUPP);   
        }
    }
    if (dl1 == NULL) {                                                  
        dl1 = dlopen("libhsa-runtime64.so", RTLD_NOW | RTLD_GLOBAL);    
    }
    if (dl1 == NULL && rocm_root != NULL) {                          
        snprintf(path_name, 1024, "%s/lib/libhsa-runtime64.so", rocm_root);  
        dl1 = dlopen(path_name, RTLD_NOW | RTLD_GLOBAL);             
    }
    if (dl1 == NULL) {
        snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "libhsa-runtime64.so not found.");
        return(PAPI_ENOSUPP);
    }
    DLSYM_AND_CHECK(dl1, hsa_init);
    DLSYM_AND_CHECK(dl1, hsa_iterate_agents);
    DLSYM_AND_CHECK(dl1, hsa_system_get_info);
    DLSYM_AND_CHECK(dl1, hsa_agent_get_info);
    DLSYM_AND_CHECK(dl1, hsa_shut_down);
    DLSYM_AND_CHECK(dl1, hsa_queue_destroy);
    dl2 = NULL;                                                 
    if (strlen(rocm_prof) > 0) {                             
        dl2 = dlopen(rocm_prof, RTLD_NOW | RTLD_GLOBAL);     
        if (dl1 == NULL) {
            snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "PAPI_ROCM_PROF override '%s' given in Rules.rocm not found.", rocm_prof);
            return(PAPI_ENOSUPP);   
        }
    }
    if (dl2 == NULL) {                                                  
        dl2 = dlopen("librocprofiler64.so", RTLD_NOW | RTLD_GLOBAL);    
    }
    if (dl2 == NULL && rocm_root != NULL) {                          
        snprintf(path_name, 1024, "%s/lib/librocprofiler64.so", rocm_root);  
        dl2 = dlopen(path_name, RTLD_NOW | RTLD_GLOBAL);             
    }
    if (dl2 == NULL) {
        snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "librocprofiler64.so not found.");
        return(PAPI_ENOSUPP);
    }
    DLSYM_AND_CHECK(dl2, rocprofiler_get_info);
    DLSYM_AND_CHECK(dl2, rocprofiler_iterate_info);
    DLSYM_AND_CHECK(dl2, rocprofiler_open);
    DLSYM_AND_CHECK(dl2, rocprofiler_close);
    DLSYM_AND_CHECK(dl2, rocprofiler_group_count);
    DLSYM_AND_CHECK(dl2, rocprofiler_start);
    DLSYM_AND_CHECK(dl2, rocprofiler_read);
    DLSYM_AND_CHECK(dl2, rocprofiler_stop);
    DLSYM_AND_CHECK(dl2, rocprofiler_get_data);
    DLSYM_AND_CHECK(dl2, rocprofiler_get_metrics);
    DLSYM_AND_CHECK(dl2, rocprofiler_reset);
    DLSYM_AND_CHECK(dl2, rocprofiler_error_string);
    if (getenv("ROCP_METRICS") == NULL) {
        snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "Env. Var. ROCP_METRICS not set; rocprofiler is not configured.");
        return(PAPI_ENOSUPP);   
    }
    if (getenv("ROCPROFILER_LOG") == NULL) {
        snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "Env. Var. ROCPROFILER_LOG not set; rocprofiler is not configured.");
        return(PAPI_ENOSUPP);   
    }
    if (getenv("HSA_VEN_AMD_AQLPROFILE_LOG") == NULL) {
        snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "Env. Var. HSA_VEN_AMD_AQLPROFILE_LOG not set; rocprofiler is not configured.");
        return(PAPI_ENOSUPP);   
    }
    if (getenv("AQLPROFILE_READ_API") == NULL) {
        snprintf(_rocm_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "Env. Var.AQLPROFILE_READ_API not set; rocprofiler is not configured.");
        return(PAPI_ENOSUPP);   
    }
    return (PAPI_OK);
}
static int _rocm_linkRocmLibraries ( void ) { ROCMDBG ( " \n " ) ; char path_name [ 1024 ] ; if ( _dl_non_dynamic_init != NULL ) { strncpy ( _rocm_vector . cmp_info . disabled_reason , " " , PAPI_MAX_STR_LEN ) ; return PAPI_ENOSUPP ; } char * rocm_root = getenv ( " " ) ; dl1 = NULL ; if ( strlen ( rocm_hsa ) > 0 ) { dl1 = dlopen ( rocm_hsa , RTLD_NOW | RTLD_GLOBAL ) ; if ( dl1 == NULL ) { snprintf ( _rocm_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " , rocm_hsa ) ; return ( PAPI_ENOSUPP ) ; } } if ( dl1 == NULL ) { dl1 = dlopen ( " " , RTLD_NOW | RTLD_GLOBAL ) ; } if ( dl1 == NULL && rocm_root != NULL ) { snprintf ( path_name , 1024 , " " , rocm_root ) ; dl1 = dlopen ( path_name , RTLD_NOW | RTLD_GLOBAL ) ; } if ( dl1 == NULL ) { snprintf ( _rocm_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " ) ; return ( PAPI_ENOSUPP ) ; } DLSYM_AND_CHECK ( dl1 , hsa_init ) ; DLSYM_AND_CHECK ( dl1 , hsa_iterate_agents ) ; DLSYM_AND_CHECK ( dl1 , hsa_system_get_info ) ; DLSYM_AND_CHECK ( dl1 , hsa_agent_get_info ) ; DLSYM_AND_CHECK ( dl1 , hsa_shut_down ) ; DLSYM_AND_CHECK ( dl1 , hsa_queue_destroy ) ; dl2 = NULL ; if ( strlen ( rocm_prof ) > 0 ) { dl2 = dlopen ( rocm_prof , RTLD_NOW | RTLD_GLOBAL ) ; if ( dl1 == NULL ) { snprintf ( _rocm_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " , rocm_prof ) ; return ( PAPI_ENOSUPP ) ; } } if ( dl2 == NULL ) { dl2 = dlopen ( " " , RTLD_NOW | RTLD_GLOBAL ) ; } if ( dl2 == NULL && rocm_root != NULL ) { snprintf ( path_name , 1024 , " " , rocm_root ) ; dl2 = dlopen ( path_name , RTLD_NOW | RTLD_GLOBAL ) ; } if ( dl2 == NULL ) { snprintf ( _rocm_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " ) ; return ( PAPI_ENOSUPP ) ; } DLSYM_AND_CHECK ( dl2 , rocprofiler_get_info ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_iterate_info ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_open ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_close ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_group_count ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_start ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_read ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_stop ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_get_data ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_get_metrics ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_reset ) ; DLSYM_AND_CHECK ( dl2 , rocprofiler_error_string ) ; if ( getenv ( " " ) == NULL ) { snprintf ( _rocm_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " ) ; return ( PAPI_ENOSUPP ) ; } if ( getenv ( " " ) == NULL ) { snprintf ( _rocm_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " ) ; return ( PAPI_ENOSUPP ) ; } if ( getenv ( " " ) == NULL ) { snprintf ( _rocm_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " ) ; return ( PAPI_ENOSUPP ) ; } if ( getenv ( " " ) == NULL ) { snprintf ( _rocm_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " ) ; return ( PAPI_ENOSUPP ) ; } return ( PAPI_OK ) ; }
Link the necessary ROCM libraries to use the rocm component.
Link the necessary ROCM libraries to use the rocm component .
/* Attempt to guess if we were statically linked to libc, if so bail */ // collect any defined environment variables, or "NULL" if not present. // Ensure reset to NULL. // Step 1: Process override if given. // If override given, it has to work. // Try to open that path. // Override given but not found. // Step 2: Try system paths, will work with Spack, LD_LIBRARY_PATH, default paths. // No override, // Try system paths. // Step 3: Try the explicit install default. // if root given, try it. // PAPI Root check. // Try to open that path. // Check for failure. // We have a dl1. (libhsa-runtime64.so). //------------------------------------------------------------------------- // Ensure reset to NULL. // Step 1: Process override if given. // If override given, it has to work. // Try to open that path. // Override given but not found. // Step 2: Try system paths, will work with Spack, LD_LIBRARY_PATH, default paths. // No override, // Try system paths. // Step 3: Try the explicit install default. // if root given, try it. // PAPI Root check. // Try to open that path. // Check for failure. // We have a dl2. (librocprofiler64.so). // Disable if ROCPROFILER env vars not present. // Wouldn't have any events. // Wouldn't have any events. // Wouldn't have any events. // Wouldn't have any events.