src/components/rocm_smi/linux-rocm-smi.c
// Link the library, set up event tables and function tables.  This routine is
// called when the PAPI process is initialized (IE PAPI_library_init)
Link the library, set up event tables and function tables.  This routine is
called when the PAPI process is initialized
Link the library set up event tables and function tables . This routine is called when the PAPI process is initialized
static int _rocm_smi_init_component(int cidx)
{
    int i, ret;
    (void) i;
    uint32_t dev;
    scanEvent_info_t* scan=NULL;                        
    SUBDBG("Entering _rocm_smi_init_component\n");
    if(_rocm_smi_linkRocmLibraries() != PAPI_OK) {
        SUBDBG("Dynamic link of ROCM libraries failed, component will be disabled.\n");
        SUBDBG("See disable reason in papi_component_avail output for more details.\n");
        return (PAPI_ENOSUPP);
    }
    RSMI(rsmi_init, (0),return(PAPI_ENOSUPP));
    ret = _rocm_smi_find_devices();             
    if (ret != PAPI_OK) return(ret);            
    scanEvents();                               
    FreqTable = calloc(TotalDevices*freqTablePerDevice, sizeof(rsmi_frequencies));
    for (dev=0; dev<TotalDevices; dev++) {
        scan = NULL;
        while (1) {                                                     
            scan = nextEvent(scan, dev, "rsmi_dev_gpu_clk_freq_get");   
            if (scan == NULL) break;                                    
            if (scan->variant<0 || scan->variant>=freqTablePerDevice)   
                continue;                                               
            int idx = dev*freqTablePerDevice+scan->variant;             
            RSMI(rsmi_dev_gpu_clk_freq_get, (dev, scan->variant, &FreqTable[idx]),); 
        } 
    }
    PCITable = calloc(TotalDevices, sizeof(rsmi_pcie_bandwidth_t));
    for (dev=0; dev<TotalDevices; dev++) {
        scan = NULL;
        scan = nextEvent(scan, dev, "rsmi_dev_pci_bandwidth_get");
        if (scan == NULL) continue;                                     
        RSMI(rsmi_dev_pci_bandwidth_get, (dev, &PCITable[dev]),);
    }
    ret = _rocm_smi_add_native_events();
    if (ret != 0) return (ret);                 
#ifdef  REPORT_DEVICE_FUNCTION_NOT_SUPPORTED_BY_THIS_SOFTWARE
    for (i=0; i<TotalScanEvents; i++) {
        if (ScanEvents[i].used == 0) 
            fprintf(stderr, "Device function not supported by this software: '%s:dev=%i:var=%i:sv=%i'\n", 
                ScanEvents[i].funcname, ScanEvents[i].device, ScanEvents[i].variant, ScanEvents[i].subvariant);
    }
#endif
    _rocm_smi_vector.cmp_info.CmpIdx = cidx;
    _rocm_smi_vector.cmp_info.num_native_events = TotalEvents;
    _rocm_smi_vector.cmp_info.num_cntrs = TotalEvents;
    _rocm_smi_vector.cmp_info.num_mpx_cntrs = TotalEvents;
    return (PAPI_OK);
}
static int _rocm_smi_init_component ( int cidx ) { int i , ret ; ( void ) i ; uint32_t dev ; scanEvent_info_t * scan = NULL ; SUBDBG ( " \n " ) ; if ( _rocm_smi_linkRocmLibraries ( ) != PAPI_OK ) { SUBDBG ( " \n " ) ; SUBDBG ( " \n " ) ; return ( PAPI_ENOSUPP ) ; } RSMI ( rsmi_init , ( 0 ) , return ( PAPI_ENOSUPP ) ) ; ret = _rocm_smi_find_devices ( ) ; if ( ret != PAPI_OK ) return ( ret ) ; scanEvents ( ) ; FreqTable = calloc ( TotalDevices * freqTablePerDevice , sizeof ( rsmi_frequencies ) ) ; for ( dev = 0 ; dev < TotalDevices ; dev ++ ) { scan = NULL ; while ( 1 ) { scan = nextEvent ( scan , dev , " " ) ; if ( scan == NULL ) break ; if ( scan -> variant < 0 || scan -> variant >= freqTablePerDevice ) continue ; int idx = dev * freqTablePerDevice + scan -> variant ; RSMI ( rsmi_dev_gpu_clk_freq_get , ( dev , scan -> variant , & FreqTable [ idx ] ) , ) ; } } PCITable = calloc ( TotalDevices , sizeof ( rsmi_pcie_bandwidth_t ) ) ; for ( dev = 0 ; dev < TotalDevices ; dev ++ ) { scan = NULL ; scan = nextEvent ( scan , dev , " " ) ; if ( scan == NULL ) continue ; RSMI ( rsmi_dev_pci_bandwidth_get , ( dev , & PCITable [ dev ] ) , ) ; } ret = _rocm_smi_add_native_events ( ) ; if ( ret != 0 ) return ( ret ) ; #ifdef REPORT_DEVICE_FUNCTION_NOT_SUPPORTED_BY_THIS_SOFTWARE for ( i = 0 ; i < TotalScanEvents ; i ++ ) { if ( ScanEvents [ i ] . used == 0 ) fprintf ( stderr , " \n " , ScanEvents [ i ] . funcname , ScanEvents [ i ] . device , ScanEvents [ i ] . variant , ScanEvents [ i ] . subvariant ) ; } #endif _rocm_smi_vector . cmp_info . CmpIdx = cidx ; _rocm_smi_vector . cmp_info . num_native_events = TotalEvents ; _rocm_smi_vector . cmp_info . num_cntrs = TotalEvents ; _rocm_smi_vector . cmp_info . num_mpx_cntrs = TotalEvents ; return ( PAPI_OK ) ; }
Link the library, set up event tables and function tables.
Link the library set up event tables and function tables .
// a scan event pointer. /* link in all the rocm libraries and resolve the symbols we need to use */ // Find AMD devices. Must find at least 1. // check for failure. // Before we can build the list of all potential events, // we have to scan the events available to determine  // how many variants & sensors we need to process when // we get to the build for each type of event. There is // no other way to query this information. // Note that some events (like the temperatures) have a // fixed number of variants.  // Note that scanEvents will sort the events by device, name, variant, subvariant. // Collect supportedEvents[]. // DEALING WITH rsmi_dev_gpu_clk_freq_get/set.  // There are five types of clock, and each has a set of frequencies we can retrieve. // rsmi_dev_gpu_clk_freq_get(device, clock_type, *rsmi_frequencies_t frequencies): // clock_types: //   RSMI_CLK_TYPE_SYS  System clock. //   RSMI_CLK_TYPE_DF   Data Fabric clock (for ASICs running on a separate clock) //   RSMI_CLK_TYPE_DCEF Display Controller Engine clock. //   RSMI_CLK_TYPE_SOC  SOC clock. //   RSMI_CLK_TYPE_MEM  Memory clock. // The rsmi_frequencies_t structure contains: //   uint32_t num_supported                         // The count of valid entries in array. //   uint32_t current                               // the INDICE of the current frequency. //   uint64_t frequency [RSMI_MAX_NUM_FREQUENCIES]  // ==32 at this writing. // In order to support these functions, we need to know up front the num_supported. // So we read these structures here, if each type is scanned. Note if one is missing, // the num_supported will remain zero, from the calloc below. // variants, no subvariants. // Get the next, if any. // Exit if done. // Out of range? // Y. Skip if variant unrecognized. // idx into FreqTable. // Getting data needed to detail rsmi_dev_pci_bandwidth_get. // Skip if not avail on this device. // Build the list of all possible native ROCM events. // This routine will only add elements we have code to support, // and only if they appear in the ScanEvents[] array. It will // produce TotalEvents. // check for failure. // This is for diagnostic/debug purposes, it shows which // routines were enumerated as available, but we do not // attempt to make an event to access.  There is a // corresponding diagnostic in nextEvent() to show what // we tried to incorporate but did not find. // Export info to PAPI.