src/components/rocm_smi/linux-rocm-smi.c
//-------------------------------------------------------------------------
// We use the ROCM iterator to list all the available functions on each 
// device.
// This code is derived from the C++ example code in the rsmi manual, Ch5.
//-------------------------------------------------------------------------
We use the ROCM iterator to list all the available functions on each
device.
This code is derived from the C++ example code in the rsmi manual, Ch5.
We use the ROCM iterator to list all the available functions on each device . This code is derived from the C ++ example code in the rsmi manual Ch5 .
static void scanEvents(void) {
    rsmi_func_id_iter_handle_t iter_handle, var_iter, sub_var_iter;
    rsmi_func_id_value_t v_name, v_enum, v_sensor;
    rsmi_status_t err;
    unsigned int ui;
    for (ui=0; ui<TotalDevices; ++ui) {                                         
        err = (*rsmi_dev_supported_func_iterator_openPtr)(ui, &iter_handle);    
        while (1) {                                                             
            err = (*rsmi_func_iter_value_getPtr)(iter_handle, &v_name);         
            err = (*rsmi_dev_supported_variant_iterator_openPtr)(               
                  iter_handle, &var_iter);
            if (err == RSMI_STATUS_NO_DATA) {                                   
                addScanEvent(v_name.name, ui, -1, -1);
            } else {                                                            
                while (err != RSMI_STATUS_NO_DATA) {                            
                    err = (*rsmi_func_iter_value_getPtr)(var_iter, &v_enum);    
                    err = (*rsmi_dev_supported_variant_iterator_openPtr)(       
                          var_iter, &sub_var_iter);
                    if (err == RSMI_STATUS_NO_DATA) {
                        addScanEvent(v_name.name, ui, v_enum.id, -1);
                    } else {
                        while (err != RSMI_STATUS_NO_DATA) {                
                            err = (*rsmi_func_iter_value_getPtr)(           
                                  sub_var_iter, &v_sensor);                  
                            addScanEvent(v_name.name, ui, v_enum.id, v_sensor.id); 
                            err = (*rsmi_func_iter_nextPtr)(sub_var_iter);  
                        }
                        err = (*rsmi_dev_supported_func_iterator_closePtr)  
                              (&sub_var_iter);                            
                    } 
                    err = (*rsmi_func_iter_nextPtr)(var_iter);              
                } 
                err = (*rsmi_dev_supported_func_iterator_closePtr)(&var_iter);
            } 
            err = (*rsmi_func_iter_nextPtr)(iter_handle);               
            if (err == RSMI_STATUS_NO_DATA) {
                break;
            }
        } 
        err = (*rsmi_dev_supported_func_iterator_closePtr) (&iter_handle);
    } 
    qsort(ScanEvents, TotalScanEvents, sizeof(scanEvent_info_t), sortScanEvents);
    MakeRoomScanEvents();                                                           
    ScanEvents[TotalScanEvents].device=-1;                                          
    ScanEvents[TotalScanEvents].funcname[0]=0;                                      
    ScanEvents[TotalScanEvents].variant=-1;                                         
    ScanEvents[TotalScanEvents].subvariant=-1;                                      
}
static void scanEvents ( void ) { rsmi_func_id_iter_handle_t iter_handle , var_iter , sub_var_iter ; rsmi_func_id_value_t v_name , v_enum , v_sensor ; rsmi_status_t err ; unsigned int ui ; for ( ui = 0 ; ui < TotalDevices ; ++ ui ) { err = ( * rsmi_dev_supported_func_iterator_openPtr ) ( ui , & iter_handle ) ; while ( 1 ) { err = ( * rsmi_func_iter_value_getPtr ) ( iter_handle , & v_name ) ; err = ( * rsmi_dev_supported_variant_iterator_openPtr ) ( iter_handle , & var_iter ) ; if ( err == RSMI_STATUS_NO_DATA ) { addScanEvent ( v_name . name , ui , -1 , -1 ) ; } else { while ( err != RSMI_STATUS_NO_DATA ) { err = ( * rsmi_func_iter_value_getPtr ) ( var_iter , & v_enum ) ; err = ( * rsmi_dev_supported_variant_iterator_openPtr ) ( var_iter , & sub_var_iter ) ; if ( err == RSMI_STATUS_NO_DATA ) { addScanEvent ( v_name . name , ui , v_enum . id , -1 ) ; } else { while ( err != RSMI_STATUS_NO_DATA ) { err = ( * rsmi_func_iter_value_getPtr ) ( sub_var_iter , & v_sensor ) ; addScanEvent ( v_name . name , ui , v_enum . id , v_sensor . id ) ; err = ( * rsmi_func_iter_nextPtr ) ( sub_var_iter ) ; } err = ( * rsmi_dev_supported_func_iterator_closePtr ) ( & sub_var_iter ) ; } err = ( * rsmi_func_iter_nextPtr ) ( var_iter ) ; } err = ( * rsmi_dev_supported_func_iterator_closePtr ) ( & var_iter ) ; } err = ( * rsmi_func_iter_nextPtr ) ( iter_handle ) ; if ( err == RSMI_STATUS_NO_DATA ) { break ; } } err = ( * rsmi_dev_supported_func_iterator_closePtr ) ( & iter_handle ) ; } qsort ( ScanEvents , TotalScanEvents , sizeof ( scanEvent_info_t ) , sortScanEvents ) ; MakeRoomScanEvents ( ) ; ScanEvents [ TotalScanEvents ] . device = -1 ; ScanEvents [ TotalScanEvents ] . funcname [ 0 ] = 0 ; ScanEvents [ TotalScanEvents ] . variant = -1 ; ScanEvents [ TotalScanEvents ] . subvariant = -1 ; }
We use the ROCM iterator to list all the available functions on each
device.
We use the ROCM iterator to list all the available functions on each device .
// For each device, // begin iterator. // until we break out, // get the next handle. // Iterate through variants. // If we have NO variance pointer, // If we have a variance pointer, // Iterate through them. // Get a value. // Now look for sub-variants. // If any, and read until empty. // Read one. // Get next from iterator. // close variant iterator. // end if there were any sub-variants (sensors)  // Get the next variant. // end while var_iter loop.    // end if we had any var_iter to do. // loop to next function. // end function iterator loop. // end for each device. // sort by device, name, variant, sub-variant. // Create an end of list marker; for scanning without an index. // Make room if needed. // Mark end of list. // name. // variant is typically enum, may be a type. // subvariant is typically a sensor-ID.