apmpi-backend.py 5.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
import cffi
import ctypes

import numpy as np
import darshan.backend.cffi_backend

# APMPI structure defs
structdefs = '''
struct darshan_apmpi_perf_record
{
    struct darshan_base_record base_rec;
12 13
    uint64_t counters[396];
    double fcounters[222];
14 15
    double fsynccounters[16];
    double fglobalcounters[2];
16
    char   node_name[128];
17 18 19
};
struct darshan_apmpi_header_record
{
20
    struct darshan_base_record base_rec;  
21
    int64_t magic;
22
    uint32_t sync_flag;
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    double apmpi_f_variance_total_mpitime;
    double apmpi_f_variance_total_mpisynctime;
};

extern char *apmpi_counter_names[];
extern char *apmpi_f_mpiop_totaltime_counter_names[]; 
extern char *apmpi_f_mpiop_synctime_counter_names[];
extern char *apmpi_f_mpi_global_counter_names[];

'''

def get_apmpi_defs():
  return structdefs


Sudheer Chunduri's avatar
Sudheer Chunduri committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
# load header record
def log_get_apmpi_record(log, mod_type, dtype='dict'):
    from darshan.backend.cffi_backend import ffi, libdutil, log_get_modules, counter_names

    mod_name = 'APMPI'
    modules = log_get_modules(log)


    rec = {}
    buf = ffi.new("void **")
    r = libdutil.darshan_log_get_record(log['handle'], modules[mod_name]['idx'], buf)
    if r < 1:
        return None

    if mod_type == 'struct darshan_apmpi_header_record **':
        hdr = ffi.cast(mod_type, buf)
        rec['id'] = hdr[0].base_rec.id
        rec['rank'] = hdr[0].base_rec.rank
        rec['magic'] = hdr[0].magic
57
        rec['sync_flag'] = hdr[0].sync_flag
Sudheer Chunduri's avatar
Sudheer Chunduri committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
        rec['variance_total_mpitime'] = hdr[0].apmpi_f_variance_total_mpitime
        rec['variance_total_mpisynctime'] = hdr[0].apmpi_f_variance_total_mpisynctime
    else:
        prf = ffi.cast(mod_type, buf)
        rec['id'] = prf[0].base_rec.id
        rec['rank'] = prf[0].base_rec.rank
        rec['node_name'] = ffi.string(prf[0].node_name).decode("utf-8")
        
        lst = []
        for i in range(0, len(prf[0].counters)):
            lst.append(prf[0].counters[i])
        np_counters = np.array(lst, dtype=np.uint64)
        d_counters = dict(zip(counter_names(mod_name), np_counters))

        lst = []
        for i in range(0, len(prf[0].fcounters)):
            lst.append(prf[0].fcounters[i])
        np_fcounters = np.array(lst, dtype=np.float64)
        d_fcounters = dict(zip(counter_names(mod_name, fcnts=True, special='mpiop_totaltime_'), np_fcounters))

        lst = []
        for i in range(0, len(prf[0].fsynccounters)):
            lst.append(prf[0].fsynccounters[i])
        np_fsynccounters = np.array(lst, dtype=np.float64)
        d_fsynccounters = dict(zip(counter_names(mod_name, fcnts=True, special='mpiop_synctime_'), np_fsynccounters))

        lst = []
        for i in range(0, len(prf[0].fglobalcounters)):
            lst.append(prf[0].fglobalcounters[i])
        np_fglobalcounters = np.array(lst, dtype=np.float64)
        d_fglobalcounters = dict(zip(counter_names(mod_name, fcnts=True, special='mpi_global_'), np_fglobalcounters))
        
        rec['all_counters'] = {}
        rec['all_counters'].update(d_counters)
        rec['all_counters'].update(d_fcounters)
        rec['all_counters'].update(d_fsynccounters)
        rec['all_counters'].update(d_fglobalcounters)

    return rec


