interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / evidence / dagsim-resolve-om / oracle.gcov

1899 lines · 96444 bytes Raw Blame History
1 -: 0:Source:tools/dagsim/dagsim.c
2 -: 0:Graph:build/dagsim-resolve/oracle.gcno
3 -: 0:Data:build/dagsim-resolve/oracle.gcda
4 -: 0:Runs:1
5 -: 1:/*
6 -: 2: * dagsim.c -- offline resource-DAG cost evaluator (omega-mv#583).
7 -: 3: *
8 -: 4: * See dagsim.h and spec/offline-evidence-v1.md. The scheduler is a
9 -: 5: * deterministic fluid simulation: compute engines have slots, bandwidth
10 -: 6: * resources are shared equally among the ops streaming on them at any
11 -: 7: * instant, launches are serialized per launch resource, and an op finishes
12 -: 8: * when both its own busy time and its traffic are done (perfect overlap
13 -: 9: * inside one op, which is the issue's stated floor max(F/P, Q/B)). Ops are
14 -: 10: * dispatched in file order, so the same file always gives the same bytes.
15 -: 11: */
16 -: 12:#include "dagsim.h"
17 -: 13:#include "runtime/rx_costmodel.h"
18 -: 14:
19 -: 15:#include <ctype.h>
20 -: 16:#include <math.h>
21 -: 17:#include <stdio.h>
22 -: 18:#include <stdlib.h>
23 -: 19:#include <string.h>
24 -: 20:#include <time.h>
25 -: 21:#if !CUDAPP_MIGRATION_PENDING_C_DAGSIM_PARSE
26 -: 22:#include "dagsim_format.h"
27 -: 23:#endif
28 -: 24:
29 -: 25:/* ---------------------------------------------------------------- names */
30 -: 26:
31 -: 27:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_PARSE
32 -: 28:const char *ds_status_name(int s) {
33 -: 29: switch (s) {
34 -: 30: case DS_OK: return "OK";
35 -: 31: case DS_REFUSED_UNKNOWN: return "REFUSED_UNKNOWN";
36 -: 32: case DS_REFUSED_STALE: return "REFUSED_STALE";
37 -: 33: case DS_REFUSED_NO_CALIBRATION: return "REFUSED_NO_CALIBRATION";
38 -: 34: case DS_REFUSED_CAPACITY: return "REFUSED_CAPACITY";
39 -: 35: case DS_REFUSED_CYCLE: return "REFUSED_CYCLE";
40 -: 36: case DS_REFUSED_UNSUPPORTED: return "REFUSED_UNSUPPORTED";
41 -: 37: case DS_REFUSED_REMOVED_REQUIRED: return "REFUSED_REMOVED_REQUIRED";
42 -: 38: case DS_REFUSED_LIFETIME: return "REFUSED_LIFETIME";
43 -: 39: case DS_PARSE_ERROR: return "PARSE_ERROR";
44 -: 40: default: return "?";
45 -: 41: }
46 -: 42:}
47 -: 43:
48 -: 44:const char *ds_prov_name(int p) {
49 -: 45: switch (p) {
50 -: 46: case DS_PROV_UNKNOWN: return "unknown";
51 -: 47: case DS_PROV_SYNTHETIC: return "synthetic";
52 -: 48: case DS_PROV_FITTED: return "fitted";
53 -: 49: case DS_PROV_MEASURED: return "measured";
54 -: 50: case DS_PROV_SPECIFIED: return "specified";
55 -: 51: default: return "?";
56 -: 52: }
57 -: 53:}
58 -: 54:
59 -: 55:static int prov_from_name(const char *s) {
60 -: 56: if (!strcmp(s, "unknown")) return DS_PROV_UNKNOWN;
61 -: 57: if (!strcmp(s, "synthetic")) return DS_PROV_SYNTHETIC;
62 -: 58: if (!strcmp(s, "fitted")) return DS_PROV_FITTED;
63 -: 59: if (!strcmp(s, "measured")) return DS_PROV_MEASURED;
64 -: 60: if (!strcmp(s, "specified")) return DS_PROV_SPECIFIED;
65 -: 61: return -1;
66 -: 62:}
67 -: 63:
68 -: 64:/* days since 1970-01-01 for a civil date (Howard Hinnant's days_from_civil) */
69 -: 65:int ds_day_from_date(const char *s) {
70 -: 66: int y, m, d;
71 -: 67: if (!s || sscanf(s, "%d-%d-%d", &y, &m, &d) != 3) return -1;
72 -: 68: y -= m <= 2;
73 -: 69: int era = (y >= 0 ? y : y - 399) / 400;
74 -: 70: unsigned yoe = (unsigned)(y - era * 400);
75 -: 71: unsigned doy = (153u * (unsigned)(m + (m > 2 ? -3 : 9)) + 2u) / 5u + (unsigned)d - 1u;
76 -: 72: unsigned doe = yoe * 365u + yoe / 4u - yoe / 100u + doy;
77 -: 73: return era * 146097 + (int)doe - 719468;
78 -: 74:}
79 -: 75:#else
80function oracle_ds_status_name called 0 returned 0% blocks executed 0%
81 #####: 76:const char *ds_status_name(int s) {
82 -: 77: static _Thread_local char out[256];
83 #####: 78: uint64_t a[16] = {(uint32_t)s}; ds_fmt(0, a, out); return out;
84call 0 never executed
85 -: 79:}
86function oracle_ds_prov_name called 0 returned 0% blocks executed 0%
87 #####: 80:const char *ds_prov_name(int p) {
88 -: 81: static _Thread_local char out[256];
89 #####: 82: uint64_t a[16] = {(uint32_t)p}; ds_fmt(1, a, out); return out;
90call 0 never executed
91 -: 83:}
92function oracle_ds_day_from_date called 0 returned 0% blocks executed 0%
93 #####: 84:int ds_day_from_date(const char *s) {
94 #####: 85: if (!s) return -1;
95branch 0 never executed (fallthrough)
96branch 1 never executed
97 -: 86: char in[256];
98 #####: 87: uint64_t a[16] = {0};
99 #####: 88: for (;;) {
100 #####: 89: size_t n = strnlen(s, sizeof in);
101 #####: 90: memcpy(in, s, n);
102 #####: 91: a[0] = n; a[13] = n < sizeof in;
103 #####: 92: uint64_t rc = ds_fmt(21, a, in);
104call 0 never executed
105 #####: 93: if (rc == 1) return (int32_t)a[12];
106branch 0 never executed (fallthrough)
107branch 1 never executed
108 #####: 94: if (rc == 2) return -1;
109branch 0 never executed (fallthrough)
110branch 1 never executed
111 #####: 95: s += n;
112 -: 96: }
113 -: 97:}
114 -: 98:#endif
115 -: 99:
116 -: 100:#if !CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE
117 -: 101:static int dr_lookup(const ds_model *, const char *, int);
118 -: 102:#endif
119function oracle_ds_find_op called 8453 returned 100% blocks executed 100%
120 8453: 103:int ds_find_op(const ds_model *m, const char *id) {
121 -: 104:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE
122 208975: 105: for (int i = 0; i < m->n_ops; i++) if (!strcmp(m->ops[i].id, id)) return i;
123branch 0 taken 5609 (fallthrough)
124branch 1 taken 200522
125branch 2 taken 206131
126branch 3 taken 2844 (fallthrough)
127 2844: 106: return -1;
128 -: 107:#else
129 -: 108: return dr_lookup(m,id,0);
130 -: 109:#endif
131 -: 110:}
132function oracle_ds_find_res called 42 returned 100% blocks executed 100%
133 42: 111:int ds_find_res(const ds_model *m, const char *id) {
134 -: 112:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE
135 573: 113: for (int i = 0; i < m->n_res; i++) if (!strcmp(m->res[i].id, id)) return i;
136branch 0 taken 34 (fallthrough)
137branch 1 taken 531
138branch 2 taken 565
139branch 3 taken 8 (fallthrough)
140 8: 114: return -1;
141 -: 115:#else
142 -: 116: return dr_lookup(m,id,1);
143 -: 117:#endif
144 -: 118:}
145 -: 119:
146 -: 120:/* ---------------------------------------------------------------- parse */
147 -: 121:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_PARSE
148 -: 122:/* bounded string copy; ids and sources are truncated, never overflowed */
149 -: 123:static void sset(char *dst, size_t cap, const char *src) {
150 -: 124: size_t n = strlen(src);
151 -: 125: if (n >= cap) n = cap - 1;
152 -: 126: memcpy(dst, src, n); dst[n] = 0;
153 -: 127:}
154 -: 128:
155 -: 129:
156 -: 130:typedef struct { char key[32]; char val[DS_SRC]; int used; } kv;
157 -: 131:
158 -: 132:static int split_kv(char *line, char *keyword, size_t kwcap, kv *kvs, int maxkv, char *positional[], int *npos) {
159 -: 133: int n = 0; *npos = 0; keyword[0] = 0;
160 -: 134: char *p = strchr(line, '#'); if (p) *p = 0;
161 -: 135: char *save = NULL;
162 -: 136: char *tok = strtok_r(line, " \t\r\n", &save);
163 -: 137: if (!tok) return -1; /* empty */
164 -: 138: snprintf(keyword, kwcap, "%s", tok);
165 -: 139: while ((tok = strtok_r(NULL, " \t\r\n", &save))) {
166 -: 140: char *eq = strchr(tok, '=');
167 -: 141: if (!eq) { if (*npos < 8) positional[(*npos)++] = tok; continue; }
168 -: 142: if (n >= maxkv) return -2;
169 -: 143: *eq = 0;
170 -: 144: sset(kvs[n].key, sizeof kvs[n].key, tok);
171 -: 145: sset(kvs[n].val, sizeof kvs[n].val, eq + 1);
172 -: 146: kvs[n].used = 0;
173 -: 147: n++;
174 -: 148: }
175 -: 149: return n;
176 -: 150:}
177 -: 151:
178 -: 152:static const char *get(kv *kvs, int n, const char *key) {
179 -: 153: for (int i = 0; i < n; i++) if (!strcmp(kvs[i].key, key)) { kvs[i].used = 1; return kvs[i].val; }
180 -: 154: return NULL;
181 -: 155:}
182 -: 156:
183 -: 157:static int unused_key(kv *kvs, int n, char *out, size_t cap) {
184 -: 158: for (int i = 0; i < n; i++) if (!kvs[i].used) { snprintf(out, cap, "%s", kvs[i].key); return 1; }
185 -: 159: return 0;
186 -: 160:}
187 -: 161:
188 -: 162:static int parse_real(const char *s, double *out) {
189 -: 163: if (!s) return 0;
190 -: 164: char *end; double v = strtod(s, &end);
191 -: 165: if (end == s || *end) return 0;
192 -: 166: if (!(v == v) || v < 0) return 0;
193 -: 167: *out = v; return 1;
194 -: 168:}
195 -: 169:
196 -: 170:#define PERR(...) do { snprintf(err, errcap, "line %d: ", lineno); size_t _l = strlen(err); snprintf(err + _l, errcap - _l, __VA_ARGS__); return DS_PARSE_ERROR; } while (0)
197 -: 171:
198 -: 172:static int parse_prov_src(kv *kvs, int n, int *prov, char *src, size_t srccap, int required, char *err, size_t errcap, int lineno) {
199 -: 173: const char *p = get(kvs, n, "prov");
200 -: 174: const char *s = get(kvs, n, "src");
201 -: 175: if (!p) { if (required) PERR("prov= is required wherever a number appears"); *prov = -1; return DS_OK; }
202 -: 176: int v = prov_from_name(p);
203 -: 177: if (v < 0) PERR("prov=%s is not one of specified|measured|fitted|synthetic|unknown", p);
204 -: 178: *prov = v;
205 -: 179: if ((v == DS_PROV_MEASURED || v == DS_PROV_FITTED) && !s) PERR("prov=%s needs src=", p);
206 -: 180: snprintf(src, srccap, "%s", s ? s : "");
207 -: 181: return DS_OK;
208 -: 182:}
209 -: 183:
210 -: 184:int ds_parse_text(const char *text, ds_model *m, char *err, size_t errcap) {
211 -: 185: memset(m, 0, sizeof *m);
212 -: 186: err[0] = 0;
213 -: 187: int lineno = 0;
214 -: 188: const char *cur = text;
215 -: 189: int seen_oev = 0, seen_machine = 0, seen_build = 0;
216 -: 190: /* two-pass is not needed: ops before deps/buffers is the convention; we
217 -: 191: * resolve references at use and require definition before use. */
218 -: 192: while (*cur) {
219 -: 193: const char *nl = strchr(cur, '\n');
220 -: 194: size_t len = nl ? (size_t)(nl - cur) : strlen(cur);
221 -: 195: char line[1024];
222 -: 196: lineno++;
223 -: 197: if (len >= sizeof line) PERR("line too long");
224 -: 198: memcpy(line, cur, len); line[len] = 0;
225 -: 199: cur = nl ? nl + 1 : cur + len;
226 -: 200: char keyword[32]; kv kvs[24]; char *pos[8]; int npos;
227 -: 201: int n = split_kv(line, keyword, sizeof keyword, kvs, 24, pos, &npos);
228 -: 202: if (n == -1) continue;
229 -: 203: if (n == -2) PERR("too many fields");
230 -: 204: if (!strcmp(keyword, "oev")) {
231 -: 205: const char *v = get(kvs, n, "version");
232 -: 206: if (!v || strcmp(v, "1")) PERR("oev version=1 required");
233 -: 207: m->version = 1; seen_oev = 1;
234 -: 208: } else if (!strcmp(keyword, "machine")) {
235 -: 209: const char *v;
236 -: 210: if (!(v = get(kvs, n, "id"))) PERR("machine needs id=");
237 -: 211: sset(m->machine_id, sizeof m->machine_id, v);
238 -: 212: if ((v = get(kvs, n, "soc"))) sset(m->soc, sizeof m->soc, v);
239 -: 213: if ((v = get(kvs, n, "cores"))) m->cores = atoi(v);
240 -: 214: if ((v = get(kvs, n, "mem_bytes")) && !parse_real(v, &m->mem_bytes)) PERR("bad mem_bytes");
241 -: 215: int prov; char src[DS_SRC];
242 -: 216: int rc = parse_prov_src(kvs, n, &prov, src, sizeof src, 1, err, errcap, lineno); if (rc) return rc;
243 -: 217: seen_machine = 1;
244 -: 218: } else if (!strcmp(keyword, "build")) {
245 -: 219: const char *v;
246 -: 220: if ((v = get(kvs, n, "repo"))) sset(m->repo, sizeof m->repo, v);
247 -: 221: if (!(v = get(kvs, n, "sha")) || strlen(v) != 40) PERR("build needs sha=<40 hex>");
248 -: 222: sset(m->build_sha, sizeof m->build_sha, v);
249 -: 223: if ((v = get(kvs, n, "physics"))) sset(m->physics, sizeof m->physics, v);
250 -: 224: seen_build = 1;
251 -: 225: } else if (!strcmp(keyword, "calibration")) {
252 -: 226: const char *v;
253 -: 227: if (m->has_calibration) PERR("one calibration record only");
254 -: 228: if (!(v = get(kvs, n, "id"))) PERR("calibration needs id=");
255 -: 229: sset(m->cal_id, sizeof m->cal_id, v);
256 -: 230: if (!(v = get(kvs, n, "taken")) || (m->cal_taken_day = ds_day_from_date(v)) < 0) PERR("calibration needs taken=YYYY-MM-DD");
257 -: 231: if (!(v = get(kvs, n, "valid_days"))) PERR("calibration needs valid_days=");
258 -: 232: m->cal_valid_days = atoi(v);
259 -: 233: if (!(v = get(kvs, n, "load1")) || !parse_real(v, &m->cal_load1)) PERR("calibration needs load1=");
260 -: 234: if (!(v = get(kvs, n, "src"))) PERR("calibration needs src=");
261 -: 235: sset(m->cal_src, sizeof m->cal_src, v);
262 -: 236: if ((v = get(kvs, n, "model"))) sset(m->cal_model, sizeof m->cal_model, v);
263 -: 237: m->has_calibration = 1;
264 -: 238: } else if (!strcmp(keyword, "resource")) {
265 -: 239: if (m->n_res >= DS_MAX_RES) PERR("too many resources (max %d)", DS_MAX_RES);
266 -: 240: ds_resource *r = &m->res[m->n_res];
267 -: 241: memset(r, 0, sizeof *r);
268 -: 242: const char *v;
269 -: 243: if (!(v = get(kvs, n, "id"))) PERR("resource needs id=");
270 -: 244: if (ds_find_res(m, v) >= 0) PERR("duplicate resource %s", v);
271 -: 245: sset(r->id, sizeof r->id, v);
272 -: 246: if (!(v = get(kvs, n, "kind"))) PERR("resource needs kind=");
273 -: 247: if (!strcmp(v, "compute")) {
274 -: 248: r->kind = DS_RES_COMPUTE;
275 -: 249: if (!(v = get(kvs, n, "slots")) || (r->slots = atoi(v)) < 1) PERR("compute resource needs slots>=1");
276 -: 250: } else if (!strcmp(v, "bandwidth")) {
277 -: 251: r->kind = DS_RES_BANDWIDTH;
278 -: 252: if (!parse_real(get(kvs, n, "cap"), &r->cap) || r->cap <= 0) PERR("bandwidth resource needs cap>0");
279 -: 253: r->lo = r->hi = r->cap;
280 -: 254: if ((v = get(kvs, n, "lo")) && !parse_real(v, &r->lo)) PERR("bad lo");
281 -: 255: if ((v = get(kvs, n, "hi")) && !parse_real(v, &r->hi)) PERR("bad hi");
282 -: 256: if (r->lo > r->cap || r->hi < r->cap) PERR("need lo <= cap <= hi");
283 -: 257: } else if (!strcmp(v, "capacity")) {
284 -: 258: r->kind = DS_RES_CAPACITY;
285 -: 259: if (!parse_real(get(kvs, n, "cap"), &r->cap) || r->cap <= 0) PERR("capacity resource needs cap>0");
286 -: 260: } else if (!strcmp(v, "launch")) {
287 -: 261: r->kind = DS_RES_LAUNCH;
288 -: 262: } else PERR("resource kind=%s unknown", v);
289 -: 263: int rc = parse_prov_src(kvs, n, &r->prov, r->src, sizeof r->src, 1, err, errcap, lineno); if (rc) return rc;
290 -: 264: m->n_res++;
291 -: 265: } else if (!strcmp(keyword, "op")) {
292 -: 266: if (m->n_ops >= DS_MAX_OPS) PERR("too many ops (max %d)", DS_MAX_OPS);
293 -: 267: ds_op *o = &m->ops[m->n_ops];
294 -: 268: memset(o, 0, sizeof *o);
295 -: 269: o->engine = o->bw = o->launcher = -1;
296 -: 270: const char *v;
297 -: 271: if (!(v = get(kvs, n, "id"))) PERR("op needs id=");
298 -: 272: if (ds_find_op(m, v) >= 0) PERR("duplicate op %s", v);
299 -: 273: sset(o->id, sizeof o->id, v);
300 -: 274: if (!(v = get(kvs, n, "kind"))) PERR("op needs kind=");
301 -: 275: if (!strcmp(v, "compute")) o->kind = DS_OP_COMPUTE;
302 -: 276: else if (!strcmp(v, "copy")) o->kind = DS_OP_COPY;
303 -: 277: else if (!strcmp(v, "matvec")) o->kind = DS_OP_MATVEC;
304 -: 278: else if (!strcmp(v, "barrier")) o->kind = DS_OP_BARRIER;
305 -: 279: else if (!strcmp(v, "storage")) o->kind = DS_OP_STORAGE;
306 -: 280: else if (!strcmp(v, "persist")) o->kind = DS_OP_PERSIST;
307 -: 281: else PERR("op kind=%s unknown", v);
308 -: 282: if ((v = get(kvs, n, "engine"))) {
309 -: 283: o->engine = ds_find_res(m, v);
310 -: 284: if (o->engine < 0 || m->res[o->engine].kind != DS_RES_COMPUTE) PERR("engine=%s is not a compute resource defined above", v);
311 -: 285: }
312 -: 286: if ((v = get(kvs, n, "t_ns"))) { if (!parse_real(v, &o->t_ns)) PERR("bad t_ns"); o->has_t = 1; o->lo = o->hi = o->t_ns; }
313 -: 287: if ((v = get(kvs, n, "lo"))) { if (!o->has_t || !parse_real(v, &o->lo) || o->lo > o->t_ns) PERR("lo needs t_ns and lo <= t_ns"); }
314 -: 288: if ((v = get(kvs, n, "hi"))) { if (!o->has_t || !parse_real(v, &o->hi) || o->hi < o->t_ns) PERR("hi needs t_ns and hi >= t_ns"); }
315 -: 289: if ((v = get(kvs, n, "bytes"))) {
316 -: 290: if (!parse_real(v, &o->bytes)) PERR("bad bytes");
317 -: 291: const char *b = get(kvs, n, "bw");
318 -: 292: if (!b || (o->bw = ds_find_res(m, b)) < 0 || m->res[o->bw].kind != DS_RES_BANDWIDTH) PERR("bytes= needs bw=<bandwidth resource defined above>");
319 -: 293: }
320 -: 294: if ((v = get(kvs, n, "launch_ns"))) {
321 -: 295: if (!parse_real(v, &o->launch_ns)) PERR("bad launch_ns");
322 -: 296: const char *l = get(kvs, n, "launcher");
323 -: 297: if (!l || (o->launcher = ds_find_res(m, l)) < 0 || m->res[o->launcher].kind != DS_RES_LAUNCH) PERR("launch_ns= needs launcher=<launch resource defined above>");
324 -: 298: }
325 -: 299: if ((v = get(kvs, n, "M"))) o->M = (uint32_t)strtoul(v, NULL, 10);
326 -: 300: if ((v = get(kvs, n, "N"))) o->N = (uint32_t)strtoul(v, NULL, 10);
327 -: 301: if ((v = get(kvs, n, "core"))) o->core = (uint32_t)strtoul(v, NULL, 10);
328 -: 302: if ((v = get(kvs, n, "arm"))) o->arm = (uint32_t)strtoul(v, NULL, 10);
329 -: 303: if (o->kind == DS_OP_MATVEC && !o->has_t && (o->M == 0 || o->N == 0)) PERR("matvec needs M= and N= (or t_ns=)");
330 -: 304: if (o->kind != DS_OP_BARRIER && o->engine < 0) PERR("op %s needs engine=", o->id);
331 -: 305: int required = o->has_t || o->bytes > 0 || o->launch_ns > 0 || o->kind == DS_OP_MATVEC;
332 -: 306: int rc = parse_prov_src(kvs, n, &o->t_prov, o->src, sizeof o->src, required, err, errcap, lineno); if (rc) return rc;
333 -: 307: if (o->t_prov < 0) o->t_prov = DS_PROV_SPECIFIED; /* a costless barrier: ordering only */
334 -: 308: if (!o->has_t && o->kind != DS_OP_MATVEC && o->t_prov == DS_PROV_UNKNOWN) { /* fine: explicitly unknown */ }
335 -: 309: m->n_ops++;
336 -: 310: } else if (!strcmp(keyword, "dep")) {
337 -: 311: if (npos != 2 || n != 0) PERR("dep <from> <to>");
338 -: 312: if (m->n_deps >= DS_MAX_DEPS) PERR("too many deps");
339 -: 313: int a = ds_find_op(m, pos[0]), b = ds_find_op(m, pos[1]);
340 -: 314: if (a < 0 || b < 0) PERR("dep names an op not defined above: %s %s", pos[0], pos[1]);
341 -: 315: m->deps[m->n_deps].from = a; m->deps[m->n_deps].to = b; m->n_deps++;
342 -: 316: } else if (!strcmp(keyword, "buffer")) {
343 -: 317: if (m->n_buf >= DS_MAX_BUF) PERR("too many buffers");
344 -: 318: ds_buffer *b = &m->buf[m->n_buf];
345 -: 319: memset(b, 0, sizeof *b); b->first = b->last = -1;
346 -: 320: const char *v;
347 -: 321: if (!(v = get(kvs, n, "id"))) PERR("buffer needs id=");
348 -: 322: sset(b->id, sizeof b->id, v);
349 -: 323: if (!parse_real(get(kvs, n, "bytes"), &b->bytes) || !isfinite(b->bytes))
350 -: 324: PERR("buffer bytes must be a finite number >= 0");
351 -: 325: if (!(v = get(kvs, n, "cap")) || (b->cap = ds_find_res(m, v)) < 0 || m->res[b->cap].kind != DS_RES_CAPACITY) PERR("buffer needs cap=<capacity resource>");
352 -: 326: if ((v = get(kvs, n, "first")) && (b->first = ds_find_op(m, v)) < 0) PERR("first=%s not an op", v);
353 -: 327: if ((v = get(kvs, n, "last")) && (b->last = ds_find_op(m, v)) < 0) PERR("last=%s not an op", v);
354 -: 328: m->n_buf++;
355 -: 329: } else if (!strcmp(keyword, "sync")) {
356 -: 330: /* a barrier op that depends on every listed op */
357 -: 331: if (m->n_ops >= DS_MAX_OPS) PERR("too many ops");
358 -: 332: const char *v, *list;
359 -: 333: if (!(v = get(kvs, n, "id"))) PERR("sync needs id=");
360 -: 334: if (ds_find_op(m, v) >= 0) PERR("duplicate op %s", v);
361 -: 335: if (!(list = get(kvs, n, "ops"))) PERR("sync needs ops=a,b,...");
362 -: 336: ds_op *o = &m->ops[m->n_ops];
363 -: 337: memset(o, 0, sizeof *o);
364 -: 338: o->engine = o->bw = o->launcher = -1; o->kind = DS_OP_BARRIER; o->t_prov = DS_PROV_SPECIFIED;
365 -: 339: sset(o->id, sizeof o->id, v);
366 -: 340: int self = m->n_ops++;
367 -: 341: char tmp[DS_SRC]; sset(tmp, sizeof tmp, list);
368 -: 342: char *save = NULL;
369 -: 343: for (char *t = strtok_r(tmp, ",", &save); t; t = strtok_r(NULL, ",", &save)) {
370 -: 344: int a = ds_find_op(m, t);
371 -: 345: if (a < 0 || a == self) PERR("sync lists unknown op %s", t);
372 -: 346: if (m->n_deps >= DS_MAX_DEPS) PERR("too many deps");
373 -: 347: m->deps[m->n_deps].from = a; m->deps[m->n_deps].to = self; m->n_deps++;
374 -: 348: }
375 -: 349: } else if (!strcmp(keyword, "energy")) {
376 -: 350: const char *v;
377 -: 351: if (m->has_energy) PERR("one energy record only");
378 -: 352: if (!(v = get(kvs, n, "instrument"))) PERR("energy needs instrument=");
379 -: 353: sset(m->instrument, sizeof m->instrument, v);
380 -: 354: if ((v = get(kvs, n, "boundary"))) sset(m->boundary, sizeof m->boundary, v);
381 -: 355: const char *j = get(kvs, n, "joules"), *pw = get(kvs, n, "power_w");
382 -: 356: int prov = -1; char src[DS_SRC];
383 -: 357: int rc = parse_prov_src(kvs, n, &prov, src, sizeof src, j || pw ? 1 : 0, err, errcap, lineno); if (rc) return rc;
384 -: 358: m->energy_prov = prov;
385 -: 359: if (j) {
386 -: 360: if (!strcmp(m->instrument, "none") || !m->boundary[0]) PERR("joules= needs a named instrument and boundary=");
387 -: 361: if (prov != DS_PROV_MEASURED) PERR("joules= must be prov=measured with src=");
388 -: 362: if (!parse_real(j, &m->joules)) PERR("bad joules");
389 -: 363: }
390 -: 364: if (pw) {
391 -: 365: if (prov != DS_PROV_SYNTHETIC) PERR("power_w= is allowed only as prov=synthetic (a sensitivity figure); measured power must be integrated into joules= by the instrument");
392 -: 366: if (!parse_real(pw, &m->power_w)) PERR("bad power_w");
393 -: 367: }
394 -: 368: m->has_energy = 1;
395 -: 369: } else if (!strcmp(keyword, "removed")) {
396 -: 370: if (m->n_removed >= DS_MAX_REMOVED) PERR("too many removed records");
397 -: 371: ds_removed *r = &m->removed[m->n_removed];
398 -: 372: memset(r, 0, sizeof *r);
399 -: 373: const char *v;
400 -: 374: if (!(v = get(kvs, n, "op"))) PERR("removed needs op=");
401 -: 375: sset(r->op, sizeof r->op, v);
402 -: 376: if (ds_find_op(m, v) >= 0) PERR("removed op %s is still present in this DAG", v);
403 -: 377: if (!(v = get(kvs, n, "reason"))) PERR("removed needs reason=");
404 -: 378: if (!strcmp(v, "eliminated")) r->reason = DS_RM_ELIMINATED;
405 -: 379: else if (!strcmp(v, "reused")) r->reason = DS_RM_REUSED;
406 -: 380: else if (!strcmp(v, "unchanged_dep")) r->reason = DS_RM_UNCHANGED_DEP;
407 -: 381: else if (!strcmp(v, "deferred")) r->reason = DS_RM_DEFERRED;
408 -: 382: else if (!strcmp(v, "moved")) r->reason = DS_RM_MOVED;
409 -: 383: else if (!strcmp(v, "shared")) r->reason = DS_RM_SHARED;
410 -: 384: else if (!strcmp(v, "lookup")) r->reason = DS_RM_LOOKUP;
411 -: 385: else PERR("removed reason=%s unknown", v);
412 -: 386: if ((v = get(kvs, n, "ref"))) sset(r->ref, sizeof r->ref, v);
413 -: 387: if ((v = get(kvs, n, "proof"))) sset(r->proof, sizeof r->proof, v);
414 -: 388: m->n_removed++;
415 -: 389: } else PERR("unknown record '%s'", keyword);
416 -: 390: char bad[32];
417 -: 391: if (unused_key(kvs, n, bad, sizeof bad)) PERR("unknown field %s= on '%s'", bad, keyword);
418 -: 392: }
419 -: 393: lineno = 0;
420 -: 394: if (!seen_oev) PERR("missing 'oev version=1'");
421 -: 395: if (!seen_machine) PERR("missing machine record");
422 -: 396: if (!seen_build) PERR("missing build record");
423 -: 397: if (!m->has_energy) PERR("missing energy record (use instrument=none for UNMEASURED)");
424 -: 398: return DS_OK;
425 -: 399:}
426 -: 400:#else
427 -: 401:/* Copy only the already-bounded source spans selected by the Omega parser. */
428function dp_copy called 0 returned 0% blocks executed 0%
429 #####: 402:static void dp_copy(char *dst, const unsigned char *text, const uint64_t *w, size_t i) {
430 #####: 403: memcpy(dst, text + w[i], (size_t)w[i + 1]);
431 #####: 404: dst[w[i + 1]] = 0;
432 #####: 405:}
433function dp_double called 0 returned 0% blocks executed 0%
434 #####: 406:static double dp_double(const uint64_t *w, size_t i) {
435 #####: 407: return ds_unbits(w[i]);
436call 0 never executed
437 -: 408:}
438function oracle_ds_parse_text called 0 returned 0% blocks executed 0%
439 #####: 409:int ds_parse_text(const char *text, ds_model *m, char *err, size_t errcap) {
440 #####: 410: memset(m, 0, sizeof *m);
441 #####: 411: if (errcap) err[0] = 0;
442branch 0 never executed (fallthrough)
443branch 1 never executed
444 #####: 412: size_t n = strnlen(text, 1048576);
445 #####: 413: if (n == 1048576) {
446branch 0 never executed (fallthrough)
447branch 1 never executed
448 #####: 414: if (errcap) snprintf(err, errcap, "file size out of range");
449branch 0 never executed (fallthrough)
450branch 1 never executed
451 #####: 415: return DS_PARSE_ERROR;
452 -: 416: }
453 #####: 417: unsigned char *t = malloc(1048576);
454 #####: 418: uint64_t *w = malloc(16384 * sizeof *w);
455 #####: 419: if (!t || !w) {
456branch 0 never executed (fallthrough)
457branch 1 never executed
458branch 2 never executed (fallthrough)
459branch 3 never executed
460 #####: 420: free(t); free(w);
461 #####: 421: if (errcap) snprintf(err, errcap, "out of memory");
462branch 0 never executed (fallthrough)
463branch 1 never executed
464 #####: 422: return DS_PARSE_ERROR;
465 -: 423: }
466 #####: 424: memcpy(t, text, n + 1);
467 #####: 425: unsigned char error[256] = {0};
468 #####: 426: uint64_t rc = 0;
469 #####: 427: uint32_t trap = omega_dag_parse(&rc, t, 1048576, n, w, 16384, error, 256);
470call 0 never executed
471 #####: 428: if (trap || rc) {
472branch 0 never executed (fallthrough)
473branch 1 never executed
474branch 2 never executed (fallthrough)
475branch 3 never executed
476 #####: 429: if (errcap) snprintf(err, errcap, "%s", trap ? "Omega parser trap" : (char *)error);
477branch 0 never executed (fallthrough)
478branch 1 never executed
479branch 2 never executed (fallthrough)
480branch 3 never executed
481 #####: 430: free(t); free(w); return DS_PARSE_ERROR;
482 -: 431: }
483 #####: 432: m->version = (int32_t)w[0]; m->cores = (int32_t)w[1];
484 #####: 433: m->mem_bytes = dp_double(w, 2); m->has_calibration = (int32_t)w[3];
485call 0 never executed
486 #####: 434: m->cal_taken_day = (int32_t)w[4]; m->cal_valid_days = (int32_t)w[5];
487 #####: 435: m->cal_load1 = dp_double(w, 6); m->has_energy = (int32_t)w[7];
488call 0 never executed
489 #####: 436: m->joules = dp_double(w, 8); m->power_w = dp_double(w, 9);
490call 0 never executed
491call 1 never executed
492 #####: 437: m->energy_prov = (int32_t)w[10];
493 #####: 438: m->n_res = (int32_t)w[11]; m->n_ops = (int32_t)w[12];
494 #####: 439: m->n_buf = (int32_t)w[13]; m->n_deps = (int32_t)w[14]; m->n_removed = (int32_t)w[15];
495 #####: 440: dp_copy(m->machine_id, t, w, 17); dp_copy(m->soc, t, w, 19);
496call 0 never executed
497call 1 never executed
498 #####: 441: dp_copy(m->repo, t, w, 21); dp_copy(m->build_sha, t, w, 23);
499call 0 never executed
500call 1 never executed
501 #####: 442: dp_copy(m->physics, t, w, 25); dp_copy(m->cal_id, t, w, 27);
502call 0 never executed
503call 1 never executed
504 #####: 443: dp_copy(m->cal_src, t, w, 29); dp_copy(m->cal_model, t, w, 31);
505call 0 never executed
506call 1 never executed
507 #####: 444: dp_copy(m->instrument, t, w, 33); dp_copy(m->boundary, t, w, 35);
508call 0 never executed
509call 1 never executed
510 #####: 445: for (int i = 0; i < m->n_res; i++) {
511branch 0 never executed
512branch 1 never executed (fallthrough)
513 #####: 446: ds_resource *r = &m->res[i]; const uint64_t *p = w + 64 + i * 12;
514 #####: 447: dp_copy(r->id, t, p, 0); r->kind = (int32_t)p[2]; r->slots = (int32_t)p[3];
515call 0 never executed
516 #####: 448: r->cap = dp_double(p, 4); r->lo = dp_double(p, 5); r->hi = dp_double(p, 6);
517call 0 never executed
518call 1 never executed
519call 2 never executed
520 #####: 449: r->prov = (int32_t)p[7]; dp_copy(r->src, t, p, 8);
521call 0 never executed
522 -: 450: }
523 #####: 451: for (int i = 0; i < m->n_ops; i++) {
524branch 0 never executed
525branch 1 never executed (fallthrough)
526 #####: 452: ds_op *o = &m->ops[i]; const uint64_t *p = w + 448 + i * 26;
527 #####: 453: dp_copy(o->id, t, p, 0); o->kind = (int32_t)p[2]; o->engine = (int32_t)p[3];
528call 0 never executed
529 #####: 454: o->t_ns = dp_double(p, 4); o->lo = dp_double(p, 5); o->hi = dp_double(p, 6);
530call 0 never executed
531call 1 never executed
532call 2 never executed
533 #####: 455: o->t_prov = (int32_t)p[7]; o->has_t = (int32_t)p[8]; o->bytes = dp_double(p, 9);
534call 0 never executed
535 #####: 456: o->bw = (int32_t)p[10]; o->launch_ns = dp_double(p, 11); o->launcher = (int32_t)p[12];
536call 0 never executed
537 #####: 457: o->M = (uint32_t)p[13]; o->N = (uint32_t)p[14]; o->core = (uint32_t)p[15]; o->arm = (uint32_t)p[16];
538 #####: 458: dp_copy(o->src, t, p, 17);
539call 0 never executed
540 -: 459: }
541 #####: 460: for (int i = 0; i < m->n_deps; i++) {
542branch 0 never executed
543branch 1 never executed (fallthrough)
544 #####: 461: m->deps[i].from = (int32_t)w[7104 + i * 2];
545 #####: 462: m->deps[i].to = (int32_t)w[7105 + i * 2];
546 -: 463: }
547 #####: 464: for (int i = 0; i < m->n_buf; i++) {
548branch 0 never executed
549branch 1 never executed (fallthrough)
550 #####: 465: ds_buffer *b = &m->buf[i]; const uint64_t *p = w + 9152 + i * 8;
551 #####: 466: dp_copy(b->id, t, p, 0); b->bytes = dp_double(p, 2); b->cap = (int32_t)p[3];
552call 0 never executed
553call 1 never executed
554 #####: 467: b->first = (int32_t)p[4]; b->last = (int32_t)p[5];
555 -: 468: }
556 #####: 469: for (int i = 0; i < m->n_removed; i++) {
557branch 0 never executed
558branch 1 never executed (fallthrough)
559 #####: 470: ds_removed *r = &m->removed[i]; const uint64_t *p = w + 11200 + i * 8;
560 #####: 471: dp_copy(r->op, t, p, 0); r->reason = (int32_t)p[2];
561call 0 never executed
562 #####: 472: dp_copy(r->ref, t, p, 3); dp_copy(r->proof, t, p, 5);
563call 0 never executed
564call 1 never executed
565 -: 473: }
566 #####: 474: free(t); free(w);
567 #####: 475: return DS_OK;
568 -: 476:}
569 -: 477:#endif
570 -: 478:
571function oracle_ds_parse_file called 0 returned 0% blocks executed 0%
572 #####: 479:int ds_parse_file(const char *path, ds_model *m, char *err, size_t errcap) {
573 #####: 480: FILE *fp = fopen(path, "r");
574call 0 never executed
575 #####: 481: if (!fp) { snprintf(err, errcap, "cannot open %s", path); return DS_PARSE_ERROR; }
576branch 0 never executed (fallthrough)
577branch 1 never executed
578 #####: 482: fseek(fp, 0, SEEK_END); long n = ftell(fp); fseek(fp, 0, SEEK_SET);
579call 0 never executed
580call 1 never executed
581call 2 never executed
582 #####: 483: if (n < 0 || n > (1 << 20)) { fclose(fp); snprintf(err, errcap, "file size out of range"); return DS_PARSE_ERROR; }
583branch 0 never executed (fallthrough)
584branch 1 never executed
585branch 2 never executed (fallthrough)
586branch 3 never executed
587call 4 never executed
588 #####: 484: char *buf = malloc((size_t)n + 1);
589 #####: 485: if (!buf) { fclose(fp); snprintf(err, errcap, "out of memory"); return DS_PARSE_ERROR; }
590branch 0 never executed (fallthrough)
591branch 1 never executed
592call 2 never executed
593 #####: 486: size_t got = fread(buf, 1, (size_t)n, fp); buf[got] = 0; fclose(fp);
594call 0 never executed
595call 1 never executed
596 #####: 487: int rc = ds_parse_text(buf, m, err, errcap);
597call 0 never executed
598 #####: 488: free(buf);
599 #####: 489: return rc;
600 -: 490:}
601 -: 491:
602 -: 492:/* ---------------------------------------------------------------- evaluate */
603 -: 493:
604 -: 494:/* resolved per-op numbers for one evaluation mode */
605 -: 495:typedef struct { double t, launch, bytes, cap; int prov; } ds_num; /* cap in B/ns */
606 -: 496:
607 -: 497:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE
608function res_cap called 874 returned 100% blocks executed 100%
609 874: 498:static double res_cap(const ds_resource *r, int mode) {
610 874: 499: if (mode < 0) return r->lo;
611branch 0 taken 82 (fallthrough)
612branch 1 taken 792
613 792: 500: if (mode > 0) return r->hi;
614branch 0 taken 156 (fallthrough)
615branch 1 taken 636
616 636: 501: return r->cap;
617 -: 502:}
618 -: 503:#endif
619 -: 504:
620function refuse called 117 returned 100% blocks executed 75%
621 117: 505:static int refuse(ds_result *r, int status, const char *fmt, const char *a, const char *b) {
622 117: 506: memset(r, 0, sizeof *r);
623 117: 507: r->status = status;
624 117*: 508: snprintf(r->reason, sizeof r->reason, fmt, a ? a : "", b ? b : "");
625branch 0 taken 117 (fallthrough)
626branch 1 taken 0
627branch 2 taken 117 (fallthrough)
628branch 3 taken 0
629 117: 509: return status;
630 -: 510:}
631 -: 511:
632function refuse_msg called 0 returned 0% blocks executed 0%
633 #####: 512:static int refuse_msg(ds_result *r, int status, const char *msg) {
634 #####: 513: memset(r, 0, sizeof *r);
635 #####: 514: r->status = status;
636 #####: 515: snprintf(r->reason, sizeof r->reason, "%s", msg ? msg : "");
637branch 0 never executed (fallthrough)
638branch 1 never executed
639 #####: 516: return status;
640 -: 517:}
641 -: 518:
642 -: 519:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE
643 -: 520:/* An unsupported operation and a refused prediction are the same as an
644 -: 521: * unknown cell: no certificate. known alone is not enough. */
645function predict_unusable called 142 returned 100% blocks executed 100%
646 142: 522:static int predict_unusable(int st, const RxCmPrediction *p) {
647 142: 523: return st == RX_CM_ERR_UNSUPPORTED || p->refused || !p->known || p->n == 0; /* PREDICT_REFUSAL_CHECK */
648branch 0 taken 121 (fallthrough)
649branch 1 taken 21
650branch 2 taken 100 (fallthrough)
651branch 3 taken 21
652branch 4 taken 79 (fallthrough)
653branch 5 taken 21
654branch 6 taken 21 (fallthrough)
655branch 7 taken 58
656 -: 524:}
657 -: 525:
658function resolve called 242 returned 100% blocks executed 100%
659 242: 526:static int resolve(const ds_model *m, const ds_opts *o, ds_num *num, ds_result *r) {
660 242: 527: int any_cal = 0;
661 1221: 528: for (int i = 0; i < m->n_res; i++) {
662branch 0 taken 983
663branch 1 taken 238 (fallthrough)
664 983: 529: if (m->res[i].prov == DS_PROV_UNKNOWN) return refuse(r, DS_REFUSED_UNKNOWN, "resource %s has prov=unknown; unknown stays unknown%s", m->res[i].id, "");
665branch 0 taken 4 (fallthrough)
666branch 1 taken 979
667call 2 returned 4
668 979: 530: if (m->res[i].prov == DS_PROV_MEASURED || m->res[i].prov == DS_PROV_FITTED) any_cal = 1;
669branch 0 taken 976 (fallthrough)
670branch 1 taken 3
671branch 2 taken 9 (fallthrough)
672branch 3 taken 967
673 -: 531: }
674 1016: 532: for (int i = 0; i < m->n_ops; i++) {
675branch 0 taken 880
676branch 1 taken 136 (fallthrough)
677 880: 533: const ds_op *op = &m->ops[i];
678 880: 534: ds_num *x = &num[i];
679 880: 535: memset(x, 0, sizeof *x);
680 880: 536: x->prov = op->t_prov;
681 880: 537: x->launch = op->launch_ns;
682 880: 538: x->bytes = op->bytes;
683 880: 539: x->cap = op->bw >= 0 ? res_cap(&m->res[op->bw], o->mode) * 1e-9 : 0; /* B/s -> B/ns */
684branch 0 taken 874 (fallthrough)
685branch 1 taken 6
686call 2 returned 874
687 880: 540: if (op->kind == DS_OP_MATVEC && !op->has_t) {
688branch 0 taken 145 (fallthrough)
689branch 1 taken 735
690branch 2 taken 143 (fallthrough)
691branch 3 taken 2
692 143: 541: const RxCostModel *cm = (const RxCostModel *)o->costmodel;
693 227: 542: if (!cm) return refuse(r, DS_REFUSED_UNKNOWN, "op %s is a matvec with no rx_costmodel blob supplied (calibration model=)%s", op->id, "");
694branch 0 taken 1 (fallthrough)
695branch 1 taken 142
696call 2 returned 1
697 142: 543: RxCmFeatures f; memset(&f, 0, sizeof f);
698 142: 544: f.op = RX_CM_OP_MATVEC; f.M = op->M; f.N = op->N;
699 142: 545: f.state_bytes = ((uint64_t)op->M * op->N + op->M + op->N) * 8u;
700 142: 546: f.cache_bytes = 1u << 20; f.core = op->core; f.eligible = 1u << op->arm; f.current_arm = op->arm;
701 -: 547: RxCmPrediction p;
702 142: 548: int st = rx_cm_predict(cm, &f, op->arm, &p);
703call 0 returned 142
704 142: 549: if (predict_unusable(st, &p)) return refuse(r, DS_REFUSED_UNKNOWN, "op %s: rx_costmodel has no known cell for this (op, core, pressure) and arm; measure it first%s", op->id, "");
705call 0 returned 142
706branch 1 taken 84 (fallthrough)
707branch 2 taken 58
708call 3 returned 84
709 58: 550: double q = o->interval_q > 0 && o->interval_q < 1 ? o->interval_q : 0.9;
710branch 0 taken 24 (fallthrough)
711branch 1 taken 34
712branch 2 taken 12 (fallthrough)
713branch 3 taken 12
714 58: 551: double k = rx_cm_t_quantile(q, p.dof);
715call 0 returned 58
716 58: 552: double l2 = p.mean_log2_ps + (o->mode < 0 ? k * p.sd_log2 : o->mode > 0 ? -k * p.sd_log2 : 0);
717branch 0 taken 14 (fallthrough)
718branch 1 taken 44
719branch 2 taken 30 (fallthrough)
720branch 3 taken 14
721 58: 553: x->t = pow(2.0, l2) / 1000.0; /* ps -> ns */
722 58: 554: x->prov = DS_PROV_FITTED;
723 58: 555: any_cal = 1;
724 -: 556: } else {
725 737: 557: if (op->t_prov == DS_PROV_UNKNOWN) return refuse(r, DS_REFUSED_UNKNOWN, "op %s has prov=unknown (%s); unknown stays unknown", op->id, op->src[0] ? op->src : "no source");
726branch 0 taken 6 (fallthrough)
727branch 1 taken 731
728branch 2 taken 3 (fallthrough)
729branch 3 taken 3
730call 4 returned 6
731 731: 558: x->t = o->mode < 0 ? op->hi : o->mode > 0 ? op->lo : op->t_ns;
732branch 0 taken 38 (fallthrough)
733branch 1 taken 693
734branch 2 taken 95 (fallthrough)
735branch 3 taken 598
736 731: 559: if (op->t_prov == DS_PROV_MEASURED || op->t_prov == DS_PROV_FITTED) any_cal = 1;
737branch 0 taken 717 (fallthrough)
738branch 1 taken 14
739branch 2 taken 6 (fallthrough)
740branch 3 taken 711
741 -: 560: }
742 789: 561: if (op->engine < 0 && op->kind != DS_OP_BARRIER) return refuse(r, DS_REFUSED_UNSUPPORTED, "op %s has no engine%s", op->id, "");
743branch 0 taken 14 (fallthrough)
744branch 1 taken 775
745branch 2 taken 10 (fallthrough)
746branch 3 taken 4
747call 4 returned 10
748 779: 562: if (op->launcher >= 0 && op->engine < 0) return refuse(r, DS_REFUSED_UNSUPPORTED, "op %s: launch without an engine%s", op->id, "");
749branch 0 taken 770 (fallthrough)
750branch 1 taken 9
751branch 2 taken 1 (fallthrough)
752branch 3 taken 769
753call 4 returned 1
754 -: 563: }
755 136: 564: if (any_cal) {
756branch 0 taken 90 (fallthrough)
757branch 1 taken 46
758 90: 565: if (!m->has_calibration) return refuse(r, DS_REFUSED_NO_CALIBRATION, "measured or fitted values need a calibration record naming when and under what load they were taken%s%s", "", "");
759branch 0 taken 6 (fallthrough)
760branch 1 taken 84
761call 2 returned 6
762 84: 566: int asof = o->asof_day;
763 84: 567: if (asof <= 0) asof = (int)(time(NULL) / 86400);
764branch 0 taken 2 (fallthrough)
765branch 1 taken 82
766call 2 returned 2
767 84: 568: if (asof > m->cal_taken_day + m->cal_valid_days) {
768branch 0 taken 4 (fallthrough)
769branch 1 taken 80
770 4: 569: char d[64]; snprintf(d, sizeof d, "asof is %d day(s) past the validity envelope", asof - m->cal_taken_day - m->cal_valid_days);
771 4: 570: return refuse(r, DS_REFUSED_STALE, "calibration %s is stale: %s", m->cal_id, d);
772call 0 returned 4
773 -: 571: }
774 -: 572: }
775 126: 573: return DS_OK;
776 -: 574:}
777 -: 575:#else
778 -: 576:#include "dagsim_resolve.h"
779 -: 577:#endif
780 -: 578:
781function pk_d called 4068 returned 100% blocks executed 100%
782 4068: 579:static void pk_d(uint64_t *dst, double x) {
783 -: 580: uint64_t b;
784 4068: 581: memcpy(&b, &x, 8);
785 4068: 582: *dst = b;
786 4068: 583:}
787 -: 584:
788 -: 585:/* Pack post-resolve numbers for omega_dag_eval. Refusal strings stay in C. */
789function oracle_ds_resolved_pack called 243 returned 100% blocks executed 100%
790 243: 586:int ds_resolved_pack(const ds_model *m, const ds_opts *o, uint64_t *model, ds_result *r) {
791 -: 587:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE
792 243: 588: if (m->n_ops == 0) return refuse(r, DS_REFUSED_UNSUPPORTED, "empty DAG%s%s", "", "");
793branch 0 taken 1 (fallthrough)
794branch 1 taken 242
795call 2 returned 1
796 -: 589: ds_num num[DS_MAX_OPS];
797 242: 590: int rc = resolve(m, o, num, r);
798call 0 returned 242
799 242: 591: if (rc) return rc;
800branch 0 taken 116 (fallthrough)
801branch 1 taken 126
802 126: 592: memset(model, 0, 8192 * sizeof *model);
803 126: 593: model[0] = (uint64_t)m->n_ops;
804 126: 594: model[1] = (uint64_t)m->n_res;
805 126: 595: model[2] = (uint64_t)m->n_deps;
806 126: 596: model[3] = (uint64_t)m->n_buf;
807 126: 597: model[4] = m->has_energy ? 1u : 0u;
808branch 0 taken 2 (fallthrough)
809branch 1 taken 124
810 126: 598: pk_d(&model[5], m->joules);
811call 0 returned 126
812 126: 599: pk_d(&model[6], m->power_w);
813call 0 returned 126
814 126: 600: model[7] = (uint64_t)m->energy_prov;
815 126: 601: model[8] = strcmp(m->instrument, "none") == 0 ? 1u : 0u;
816branch 0 taken 124 (fallthrough)
817branch 1 taken 2
818 126: 602: model[9] = 1u;
819 884: 603: for (int i = 0; i < m->n_ops; i++) {
820branch 0 taken 758
821branch 1 taken 126 (fallthrough)
822 758: 604: uint64_t *p = &model[32 + i * 10];
823 758: 605: pk_d(&p[0], num[i].t);
824call 0 returned 758
825 758: 606: pk_d(&p[1], num[i].bytes);
826call 0 returned 758
827 758: 607: pk_d(&p[2], num[i].launch);
828call 0 returned 758
829 758: 608: pk_d(&p[3], num[i].cap);
830call 0 returned 758
831 758: 609: p[4] = (uint64_t)(int64_t)m->ops[i].engine;
832 758: 610: p[5] = (uint64_t)(int64_t)m->ops[i].bw;
833 758: 611: p[6] = (uint64_t)(int64_t)m->ops[i].launcher;
834 758: 612: p[7] = (uint64_t)m->ops[i].kind;
835 758: 613: p[8] = (uint64_t)num[i].prov;
836 -: 614: }
837 654: 615: for (int i = 0; i < m->n_res; i++) {
838branch 0 taken 528
839branch 1 taken 126 (fallthrough)
840 528: 616: uint64_t *p = &model[2592 + i * 4];
841 528: 617: p[0] = (uint64_t)m->res[i].kind;
842 528: 618: p[1] = (uint64_t)m->res[i].slots;
843 528: 619: pk_d(&p[2], m->res[i].cap);
844call 0 returned 528
845 528: 620: p[3] = (uint64_t)m->res[i].prov;
846 -: 621: }
847 -: 622:#else
848 -: 623: int rc=dr_resolved(m,o,model,r);
849 -: 624: if(rc)return rc;
850 -: 625:#endif
851 1150: 626: for (int i = 0; i < m->n_deps; i++) {
852branch 0 taken 1024
853branch 1 taken 126 (fallthrough)
854 1024: 627: uint64_t *p = &model[2720 + i * 2];
855 1024: 628: p[0] = (uint64_t)m->deps[i].from;
856 1024: 629: p[1] = (uint64_t)m->deps[i].to;
857 -: 630: }
858 382: 631: for (int i = 0; i < m->n_buf; i++) {
859branch 0 taken 256
860branch 1 taken 126 (fallthrough)
861 256: 632: uint64_t *p = &model[4768 + i * 4];
862 256: 633: pk_d(&p[0], m->buf[i].bytes);
863call 0 returned 256
864 256: 634: p[1] = (uint64_t)m->buf[i].cap;
865 256: 635: p[2] = (uint64_t)(int64_t)m->buf[i].first;
866 256: 636: p[3] = (uint64_t)(int64_t)m->buf[i].last;
867 -: 637: }
868 126: 638: return DS_OK;
869 -: 639:}
870 -: 640:
871 -: 641:/* Kahn topological order; returns 0 on a cycle */
872function topo called 0 returned 0% blocks executed 0%
873 #####: 642:static int topo(const ds_model *m, int *order) {
874 #####: 643: int indeg[DS_MAX_OPS] = {0};
875 #####: 644: for (int i = 0; i < m->n_deps; i++) indeg[m->deps[i].to]++;
876branch 0 never executed
877branch 1 never executed (fallthrough)
878 #####: 645: int n = 0, head = 0;
879 #####: 646: for (int i = 0; i < m->n_ops; i++) if (indeg[i] == 0) order[n++] = i;
880branch 0 never executed (fallthrough)
881branch 1 never executed
882branch 2 never executed
883branch 3 never executed (fallthrough)
884 #####: 647: while (head < n) {
885branch 0 never executed
886branch 1 never executed (fallthrough)
887 #####: 648: int u = order[head++];
888 #####: 649: for (int i = 0; i < m->n_deps; i++) if (m->deps[i].from == u && --indeg[m->deps[i].to] == 0) order[n++] = m->deps[i].to;
889branch 0 never executed (fallthrough)
890branch 1 never executed
891branch 2 never executed (fallthrough)
892branch 3 never executed
893branch 4 never executed
894branch 5 never executed (fallthrough)
895 -: 650: }
896 #####: 651: return n == m->n_ops;
897 -: 652:}
898 -: 653:
899 -: 654:enum { ST_WAIT = 0, ST_READY, ST_LAUNCH, ST_RUN, ST_DONE };
900 -: 655:enum { BLK_NONE = 0, BLK_SLOT, BLK_LAUNCHER };
901 -: 656:
902 -: 657:/* Half-open [start, end). Missing first -> 0; missing last -> makespan. */
903function buffer_window called 0 returned 0% blocks executed 0%
904 #####: 658:static void buffer_window(const ds_model *m, const ds_result *r, int b, double *s, double *e) {
905 #####: 659: *s = m->buf[b].first >= 0 ? r->start_ns[m->buf[b].first] : 0.0;
906branch 0 never executed (fallthrough)
907branch 1 never executed
908 #####: 660: *e = m->buf[b].last >= 0 ? r->end_ns[m->buf[b].last] : r->makespan_ns;
909branch 0 never executed (fallthrough)
910branch 1 never executed
911 #####: 661:}
912 -: 662:
913function endpoint_name called 0 returned 0% blocks executed 0%
914 #####: 663:static const char *endpoint_name(const ds_model *m, int op) {
915 #####: 664: return op >= 0 ? m->ops[op].id : "omitted";
916branch 0 never executed (fallthrough)
917branch 1 never executed
918 -: 665:}
919 -: 666:
920 -: 667:/* Resolved end earlier than start is not an interval. Refuse before the ledger. */
921function reject_inverted_lifetimes called 0 returned 0% blocks executed 0%
922 #####: 668:static int reject_inverted_lifetimes(const ds_model *m, ds_result *r) {
923 #####: 669: for (int b = 0; b < m->n_buf; b++) {
924branch 0 never executed
925branch 1 never executed (fallthrough)
926 -: 670: double s, e;
927 #####: 671: buffer_window(m, r, b, &s, &e);
928call 0 never executed
929 #####: 672: if (e + 1e-9 < s) {
930branch 0 never executed (fallthrough)
931branch 1 never executed
932 -: 673: char msg[256];
933 #####: 674: snprintf(msg, sizeof msg,
934 -: 675: "inverted lifetime for buffer %s: first=%s start_ns=%.9g last=%s end_ns=%.9g",
935 #####: 676: m->buf[b].id, endpoint_name(m, m->buf[b].first), s,
936call 0 never executed
937 #####: 677: endpoint_name(m, m->buf[b].last), e);
938call 0 never executed
939 #####: 678: return refuse_msg(r, DS_REFUSED_LIFETIME, msg);
940call 0 never executed
941 -: 679: }
942 -: 680: }
943 #####: 681: return DS_OK;
944 -: 682:}
945 -: 683:
946function oracle_ds_eval_c called 0 returned 0% blocks executed 0%
947 #####: 684:int ds_eval_c(const ds_model *m, const ds_opts *o, ds_result *r) {
948 #####: 685: memset(r, 0, sizeof *r);
949 #####: 686: if (m->n_ops == 0) return refuse(r, DS_REFUSED_UNSUPPORTED, "empty DAG%s%s", "", "");
950branch 0 never executed (fallthrough)
951branch 1 never executed
952call 2 never executed
953 -: 687: ds_num num[DS_MAX_OPS];
954 #####: 688: int rc = resolve(m, o, num, r);
955call 0 never executed
956 #####: 689: if (rc) return rc;
957branch 0 never executed (fallthrough)
958branch 1 never executed
959 -: 690: int order[DS_MAX_OPS];
960 #####: 691: if (!topo(m, order)) return refuse(r, DS_REFUSED_CYCLE, "dependency cycle%s%s", "", "");
961call 0 never executed
962branch 1 never executed (fallthrough)
963branch 2 never executed
964call 3 never executed
965 -: 692: /* a buffer that never fits */
966 #####: 693: for (int i = 0; i < m->n_buf; i++)
967branch 0 never executed
968branch 1 never executed (fallthrough)
969 #####: 694: if (m->buf[i].bytes > m->res[m->buf[i].cap].cap)
970branch 0 never executed (fallthrough)
971branch 1 never executed
972 #####: 695: return refuse(r, DS_REFUSED_CAPACITY, "buffer %s alone exceeds capacity %s", m->buf[i].id, m->res[m->buf[i].cap].id);
973call 0 never executed
974 -: 696:
975 -: 697: /* provenance mask */
976 #####: 698: for (int i = 0; i < m->n_ops; i++) r->prov_mask |= 1u << num[i].prov;
977branch 0 never executed
978branch 1 never executed (fallthrough)
979 #####: 699: for (int i = 0; i < m->n_res; i++) {
980branch 0 never executed
981branch 1 never executed (fallthrough)
982 #####: 700: int used = 0;
983 #####: 701: for (int j = 0; j < m->n_ops; j++) if (m->ops[j].engine == i || m->ops[j].bw == i || m->ops[j].launcher == i) used = 1;
984branch 0 never executed (fallthrough)
985branch 1 never executed
986branch 2 never executed (fallthrough)
987branch 3 never executed
988branch 4 never executed (fallthrough)
989branch 5 never executed
990branch 6 never executed
991branch 7 never executed (fallthrough)
992 #####: 702: for (int j = 0; j < m->n_buf; j++) if (m->buf[j].cap == i) used = 1;
993branch 0 never executed (fallthrough)
994branch 1 never executed
995branch 2 never executed
996branch 3 never executed (fallthrough)
997 #####: 703: if (used) r->prov_mask |= 1u << m->res[i].prov;
998branch 0 never executed (fallthrough)
999branch 1 never executed
1000 -: 704: }
1001 -: 705:
1002 -: 706: /* ---- fluid simulation ---- */
1003 #####: 707: int state[DS_MAX_OPS] = {0}, blocked[DS_MAX_OPS] = {0}, npred[DS_MAX_OPS] = {0}, done_pred[DS_MAX_OPS] = {0};
1004 -: 708: double rem_t[DS_MAX_OPS], rem_b[DS_MAX_OPS], rem_l[DS_MAX_OPS], run_start[DS_MAX_OPS], bytes_end[DS_MAX_OPS];
1005 #####: 709: int free_slots[DS_MAX_RES], launcher_busy[DS_MAX_RES] = {0};
1006 #####: 710: for (int i = 0; i < m->n_res; i++) free_slots[i] = m->res[i].slots;
1007branch 0 never executed
1008branch 1 never executed (fallthrough)
1009 #####: 711: for (int i = 0; i < m->n_deps; i++) npred[m->deps[i].to]++;
1010branch 0 never executed
1011branch 1 never executed (fallthrough)
1012 #####: 712: for (int i = 0; i < m->n_ops; i++) {
1013branch 0 never executed
1014branch 1 never executed (fallthrough)
1015 #####: 713: rem_t[i] = num[i].t; rem_b[i] = num[i].bytes; rem_l[i] = num[i].launch;
1016 #####: 714: run_start[i] = bytes_end[i] = -1;
1017 #####: 715: r->n_ops++;
1018 #####: 716: r->total_bytes += num[i].bytes; r->total_busy_ns += num[i].t; r->total_launch_ns += num[i].launch;
1019 -: 717: }
1020 #####: 718: double t = 0;
1021 #####: 719: int remaining = m->n_ops, guard = 0;
1022 #####: 720: while (remaining > 0) {
1023branch 0 never executed
1024branch 1 never executed (fallthrough)
1025 #####: 721: if (++guard > 8 * DS_MAX_OPS + 16) return refuse(r, DS_REFUSED_UNSUPPORTED, "scheduler did not converge%s%s", "", "");
1026branch 0 never executed (fallthrough)
1027branch 1 never executed
1028call 2 never executed
1029 -: 722: /* deps satisfied -> ready */
1030 #####: 723: for (int i = 0; i < m->n_ops; i++) if (state[i] == ST_WAIT && done_pred[i] == npred[i]) { state[i] = ST_READY; r->ready_ns[i] = t; }
1031branch 0 never executed (fallthrough)
1032branch 1 never executed
1033branch 2 never executed (fallthrough)
1034branch 3 never executed
1035branch 4 never executed
1036branch 5 never executed (fallthrough)
1037 -: 724: /* dispatch in file order */
1038 #####: 725: for (int i = 0; i < m->n_ops; i++) {
1039branch 0 never executed
1040branch 1 never executed (fallthrough)
1041 #####: 726: if (state[i] != ST_READY) continue;
1042branch 0 never executed (fallthrough)
1043branch 1 never executed
1044 #####: 727: const ds_op *op = &m->ops[i];
1045 #####: 728: if (op->engine >= 0 && free_slots[op->engine] <= 0) { blocked[i] = BLK_SLOT; continue; }
1046branch 0 never executed (fallthrough)
1047branch 1 never executed
1048branch 2 never executed (fallthrough)
1049branch 3 never executed
1050 #####: 729: if (op->launcher >= 0 && rem_l[i] > 0 && launcher_busy[op->launcher]) { blocked[i] = BLK_LAUNCHER; continue; }
1051branch 0 never executed (fallthrough)
1052branch 1 never executed
1053branch 2 never executed (fallthrough)
1054branch 3 never executed
1055branch 4 never executed (fallthrough)
1056branch 5 never executed
1057 #####: 730: if (op->engine >= 0) free_slots[op->engine]--;
1058branch 0 never executed (fallthrough)
1059branch 1 never executed
1060 #####: 731: r->start_ns[i] = t;
1061 #####: 732: if (op->launcher >= 0 && rem_l[i] > 0) { launcher_busy[op->launcher] = 1; state[i] = ST_LAUNCH; }
1062branch 0 never executed (fallthrough)
1063branch 1 never executed
1064branch 2 never executed (fallthrough)
1065branch 3 never executed
1066 #####: 733: else { state[i] = ST_RUN; run_start[i] = t; }
1067 -: 734: }
1068 -: 735: /* next event */
1069 #####: 736: int active[DS_MAX_RES] = {0};
1070 #####: 737: for (int i = 0; i < m->n_ops; i++) if (state[i] == ST_RUN && rem_b[i] > 0) active[m->ops[i].bw]++;
1071branch 0 never executed (fallthrough)
1072branch 1 never executed
1073branch 2 never executed (fallthrough)
1074branch 3 never executed
1075branch 4 never executed
1076branch 5 never executed (fallthrough)
1077 #####: 738: double dt = -1; int any = 0;
1078 #####: 739: for (int i = 0; i < m->n_ops; i++) {
1079branch 0 never executed
1080branch 1 never executed (fallthrough)
1081 #####: 740: if (state[i] == ST_LAUNCH) { any = 1; if (dt < 0 || rem_l[i] < dt) dt = rem_l[i]; }
1082branch 0 never executed (fallthrough)
1083branch 1 never executed
1084branch 2 never executed (fallthrough)
1085branch 3 never executed
1086branch 4 never executed (fallthrough)
1087branch 5 never executed
1088 #####: 741: else if (state[i] == ST_RUN) {
1089branch 0 never executed (fallthrough)
1090branch 1 never executed
1091 #####: 742: any = 1;
1092 -: 743: /* next event for this op: the earlier of its two progress bars */
1093 #####: 744: double d = -1;
1094 #####: 745: if (rem_t[i] > 0) d = rem_t[i];
1095branch 0 never executed (fallthrough)
1096branch 1 never executed
1097 #####: 746: if (rem_b[i] > 0) {
1098branch 0 never executed (fallthrough)
1099branch 1 never executed
1100 #####: 747: double share = num[i].cap / active[m->ops[i].bw];
1101 #####: 748: double db = rem_b[i] / share;
1102 #####: 749: if (d < 0 || db < d) d = db;
1103branch 0 never executed (fallthrough)
1104branch 1 never executed
1105branch 2 never executed (fallthrough)
1106branch 3 never executed
1107 -: 750: }
1108 #####: 751: if (d < 0) d = 0;
1109branch 0 never executed (fallthrough)
1110branch 1 never executed
1111 #####: 752: if (dt < 0 || d < dt) dt = d;
1112branch 0 never executed (fallthrough)
1113branch 1 never executed
1114branch 2 never executed (fallthrough)
1115branch 3 never executed
1116 -: 753: }
1117 -: 754: }
1118 #####: 755: if (!any) return refuse(r, DS_REFUSED_UNSUPPORTED, "no op can make progress (slots=0 or all blocked)%s%s", "", "");
1119branch 0 never executed (fallthrough)
1120branch 1 never executed
1121call 2 never executed
1122 #####: 756: if (dt < 0) dt = 0;
1123branch 0 never executed (fallthrough)
1124branch 1 never executed
1125 #####: 757: t += dt;
1126 #####: 758: const double eps = 1e-9;
1127 #####: 759: for (int i = 0; i < m->n_ops; i++) {
1128branch 0 never executed
1129branch 1 never executed (fallthrough)
1130 #####: 760: if (state[i] == ST_LAUNCH) {
1131branch 0 never executed (fallthrough)
1132branch 1 never executed
1133 #####: 761: rem_l[i] -= dt;
1134 #####: 762: if (rem_l[i] <= eps) { rem_l[i] = 0; launcher_busy[m->ops[i].launcher] = 0; state[i] = ST_RUN; run_start[i] = t; }
1135branch 0 never executed (fallthrough)
1136branch 1 never executed
1137 #####: 763: } else if (state[i] == ST_RUN) {
1138branch 0 never executed (fallthrough)
1139branch 1 never executed
1140 #####: 764: if (rem_t[i] > 0) { rem_t[i] -= dt; if (rem_t[i] <= eps) rem_t[i] = 0; }
1141branch 0 never executed (fallthrough)
1142branch 1 never executed
1143branch 2 never executed (fallthrough)
1144branch 3 never executed
1145 #####: 765: if (rem_b[i] > 0) {
1146branch 0 never executed (fallthrough)
1147branch 1 never executed
1148 #####: 766: double share = num[i].cap / active[m->ops[i].bw];
1149 #####: 767: rem_b[i] -= share * dt;
1150 #####: 768: if (rem_b[i] <= eps * (num[i].bytes > 1 ? num[i].bytes : 1)) { rem_b[i] = 0; bytes_end[i] = t; }
1151branch 0 never executed (fallthrough)
1152branch 1 never executed
1153branch 2 never executed (fallthrough)
1154branch 3 never executed
1155 -: 769: }
1156 #####: 770: if (rem_t[i] <= 0 && rem_b[i] <= 0) {
1157branch 0 never executed (fallthrough)
1158branch 1 never executed
1159branch 2 never executed (fallthrough)
1160branch 3 never executed
1161 #####: 771: state[i] = ST_DONE; r->end_ns[i] = t; remaining--;
1162 #####: 772: if (m->ops[i].engine >= 0) free_slots[m->ops[i].engine]++;
1163branch 0 never executed (fallthrough)
1164branch 1 never executed
1165 #####: 773: for (int d = 0; d < m->n_deps; d++) if (m->deps[d].from == i) done_pred[m->deps[d].to]++;
1166branch 0 never executed (fallthrough)
1167branch 1 never executed
1168branch 2 never executed
1169branch 3 never executed (fallthrough)
1170 #####: 774: if (num[i].bytes > 0) {
1171branch 0 never executed (fallthrough)
1172branch 1 never executed
1173 #####: 775: double ideal = num[i].bytes / num[i].cap;
1174 #####: 776: double actual = (bytes_end[i] >= 0 ? bytes_end[i] : t) - run_start[i];
1175branch 0 never executed (fallthrough)
1176branch 1 never executed
1177 #####: 777: r->op_contention_ns[i] = actual - ideal > 0 ? actual - ideal : 0;
1178branch 0 never executed (fallthrough)
1179branch 1 never executed
1180 -: 778: }
1181 -: 779: }
1182 -: 780: }
1183 -: 781: }
1184 #####: 782: if (t > r->makespan_ns) r->makespan_ns = t;
1185branch 0 never executed (fallthrough)
1186branch 1 never executed
1187 -: 783: }
1188 -: 784:
1189 -: 785: /* ---- bounds ---- */
1190 -: 786: double cp[DS_MAX_OPS];
1191 #####: 787: for (int k = 0; k < m->n_ops; k++) {
1192branch 0 never executed
1193branch 1 never executed (fallthrough)
1194 #####: 788: int i = order[k];
1195 #####: 789: double floor_ = num[i].t;
1196 #####: 790: if (num[i].bytes > 0 && num[i].bytes / num[i].cap > floor_) floor_ = num[i].bytes / num[i].cap;
1197branch 0 never executed (fallthrough)
1198branch 1 never executed
1199branch 2 never executed (fallthrough)
1200branch 3 never executed
1201 #####: 791: floor_ += num[i].launch;
1202 #####: 792: r->op_floor_ns[i] = floor_;
1203 #####: 793: double best = 0;
1204 #####: 794: for (int d = 0; d < m->n_deps; d++) if (m->deps[d].to == i && cp[m->deps[d].from] > best) best = cp[m->deps[d].from];
1205branch 0 never executed (fallthrough)
1206branch 1 never executed
1207branch 2 never executed (fallthrough)
1208branch 3 never executed
1209branch 4 never executed
1210branch 5 never executed (fallthrough)
1211 #####: 795: cp[i] = best + floor_;
1212 #####: 796: if (cp[i] > r->bound_critical_path_ns) r->bound_critical_path_ns = cp[i];
1213branch 0 never executed (fallthrough)
1214branch 1 never executed
1215 -: 797: }
1216 #####: 798: r->bound_ns = r->bound_critical_path_ns;
1217 #####: 799: for (int i = 0; i < m->n_res; i++) {
1218branch 0 never executed
1219branch 1 never executed (fallthrough)
1220 #####: 800: double w = 0;
1221 #####: 801: for (int j = 0; j < m->n_ops; j++) {
1222branch 0 never executed
1223branch 1 never executed (fallthrough)
1224 #####: 802: if (m->res[i].kind == DS_RES_BANDWIDTH && m->ops[j].bw == i) w += num[j].bytes / num[j].cap;
1225branch 0 never executed (fallthrough)
1226branch 1 never executed
1227branch 2 never executed (fallthrough)
1228branch 3 never executed
1229 #####: 803: if (m->res[i].kind == DS_RES_COMPUTE && m->ops[j].engine == i) w += (num[j].t + num[j].launch) / m->res[i].slots;
1230branch 0 never executed (fallthrough)
1231branch 1 never executed
1232branch 2 never executed (fallthrough)
1233branch 3 never executed
1234 #####: 804: if (m->res[i].kind == DS_RES_LAUNCH && m->ops[j].launcher == i) w += num[j].launch;
1235branch 0 never executed (fallthrough)
1236branch 1 never executed
1237branch 2 never executed (fallthrough)
1238branch 3 never executed
1239 -: 805: }
1240 #####: 806: r->bound_resource_ns[i] = w;
1241 #####: 807: if (w > r->bound_ns) r->bound_ns = w;
1242branch 0 never executed (fallthrough)
1243branch 1 never executed
1244 -: 808: }
1245 -: 809:
1246 -: 810: /* Inverted lifetimes never enter the ledger (and never rank). */
1247 #####: 811: if ((rc = reject_inverted_lifetimes(m, r)) != DS_OK) return rc; /* LIFETIME_ORDER_CHECK */
1248call 0 never executed
1249branch 1 never executed (fallthrough)
1250branch 2 never executed
1251 -: 812:
1252 -: 813: /* ---- capacity ledger: frees before allocations at the same instant ----
1253 -: 814: * Positive intervals only. A zero-duration [s, e) is empty and emits no
1254 -: 815: * event, so a same-time free cannot pull the ledger negative or offset
1255 -: 816: * another buffer. Frees of earlier intervals still precede allocs, which
1256 -: 817: * is the completion/allocation tie. */
1257 #####: 818: for (int c = 0; c < m->n_res; c++) {
1258branch 0 never executed
1259branch 1 never executed (fallthrough)
1260 #####: 819: if (m->res[c].kind != DS_RES_CAPACITY) continue;
1261branch 0 never executed (fallthrough)
1262branch 1 never executed
1263 #####: 820: double live = 0, peak = 0, peak_at = 0;
1264 -: 821: /* event list */
1265 #####: 822: double et[2 * DS_MAX_BUF]; double ev[2 * DS_MAX_BUF]; int en = 0;
1266 #####: 823: for (int b = 0; b < m->n_buf; b++) {
1267branch 0 never executed
1268branch 1 never executed (fallthrough)
1269 #####: 824: if (m->buf[b].cap != c) continue;
1270branch 0 never executed (fallthrough)
1271branch 1 never executed
1272 -: 825: double s, e;
1273 #####: 826: buffer_window(m, r, b, &s, &e);
1274call 0 never executed
1275 #####: 827: if (!(s + 1e-9 < e)) continue;
1276branch 0 never executed (fallthrough)
1277branch 1 never executed
1278 #####: 828: et[en] = s; ev[en] = m->buf[b].bytes; en++;
1279 #####: 829: et[en] = e; ev[en] = -m->buf[b].bytes; en++;
1280 -: 830: }
1281 -: 831: /* insertion sort by time, frees (negative) first on ties; stable */
1282 #####: 832: for (int i = 1; i < en; i++) {
1283branch 0 never executed
1284branch 1 never executed (fallthrough)
1285 #####: 833: double kt = et[i], kv_ = ev[i]; int j = i - 1;
1286 #####: 834: while (j >= 0 && (et[j] > kt || (et[j] == kt && ev[j] > 0 && kv_ < 0))) { et[j + 1] = et[j]; ev[j + 1] = ev[j]; j--; }
1287branch 0 never executed (fallthrough)
1288branch 1 never executed
1289branch 2 never executed
1290branch 3 never executed (fallthrough)
1291branch 4 never executed (fallthrough)
1292branch 5 never executed
1293branch 6 never executed (fallthrough)
1294branch 7 never executed
1295branch 8 never executed
1296branch 9 never executed (fallthrough)
1297 #####: 835: et[j + 1] = kt; ev[j + 1] = kv_;
1298 -: 836: }
1299 #####: 837: for (int i = 0; i < en; i++) {
1300branch 0 never executed
1301branch 1 never executed (fallthrough)
1302 #####: 838: live += ev[i];
1303 -: 839: /* Reachable by rounding: 1e20 + 1 sums to 1e20, so the later
1304 -: 840: * frees overshoot (dagsim_unit rounding_drives_live_negative). */
1305 #####: 841: if (live < -1e-6) {
1306branch 0 never executed (fallthrough)
1307branch 1 never executed
1308 -: 842: char msg[256];
1309 #####: 843: snprintf(msg, sizeof msg,
1310 -: 844: "capacity %s live bytes went negative (%.9g at t=%.9g); refusing the certificate",
1311 #####: 845: m->res[c].id, live, et[i]);
1312 #####: 846: return refuse_msg(r, DS_REFUSED_LIFETIME, msg);
1313call 0 never executed
1314 -: 847: }
1315 #####: 848: if (live > peak) { peak = live; peak_at = et[i]; }
1316branch 0 never executed (fallthrough)
1317branch 1 never executed
1318 -: 849: }
1319 #####: 850: r->peak_live_bytes[c] = peak; r->peak_live_at_ns[c] = peak_at;
1320 #####: 851: if (peak > m->res[c].cap + 1e-9) {
1321branch 0 never executed (fallthrough)
1322branch 1 never executed
1323 #####: 852: char names[160] = ""; size_t L = 0;
1324 #####: 853: for (int b = 0; b < m->n_buf && L < sizeof names - 8; b++) {
1325branch 0 never executed (fallthrough)
1326branch 1 never executed
1327branch 2 never executed
1328branch 3 never executed (fallthrough)
1329 #####: 854: if (m->buf[b].cap != c) continue;
1330branch 0 never executed (fallthrough)
1331branch 1 never executed
1332 -: 855: double s, e;
1333 #####: 856: buffer_window(m, r, b, &s, &e);
1334call 0 never executed
1335 #####: 857: if (s <= peak_at && e > peak_at) { snprintf(names + L, sizeof names - L, "%s%s", L ? "," : "", m->buf[b].id); L = strlen(names); }
1336branch 0 never executed (fallthrough)
1337branch 1 never executed
1338branch 2 never executed (fallthrough)
1339branch 3 never executed
1340branch 4 never executed (fallthrough)
1341branch 5 never executed
1342 -: 858: }
1343 #####: 859: char what[200]; snprintf(what, sizeof what, "%.0f B live at t=%.0f ns (%s) exceeds", peak, peak_at, names);
1344 #####: 860: int st = refuse(r, DS_REFUSED_CAPACITY, "%s %s", what, m->res[c].id);
1345call 0 never executed
1346 #####: 861: return st;
1347 -: 862: }
1348 -: 863: }
1349 -: 864:
1350 -: 865: /* ---- attribution along the schedule's critical chain ---- */
1351 #####: 866: int cur = 0;
1352 #####: 867: for (int i = 1; i < m->n_ops; i++) if (r->end_ns[i] > r->end_ns[cur]) cur = i;
1353branch 0 never executed (fallthrough)
1354branch 1 never executed
1355branch 2 never executed
1356branch 3 never executed (fallthrough)
1357 #####: 868: double accounted = 0;
1358 #####: 869: int chain[DS_MAX_OPS]; int nc = 0;
1359 #####: 870: while (cur >= 0 && nc < DS_MAX_OPS) {
1360branch 0 never executed (fallthrough)
1361branch 1 never executed
1362branch 2 never executed
1363branch 3 never executed (fallthrough)
1364 #####: 871: chain[nc++] = cur;
1365 #####: 872: const ds_op *op = &m->ops[cur];
1366 #####: 873: double runtime = r->end_ns[cur] - (run_start[cur] >= 0 ? run_start[cur] : r->start_ns[cur]);
1367branch 0 never executed (fallthrough)
1368branch 1 never executed
1369 #####: 874: r->attr_ns[DS_ATTR_LAUNCH] += num[cur].launch;
1370 #####: 875: accounted += num[cur].launch;
1371 #####: 876: if (op->kind == DS_OP_BARRIER) r->attr_ns[DS_ATTR_SYNC] += runtime;
1372branch 0 never executed (fallthrough)
1373branch 1 never executed
1374 #####: 877: else if (num[cur].bytes > 0) {
1375branch 0 never executed (fallthrough)
1376branch 1 never executed
1377 #####: 878: double ideal = num[cur].bytes / num[cur].cap;
1378 #####: 879: double actual = ideal + r->op_contention_ns[cur];
1379 #####: 880: if (num[cur].t >= actual) r->attr_ns[DS_ATTR_COMPUTE] += runtime;
1380branch 0 never executed (fallthrough)
1381branch 1 never executed
1382 #####: 881: else { r->attr_ns[DS_ATTR_BANDWIDTH] += ideal; r->attr_ns[DS_ATTR_CONTENTION] += r->op_contention_ns[cur]; if (runtime > actual) r->attr_ns[DS_ATTR_RESIDUAL] += runtime - actual; }
1383branch 0 never executed (fallthrough)
1384branch 1 never executed
1385 #####: 882: } else r->attr_ns[DS_ATTR_COMPUTE] += runtime;
1386 #####: 883: accounted += runtime;
1387 -: 884: /* predecessor: the dep that finished last */
1388 #####: 885: int pred = -1;
1389 #####: 886: for (int d = 0; d < m->n_deps; d++) if (m->deps[d].to == cur && (pred < 0 || r->end_ns[m->deps[d].from] > r->end_ns[pred])) pred = m->deps[d].from;
1390branch 0 never executed (fallthrough)
1391branch 1 never executed
1392branch 2 never executed (fallthrough)
1393branch 3 never executed
1394branch 4 never executed (fallthrough)
1395branch 5 never executed
1396branch 6 never executed
1397branch 7 never executed (fallthrough)
1398 #####: 887: double gap = r->start_ns[cur] - (pred >= 0 ? r->end_ns[pred] : 0);
1399branch 0 never executed (fallthrough)
1400branch 1 never executed
1401 #####: 888: if (gap > 0) {
1402branch 0 never executed (fallthrough)
1403branch 1 never executed
1404 #####: 889: if (blocked[cur] == BLK_SLOT) r->attr_ns[DS_ATTR_SERIALIZATION] += gap;
1405branch 0 never executed (fallthrough)
1406branch 1 never executed
1407 #####: 890: else if (blocked[cur] == BLK_LAUNCHER) r->attr_ns[DS_ATTR_LAUNCH] += gap;
1408branch 0 never executed (fallthrough)
1409branch 1 never executed
1410 #####: 891: else r->attr_ns[DS_ATTR_RESIDUAL] += gap;
1411 #####: 892: accounted += gap;
1412 -: 893: }
1413 #####: 894: cur = pred;
1414 -: 895: }
1415 #####: 896: for (int i = 0; i < nc; i++) r->critical_path[i] = chain[nc - 1 - i];
1416branch 0 never executed
1417branch 1 never executed (fallthrough)
1418 #####: 897: r->n_critical = nc;
1419 #####: 898: double leftover = r->makespan_ns - accounted;
1420 #####: 899: if (fabs(leftover) > 1e-6) r->attr_ns[DS_ATTR_RESIDUAL] += leftover;
1421branch 0 never executed (fallthrough)
1422branch 1 never executed
1423 -: 900:
1424 -: 901: /* ---- energy ---- */
1425 #####: 902: if (m->has_energy && m->joules > 0 && strcmp(m->instrument, "none")) { r->energy_measured = 1; r->energy_j = m->joules; }
1426branch 0 never executed (fallthrough)
1427branch 1 never executed
1428branch 2 never executed (fallthrough)
1429branch 3 never executed
1430branch 4 never executed (fallthrough)
1431branch 5 never executed
1432 #####: 903: else if (m->has_energy && m->power_w > 0 && m->energy_prov == DS_PROV_SYNTHETIC) { r->energy_synthetic = 1; r->energy_j = m->power_w * r->makespan_ns * 1e-9; r->prov_mask |= 1u << DS_PROV_SYNTHETIC; }
1433branch 0 never executed (fallthrough)
1434branch 1 never executed
1435branch 2 never executed (fallthrough)
1436branch 3 never executed
1437branch 4 never executed (fallthrough)
1438branch 5 never executed
1439 #####: 904: r->synthetic = (r->prov_mask & (1u << DS_PROV_SYNTHETIC)) ? 1 : 0;
1440 #####: 905: r->status = DS_OK;
1441 #####: 906: return DS_OK;
1442 -: 907:}
1443 -: 908:
1444 -: 909:#ifndef CUDAPP_MIGRATION_PENDING_C_TOOLS
1445 -: 910:extern uint32_t omega_dag_eval(uint64_t *result, const void *p0, uint64_t p0_n, void *p1, uint64_t p1_n) __attribute__((weak));
1446 -: 911:
1447function om_f called 648 returned 100% blocks executed 100%
1448 648: 912:static double om_f(const uint64_t *s, int i) {
1449 -: 913: double x;
1450 648: 914: memcpy(&x, &s[i], 8);
1451 648: 915: return x;
1452 -: 916:}
1453 -: 917:
1454function om_names called 0 returned 0% blocks executed 0%
1455 #####: 918:static void om_names(const ds_model *m, const uint64_t *s, char *names, size_t cap) {
1456 #####: 919: names[0] = 0;
1457 #####: 920: size_t L = 0;
1458 #####: 921: for (int b = 0; b < m->n_buf && L < cap - 8; b++) {
1459branch 0 never executed (fallthrough)
1460branch 1 never executed
1461branch 2 never executed
1462branch 3 never executed (fallthrough)
1463 #####: 922: if (!(s[6336 + b / 64] & (1ull << (b % 64)))) continue;
1464branch 0 never executed (fallthrough)
1465branch 1 never executed
1466 #####: 923: snprintf(names + L, cap - L, "%s%s", L ? "," : "", m->buf[b].id);
1467branch 0 never executed (fallthrough)
1468branch 1 never executed
1469 #####: 924: L = strlen(names);
1470 -: 925: }
1471 #####: 926:}
1472 -: 927:
1473function om_refuse called 0 returned 0% blocks executed 0%
1474 #####: 928:static int om_refuse(const ds_model *m, const uint64_t *s, ds_result *r) {
1475 #####: 929: int why = (int)s[5], a = (int)s[6], b = (int)s[7];
1476 #####: 930: double fa = om_f(s, 8), fb = om_f(s, 9);
1477call 0 never executed
1478call 1 never executed
1479 -: 931: char msg[256];
1480 #####: 932: if (why == 2) return refuse(r, DS_REFUSED_CYCLE, "dependency cycle%s%s", "", "");
1481branch 0 never executed (fallthrough)
1482branch 1 never executed
1483call 2 never executed
1484 #####: 933: if (why == 3 && a >= 0 && a < m->n_buf && b >= 0 && b < m->n_res)
1485branch 0 never executed (fallthrough)
1486branch 1 never executed
1487branch 2 never executed (fallthrough)
1488branch 3 never executed
1489branch 4 never executed (fallthrough)
1490branch 5 never executed
1491branch 6 never executed (fallthrough)
1492branch 7 never executed
1493branch 8 never executed (fallthrough)
1494branch 9 never executed
1495 #####: 934: return refuse(r, DS_REFUSED_CAPACITY, "buffer %s alone exceeds capacity %s", m->buf[a].id, m->res[b].id);
1496call 0 never executed
1497 #####: 935: if (why == 4) return refuse(r, DS_REFUSED_UNSUPPORTED, "no op can make progress (slots=0 or all blocked)%s%s", "", "");
1498branch 0 never executed (fallthrough)
1499branch 1 never executed
1500call 2 never executed
1501 #####: 936: if (why == 5) return refuse(r, DS_REFUSED_UNSUPPORTED, "scheduler did not converge%s%s", "", "");
1502branch 0 never executed (fallthrough)
1503branch 1 never executed
1504call 2 never executed
1505 #####: 937: if (why == 6 && a >= 0 && a < m->n_buf) {
1506branch 0 never executed (fallthrough)
1507branch 1 never executed
1508branch 2 never executed (fallthrough)
1509branch 3 never executed
1510branch 4 never executed (fallthrough)
1511branch 5 never executed
1512 #####: 938: snprintf(msg, sizeof msg, "inverted lifetime for buffer %s: first=%s start_ns=%.9g last=%s end_ns=%.9g",
1513 #####: 939: m->buf[a].id, endpoint_name(m, m->buf[a].first), fa, endpoint_name(m, m->buf[a].last), fb);
1514call 0 never executed
1515call 1 never executed
1516 #####: 940: return refuse_msg(r, DS_REFUSED_LIFETIME, msg);
1517call 0 never executed
1518 -: 941: }
1519 #####: 942: if (why == 7 && a >= 0 && a < m->n_res) {
1520branch 0 never executed (fallthrough)
1521branch 1 never executed
1522branch 2 never executed (fallthrough)
1523branch 3 never executed
1524branch 4 never executed (fallthrough)
1525branch 5 never executed
1526 #####: 943: snprintf(msg, sizeof msg, "capacity %s live bytes went negative (%.9g at t=%.9g); refusing the certificate",
1527 #####: 944: m->res[a].id, fa, fb);
1528 #####: 945: return refuse_msg(r, DS_REFUSED_LIFETIME, msg);
1529call 0 never executed
1530 -: 946: }
1531 #####: 947: if (why == 8 && a >= 0 && a < m->n_res) {
1532branch 0 never executed (fallthrough)
1533branch 1 never executed
1534branch 2 never executed (fallthrough)
1535branch 3 never executed
1536branch 4 never executed (fallthrough)
1537branch 5 never executed
1538 -: 948: char names[160], what[200];
1539 #####: 949: om_names(m, s, names, sizeof names);
1540call 0 never executed
1541 #####: 950: snprintf(what, sizeof what, "%.0f B live at t=%.0f ns (%s) exceeds", fa, fb, names);
1542 #####: 951: return refuse(r, DS_REFUSED_CAPACITY, "%s %s", what, m->res[a].id);
1543call 0 never executed
1544 -: 952: }
1545 #####: 953: return refuse(r, DS_REFUSED_UNSUPPORTED, "omega refusal %s%s", "", "");
1546call 0 never executed
1547 -: 954:}
1548 -: 955:
1549function om_fill called 18 returned 100% blocks executed 94%
1550 18: 956:static int om_fill(const ds_model *m, const uint64_t *s, ds_result *r) {
1551 18*: 957: if ((int)s[4] != DS_OK) return om_refuse(m, s, r);
1552branch 0 taken 0 (fallthrough)
1553branch 1 taken 18
1554call 2 never executed
1555 18: 958: memset(r, 0, sizeof *r);
1556 18: 959: r->status = DS_OK;
1557 18: 960: r->makespan_ns = om_f(s, 3);
1558call 0 returned 18
1559 18: 961: r->total_bytes = om_f(s, 15);
1560call 0 returned 18
1561 18: 962: r->total_busy_ns = om_f(s, 16);
1562call 0 returned 18
1563 18: 963: r->total_launch_ns = om_f(s, 17);
1564call 0 returned 18
1565 18: 964: r->bound_ns = om_f(s, 19);
1566call 0 returned 18
1567 18: 965: r->bound_critical_path_ns = om_f(s, 20);
1568call 0 returned 18
1569 18: 966: r->n_critical = (int)s[21];
1570 18: 967: r->prov_mask = (uint32_t)s[11];
1571 18: 968: r->energy_measured = (int)s[22];
1572 18: 969: r->energy_synthetic = (int)s[23];
1573 18: 970: r->energy_j = om_f(s, 24);
1574call 0 returned 18
1575 18: 971: r->synthetic = (int)s[26];
1576 18: 972: r->n_ops = m->n_ops;
1577 54: 973: for (int i = 0; i < m->n_ops; i++) {
1578branch 0 taken 36
1579branch 1 taken 18 (fallthrough)
1580 36: 974: r->start_ns[i] = om_f(s, 4512 + i);
1581call 0 returned 36
1582 36: 975: r->end_ns[i] = om_f(s, 4768 + i);
1583call 0 returned 36
1584 36: 976: r->ready_ns[i] = om_f(s, 5024 + i);
1585call 0 returned 36
1586 36: 977: r->op_contention_ns[i] = om_f(s, 5536 + i);
1587call 0 returned 36
1588 36: 978: r->op_floor_ns[i] = om_f(s, 5280 + i);
1589call 0 returned 36
1590 36: 979: if (i < r->n_critical) r->critical_path[i] = (int)s[6080 + i];
1591branch 0 taken 18 (fallthrough)
1592branch 1 taken 18
1593 -: 980: }
1594 144: 981: for (int i = 0; i < DS_ATTR_N; i++) r->attr_ns[i] = om_f(s, 5824 + i);
1595call 0 returned 126
1596branch 1 taken 126
1597branch 2 taken 18 (fallthrough)
1598 90: 982: for (int i = 0; i < m->n_res; i++) {
1599branch 0 taken 72
1600branch 1 taken 18 (fallthrough)
1601 72: 983: r->bound_resource_ns[i] = om_f(s, 5792 + i);
1602call 0 returned 72
1603 72: 984: r->peak_live_bytes[i] = om_f(s, 6344 + i);
1604call 0 returned 72
1605 72: 985: r->peak_live_at_ns[i] = om_f(s, 6376 + i);
1606call 0 returned 72
1607 -: 986: }
1608 18: 987: return DS_OK;
1609 -: 988:}
1610 -: 989:
1611 -: 990:#endif
1612function oracle_ds_eval called 19 returned 100% blocks executed 69%
1613 19: 991:int ds_eval(const ds_model *m, const ds_opts *o, ds_result *r) {
1614 -: 992:#if defined(CUDAPP_MIGRATION_PENDING_C_TOOLS)
1615 -: 993: return ds_eval_c(m, o, r);
1616 -: 994:#else
1617 19*: 995: if (!omega_dag_eval) return ds_eval_c(m, o, r);
1618branch 0 taken 0 (fallthrough)
1619branch 1 taken 19
1620call 2 never executed
1621 19: 996: memset(r, 0, sizeof *r);
1622 19: 997: uint64_t model[8192], scratch[8192], result = 0;
1623 19: 998: int rc = ds_resolved_pack(m, o, model, r);
1624call 0 returned 19
1625 19: 999: if (rc) return rc;
1626branch 0 taken 1 (fallthrough)
1627branch 1 taken 18
1628 18: 1000: memset(scratch, 0, sizeof scratch);
1629 18: 1001: if (omega_dag_eval(&result, model, 8192, scratch, 8192))
1630call 0 returned 18
1631branch 1 taken 0 (fallthrough)
1632branch 2 taken 18
1633 #####: 1002: return refuse(r, DS_REFUSED_UNSUPPORTED, "omega trap%s%s", "", "");
1634call 0 never executed
1635 18: 1003: return om_fill(m, scratch, r);
1636call 0 returned 18
1637 -: 1004:#endif
1638 -: 1005:}
1639 -: 1006:
1640function oracle_ds_eval_interval called 0 returned 0% blocks executed 0%
1641 #####: 1007:int ds_eval_interval(const ds_model *m, const ds_opts *o, ds_result *nominal, double *lo_ns, double *hi_ns) {
1642 #####: 1008: ds_opts x = *o; x.mode = 0;
1643 #####: 1009: int rc = ds_eval(m, &x, nominal);
1644call 0 never executed
1645 #####: 1010: *lo_ns = *hi_ns = 0;
1646 #####: 1011: if (rc) return rc;
1647branch 0 never executed (fallthrough)
1648branch 1 never executed
1649 -: 1012: ds_result tmp;
1650 #####: 1013: x.mode = +1; if (ds_eval(m, &x, &tmp) == DS_OK) *lo_ns = tmp.makespan_ns;
1651call 0 never executed
1652branch 1 never executed (fallthrough)
1653branch 2 never executed
1654 #####: 1014: x.mode = -1; if (ds_eval(m, &x, &tmp) == DS_OK) *hi_ns = tmp.makespan_ns;
1655call 0 never executed
1656branch 1 never executed (fallthrough)
1657branch 2 never executed
1658 #####: 1015: return rc;
1659 -: 1016:}
1660 -: 1017:
1661function oracle_ds_counterfactual called 26 returned 100% blocks executed 100%
1662 26: 1018:double ds_counterfactual(const ds_model *m, const ds_opts *o, int res_index) {
1663 -: 1019:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE
1664 26: 1020: if (res_index < 0 || res_index >= m->n_res) return -DS_REFUSED_UNSUPPORTED;
1665branch 0 taken 23 (fallthrough)
1666branch 1 taken 3
1667branch 2 taken 3 (fallthrough)
1668branch 3 taken 20
1669 20: 1021: ds_model *c = malloc(sizeof *c);
1670 20: 1022: if (!c) return -DS_REFUSED_UNSUPPORTED;
1671branch 0 taken 1 (fallthrough)
1672branch 1 taken 19
1673 19: 1023: *c = *m;
1674 19: 1024: ds_resource *r = &c->res[res_index];
1675 19: 1025: switch (r->kind) {
1676branch 0 taken 4
1677branch 1 taken 5
1678branch 2 taken 4
1679branch 3 taken 4
1680branch 4 taken 2
1681 4: 1026: case DS_RES_BANDWIDTH: r->cap *= 2; r->lo *= 2; r->hi *= 2; break;
1682 5: 1027: case DS_RES_COMPUTE: r->slots *= 2; break;
1683 12: 1028: case DS_RES_LAUNCH: for (int i = 0; i < c->n_ops; i++) if (c->ops[i].launcher == res_index) c->ops[i].launch_ns = 0; break;
1684branch 0 taken 7 (fallthrough)
1685branch 1 taken 1
1686branch 2 taken 8
1687branch 3 taken 4 (fallthrough)
1688 4: 1029: case DS_RES_CAPACITY: r->cap *= 2; break;
1689 -: 1030: }
1690 19: 1031: ds_result res; ds_opts x = *o; x.mode = 0;
1691 19: 1032: int rc = ds_eval(c, &x, &res);
1692call 0 returned 19
1693 19: 1033: free(c);
1694 19: 1034: return rc == DS_OK ? res.makespan_ns : -(double)rc;
1695branch 0 taken 18 (fallthrough)
1696branch 1 taken 1
1697 -: 1035:#else
1698 -: 1036: return dr_counter(m,o,res_index);
1699 -: 1037:#endif
1700 -: 1038:}
1701 -: 1039:
1702 -: 1040:/* ---------------------------------------------------------------- diff */
1703 -: 1041:
1704 -: 1042:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE
1705function in_changed called 1074 returned 100% blocks executed 100%
1706 1074: 1043:static int in_changed(const char *list, const char *id) {
1707 1074: 1044: if (!list) return 0;
1708branch 0 taken 17 (fallthrough)
1709branch 1 taken 1057
1710 1057: 1045: const char *p = list; size_t L = strlen(id);
1711 2130: 1046: while (*p) {
1712branch 0 taken 2122
1713branch 1 taken 8 (fallthrough)
1714 2122: 1047: const char *q = strchr(p, ','); size_t n = q ? (size_t)(q - p) : strlen(p);
1715branch 0 taken 2106 (fallthrough)
1716branch 1 taken 16
1717 2122: 1048: if (n == L && !strncmp(p, id, L)) return 1;
1718branch 0 taken 1058 (fallthrough)
1719branch 1 taken 1064
1720branch 2 taken 1041 (fallthrough)
1721branch 3 taken 17
1722 1081: 1049: if (!q) break;
1723branch 0 taken 8 (fallthrough)
1724branch 1 taken 1073
1725 1073: 1050: p = q + 1;
1726 -: 1051: }
1727 16: 1052: return 0;
1728 -: 1053:}
1729 -: 1054:#endif
1730 -: 1055:
1731function oracle_ds_diff_models called 1820 returned 100% blocks executed 100%
1732 1820: 1056:int ds_diff_models(const ds_model *b, const ds_model *t, const ds_opts *o, ds_diff *d) {
1733 -: 1057:#if CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE
1734 1820: 1058: memset(d, 0, sizeof *d);
1735 4147: 1059: for (int i = 0; i < t->n_ops; i++) if (ds_find_op(b, t->ops[i].id) < 0) d->n_added++;
1736call 0 returned 2327
1737branch 1 taken 1 (fallthrough)
1738branch 2 taken 2326
1739branch 3 taken 2327
1740branch 4 taken 1820 (fallthrough)
1741 3738: 1060: for (int i = 0; i < b->n_ops; i++) {
1742branch 0 taken 3335
1743branch 1 taken 403 (fallthrough)
1744 3335: 1061: int j = ds_find_op(t, b->ops[i].id);
1745call 0 returned 3335
1746 3335: 1062: if (j >= 0) {
1747branch 0 taken 909 (fallthrough)
1748branch 1 taken 2426
1749 909: 1063: d->n_kept++;
1750 909: 1064: if (b->ops[i].t_ns != t->ops[j].t_ns || b->ops[i].bytes != t->ops[j].bytes)
1751branch 0 taken 908 (fallthrough)
1752branch 1 taken 1
1753branch 2 taken 2 (fallthrough)
1754branch 3 taken 906
1755 3: 1065: snprintf(d->reason, sizeof d->reason, "op %s kept but its demand changed; trace conservation broken", b->ops[i].id);
1756 909: 1066: continue;
1757 -: 1067: }
1758 2426: 1068: d->n_removed++;
1759 -: 1069: /* find its removed record(s) */
1760 2426: 1070: int found = 0; const ds_removed *rec = NULL;
1761 135199: 1071: for (int k = 0; k < t->n_removed; k++) if (!strcmp(t->removed[k].op, b->ops[i].id)) { found++; rec = &t->removed[k]; }
1762branch 0 taken 2426 (fallthrough)
1763branch 1 taken 130347
1764branch 2 taken 132773
1765branch 3 taken 2426 (fallthrough)
1766 2426: 1072: if (found == 0) { d->required_removed = 1; snprintf(d->reason, sizeof d->reason, "op %s vanished without a removed record", b->ops[i].id); return DS_REFUSED_REMOVED_REQUIRED; }
1767branch 0 taken 1 (fallthrough)
1768branch 1 taken 2425
1769 2425: 1073: if (found > 1) { d->double_counted = 1; snprintf(d->reason, sizeof d->reason, "op %s removed %d times (double counted)", b->ops[i].id, found); return DS_REFUSED_REMOVED_REQUIRED; }
1770branch 0 taken 1 (fallthrough)
1771branch 1 taken 2424
1772 -: 1074: /* consumers of the removed op in the baseline that still exist */
1773 2424: 1075: int has_consumer = 0;
1774 3104: 1076: for (int k = 0; k < b->n_deps; k++) if (b->deps[k].from == i && ds_find_op(t, b->ops[b->deps[k].to].id) >= 0) has_consumer = 1;
1775branch 0 taken 384 (fallthrough)
1776branch 1 taken 296
1777call 2 returned 384
1778branch 3 taken 192 (fallthrough)
1779branch 4 taken 192
1780branch 5 taken 680
1781branch 6 taken 2424 (fallthrough)
1782 2424: 1077: int ok = 1;
1783 2424: 1078: switch (rec->reason) {
1784branch 0 taken 724
1785branch 1 taken 288
1786branch 2 taken 1123
1787branch 3 taken 96
1788branch 4 taken 97
1789branch 5 taken 96
1790 724: 1079: case DS_RM_ELIMINATED: if (has_consumer && !rec->proof[0]) ok = 0; break;
1791branch 0 taken 24 (fallthrough)
1792branch 1 taken 700
1793branch 2 taken 12 (fallthrough)
1794branch 3 taken 12
1795 288: 1080: case DS_RM_REUSED: case DS_RM_LOOKUP: case DS_RM_MOVED: if (!rec->ref[0] || ds_find_op(t, rec->ref) < 0) ok = 0; break;
1796branch 0 taken 216 (fallthrough)
1797branch 1 taken 72
1798call 2 returned 216
1799branch 3 taken 144 (fallthrough)
1800branch 4 taken 72
1801 1123: 1081: case DS_RM_UNCHANGED_DEP: if (!rec->ref[0] || ds_find_op(b, rec->ref) < 0 || in_changed(o ? o->changed : NULL, rec->ref)) ok = 0; break;
1802branch 0 taken 1098 (fallthrough)
1803branch 1 taken 25
1804call 2 returned 1098
1805branch 3 taken 1074 (fallthrough)
1806branch 4 taken 24
1807branch 5 taken 1073 (fallthrough)
1808branch 6 taken 1
1809call 7 returned 1074
1810branch 8 taken 1041 (fallthrough)
1811branch 9 taken 33
1812 96: 1082: case DS_RM_DEFERRED: if (has_consumer) ok = 0; break;
1813branch 0 taken 24 (fallthrough)
1814branch 1 taken 72
1815 97: 1083: case DS_RM_SHARED:
1816 97: 1084: if (!rec->ref[0] || ds_find_op(t, rec->ref) < 0) ok = 0;
1817branch 0 taken 73 (fallthrough)
1818branch 1 taken 24
1819call 2 returned 73
1820branch 3 taken 48 (fallthrough)
1821branch 4 taken 25
1822 219: 1085: for (int k = 0; k < t->n_removed; k++) if (!strcmp(t->removed[k].op, rec->ref)) { d->double_counted = 1; ok = 0; }
1823branch 0 taken 25 (fallthrough)
1824branch 1 taken 97
1825branch 2 taken 122
1826branch 3 taken 97 (fallthrough)
1827 97: 1086: break;
1828 -: 1087: }
1829 2424: 1088: if (!ok) {
1830branch 0 taken 1415 (fallthrough)
1831branch 1 taken 1009
1832 1415: 1089: d->required_removed = 1;
1833 1415: 1090: snprintf(d->reason, sizeof d->reason, "op %s: removal reason %d not supported by its evidence (ref=%s proof=%s changed=%s)",
1834 1415: 1091: b->ops[i].id, rec->reason, rec->ref, rec->proof, o && o->changed ? o->changed : "");
1835branch 0 taken 1414 (fallthrough)
1836branch 1 taken 1
1837branch 2 taken 1290 (fallthrough)
1838branch 3 taken 124
1839 1415: 1092: return DS_REFUSED_REMOVED_REQUIRED;
1840 -: 1093: }
1841 1009: 1094: double w = b->ops[i].t_ns + b->ops[i].launch_ns;
1842 1009: 1095: if (b->ops[i].bytes > 0 && b->ops[i].bw >= 0) { double tb = b->ops[i].bytes / (b->res[b->ops[i].bw].cap * 1e-9); if (tb > b->ops[i].t_ns) w = tb + b->ops[i].launch_ns; }
1843branch 0 taken 1007 (fallthrough)
1844branch 1 taken 2
1845branch 2 taken 1003 (fallthrough)
1846branch 3 taken 4
1847branch 4 taken 2 (fallthrough)
1848branch 5 taken 1001
1849 1009: 1096: d->removed_ns[rec->reason] += w;
1850 -: 1097: }
1851 -: 1098: /* removed records that name ops never in the baseline are fabricated savings */
1852 1412: 1099: for (int k = 0; k < t->n_removed; k++) if (ds_find_op(b, t->removed[k].op) < 0) {
1853call 0 returned 1010
1854branch 1 taken 1 (fallthrough)
1855branch 2 taken 1009
1856branch 3 taken 1010
1857branch 4 taken 402 (fallthrough)
1858 1: 1100: d->double_counted = 1;
1859 1: 1101: snprintf(d->reason, sizeof d->reason, "removed record for %s, which was never in the baseline", t->removed[k].op);
1860 1: 1102: return DS_REFUSED_REMOVED_REQUIRED;
1861 -: 1103: }
1862 402: 1104: return DS_OK;
1863 -: 1105:#else
1864 -: 1106: return dr_diff(b,t,o,d);
1865 -: 1107:#endif
1866 -: 1108:}
1867 -: 0:Source:tools/dagsim/dagsim_format.h
1868 -: 0:Graph:build/dagsim-resolve/oracle.gcno
1869 -: 0:Data:build/dagsim-resolve/oracle.gcda
1870 -: 0:Runs:1
1871 -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1872 -: 2: * Fixed-view ABI marshalling only; decisions and arithmetic live in dag_fmt.om. */
1873 -: 3:#ifndef DAGSIM_FORMAT_H
1874 -: 4:#define DAGSIM_FORMAT_H
1875 -: 5:#include "cudapp_native.h"
1876 -: 6:#include <stdint.h>
1877 -: 7:#include <stdlib.h>
1878 -: 8:#include <string.h>
1879function ds_fmt called 0 returned 0% blocks executed 0%
1880 #####: 9:static inline uint64_t ds_fmt(unsigned mode, uint64_t a[16], char s[256]) {
1881 #####: 10: uint64_t result = 0;
1882 #####: 11: if (omega_dag_fmt(&result, mode, a, 16, s, 256)) abort();
1883call 0 never executed
1884branch 1 never executed (fallthrough)
1885branch 2 never executed
1886call 3 never executed
1887 #####: 12: return result;
1888 -: 13:}
1889 -: 14:static inline uint64_t ds_bits(double d) {
1890 -: 15: uint64_t u; memcpy(&u, &d, sizeof u); return u;
1891 -: 16:}
1892function ds_unbits called 0 returned 0% blocks executed 0%
1893 #####: 17:static inline double ds_unbits(uint64_t u) {
1894 #####: 18: double d; memcpy(&d, &u, sizeof d); return d;
1895 -: 19:}
1896 -: 20:static inline uint64_t ds_decide(unsigned mode, uint64_t a[16]) {
1897 -: 21: char s[256]; return ds_fmt(mode, a, s);
1898 -: 22:}
1899 -: 23:#endif