src/components/rocm_smi/linux-rocm-smi.c
//----------------------------------------------------------------------------
// Link the necessary ROCM libraries to use the rocm component.  If any of
// them cannot 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 cannot 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 cannot 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_smi_linkRocmLibraries(void)
{
    char path_name[1024];
    if(_dl_non_dynamic_init != NULL) {
        strncpy(_rocm_smi_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_smi_main) > 0) {                            
        dl1 = dlopen(rocm_smi_main, RTLD_NOW | RTLD_GLOBAL);    
        if (dl1 == NULL) {
            snprintf(_rocm_smi_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "PAPI_ROCM_SMI_MAIN override '%s' given in Rules.rocm_smi not found.", rocm_smi_main);
            return(PAPI_ENOSUPP);   
        }
    }
    if (dl1 == NULL) {                                              
        dl1 = dlopen("librocm_smi64.so", RTLD_NOW | RTLD_GLOBAL);   
    }
    if (dl1 == NULL && rocm_root != NULL) {                          
        snprintf(path_name, 1024, "%s/rocm_smi/lib/librocm_smi64.so", rocm_root);  
        dl1 = dlopen(path_name, RTLD_NOW | RTLD_GLOBAL);             
    }
    if (dl1 == NULL) {
        snprintf(_rocm_smi_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "librocm_smi64.so not found.");
        return(PAPI_ENOSUPP);
    }
    DLSYM_SMI(rsmi_num_monitor_devices);
    DLSYM_SMI(rsmi_dev_supported_func_iterator_open);
    DLSYM_SMI(rsmi_dev_supported_variant_iterator_open);
    DLSYM_SMI(rsmi_dev_supported_variant_iterator_open);
    DLSYM_SMI(rsmi_dev_supported_func_iterator_close);
    DLSYM_SMI(rsmi_func_iter_value_get);
    DLSYM_SMI(rsmi_func_iter_next);
    DLSYM_SMI(rsmi_dev_id_get);
    DLSYM_SMI(rsmi_dev_unique_id_get);
    DLSYM_SMI(rsmi_dev_subsystem_vendor_id_get);
    DLSYM_SMI(rsmi_dev_vendor_id_get);
    DLSYM_SMI(rsmi_dev_subsystem_id_get);
    DLSYM_SMI(rsmi_dev_drm_render_minor_get);
    DLSYM_SMI(rsmi_dev_overdrive_level_get);
    DLSYM_SMI(rsmi_dev_overdrive_level_set);
    DLSYM_SMI(rsmi_dev_pci_id_get);
    DLSYM_SMI(rsmi_dev_memory_busy_percent_get);
    DLSYM_SMI(rsmi_dev_memory_reserved_pages_get);  
    DLSYM_SMI(rsmi_dev_perf_level_get);
    DLSYM_SMI(rsmi_dev_perf_level_set);
    DLSYM_SMI(rsmi_dev_gpu_clk_freq_get);
    DLSYM_SMI(rsmi_dev_memory_total_get);
    DLSYM_SMI(rsmi_dev_memory_usage_get);
    DLSYM_SMI(rsmi_dev_busy_percent_get);
    DLSYM_SMI(rsmi_dev_firmware_version_get);
    DLSYM_SMI(rsmi_dev_ecc_count_get);
    DLSYM_SMI(rsmi_dev_ecc_enabled_get);
    DLSYM_SMI(rsmi_dev_ecc_status_get);
    DLSYM_SMI(rsmi_dev_fan_reset);
    DLSYM_SMI(rsmi_dev_fan_rpms_get);
    DLSYM_SMI(rsmi_dev_fan_speed_get);
    DLSYM_SMI(rsmi_dev_fan_speed_max_get);
    DLSYM_SMI(rsmi_dev_fan_speed_set);
    DLSYM_SMI(rsmi_dev_power_ave_get);
    DLSYM_SMI(rsmi_dev_power_cap_get);
    DLSYM_SMI(rsmi_dev_power_profile_presets_get);
    DLSYM_SMI(rsmi_dev_power_profile_set);
    DLSYM_SMI(rsmi_dev_temp_metric_get);
    DLSYM_SMI(rsmi_version_get);
    DLSYM_SMI(rsmi_dev_pci_throughput_get);
    DLSYM_SMI(rsmi_dev_pci_replay_counter_get);
    DLSYM_SMI(rsmi_dev_power_cap_range_get);
    DLSYM_SMI(rsmi_dev_power_cap_set);
    DLSYM_SMI(rsmi_dev_gpu_clk_freq_get);
    DLSYM_SMI(rsmi_dev_gpu_clk_freq_set);
    DLSYM_SMI(rsmi_dev_od_volt_curve_regions_get);
    DLSYM_SMI(rsmi_dev_od_volt_info_get);
    DLSYM_SMI(rsmi_dev_pci_bandwidth_get);
    DLSYM_SMI(rsmi_dev_pci_bandwidth_set);
    DLSYM_SMI(rsmi_dev_brand_get);
    DLSYM_SMI(rsmi_dev_name_get);
    DLSYM_SMI(rsmi_dev_serial_number_get);
    DLSYM_SMI(rsmi_dev_subsystem_name_get);
    DLSYM_SMI(rsmi_dev_vbios_version_get);
    DLSYM_SMI(rsmi_dev_vendor_name_get);
    DLSYM_SMI(rsmi_version_str_get);
    DLSYM_SMI(rsmi_init);
    DLSYM_SMI(rsmi_shut_down);
    DLSYM_SMI(rsmi_status_string);
    return (PAPI_OK);
}
static int _rocm_smi_linkRocmLibraries ( void ) { char path_name [ 1024 ] ; if ( _dl_non_dynamic_init != NULL ) { strncpy ( _rocm_smi_vector . cmp_info . disabled_reason , " " , PAPI_MAX_STR_LEN ) ; return PAPI_ENOSUPP ; } char * rocm_root = getenv ( " " ) ; dl1 = NULL ; if ( strlen ( rocm_smi_main ) > 0 ) { dl1 = dlopen ( rocm_smi_main , RTLD_NOW | RTLD_GLOBAL ) ; if ( dl1 == NULL ) { snprintf ( _rocm_smi_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " , rocm_smi_main ) ; 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_smi_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN , " " ) ; return ( PAPI_ENOSUPP ) ; } DLSYM_SMI ( rsmi_num_monitor_devices ) ; DLSYM_SMI ( rsmi_dev_supported_func_iterator_open ) ; DLSYM_SMI ( rsmi_dev_supported_variant_iterator_open ) ; DLSYM_SMI ( rsmi_dev_supported_variant_iterator_open ) ; DLSYM_SMI ( rsmi_dev_supported_func_iterator_close ) ; DLSYM_SMI ( rsmi_func_iter_value_get ) ; DLSYM_SMI ( rsmi_func_iter_next ) ; DLSYM_SMI ( rsmi_dev_id_get ) ; DLSYM_SMI ( rsmi_dev_unique_id_get ) ; DLSYM_SMI ( rsmi_dev_subsystem_vendor_id_get ) ; DLSYM_SMI ( rsmi_dev_vendor_id_get ) ; DLSYM_SMI ( rsmi_dev_subsystem_id_get ) ; DLSYM_SMI ( rsmi_dev_drm_render_minor_get ) ; DLSYM_SMI ( rsmi_dev_overdrive_level_get ) ; DLSYM_SMI ( rsmi_dev_overdrive_level_set ) ; DLSYM_SMI ( rsmi_dev_pci_id_get ) ; DLSYM_SMI ( rsmi_dev_memory_busy_percent_get ) ; DLSYM_SMI ( rsmi_dev_memory_reserved_pages_get ) ; DLSYM_SMI ( rsmi_dev_perf_level_get ) ; DLSYM_SMI ( rsmi_dev_perf_level_set ) ; DLSYM_SMI ( rsmi_dev_gpu_clk_freq_get ) ; DLSYM_SMI ( rsmi_dev_memory_total_get ) ; DLSYM_SMI ( rsmi_dev_memory_usage_get ) ; DLSYM_SMI ( rsmi_dev_busy_percent_get ) ; DLSYM_SMI ( rsmi_dev_firmware_version_get ) ; DLSYM_SMI ( rsmi_dev_ecc_count_get ) ; DLSYM_SMI ( rsmi_dev_ecc_enabled_get ) ; DLSYM_SMI ( rsmi_dev_ecc_status_get ) ; DLSYM_SMI ( rsmi_dev_fan_reset ) ; DLSYM_SMI ( rsmi_dev_fan_rpms_get ) ; DLSYM_SMI ( rsmi_dev_fan_speed_get ) ; DLSYM_SMI ( rsmi_dev_fan_speed_max_get ) ; DLSYM_SMI ( rsmi_dev_fan_speed_set ) ; DLSYM_SMI ( rsmi_dev_power_ave_get ) ; DLSYM_SMI ( rsmi_dev_power_cap_get ) ; DLSYM_SMI ( rsmi_dev_power_profile_presets_get ) ; DLSYM_SMI ( rsmi_dev_power_profile_set ) ; DLSYM_SMI ( rsmi_dev_temp_metric_get ) ; DLSYM_SMI ( rsmi_version_get ) ; DLSYM_SMI ( rsmi_dev_pci_throughput_get ) ; DLSYM_SMI ( rsmi_dev_pci_replay_counter_get ) ; DLSYM_SMI ( rsmi_dev_power_cap_range_get ) ; DLSYM_SMI ( rsmi_dev_power_cap_set ) ; DLSYM_SMI ( rsmi_dev_gpu_clk_freq_get ) ; DLSYM_SMI ( rsmi_dev_gpu_clk_freq_set ) ; DLSYM_SMI ( rsmi_dev_od_volt_curve_regions_get ) ; DLSYM_SMI ( rsmi_dev_od_volt_info_get ) ; DLSYM_SMI ( rsmi_dev_pci_bandwidth_get ) ; DLSYM_SMI ( rsmi_dev_pci_bandwidth_set ) ; DLSYM_SMI ( rsmi_dev_brand_get ) ; DLSYM_SMI ( rsmi_dev_name_get ) ; DLSYM_SMI ( rsmi_dev_serial_number_get ) ; DLSYM_SMI ( rsmi_dev_subsystem_name_get ) ; DLSYM_SMI ( rsmi_dev_vbios_version_get ) ; DLSYM_SMI ( rsmi_dev_vendor_name_get ) ; DLSYM_SMI ( rsmi_version_str_get ) ; DLSYM_SMI ( rsmi_init ) ; DLSYM_SMI ( rsmi_shut_down ) ; DLSYM_SMI ( rsmi_status_string ) ; 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, get out. // 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. (librocm_smi64.so). // SMI Library routines. // All by device id. // Not implemented; data does not seem like useful performance data for PAPI users. // retrieves an array.  // rsmi_dev_perf_level_t is just an enum; this can be returned as uint32. // Iterate by memory type; an enum: // RSMI_MEM_TYPE_VRAM; RSMI_MEM_TYPE_VIS_VRAM; RSMI_MEM_TYPE_GTT. (VIS=visible). // Iterate by GPU_BLOCK enum. // Need sensor-id (0...n) in name. All zero for starters. // rsmi_temperature_metric_t is an enum with 14 settings; each would need to be an event. // rsmi_version_t contains uint32 for major; minor; patch. but could return 16-bit packed version as uint64_t. // rsmi_range_t contains two uint64's; lower_bound; upper_bound. // This function has a prototype in the header file, but does not exist in the library. (circa Apr 5 2019). //  DLSYM_SMI(rsmi_dev_od_freq_range_set); // Needs to be two events; sent and received. // Needs to be two events; max and min. // rsmi_frequencies_t contains uint32 num_supported; uint32 current; uint64[] frequency. // rsmi_freq_volt_region_t contains two rsmi_range_t; each has two uint64's lower_bound; upper_bound. // rsmi_od_volt_freq_data_t Complex structure with 4 rsmi_range_t and a 2D array of voltage curve points. // rsmi_pcie_bandwidth_t is a structure containing two arrays; for transfer_rates and lanes. //  These functions return strings. // Non-Events.