CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tools / dagsim / dagsim.h
| 1 | /* |
| 2 | * dagsim.h -- offline resource-DAG cost evaluator (omega-mv#583). |
| 3 | * |
| 4 | * Reads an OEV1 file (spec/offline-evidence-v1.md) and composes the per-op |
| 5 | * costs it carries, or that rx_costmodel predicts for matvec ops, into a |
| 6 | * whole-DAG schedule under finite resources: compute slots, shared |
| 7 | * bandwidth (processor sharing), serialized launches, one capacity ledger, |
| 8 | * dependencies and barriers. It never executes anything. It refuses rather |
| 9 | * than guess: unknown provenance, stale calibration, capacity overflow, |
| 10 | * an inverted buffer lifetime (resolved end before start), unsupported |
| 11 | * constructs and cycles are all refusals with a reason. |
| 12 | * |
| 13 | * Host only. No GPU, no authority, no generation store. |
| 14 | */ |
| 15 | #ifndef DAGSIM_H |
| 16 | #define DAGSIM_H |
| 17 | |
| 18 | #include <stddef.h> |
| 19 | #include <stdint.h> |
| 20 | |
| 21 | /* Explicit migration oracle only; the production parser/formatter is seeded Omega. */ |
| 22 | #ifndef CUDAPP_MIGRATION_PENDING_C_DAGSIM_PARSE |
| 23 | #define CUDAPP_MIGRATION_PENDING_C_DAGSIM_PARSE 0 |
| 24 | #endif |
| 25 | |
| 26 | /* Explicit migration oracle only; resolve/diff decisions are seeded Omega. */ |
| 27 | #ifndef CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE |
| 28 | #define CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE 0 |
| 29 | #endif |
| 30 | |
| 31 | #define DS_MAX_OPS 256 |
| 32 | #define DS_MAX_RES 32 |
| 33 | #define DS_MAX_BUF 256 |
| 34 | #define DS_MAX_DEPS 1024 |
| 35 | #define DS_MAX_REMOVED 256 |
| 36 | #define DS_ID 40 |
| 37 | #define DS_SRC 128 |
| 38 | |
| 39 | enum ds_prov { DS_PROV_UNKNOWN = 0, DS_PROV_SYNTHETIC, DS_PROV_FITTED, DS_PROV_MEASURED, DS_PROV_SPECIFIED }; |
| 40 | enum ds_res_kind { DS_RES_COMPUTE = 1, DS_RES_BANDWIDTH, DS_RES_CAPACITY, DS_RES_LAUNCH }; |
| 41 | enum ds_op_kind { DS_OP_COMPUTE = 1, DS_OP_COPY, DS_OP_MATVEC, DS_OP_BARRIER, DS_OP_STORAGE, DS_OP_PERSIST }; |
| 42 | enum ds_removed_reason { DS_RM_ELIMINATED = 1, DS_RM_REUSED, DS_RM_UNCHANGED_DEP, DS_RM_DEFERRED, DS_RM_MOVED, DS_RM_SHARED, DS_RM_LOOKUP }; |
| 43 | |
| 44 | enum ds_status { |
| 45 | DS_OK = 0, |
| 46 | DS_REFUSED_UNKNOWN, /* an op or resource with prov=unknown feeds the result */ |
| 47 | DS_REFUSED_STALE, /* asof is past calibration taken + valid_days */ |
| 48 | DS_REFUSED_NO_CALIBRATION, /* measured/fitted values but no calibration record */ |
| 49 | DS_REFUSED_CAPACITY, /* peak live bytes exceed a capacity resource */ |
| 50 | DS_REFUSED_CYCLE, |
| 51 | DS_REFUSED_UNSUPPORTED, /* construct the evaluator does not model */ |
| 52 | DS_REFUSED_REMOVED_REQUIRED, /* a remaining op depends on removed work without a valid derivation */ |
| 53 | DS_REFUSED_LIFETIME, /* resolved buffer end is earlier than its start */ |
| 54 | DS_PARSE_ERROR |
| 55 | }; |
| 56 | |
| 57 | typedef struct { |
| 58 | char id[DS_ID]; |
| 59 | int kind; |
| 60 | int slots; /* compute */ |
| 61 | double cap, lo, hi; /* bandwidth (B/s) or capacity (B) */ |
| 62 | int prov; |
| 63 | char src[DS_SRC]; |
| 64 | } ds_resource; |
| 65 | |
| 66 | typedef struct { |
| 67 | char id[DS_ID]; |
| 68 | int kind; |
| 69 | int engine; /* resource index or -1 */ |
| 70 | double t_ns, lo, hi; /* own busy time */ |
| 71 | int t_prov; |
| 72 | int has_t; |
| 73 | double bytes; |
| 74 | int bw; /* bandwidth resource index or -1 */ |
| 75 | double launch_ns; |
| 76 | int launcher; /* launch resource index or -1 */ |
| 77 | uint32_t M, N, core, arm; /* matvec */ |
| 78 | char src[DS_SRC]; |
| 79 | } ds_op; |
| 80 | |
| 81 | typedef struct { char id[DS_ID]; double bytes; int cap; int first, last; } ds_buffer; |
| 82 | typedef struct { int from, to; } ds_dep; |
| 83 | typedef struct { char op[DS_ID]; int reason; char ref[DS_ID]; char proof[DS_SRC]; } ds_removed; |
| 84 | |
| 85 | typedef struct { |
| 86 | int version; |
| 87 | char machine_id[DS_ID], soc[DS_ID]; |
| 88 | int cores; |
| 89 | double mem_bytes; |
| 90 | char build_sha[48], physics[48], repo[DS_ID]; |
| 91 | int has_calibration; |
| 92 | char cal_id[DS_ID]; |
| 93 | int cal_taken_day; /* days since 1970-01-01 */ |
| 94 | int cal_valid_days; |
| 95 | double cal_load1; |
| 96 | char cal_src[DS_SRC], cal_model[DS_SRC]; |
| 97 | int n_res, n_ops, n_buf, n_deps, n_removed; |
| 98 | ds_resource res[DS_MAX_RES]; |
| 99 | ds_op ops[DS_MAX_OPS]; |
| 100 | ds_buffer buf[DS_MAX_BUF]; |
| 101 | ds_dep deps[DS_MAX_DEPS]; |
| 102 | ds_removed removed[DS_MAX_REMOVED]; |
| 103 | /* energy */ |
| 104 | char instrument[DS_ID], boundary[DS_ID]; |
| 105 | int energy_prov; |
| 106 | double joules, power_w; |
| 107 | int has_energy; |
| 108 | } ds_model; |
| 109 | |
| 110 | typedef struct { |
| 111 | int asof_day; /* days since epoch; 0 = today */ |
| 112 | int mode; /* 0 nominal, -1 pessimistic (lo bandwidth, hi time), +1 optimistic */ |
| 113 | const void *costmodel; /* const RxCostModel* or NULL */ |
| 114 | double interval_q; /* for rx_costmodel intervals, e.g. 0.9 */ |
| 115 | const char *changed; /* diff only: comma list of baseline ops whose inputs changed */ |
| 116 | } ds_opts; |
| 117 | |
| 118 | enum { DS_ATTR_COMPUTE = 0, DS_ATTR_BANDWIDTH, DS_ATTR_CONTENTION, DS_ATTR_LAUNCH, DS_ATTR_SERIALIZATION, DS_ATTR_SYNC, DS_ATTR_RESIDUAL, DS_ATTR_N }; |
| 119 | |
| 120 | typedef struct { |
| 121 | int status; |
| 122 | char reason[256]; |
| 123 | double makespan_ns; |
| 124 | double start_ns[DS_MAX_OPS], end_ns[DS_MAX_OPS], ready_ns[DS_MAX_OPS]; |
| 125 | double op_contention_ns[DS_MAX_OPS]; /* extra traffic time due to sharing */ |
| 126 | double op_floor_ns[DS_MAX_OPS]; /* launch + max(t, bytes/cap) */ |
| 127 | double bound_critical_path_ns; |
| 128 | double bound_resource_ns[DS_MAX_RES]; /* per resource work bound */ |
| 129 | double bound_ns; /* max of all bounds */ |
| 130 | double peak_live_bytes[DS_MAX_RES]; /* per capacity resource */ |
| 131 | double peak_live_at_ns[DS_MAX_RES]; |
| 132 | double attr_ns[DS_ATTR_N]; |
| 133 | int critical_path[DS_MAX_OPS], n_critical; |
| 134 | uint32_t prov_mask; /* bit per ds_prov that fed the result */ |
| 135 | int synthetic; |
| 136 | /* conservation: what went in is what was scheduled */ |
| 137 | int n_ops; |
| 138 | double total_bytes, total_busy_ns, total_launch_ns; |
| 139 | /* energy */ |
| 140 | int energy_measured; /* 1: joules from a named instrument */ |
| 141 | int energy_synthetic; /* 1: E = P*T from a synthetic power figure */ |
| 142 | double energy_j; |
| 143 | } ds_result; |
| 144 | |
| 145 | /* Parse. Returns DS_OK or DS_PARSE_ERROR with the line and reason in `err`. */ |
| 146 | int ds_parse_file(const char *path, ds_model *m, char *err, size_t errcap); |
| 147 | int ds_parse_text(const char *text, ds_model *m, char *err, size_t errcap); |
| 148 | |
| 149 | /* Evaluate deterministically. Fills every field of `r` or sets a refusal. */ |
| 150 | int ds_eval(const ds_model *m, const ds_opts *o, ds_result *r); |
| 151 | |
| 152 | /* Three-point interval: nominal, lo (optimistic) and hi (pessimistic) makespan. |
| 153 | * Returns the nominal status; lo/hi are 0 when any point refused. */ |
| 154 | int ds_eval_interval(const ds_model *m, const ds_opts *o, ds_result *nominal, double *lo_ns, double *hi_ns); |
| 155 | |
| 156 | /* Counterfactual sensitivity: makespan with one resource doubled (bandwidth cap x2, |
| 157 | * compute slots x2, launch cost 0). Returns the new makespan or a negative status. */ |
| 158 | double ds_counterfactual(const ds_model *m, const ds_opts *o, int res_index); |
| 159 | |
| 160 | /* Minimum-work accounting: compare a baseline and a transformed model by stable op |
| 161 | * ids. Sums removed work by reason and detects double-counted shared work and removal |
| 162 | * of required work. */ |
| 163 | typedef struct { |
| 164 | double removed_ns[8]; /* by ds_removed_reason */ |
| 165 | int n_removed, n_added, n_kept; |
| 166 | int double_counted; /* an op removed with reason=shared appears twice or refs a missing op */ |
| 167 | int required_removed; /* a removed op without a valid derivation still has consumers */ |
| 168 | char reason[256]; |
| 169 | } ds_diff; |
| 170 | int ds_diff_models(const ds_model *baseline, const ds_model *transformed, const ds_opts *o, ds_diff *d); |
| 171 | |
| 172 | const char *ds_status_name(int s); |
| 173 | const char *ds_prov_name(int p); |
| 174 | int ds_day_from_date(const char *yyyy_mm_dd); |
| 175 | int ds_find_op(const ds_model *m, const char *id); |
| 176 | int ds_find_res(const ds_model *m, const char *id); |
| 177 | |
| 178 | #endif /* DAGSIM_H */ |