'''
        if dtype == 'numpy':
            rec['counters'] = np_counters
            rec['fcounters'] = np_fcounters
            rec['fsynccounters'] = np_fsynccounters
            rec['fglobalcounters'] = np_fglobalcounters
        else:
            rec['counters'] = d_counters
            rec['fcounters'] = d_fcounters
            rec['fsynccounters'] = d_fsynccounters
            rec['fglobalcounters'] = d_fglobalcounters
'''    


'''

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
# load header record
def log_get_apmpi_record(log, dtype='dict'):
    from darshan.backend.cffi_backend import ffi, libdutil, log_get_modules, counter_names

    mod_name = 'APMPI'
    modules = log_get_modules(log)


    rec = {}
    buf = ffi.new("void **")
    r = libdutil.darshan_log_get_record(log['handle'], modules[mod_name]['idx'], buf)
    if r < 1:
        return None

    hdr = ffi.cast('struct darshan_apmpi_header_record **', buf)

    rec['id'] = hdr[0].base_rec.id
    rec['rank'] = hdr[0].base_rec.rank

    if hdr[0].magic == 280520118345:
      rec['magic'] = hdr[0].magic
      rec['variance_total_mpitime'] = hdr[0].apmpi_f_variance_total_mpitime
      rec['variance_total_mpisynctime'] = hdr[0].apmpi_f_variance_total_mpisynctime
    else:
Sudheer Chunduri's avatar
Sudheer Chunduri committed
139
      prf = ffi.cast('struct darshan_apmpi_perf_record **', buf)
140
      rec['node_name'] = ffi.string(prf[0].node_name).decode("utf-8")
141 142 143 144

      lst = []
      for i in range(0, len(prf[0].counters)):
        lst.append(prf[0].counters[i])
Sudheer Chunduri's avatar
Sudheer Chunduri committed
145 146
      np_counters = np.array(lst, dtype=np.uint64)
      d_counters = dict(zip(counter_names(mod_name), np_counters))
147 148 149 150

      lst = []
      for i in range(0, len(prf[0].fcounters)):
        lst.append(prf[0].fcounters[i])
Sudheer Chunduri's avatar
Sudheer Chunduri committed
151 152
      np_fcounters = np.array(lst, dtype=np.float64)
      d_fcounters = dict(zip(counter_names(mod_name, fcnts=True, special='mpiop_totaltime_'), np_fcounters))
153 154 155 156

      lst = []
      for i in range(0, len(prf[0].fsynccounters)):
        lst.append(prf[0].fsynccounters[i])
Sudheer Chunduri's avatar
Sudheer Chunduri committed
157 158
      np_fsynccounters = np.array(lst, dtype=np.float64)
      d_fsynccounters = dict(zip(counter_names(mod_name, fcnts=True, special='mpiop_synctime_'), np_fsynccounters))
159 160 161 162

      lst = []
      for i in range(0, len(prf[0].fglobalcounters)):
        lst.append(prf[0].fglobalcounters[i])
Sudheer Chunduri's avatar
Sudheer Chunduri committed
163 164
      np_fglobalcounters = np.array(lst, dtype=np.float64)
      d_fglobalcounters = dict(zip(counter_names(mod_name, fcnts=True, special='mpi_global_'), np_fglobalcounters))
165 166 167 168 169 170 171 172 173 174 175 176 177 178

      if dtype == 'numpy':
        rec['counters'] = np_counters
        rec['fcounters'] = np_fcounters
        rec['fsynccounters'] = np_fsynccounters
        rec['fglobalcounters'] = np_fglobalcounters
      else:
        rec['counters'] = d_counters
        rec['fcounters'] = d_fcounters
        rec['fsynccounters'] = d_fsynccounters
        rec['fglobalcounters'] = d_fglobalcounters
    
    return rec

Sudheer Chunduri's avatar
Sudheer Chunduri committed
179
'''