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 / mathlibs-host-20261106 / omega_gpu_mathlibs_api.c.gcov

2318 lines · 107827 bytes Raw Blame History
1 -: 0:Source:src/omega_gpu_mathlibs_api.c
2 -: 0:Graph:~/work/cudastack/lanes/MathlibsHostOm/build/mathlibs-host-om/differential-mathlibs_host_om_test.gcno
3 -: 0:Data:~/work/cudastack/lanes/MathlibsHostOm/build/mathlibs-host-om/differential-mathlibs_host_om_test.gcda
4 -: 0:Runs:2
5 -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
6 -: 2:/* Device execution and byte-moving effects for the seeded Omega mathlibs units.
7 -: 3: * Host planning/admission is in om/mathlibs/host.om. The default-OFF C branch
8 -: 4: * is retained solely as the migration differential oracle. */
9 -: 5:#include "omega_gpu_mathlibs_api.h"
10 -: 6:
11 -: 7:#include <stdbool.h>
12 -: 8:#include <stdlib.h>
13 -: 9:#include <string.h>
14 -: 10:#include <time.h>
15 -: 11:
16 -: 12:#include "omega_blackwell_codegen.h"
17 -: 13:#include "omega_gpu_om_ir.h"
18 -: 14:#include "omega_gpu_session.h"
19 -: 15:#include "omega_gpu_mathlibs_host.h"
20 -: 16:
21 -: 17:#ifndef CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
22 -: 18:#define CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST 0
23 -: 19:#endif
24 -: 20:
25 -: 21:#define ML_POISON32 0xffbadbadu
26 -: 22:#define ML_POISON32_ALT 0x00badbadu
27 -: 23:#define ML_POISON64 0xffbadbadffbadbadull
28 -: 24:#define ML_WAIT_MS 600000ull
29 -: 25:#define ML_GOLDEN 11400714819323198485ull /* SplitMix64 increment, 0x9E3779B97F4A7C15 */
30 -: 26:
31 -: 27:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
32 -: 28:#define ml_sub(a, b) ((a) - (b))
33 -: 29:#define ml_mul(a, b) ((a) * (b))
34 -: 30:#define ml_overlap(a, na, b, nb) ((b) < (a) + (na) && (a) < (b) + (nb))
35 -: 31:#define ml_scan(n, v) ((n) + ((v) == ML_POISON32))
36 -: 32:#else
37 -: 33:#define ml_sub omega_mh_sub
38 -: 34:#define ml_mul omega_mh_mul
39 -: 35:#define ml_overlap(a, na, b, nb) omega_mh_overlap((uintptr_t)(a), (na), (uintptr_t)(b), (nb))
40 -: 36:#define ml_scan(n, v) omega_mh_add((n), omega_mh_poison((v), 0, 0, 0))
41 -: 37:#endif
42 -: 38:
43 -: 39:/* One kernel per (kind, a, b, mutant), device copy uploaded once and resident for the process. */
44 -: 40:typedef struct {
45 -: 41: int used;
46 -: 42: uint64_t kind, a, b, mutant;
47 -: 43: uint32_t threads, declared;
48 -: 44: uint8_t *buf;
49 -: 45: OmegaBlackwellKernel kernel;
50 -: 46: OmegaGpuMem code;
51 -: 47:} Slot;
52 -: 48:static Slot g_cache[64];
53 -: 49:static int g_mutant_which, g_mutant_level;
54 -: 50:static OmegaGpuScratch g_in, g_out, g_tw, g_scr, g_s1, g_w, g_w2, g_b; /* g_s1..g_b: omega_gpu_fft_many */
55 -: 51:static bool g_hooked;
56 -: 52:
57function now_ns called 46 returned 100% blocks executed 100%
58 46: 53:static uint64_t now_ns(void) {
59 -: 54: struct timespec t;
60 46: 55: clock_gettime(CLOCK_MONOTONIC, &t);
61call 0 returned 46
62 -: 56:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
63 46: 57: return (uint64_t)t.tv_sec * 1000000000ULL + (uint64_t)t.tv_nsec;
64 -: 58:#else
65 -: 59: return omega_mh_time((uint64_t)t.tv_sec, (uint64_t)t.tv_nsec);
66 -: 60:#endif
67 -: 61:}
68 -: 62:
69function slot_clear called 0 returned 0% blocks executed 0%
70 #####: 63:static void slot_clear(Slot *s) {
71 #####: 64: free(s->buf);
72 #####: 65: omega_gpu_session_free(&s->code);
73call 0 never executed
74 #####: 66: memset(s, 0, sizeof *s);
75 #####: 67:}
76 -: 68:
77function cache_clear_locked called 0 returned 0% blocks executed 0%
78 #####: 69:static void cache_clear_locked(void) {
79 #####: 70: for (size_t i = 0; i < sizeof g_cache / sizeof g_cache[0]; i++)
80branch 0 never executed
81branch 1 never executed (fallthrough)
82 #####: 71: if (g_cache[i].used) slot_clear(&g_cache[i]);
83branch 0 never executed (fallthrough)
84branch 1 never executed
85call 2 never executed
86 #####: 72:}
87 -: 73:
88function oracle_cache_clear called 0 returned 0% blocks executed 0%
89 #####: 74:void omega_gpu_mathlibs_cache_clear(void) {
90 #####: 75: omega_gpu_session_lock();
91call 0 never executed
92 #####: 76: cache_clear_locked();
93call 0 never executed
94 #####: 77: omega_gpu_session_unlock();
95call 0 never executed
96 #####: 78:}
97 -: 79:
98function on_session_close called 0 returned 0% blocks executed 0%
99 #####: 80:static void on_session_close(void) {
100 #####: 81: cache_clear_locked();
101call 0 never executed
102 #####: 82: omega_gpu_session_scratch_free(&g_in);
103call 0 never executed
104 #####: 83: omega_gpu_session_scratch_free(&g_out);
105call 0 never executed
106 #####: 84: omega_gpu_session_scratch_free(&g_tw);
107call 0 never executed
108 #####: 85: omega_gpu_session_scratch_free(&g_scr);
109call 0 never executed
110 #####: 86: omega_gpu_session_scratch_free(&g_s1);
111call 0 never executed
112 #####: 87: omega_gpu_session_scratch_free(&g_w);
113call 0 never executed
114 #####: 88: omega_gpu_session_scratch_free(&g_w2);
115call 0 never executed
116 #####: 89: omega_gpu_session_scratch_free(&g_b);
117call 0 never executed
118 #####: 90:}
119 -: 91:
120function oracle_set_mutant called 0 returned 0% blocks executed 0%
121 #####: 92:void omega_gpu_mathlibs_test_set_mutant(int which, int level) {
122 #####: 93: omega_gpu_session_lock();
123call 0 never executed
124 #####: 94: g_mutant_which = which;
125 #####: 95: g_mutant_level = level < 0 ? 0 : level > 6 ? 6 : level;
126branch 0 never executed (fallthrough)
127branch 1 never executed
128 #####: 96: cache_clear_locked();
129call 0 never executed
130 #####: 97: omega_gpu_session_unlock();
131call 0 never executed
132 #####: 98:}
133 -: 99:
134function oracle_last_error called 0 returned 0% blocks executed 0%
135 #####: 100:const char *omega_gpu_mathlibs_last_error(void) { return omega_gpu_session_last_error(); }
136call 0 never executed
137 -: 101:
138 -: 102:/* Caller holds the lock. Builds the kernel on a miss; uploads it when upload is set. */
139 -: 103:/* Mutant targets: which 1 RNG (kind 0), 2 FFT (kind 1), 3 Philox (kind 3), 4 real split / merge (kind 4),
140 -: 104: * 5 transpose (kind 5), 7 Stockham pass (kind 7), 8 Bluestein step (kind 8), 9 strided copy (kind 9). */
141function kernel_for called 0 returned 0% blocks executed 0%
142 #####: 105:static int kernel_for(uint64_t kind, uint64_t a, uint64_t b, uint32_t threads, bool upload, Slot **out, bool *hit) {
143 #####: 106: bool target = (g_mutant_which == 1 && kind == 0) || (g_mutant_which == 2 && kind == 1) ||
144branch 0 never executed (fallthrough)
145branch 1 never executed
146branch 2 never executed (fallthrough)
147branch 3 never executed
148branch 4 never executed (fallthrough)
149branch 5 never executed
150branch 6 never executed (fallthrough)
151branch 7 never executed
152 #####: 107: (g_mutant_which >= 3 && (uint64_t)g_mutant_which == kind);
153branch 0 never executed (fallthrough)
154branch 1 never executed
155branch 2 never executed (fallthrough)
156branch 3 never executed
157 #####: 108: uint64_t mutant = target ? (uint64_t)g_mutant_level : 0;
158branch 0 never executed (fallthrough)
159branch 1 never executed
160 #####: 109: Slot *s = NULL;
161 #####: 110: *hit = false;
162 #####: 111: for (size_t i = 0; i < sizeof g_cache / sizeof g_cache[0]; i++)
163branch 0 never executed
164branch 1 never executed (fallthrough)
165 #####: 112: if (g_cache[i].used && g_cache[i].kind == kind && g_cache[i].a == a && g_cache[i].b == b &&
166branch 0 never executed (fallthrough)
167branch 1 never executed
168branch 2 never executed (fallthrough)
169branch 3 never executed
170branch 4 never executed (fallthrough)
171branch 5 never executed
172branch 6 never executed (fallthrough)
173branch 7 never executed
174 #####: 113: g_cache[i].mutant == mutant) {
175branch 0 never executed (fallthrough)
176branch 1 never executed
177 #####: 114: s = &g_cache[i];
178 #####: 115: *hit = true;
179 #####: 116: break;
180 -: 117: }
181 #####: 118: if (!s) {
182branch 0 never executed (fallthrough)
183branch 1 never executed
184 #####: 119: BlackwellIRProgram *prog = (BlackwellIRProgram *)malloc(sizeof *prog);
185 #####: 120: uint8_t *buf = (uint8_t *)malloc(OMEGA_BW_CODE_CAP_MAX);
186 -: 121: OmegaBlackwellKernel k;
187 #####: 122: uint32_t declared = 0;
188 #####: 123: int rc = (prog && buf) ? omega_gpu_om_ir_build(kind, a, b, mutant, threads, prog, buf, OMEGA_BW_CODE_CAP_MAX,
189branch 0 never executed (fallthrough)
190branch 1 never executed
191call 2 never executed
192 -: 124: &k, &declared, NULL)
193 #####: 125: : OMEGA_OM_IR_REPLAY;
194branch 0 never executed (fallthrough)
195branch 1 never executed
196 #####: 126: free(prog);
197 #####: 127: if (rc != OMEGA_OM_IR_OK) {
198branch 0 never executed (fallthrough)
199branch 1 never executed
200 #####: 128: free(buf);
201 #####: 129: omega_gpu_session_set_error(omega_gpu_om_ir_rc_name(rc));
202call 0 never executed
203call 1 never executed
204 #####: 130: return OMEGA_GPU_ML_CODEGEN_FAIL;
205 -: 131: }
206 #####: 132: size_t slot = 0;
207 #####: 133: for (size_t i = 0; i < sizeof g_cache / sizeof g_cache[0]; i++)
208branch 0 never executed
209branch 1 never executed (fallthrough)
210 #####: 134: if (!g_cache[i].used) { slot = i; break; }
211branch 0 never executed (fallthrough)
212branch 1 never executed
213 #####: 135: s = &g_cache[slot];
214 #####: 136: if (s->used) slot_clear(s); /* full: evict slot 0 */
215branch 0 never executed (fallthrough)
216branch 1 never executed
217call 2 never executed
218 #####: 137: s->used = 1;
219 #####: 138: s->kind = kind; s->a = a; s->b = b; s->mutant = mutant;
220 #####: 139: s->threads = threads; s->declared = declared;
221 #####: 140: s->buf = buf;
222 #####: 141: s->kernel = k;
223 -: 142: }
224 #####: 143: if (upload && !s->code.cpu) {
225branch 0 never executed (fallthrough)
226branch 1 never executed
227branch 2 never executed (fallthrough)
228branch 3 never executed
229 #####: 144: if (omega_gpu_session_alloc_code(s->kernel.code_size, &s->code) != 0) return OMEGA_GPU_ML_CHIP_FAIL;
230call 0 never executed
231branch 1 never executed (fallthrough)
232branch 2 never executed
233 #####: 145: memcpy(s->code.cpu, s->kernel.code, s->kernel.code_size);
234 #####: 146: if (omega_gpu_session_sync_to_gpu(&s->code) != 0) { omega_gpu_session_free(&s->code); return OMEGA_GPU_ML_CHIP_FAIL; }
235call 0 never executed
236branch 1 never executed (fallthrough)
237branch 2 never executed
238call 3 never executed
239 -: 147: }
240 #####: 148: *out = s;
241 #####: 149: return OMEGA_GPU_ML_OK;
242 -: 150:}
243 -: 151:
244function info_kernel called 0 returned 0% blocks executed 0%
245 #####: 152:static void info_kernel(OmegaGpuMathInfo *info, const Slot *s, bool hit) {
246 #####: 153: if (!info) return;
247branch 0 never executed (fallthrough)
248branch 1 never executed
249 #####: 154: info->kernel_cache_hit = hit;
250 #####: 155: info->insn_count = (uint32_t)s->kernel.insn_count;
251 #####: 156: info->gpr_peak = s->kernel.gpr_count;
252 #####: 157: info->gpr_declared = s->declared;
253 #####: 158: memcpy(info->code_digest, s->kernel.code_digest, 32);
254 #####: 159: info->threads_per_cta = s->threads;
255 -: 160:}
256 -: 161:
257function info_begin called 0 returned 0% blocks executed 0%
258 #####: 162:static void info_begin(OmegaGpuMathInfo *info, const Slot *s, bool hit) {
259 #####: 163: if (!info) return;
260branch 0 never executed (fallthrough)
261branch 1 never executed
262 #####: 164: memset(info, 0, sizeof *info);
263 #####: 165: info_kernel(info, s, hit);
264call 0 never executed
265 -: 166:}
266 -: 167:
267function codegen_only called 0 returned 0% blocks executed 0%
268 #####: 168:static int codegen_only(uint64_t kind, uint64_t a, uint64_t b, uint32_t threads, OmegaGpuMathInfo *info) {
269 #####: 169: omega_gpu_session_lock();
270call 0 never executed
271 -: 170: Slot *s;
272 -: 171: bool hit;
273 #####: 172: int rc = kernel_for(kind, a, b, threads, false, &s, &hit);
274call 0 never executed
275 #####: 173: if (rc == OMEGA_GPU_ML_OK) info_begin(info, s, hit);
276branch 0 never executed (fallthrough)
277branch 1 never executed
278call 2 never executed
279 #####: 174: omega_gpu_session_unlock();
280call 0 never executed
281 #####: 175: return rc;
282 -: 176:}
283 -: 177:
284 -: 178:/* Caller holds the lock: open the shared device, build and upload the kernel. */
285function begin called 0 returned 0% blocks executed 0%
286 #####: 179:static int begin(uint64_t kind, uint64_t a, uint64_t b, uint32_t threads, Slot **s, OmegaGpuMathInfo *info) {
287 #####: 180: if (!g_hooked) { (void)omega_gpu_session_on_close(on_session_close); g_hooked = true; }
288branch 0 never executed (fallthrough)
289branch 1 never executed
290call 2 never executed
291 #####: 181: if (!omega_gpu_session_open()) return OMEGA_GPU_ML_CHIP_FAIL;
292call 0 never executed
293branch 1 never executed (fallthrough)
294branch 2 never executed
295 -: 182: bool hit;
296 #####: 183: int rc = kernel_for(kind, a, b, threads, true, s, &hit);
297call 0 never executed
298 #####: 184: if (rc == OMEGA_GPU_ML_OK) info_begin(info, *s, hit);
299branch 0 never executed (fallthrough)
300branch 1 never executed
301call 2 never executed
302 #####: 185: return rc;
303 -: 186:}
304 -: 187:
305function launch called 0 returned 0% blocks executed 0%
306 #####: 188:static int launch(const Slot *s, const uint32_t *args, uint32_t n_args, uint32_t grid, size_t elements,
307 -: 189: uint32_t shared_bytes, OmegaGpuMathInfo *info) {
308 #####: 190: OmegaGpuLaunch L = {
309 #####: 191: .code_va = s->code.va, .gpr_count = s->declared, .threads_x = s->threads, .threads_y = 1,
310 -: 192: .grid_x = grid, .grid_y = 1, .num_elements = elements, .args = args, .n_args = n_args,
311 -: 193: .timeout_ms = ML_WAIT_MS, .shared_bytes = shared_bytes,
312 -: 194: };
313 #####: 195: uint64_t elapsed = 0;
314 #####: 196: uint32_t marker = 0;
315 #####: 197: if (omega_gpu_session_launch(&L, &elapsed, &marker) != 0) return OMEGA_GPU_ML_CHIP_FAIL;
316call 0 never executed
317branch 1 never executed (fallthrough)
318branch 2 never executed
319 #####: 198: if (info) {
320branch 0 never executed (fallthrough)
321branch 1 never executed
322 #####: 199: info->chip_calls++;
323 #####: 200: info->elapsed_ns += elapsed;
324 #####: 201: info->completion_marker = marker;
325 #####: 202: info->ctas_last_launch = grid;
326 -: 203: }
327 #####: 204: return OMEGA_GPU_ML_OK;
328 -: 205:}
329 -: 206:
330function put64 called 0 returned 0% blocks executed 0%
331 #####: 207:static void put64(uint32_t *w, uint64_t v) { w[0] = (uint32_t)v; w[1] = (uint32_t)(v >> 32); }
332 -: 208:
333 -: 209:/* ------------------------------------------------------------------ RNG */
334 -: 210:
335 -: 211:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
336function rng_args_ok called 730 returned 100% blocks executed 100%
337 730: 212:static int rng_args_ok(OmegaGpuRngKind kind, uint32_t nstreams, uint32_t per) {
338 730: 213: if ((unsigned)kind > OMEGA_GPU_RNG_NORMAL || nstreams == 0 || per == 0) return OMEGA_GPU_ML_BAD_ARGS;
339branch 0 taken 548 (fallthrough)
340branch 1 taken 182
341branch 2 taken 486 (fallthrough)
342branch 3 taken 62
343branch 4 taken 50 (fallthrough)
344branch 5 taken 436
345 436: 214: if (nstreams > OMEGA_GPU_RNG_MAX_STREAMS || (uint64_t)nstreams * per > OMEGA_GPU_RNG_MAX_OUTPUTS)
346branch 0 taken 324 (fallthrough)
347branch 1 taken 112
348branch 2 taken 48 (fallthrough)
349branch 3 taken 276
350 160: 215: return OMEGA_GPU_ML_TOO_LARGE;
351 276: 216: return OMEGA_GPU_ML_OK;
352 -: 217:}
353 -: 218:
354function oracle_rng_codegen called 0 returned 0% blocks executed 0%
355 #####: 219:int omega_gpu_rng_codegen(OmegaGpuRngKind kind, OmegaGpuMathInfo *info) {
356 #####: 220: if ((unsigned)kind > OMEGA_GPU_RNG_NORMAL) return OMEGA_GPU_ML_BAD_ARGS;
357branch 0 never executed (fallthrough)
358branch 1 never executed
359 #####: 221: return codegen_only(0, (uint64_t)kind, 0, OMEGA_GPU_RNG_THREADS, info);
360call 0 never executed
361 -: 222:}
362 -: 223:
363function oracle_rng_generate called 12 returned 100% blocks executed 13%
364 12: 224:int omega_gpu_rng_generate(OmegaGpuRngKind kind, uint64_t seed, uint64_t stream0, uint32_t nstreams,
365 -: 225: uint32_t offset, uint32_t per_stream, void *out, OmegaGpuMathInfo *info) {
366 12: 226: if (!out) return OMEGA_GPU_ML_BAD_ARGS;
367branch 0 taken 2 (fallthrough)
368branch 1 taken 10
369 10: 227: int rc = rng_args_ok(kind, nstreams, per_stream);
370call 0 returned 10
371 10: 228: if (rc != OMEGA_GPU_ML_OK) return rc;
372branch 0 taken 10 (fallthrough)
373branch 1 taken 0
374 #####: 229: uint64_t t0 = now_ns();
375call 0 never executed
376 #####: 230: size_t count = (size_t)nstreams * per_stream;
377 #####: 231: size_t esize = kind == OMEGA_GPU_RNG_U64 ? 8u : 4u;
378branch 0 never executed (fallthrough)
379branch 1 never executed
380 #####: 232: size_t bytes = count * esize;
381 #####: 233: omega_gpu_session_lock();
382call 0 never executed
383 -: 234: Slot *s;
384 #####: 235: rc = begin(0, (uint64_t)kind, 0, OMEGA_GPU_RNG_THREADS, &s, info);
385call 0 never executed
386 #####: 236: if (rc == OMEGA_GPU_ML_OK && omega_gpu_session_scratch(&g_out, bytes) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL;
387branch 0 never executed (fallthrough)
388branch 1 never executed
389call 2 never executed
390branch 3 never executed (fallthrough)
391branch 4 never executed
392 #####: 237: if (rc == OMEGA_GPU_ML_OK) {
393branch 0 never executed (fallthrough)
394branch 1 never executed
395 #####: 238: uint32_t *dev = (uint32_t *)g_out.mem.cpu;
396 #####: 239: for (size_t i = 0; i < bytes / 4; i++) dev[i] = ML_POISON32;
397branch 0 never executed
398branch 1 never executed (fallthrough)
399 #####: 240: if (omega_gpu_session_sync_to_gpu(&g_out.mem) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL;
400call 0 never executed
401branch 1 never executed (fallthrough)
402branch 2 never executed
403 -: 241: /* 0x380 out, 0x388 + 8 i base_i, 0x3a8 skip, 0x3ac per-stream count, 0x3b0 streams */
404 -: 242: uint32_t args[13];
405 #####: 243: put64(&args[0], g_out.mem.va);
406call 0 never executed
407 #####: 244: uint64_t x = seed + stream0;
408 #####: 245: for (int i = 0; i < 4; i++) { x += ML_GOLDEN; put64(&args[2 + 2 * i], x); }
409call 0 never executed
410branch 1 never executed
411branch 2 never executed (fallthrough)
412 #####: 246: args[10] = offset;
413 #####: 247: args[11] = per_stream;
414 #####: 248: args[12] = nstreams;
415 #####: 249: uint32_t grid = (nstreams + OMEGA_GPU_RNG_THREADS - 1) / OMEGA_GPU_RNG_THREADS;
416 #####: 250: if (rc == OMEGA_GPU_ML_OK) rc = launch(s, args, 13, grid, count, 0, info);
417branch 0 never executed (fallthrough)
418branch 1 never executed
419call 2 never executed
420 #####: 251: if (rc == OMEGA_GPU_ML_OK && omega_gpu_session_sync_to_cpu(&g_out.mem) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL;
421branch 0 never executed (fallthrough)
422branch 1 never executed
423call 2 never executed
424branch 3 never executed (fallthrough)
425branch 4 never executed
426 #####: 252: if (rc == OMEGA_GPU_ML_OK) {
427branch 0 never executed (fallthrough)
428branch 1 never executed
429 #####: 253: memcpy(out, g_out.mem.cpu, bytes);
430 #####: 254: uint64_t unwritten = 0;
431 #####: 255: if (esize == 8) {
432branch 0 never executed (fallthrough)
433branch 1 never executed
434 #####: 256: for (size_t i = 0; i < count; i++) unwritten += ((const uint64_t *)out)[i] == ML_POISON64;
435branch 0 never executed
436branch 1 never executed
437 -: 257: } else {
438 #####: 258: for (size_t i = 0; i < count; i++) unwritten += ((const uint32_t *)out)[i] == ML_POISON32;
439branch 0 never executed
440branch 1 never executed (fallthrough)
441 -: 259: }
442 #####: 260: if (info) info->unwritten_words = unwritten;
443branch 0 never executed (fallthrough)
444branch 1 never executed
445 #####: 261: if (unwritten) rc = OMEGA_GPU_ML_UNWRITTEN;
446branch 0 never executed (fallthrough)
447branch 1 never executed
448 -: 262: }
449 -: 263: }
450 #####: 264: omega_gpu_session_unlock();
451call 0 never executed
452 #####: 265: if (info) info->call_ns = now_ns() - t0;
453branch 0 never executed (fallthrough)
454branch 1 never executed
455call 2 never executed
456 #####: 266: return rc;
457 -: 267:}
458 -: 268:#endif
459 -: 269:
460 -: 270:/* ------------------------------------------------------------------ FFT */
461 -: 271:
462function lg_in called 924 returned 100% blocks executed 100%
463 924: 272:static int lg_in(uint32_t n, uint32_t lo, uint32_t hi) {
464 -: 273:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
465 924: 274: if (n < lo || n > hi || (n & (n - 1)) != 0) return -1;
466branch 0 taken 838 (fallthrough)
467branch 1 taken 86
468branch 2 taken 766 (fallthrough)
469branch 3 taken 72
470branch 4 taken 30 (fallthrough)
471branch 5 taken 736
472 736: 275: int k = 0;
473 4170: 276: while ((1u << k) < n) k++;
474branch 0 taken 3434
475branch 1 taken 736 (fallthrough)
476 736: 277: return k;
477 -: 278:#else
478 -: 279: uint64_t k = omega_mh_lg(n, lo, hi);
479 -: 280: return k == UINT32_MAX ? -1 : (int)k;
480 -: 281:#endif
481 -: 282:}
482 -: 283:
483function fft_log2 called 768 returned 100% blocks executed 100%
484 768: 284:static int fft_log2(uint32_t n) { return lg_in(n, OMEGA_GPU_FFT_MIN_N, OMEGA_GPU_FFT_MAX_N); }
485call 0 returned 768
486 -: 285:
487 -: 286:static float g_twf[2u * OMEGA_GPU_FFT_REAL_MAX_N];
488 -: 287:static uint64_t g_words[OMEGA_OM_IR_WORDS];
489 -: 288:
490 -: 289:/* Caller holds the lock: g_twf = the unit's f32 table of 2^lg points (kind 2). */
491function twiddles_locked called 664 returned 100% blocks executed 88%
492 664: 290:static int twiddles_locked(uint64_t lg, uint64_t inverse) {
493 664*: 291: if (omega_gpu_om_ir_data(2, lg, inverse, 0, g_words) != OMEGA_OM_IR_OK) return OMEGA_GPU_ML_CODEGEN_FAIL;
494call 0 returned 664
495branch 1 taken 0 (fallthrough)
496branch 2 taken 664
497 190088: 292: for (uint32_t m = 0; m < (1u << lg); m++) {
498branch 0 taken 189424
499branch 1 taken 664 (fallthrough)
500 189424: 293: uint32_t re = (uint32_t)g_words[m], im = (uint32_t)(g_words[m] >> 32);
501 189424: 294: memcpy(&g_twf[2 * m], &re, 4);
502 189424: 295: memcpy(&g_twf[2 * m + 1], &im, 4);
503 -: 296: }
504 664: 297: return OMEGA_GPU_ML_OK;
505 -: 298:}
506 -: 299:
507function oracle_fft_codegen called 0 returned 0% blocks executed 0%
508 #####: 300:int omega_gpu_fft_codegen(uint32_t n, int inverse, OmegaGpuMathInfo *info) {
509 #####: 301: int lg = fft_log2(n);
510call 0 never executed
511 #####: 302: if (lg < 0 || (inverse != 0 && inverse != 1)) return OMEGA_GPU_ML_BAD_ARGS;
512branch 0 never executed (fallthrough)
513branch 1 never executed
514branch 2 never executed (fallthrough)
515branch 3 never executed
516branch 4 never executed (fallthrough)
517branch 5 never executed
518 #####: 303: return codegen_only(1, (uint64_t)lg, (uint64_t)inverse, n / 4, info);
519call 0 never executed
520 -: 304:}
521 -: 305:
522function oracle_fft_twiddles called 0 returned 0% blocks executed 0%
523 #####: 306:int omega_gpu_fft_twiddles(uint32_t n, int inverse, float *tw) {
524 #####: 307: int lg = fft_log2(n);
525call 0 never executed
526 #####: 308: if (lg < 0 || !tw || (inverse != 0 && inverse != 1)) return OMEGA_GPU_ML_BAD_ARGS;
527branch 0 never executed (fallthrough)
528branch 1 never executed
529branch 2 never executed (fallthrough)
530branch 3 never executed
531branch 4 never executed (fallthrough)
532branch 5 never executed
533branch 6 never executed (fallthrough)
534branch 7 never executed
535 #####: 309: omega_gpu_session_lock();
536call 0 never executed
537 #####: 310: int rc = twiddles_locked((uint64_t)lg, (uint64_t)inverse);
538call 0 never executed
539 #####: 311: if (rc == OMEGA_GPU_ML_OK) memcpy(tw, g_twf, (size_t)8 * n);
540branch 0 never executed (fallthrough)
541branch 1 never executed
542 #####: 312: omega_gpu_session_unlock();
543call 0 never executed
544 #####: 313: return rc;
545 -: 314:}
546 -: 315:
547 -: 316:static int many_basic(OmegaGpuFftType type, uint32_t rank, const uint32_t *n, uint32_t batch, int inverse,
548 -: 317: const float *in, float *out, OmegaGpuMathInfo *info);
549 -: 318:
550 -: 319:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
551function oracle_fft_c2c called 18 returned 100% blocks executed 25%
552 18: 320:int omega_gpu_fft_c2c(const float *in, float *out, uint32_t n, uint32_t batch, int inverse, OmegaGpuMathInfo *info) {
553 18: 321: int lg = fft_log2(n);
554call 0 returned 18
555 18: 322: if (lg < 0 && n >= 2 && n <= OMEGA_GPU_FFT_MANY_MAX_N)
556branch 0 taken 14 (fallthrough)
557branch 1 taken 4
558branch 2 taken 10 (fallthrough)
559branch 3 taken 4
560branch 4 taken 6 (fallthrough)
561branch 5 taken 4
562 6: 323: return many_basic(OMEGA_GPU_FFT_TYPE_C2C, 1, &n, batch, inverse, in, out, info);
563call 0 returned 6
564 12*: 324: if (lg < 0 || !in || !out || batch == 0 || (inverse != 0 && inverse != 1)) return OMEGA_GPU_ML_BAD_ARGS;
565branch 0 taken 4 (fallthrough)
566branch 1 taken 8
567branch 2 taken 4 (fallthrough)
568branch 3 taken 0
569branch 4 taken 4 (fallthrough)
570branch 5 taken 0
571branch 6 taken 4 (fallthrough)
572branch 7 taken 0
573branch 8 taken 0 (fallthrough)
574branch 9 taken 4
575branch 10 never executed (fallthrough)
576branch 11 never executed
577 4: 325: size_t floats = (size_t)2 * n * batch;
578 4*: 326: if (floats > ((size_t)1 << 28)) return OMEGA_GPU_ML_TOO_LARGE;
579branch 0 taken 0 (fallthrough)
580branch 1 taken 4
581 4: 327: if ((out < in + floats) && (in < out + floats)) return OMEGA_GPU_ML_BAD_ARGS;
582branch 0 taken 4 (fallthrough)
583branch 1 taken 0
584branch 2 taken 4 (fallthrough)
585branch 3 taken 0
586 #####: 328: float *tw = (float *)malloc((size_t)2 * n * sizeof *tw);
587 #####: 329: if (!tw) return OMEGA_GPU_ML_CHIP_FAIL;
588branch 0 never executed (fallthrough)
589branch 1 never executed
590 #####: 330: int rc = omega_gpu_fft_twiddles(n, inverse, tw);
591call 0 never executed
592 #####: 331: if (rc != OMEGA_GPU_ML_OK) { free(tw); return rc; }
593branch 0 never executed (fallthrough)
594branch 1 never executed
595 #####: 332: uint64_t t0 = now_ns();
596call 0 never executed
597 #####: 333: size_t bytes = floats * 4;
598 #####: 334: omega_gpu_session_lock();
599call 0 never executed
600 -: 335: Slot *s;
601 #####: 336: rc = begin(1, (uint64_t)lg, (uint64_t)inverse, n / 4, &s, info);
602call 0 never executed
603 #####: 337: if (rc == OMEGA_GPU_ML_OK && (omega_gpu_session_scratch(&g_in, bytes) != 0 ||
604branch 0 never executed (fallthrough)
605branch 1 never executed
606call 2 never executed
607branch 3 never executed (fallthrough)
608branch 4 never executed
609branch 5 never executed (fallthrough)
610branch 6 never executed
611 #####: 338: omega_gpu_session_scratch(&g_out, bytes) != 0 ||
612call 0 never executed
613branch 1 never executed (fallthrough)
614branch 2 never executed
615 #####: 339: omega_gpu_session_scratch(&g_tw, (size_t)8 * n) != 0))
616call 0 never executed
617 #####: 340: rc = OMEGA_GPU_ML_CHIP_FAIL;
618 #####: 341: if (rc == OMEGA_GPU_ML_OK) {
619branch 0 never executed (fallthrough)
620branch 1 never executed
621 #####: 342: memcpy(g_in.mem.cpu, in, bytes);
622 #####: 343: memcpy(g_tw.mem.cpu, tw, (size_t)8 * n);
623 #####: 344: uint32_t *dev = (uint32_t *)g_out.mem.cpu;
624 #####: 345: for (size_t i = 0; i < floats; i++) dev[i] = ML_POISON32;
625branch 0 never executed
626branch 1 never executed (fallthrough)
627 #####: 346: if (omega_gpu_session_sync_to_gpu(&g_in.mem) != 0 || omega_gpu_session_sync_to_gpu(&g_tw.mem) != 0 ||
628call 0 never executed
629branch 1 never executed (fallthrough)
630branch 2 never executed
631call 3 never executed
632branch 4 never executed (fallthrough)
633branch 5 never executed
634branch 6 never executed (fallthrough)
635branch 7 never executed
636 #####: 347: omega_gpu_session_sync_to_gpu(&g_out.mem) != 0)
637call 0 never executed
638 #####: 348: rc = OMEGA_GPU_ML_CHIP_FAIL;
639 #####: 349: for (uint32_t b0 = 0; b0 < batch && rc == OMEGA_GPU_ML_OK; b0 += OMEGA_GPU_FFT_MAX_CTAS) {
640branch 0 never executed (fallthrough)
641branch 1 never executed
642branch 2 never executed
643branch 3 never executed (fallthrough)
644 #####: 350: uint32_t grid = batch - b0 < OMEGA_GPU_FFT_MAX_CTAS ? batch - b0 : OMEGA_GPU_FFT_MAX_CTAS;
645 #####: 351: uint64_t off = (uint64_t)b0 * n * 8u;
646 -: 352: uint32_t args[6]; /* 0x380 in, 0x388 out, 0x390 twiddles */
647 #####: 353: put64(&args[0], g_in.mem.va + off);
648call 0 never executed
649 #####: 354: put64(&args[2], g_out.mem.va + off);
650call 0 never executed
651 #####: 355: put64(&args[4], g_tw.mem.va);
652call 0 never executed
653 #####: 356: rc = launch(s, args, 6, grid, (size_t)grid * n * 2u, 8u * n, info);
654call 0 never executed
655 -: 357: }
656 #####: 358: if (rc == OMEGA_GPU_ML_OK && omega_gpu_session_sync_to_cpu(&g_out.mem) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL;
657branch 0 never executed (fallthrough)
658branch 1 never executed
659call 2 never executed
660branch 3 never executed (fallthrough)
661branch 4 never executed
662 #####: 359: if (rc == OMEGA_GPU_ML_OK) {
663branch 0 never executed (fallthrough)
664branch 1 never executed
665 #####: 360: memcpy(out, g_out.mem.cpu, bytes);
666 #####: 361: uint64_t unwritten = 0;
667 #####: 362: for (size_t i = 0; i < floats; i++) {
668branch 0 never executed
669branch 1 never executed (fallthrough)
670 -: 363: uint32_t u;
671 #####: 364: memcpy(&u, &out[i], 4);
672 #####: 365: unwritten += u == ML_POISON32;
673 -: 366: }
674 #####: 367: if (info) info->unwritten_words = unwritten;
675branch 0 never executed (fallthrough)
676branch 1 never executed
677 #####: 368: if (unwritten) rc = OMEGA_GPU_ML_UNWRITTEN;
678branch 0 never executed (fallthrough)
679branch 1 never executed
680 -: 369: }
681 -: 370: }
682 #####: 371: omega_gpu_session_unlock();
683call 0 never executed
684 #####: 372: free(tw);
685 #####: 373: if (info) info->call_ns = now_ns() - t0;
686branch 0 never executed (fallthrough)
687branch 1 never executed
688call 2 never executed
689 #####: 374: return rc;
690 -: 375:}
691 -: 376:#endif
692 -: 377:
693 -: 378:/* ------------------------------------------------------------------ Philox */
694 -: 379:
695function oracle_philox_codegen called 0 returned 0% blocks executed 0%
696 #####: 380:int omega_gpu_philox_codegen(OmegaGpuMathInfo *info) { return codegen_only(3, 0, 0, OMEGA_GPU_PHILOX_THREADS, info); }
697call 0 never executed
698 -: 381:
699 -: 382:/* Caller holds the lock: fill g_out with poison, run, read back into out. */
700function philox_pass called 0 returned 0% blocks executed 0%
701 #####: 383:static int philox_pass(const Slot *s, const uint32_t *args, uint32_t grid, size_t count, uint32_t poison, uint32_t *out,
702 -: 384: OmegaGpuMathInfo *info) {
703 #####: 385: uint32_t *dev = (uint32_t *)g_out.mem.cpu;
704 #####: 386: for (size_t i = 0; i < count; i++) dev[i] = poison;
705branch 0 never executed
706branch 1 never executed (fallthrough)
707 #####: 387: if (omega_gpu_session_sync_to_gpu(&g_out.mem) != 0) return OMEGA_GPU_ML_CHIP_FAIL;
708call 0 never executed
709branch 1 never executed (fallthrough)
710branch 2 never executed
711 #####: 388: int rc = launch(s, args, 11, grid, count, 0, info);
712call 0 never executed
713 #####: 389: if (rc == OMEGA_GPU_ML_OK && omega_gpu_session_sync_to_cpu(&g_out.mem) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL;
714branch 0 never executed (fallthrough)
715branch 1 never executed
716call 2 never executed
717branch 3 never executed (fallthrough)
718branch 4 never executed
719 #####: 390: if (rc == OMEGA_GPU_ML_OK) memcpy(out, dev, count * 4u);
720branch 0 never executed (fallthrough)
721branch 1 never executed
722 #####: 391: return rc;
723 -: 392:}
724 -: 393:
725 -: 394:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
726function oracle_philox_dist called 12 returned 100% blocks executed 12%
727 12: 395:int omega_gpu_philox_generate_dist(OmegaGpuPhiloxDist dist, uint64_t seed, uint64_t subseq0, uint32_t nstreams,
728 -: 396: uint64_t offset, uint32_t per_stream, void *out, OmegaGpuMathInfo *info) {
729 12: 397: if (!out || (unsigned)dist > OMEGA_GPU_PHILOX_NORMAL || nstreams == 0 || per_stream == 0)
730branch 0 taken 10 (fallthrough)
731branch 1 taken 2
732branch 2 taken 8 (fallthrough)
733branch 3 taken 2
734branch 4 taken 6 (fallthrough)
735branch 5 taken 2
736branch 6 taken 2 (fallthrough)
737branch 7 taken 4
738 8: 398: return OMEGA_GPU_ML_BAD_ARGS;
739 4*: 399: if (nstreams > OMEGA_GPU_PHILOX_MAX_STREAMS || (uint64_t)nstreams * per_stream > OMEGA_GPU_RNG_MAX_OUTPUTS)
740branch 0 taken 0 (fallthrough)
741branch 1 taken 4
742branch 2 never executed (fallthrough)
743branch 3 never executed
744 4: 400: return OMEGA_GPU_ML_TOO_LARGE;
745 #####: 401: uint64_t t0 = now_ns();
746call 0 never executed
747 -: 402: /* G outputs per group of four words; 64-bit outputs are two words each */
748 #####: 403: uint32_t g = dist == OMEGA_GPU_PHILOX_UNIFORM2_DOUBLE ? 2u : 4u;
749branch 0 never executed (fallthrough)
750branch 1 never executed
751 #####: 404: uint32_t esz = dist == OMEGA_GPU_PHILOX_UNIFORM_DOUBLE || dist == OMEGA_GPU_PHILOX_UNIFORM2_DOUBLE ? 2u : 1u;
752branch 0 never executed (fallthrough)
753branch 1 never executed
754branch 2 never executed (fallthrough)
755branch 3 never executed
756 #####: 405: size_t count = (size_t)nstreams * per_stream * esz;
757 #####: 406: uint32_t *words = (uint32_t *)out;
758 #####: 407: omega_gpu_session_lock();
759call 0 never executed
760 -: 408: Slot *s;
761 #####: 409: int rc = begin(3, (uint64_t)dist, offset % 4u, OMEGA_GPU_PHILOX_THREADS, &s, info);
762call 0 never executed
763 #####: 410: if (rc == OMEGA_GPU_ML_OK && omega_gpu_session_scratch(&g_out, count * 4u) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL;
764branch 0 never executed (fallthrough)
765branch 1 never executed
766call 2 never executed
767branch 3 never executed (fallthrough)
768branch 4 never executed
769 #####: 411: if (rc == OMEGA_GPU_ML_OK) {
770branch 0 never executed (fallthrough)
771branch 1 never executed
772 -: 412: /* 0x380 out, 0x388 key, 0x390 subsequence of stream 0, 0x398 first counter block (offset / 4), 0x3a0 groups
773 -: 413: * T = ceil(per / G), 0x3a4 streams, 0x3a8 tail delta (per % G - G mod 2^32, 0 without a partial group) */
774 -: 414: uint32_t args[11];
775 #####: 415: put64(&args[0], g_out.mem.va);
776call 0 never executed
777 #####: 416: put64(&args[2], seed);
778call 0 never executed
779 #####: 417: put64(&args[4], subseq0);
780call 0 never executed
781 #####: 418: put64(&args[6], offset / 4u);
782call 0 never executed
783 #####: 419: uint32_t r = per_stream % g;
784 #####: 420: args[8] = per_stream / g + (r != 0);
785 #####: 421: args[9] = nstreams;
786 #####: 422: args[10] = r ? r - g : 0u;
787branch 0 never executed (fallthrough)
788branch 1 never executed
789 #####: 423: uint32_t grid = (nstreams + OMEGA_GPU_PHILOX_THREADS - 1) / OMEGA_GPU_PHILOX_THREADS;
790 #####: 424: rc = philox_pass(s, args, grid, count, ML_POISON32, words, info);
791call 0 never executed
792 #####: 425: uint64_t unwritten = 0;
793 #####: 426: if (dist == OMEGA_GPU_PHILOX_RAW) {
794branch 0 never executed (fallthrough)
795branch 1 never executed
796 -: 427: /* Every 32-bit value is a possible output: a word equal to the poison is unwritten only if a second
797 -: 428: * run with another poison leaves that poison there too. */
798 #####: 429: uint64_t hits = 0;
799 #####: 430: for (size_t i = 0; rc == OMEGA_GPU_ML_OK && i < count; i++) hits += words[i] == ML_POISON32;
800branch 0 never executed (fallthrough)
801branch 1 never executed
802branch 2 never executed
803branch 3 never executed (fallthrough)
804 #####: 431: if (rc == OMEGA_GPU_ML_OK && hits) {
805branch 0 never executed (fallthrough)
806branch 1 never executed
807branch 2 never executed (fallthrough)
808branch 3 never executed
809 #####: 432: uint32_t *first = (uint32_t *)malloc(count * 4u);
810 #####: 433: if (!first) rc = OMEGA_GPU_ML_CHIP_FAIL;
811branch 0 never executed (fallthrough)
812branch 1 never executed
813 #####: 434: if (first) {
814branch 0 never executed (fallthrough)
815branch 1 never executed
816 #####: 435: memcpy(first, words, count * 4u);
817 #####: 436: rc = philox_pass(s, args, grid, count, ML_POISON32_ALT, words, info);
818call 0 never executed
819 #####: 437: for (size_t i = 0; rc == OMEGA_GPU_ML_OK && i < count; i++)
820branch 0 never executed (fallthrough)
821branch 1 never executed
822branch 2 never executed
823branch 3 never executed (fallthrough)
824 #####: 438: unwritten += first[i] == ML_POISON32 && words[i] == ML_POISON32_ALT;
825branch 0 never executed (fallthrough)
826branch 1 never executed
827branch 2 never executed (fallthrough)
828branch 3 never executed
829 #####: 439: free(first);
830 -: 440: }
831 -: 441: }
832 #####: 442: } else if (esz == 1) {
833branch 0 never executed (fallthrough)
834branch 1 never executed
835 -: 443: /* the poison is a NaN: no f32 output of these distributions */
836 #####: 444: for (size_t i = 0; rc == OMEGA_GPU_ML_OK && i < count; i++) unwritten += words[i] == ML_POISON32;
837branch 0 never executed (fallthrough)
838branch 1 never executed
839branch 2 never executed
840branch 3 never executed
841 -: 445: } else {
842 -: 446: /* the poison pair is a NaN: no f64 output */
843 #####: 447: const uint64_t *d = (const uint64_t *)out;
844 #####: 448: for (size_t i = 0; rc == OMEGA_GPU_ML_OK && i < count / 2; i++) unwritten += d[i] == ML_POISON64;
845branch 0 never executed (fallthrough)
846branch 1 never executed
847branch 2 never executed
848branch 3 never executed (fallthrough)
849 -: 449: }
850 #####: 450: if (info) info->unwritten_words = unwritten;
851branch 0 never executed (fallthrough)
852branch 1 never executed
853 #####: 451: if (rc == OMEGA_GPU_ML_OK && unwritten) rc = OMEGA_GPU_ML_UNWRITTEN;
854branch 0 never executed (fallthrough)
855branch 1 never executed
856branch 2 never executed (fallthrough)
857branch 3 never executed
858 -: 452: }
859 #####: 453: omega_gpu_session_unlock();
860call 0 never executed
861 #####: 454: if (info) info->call_ns = now_ns() - t0;
862branch 0 never executed (fallthrough)
863branch 1 never executed
864call 2 never executed
865 #####: 455: return rc;
866 -: 456:}
867 -: 457:#endif
868 -: 458:
869function oracle_philox_generate called 0 returned 0% blocks executed 0%
870 #####: 459:int omega_gpu_philox_generate(uint64_t seed, uint64_t subseq0, uint32_t nstreams, uint64_t offset, uint32_t per_stream,
871 -: 460: uint32_t *out, OmegaGpuMathInfo *info) {
872 #####: 461: return omega_gpu_philox_generate_dist(OMEGA_GPU_PHILOX_RAW, seed, subseq0, nstreams, offset, per_stream, out, info);
873call 0 never executed
874 -: 462:}
875 -: 463:
876 -: 464:/* ------------------------------------------------------------------ FFT plans (R2C, C2R, 2-D, 3-D) */
877 -: 465:
878 -: 466:/* Caller holds the lock. Validates, sizes the buffers, asks the unit for the pass plan (kind 6) and, when fn is set,
879 -: 467: * turns each step into launches of at most OMEGA_GPU_FFT_MAX_CTAS CTAs. */
880 -: 468:static int walk_locked(OmegaGpuFftPlanMode mode, uint32_t ndim, const uint32_t *dims, uint32_t batch, int inverse,
881 -: 469: size_t bytes[3], OmegaGpuFftLaunchFn fn, void *ctx);
882 -: 470:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
883function walk_locked called 648 returned 100% blocks executed 90%
884 648: 471:static int walk_locked(OmegaGpuFftPlanMode mode, uint32_t ndim, const uint32_t *dims, uint32_t batch, int inverse,
885 -: 472: size_t bytes[3], OmegaGpuFftLaunchFn fn, void *ctx) {
886 648: 473: if (!dims || !bytes || batch == 0 || (inverse != 0 && inverse != 1)) return OMEGA_GPU_ML_BAD_ARGS;
887branch 0 taken 646 (fallthrough)
888branch 1 taken 2
889branch 2 taken 644 (fallthrough)
890branch 3 taken 2
891branch 4 taken 564 (fallthrough)
892branch 5 taken 80
893branch 6 taken 164 (fallthrough)
894branch 7 taken 400
895branch 8 taken 2 (fallthrough)
896branch 9 taken 162
897 562: 474: uint64_t lgs = 0;
898 562: 475: uint32_t sum = 0;
899 562: 476: if (mode == OMEGA_GPU_FFT_C2C_ND) {
900branch 0 taken 466 (fallthrough)
901branch 1 taken 96
902 466: 477: if (ndim < 1 || ndim > 3) return OMEGA_GPU_ML_BAD_ARGS;
903branch 0 taken 464 (fallthrough)
904branch 1 taken 2
905branch 2 taken 20 (fallthrough)
906branch 3 taken 444
907 1108: 478: for (uint32_t i = 0; i < ndim; i++) {
908branch 0 taken 744
909branch 1 taken 364
910 744: 479: int k = fft_log2(dims[i]);
911call 0 returned 744
912 744: 480: if (k < 0) return OMEGA_GPU_ML_BAD_ARGS;
913branch 0 taken 80 (fallthrough)
914branch 1 taken 664
915 664: 481: lgs |= (uint64_t)k << (4 * i);
916 664: 482: sum += (uint32_t)k;
917 -: 483: }
918 96: 484: } else if (mode == OMEGA_GPU_FFT_R2C || mode == OMEGA_GPU_FFT_C2R) {
919branch 0 taken 48 (fallthrough)
920branch 1 taken 48
921branch 2 taken 44 (fallthrough)
922branch 3 taken 4
923 92: 485: if (ndim != 1 || inverse != 0) return OMEGA_GPU_ML_BAD_ARGS;
924branch 0 taken 90 (fallthrough)
925branch 1 taken 2
926branch 2 taken 2 (fallthrough)
927branch 3 taken 88
928 88: 486: int k = lg_in(dims[0], OMEGA_GPU_FFT_REAL_MIN_N, OMEGA_GPU_FFT_REAL_MAX_N);
929call 0 returned 88
930 88: 487: if (k < 0) return OMEGA_GPU_ML_BAD_ARGS;
931branch 0 taken 40 (fallthrough)
932branch 1 taken 48
933 48: 488: lgs = (uint64_t)k;
934 48: 489: sum = (uint32_t)k;
935 -: 490: } else {
936 4: 491: return OMEGA_GPU_ML_BAD_ARGS;
937 -: 492: }
938 412: 493: if (sum > 27 || ((uint64_t)batch << sum) > OMEGA_GPU_FFT_MAX_ELEMENTS) return OMEGA_GPU_ML_TOO_LARGE;
939branch 0 taken 410 (fallthrough)
940branch 1 taken 2
941branch 2 taken 2 (fallthrough)
942branch 3 taken 408
943 408: 494: size_t elems = (size_t)batch << sum, half = ((size_t)1 << sum) / 2u + 1u;
944 408: 495: bytes[0] = bytes[1] = bytes[2] = elems * 8u;
945 408: 496: if (mode == OMEGA_GPU_FFT_R2C) { bytes[0] = elems * 4u; bytes[1] = half * 8u * batch; bytes[2] = elems * 4u; }
946branch 0 taken 24 (fallthrough)
947branch 1 taken 384
948 408: 497: if (mode == OMEGA_GPU_FFT_C2R) { bytes[0] = half * 8u * batch; bytes[1] = elems * 4u; bytes[2] = elems * 4u; }
949branch 0 taken 24 (fallthrough)
950branch 1 taken 384
951 408: 498: int rc = omega_gpu_om_ir_data(6, (uint64_t)mode | (uint64_t)ndim << 4, lgs, (uint64_t)inverse, g_words);
952call 0 returned 408
953 408*: 499: if (rc == OMEGA_OM_IR_REFUSED) return OMEGA_GPU_ML_BAD_ARGS;
954branch 0 taken 0 (fallthrough)
955branch 1 taken 408
956 408*: 500: if (rc != OMEGA_OM_IR_OK || g_words[0] == 0 || g_words[0] > 6) return OMEGA_GPU_ML_CODEGEN_FAIL;
957branch 0 taken 408 (fallthrough)
958branch 1 taken 0
959branch 2 taken 408 (fallthrough)
960branch 3 taken 0
961branch 4 taken 0 (fallthrough)
962branch 5 taken 408
963 -: 501: uint64_t steps[6];
964 408: 502: uint32_t nsteps = (uint32_t)g_words[0];
965 408: 503: memcpy(steps, &g_words[1], nsteps * sizeof steps[0]);
966 1492: 504: for (uint32_t i = 0; fn && i < nsteps; i++) {
967branch 0 taken 1482 (fallthrough)
968branch 1 taken 10
969branch 2 taken 1084
970branch 3 taken 398 (fallthrough)
971 -: 505: OmegaGpuFftLaunch L;
972 1084: 506: memset(&L, 0, sizeof L);
973 1084: 507: L.kind = (uint32_t)(steps[i] & 255u);
974 1084: 508: L.a = (uint32_t)(steps[i] >> 8 & 255u);
975 1084: 509: L.b = (uint32_t)(steps[i] >> 16 & 255u);
976 1084: 510: L.src = (uint32_t)(steps[i] >> 24 & 255u);
977 1084: 511: L.dst = (uint32_t)(steps[i] >> 32 & 255u);
978 1084: 512: uint64_t rows = (uint64_t)batch << (steps[i] >> 40 & 255u);
979 1084*: 513: if (L.src > 2 || L.dst > 2) return OMEGA_GPU_ML_CODEGEN_FAIL;
980branch 0 taken 1084 (fallthrough)
981branch 1 taken 0
982branch 2 taken 0 (fallthrough)
983branch 3 taken 1084
984 1748: 514: if (L.kind == 1 || L.kind == 4) {
985branch 0 taken 460 (fallthrough)
986branch 1 taken 624
987branch 2 taken 40 (fallthrough)
988branch 3 taken 420
989 664: 515: rc = twiddles_locked(L.a, L.b);
990call 0 returned 664
991 664*: 516: if (rc != OMEGA_GPU_ML_OK) return rc;
992branch 0 taken 0 (fallthrough)
993branch 1 taken 664
994 664: 517: uint64_t n = 1ull << L.a, si = n, so = n;
995 664: 518: L.tw = g_twf;
996 664: 519: L.tw_n = (uint32_t)n;
997 664: 520: L.tw_inverse = L.b;
998 664: 521: L.threads = (uint32_t)n / 4u;
999 664: 522: L.shared_bytes = L.kind == 1 ? (uint32_t)(8u * n) : 0u;
1000branch 0 taken 624 (fallthrough)
1001branch 1 taken 40
1002 664: 523: if (L.kind == 4) { si = n / 2u + L.b; so = n / 2u + 1u - L.b; }
1003branch 0 taken 40 (fallthrough)
1004branch 1 taken 624
1005 50932: 524: for (uint64_t r0 = 0; r0 < rows; r0 += OMEGA_GPU_FFT_MAX_CTAS) {
1006branch 0 taken 50268
1007branch 1 taken 664 (fallthrough)
1008 50268: 525: L.grid = (uint32_t)(rows - r0 < OMEGA_GPU_FFT_MAX_CTAS ? rows - r0 : OMEGA_GPU_FFT_MAX_CTAS);
1009branch 0 taken 500 (fallthrough)
1010branch 1 taken 49768
1011 50268: 526: L.src_off = r0 * si * 8u;
1012 50268: 527: L.dst_off = r0 * so * 8u;
1013 50268: 528: L.elements = (size_t)2u * so * L.grid;
1014 50268: 529: rc = fn(ctx, &L);
1015call 0 returned 50268
1016 50268*: 530: if (rc != OMEGA_GPU_ML_OK) return rc;
1017branch 0 taken 0 (fallthrough)
1018branch 1 taken 50268
1019 -: 531: }
1020 420: 532: } else if (L.kind == 5) {
1021branch 0 taken 420 (fallthrough)
1022branch 1 taken 0
1023 420: 533: uint64_t total = rows << (L.a + L.b);
1024 420: 534: uint64_t ctas = (total + 255u) / 256u;
1025 420: 535: L.threads = 256;
1026 420: 536: L.total = (uint32_t)total;
1027 2256: 537: for (uint64_t c0 = 0; c0 < ctas; c0 += OMEGA_GPU_FFT_MAX_CTAS) {
1028branch 0 taken 1836
1029branch 1 taken 420
1030 1836: 538: L.grid = (uint32_t)(ctas - c0 < OMEGA_GPU_FFT_MAX_CTAS ? ctas - c0 : OMEGA_GPU_FFT_MAX_CTAS);
1031branch 0 taken 372 (fallthrough)
1032branch 1 taken 1464
1033 1836: 539: L.first = (uint32_t)(c0 * 256u);
1034 1836: 540: uint64_t left = total - L.first;
1035 1836: 541: L.elements = (size_t)2u * ((uint64_t)L.grid * 256u < left ? (uint64_t)L.grid * 256u : left);
1036 1836: 542: rc = fn(ctx, &L);
1037call 0 returned 1836
1038 1836*: 543: if (rc != OMEGA_GPU_ML_OK) return rc;
1039branch 0 taken 0 (fallthrough)
1040branch 1 taken 1836
1041 -: 544: }
1042 -: 545: } else {
1043 #####: 546: return OMEGA_GPU_ML_CODEGEN_FAIL;
1044 -: 547: }
1045 -: 548: }
1046 408: 549: return OMEGA_GPU_ML_OK;
1047 -: 550:}
1048 -: 551:#endif
1049 -: 552:
1050 -: 553:/* The launches of a walk with private copies of their twiddle tables, so the caller's fn runs unlocked. */
1051 -: 554:typedef struct {
1052 -: 555: OmegaGpuFftLaunch *l;
1053 -: 556: size_t n, cap;
1054 -: 557: float **tw;
1055 -: 558: size_t ntw, twcap;
1056 -: 559:} Collect;
1057 -: 560:
1058function collect called 52104 returned 100% blocks executed 87%
1059 52104: 561:static int collect(void *ctx, const OmegaGpuFftLaunch *L) {
1060 52104: 562: Collect *c = (Collect *)ctx;
1061 52104: 563: if (c->n == c->cap) {
1062branch 0 taken 736 (fallthrough)
1063branch 1 taken 51368
1064 736: 564: size_t cap = c->cap ? 2u * c->cap : 32u;
1065branch 0 taken 338 (fallthrough)
1066branch 1 taken 398
1067 736: 565: OmegaGpuFftLaunch *l = (OmegaGpuFftLaunch *)realloc(c->l, cap * sizeof *l);
1068 736*: 566: if (!l) return OMEGA_GPU_ML_CHIP_FAIL;
1069branch 0 taken 0 (fallthrough)
1070branch 1 taken 736
1071 736: 567: c->l = l;
1072 736: 568: c->cap = cap;
1073 -: 569: }
1074 52104: 570: OmegaGpuFftLaunch x = *L;
1075 52104: 571: if (L->tw_n) {
1076branch 0 taken 50268 (fallthrough)
1077branch 1 taken 1836
1078 50268: 572: const OmegaGpuFftLaunch *p = NULL;
1079 51202: 573: for (size_t i = c->n; i-- > 0;)
1080branch 0 taken 50804
1081branch 1 taken 398 (fallthrough)
1082 50804: 574: if (c->l[i].tw_n) { p = &c->l[i]; break; }
1083branch 0 taken 49870 (fallthrough)
1084branch 1 taken 934
1085 50268: 575: if (p && p->tw_n == L->tw_n && p->tw_inverse == L->tw_inverse) {
1086branch 0 taken 49870 (fallthrough)
1087branch 1 taken 398
1088branch 2 taken 49662 (fallthrough)
1089branch 3 taken 208
1090branch 4 taken 49662 (fallthrough)
1091branch 5 taken 0
1092 49662: 576: x.tw = p->tw;
1093 -: 577: } else {
1094 606: 578: if (c->ntw == c->twcap) {
1095branch 0 taken 398 (fallthrough)
1096branch 1 taken 208
1097 398*: 579: size_t cap = c->twcap ? 2u * c->twcap : 8u;
1098branch 0 taken 0 (fallthrough)
1099branch 1 taken 398
1100 398: 580: float **t = (float **)realloc(c->tw, cap * sizeof *t);
1101 398*: 581: if (!t) return OMEGA_GPU_ML_CHIP_FAIL;
1102branch 0 taken 0 (fallthrough)
1103branch 1 taken 398
1104 398: 582: c->tw = t;
1105 398: 583: c->twcap = cap;
1106 -: 584: }
1107 606: 585: float *copy = (float *)malloc((size_t)8 * L->tw_n);
1108 606*: 586: if (!copy) return OMEGA_GPU_ML_CHIP_FAIL;
1109branch 0 taken 0 (fallthrough)
1110branch 1 taken 606
1111 606: 587: memcpy(copy, L->tw, (size_t)8 * L->tw_n);
1112 606: 588: c->tw[c->ntw++] = copy;
1113 606: 589: x.tw = copy;
1114 -: 590: }
1115 -: 591: }
1116 52104: 592: c->l[c->n++] = x;
1117 52104: 593: return OMEGA_GPU_ML_OK;
1118 -: 594:}
1119 -: 595:
1120function oracle_walk called 622 returned 100% blocks executed 100%
1121 622: 596:int omega_gpu_fft_plan_walk(OmegaGpuFftPlanMode mode, uint32_t ndim, const uint32_t *dims, uint32_t batch, int inverse,
1122 -: 597: size_t bytes[3], OmegaGpuFftLaunchFn fn, void *ctx) {
1123 -: 598: Collect c;
1124 622: 599: memset(&c, 0, sizeof c);
1125 622: 600: omega_gpu_session_lock();
1126call 0 returned 622
1127 622: 601: int rc = walk_locked(mode, ndim, dims, batch, inverse, bytes, fn ? collect : NULL, &c);
1128branch 0 taken 618 (fallthrough)
1129branch 1 taken 4
1130call 2 returned 622
1131 622: 602: omega_gpu_session_unlock();
1132call 0 returned 622
1133 52726: 603: for (size_t i = 0; rc == OMEGA_GPU_ML_OK && i < c.n; i++) rc = fn(ctx, &c.l[i]);
1134call 0 returned 52104
1135branch 1 taken 52500 (fallthrough)
1136branch 2 taken 226
1137branch 3 taken 52104
1138branch 4 taken 396 (fallthrough)
1139 1228: 604: for (size_t i = 0; i < c.ntw; i++) free(c.tw[i]);
1140branch 0 taken 606
1141branch 1 taken 622 (fallthrough)
1142 622: 605: free(c.tw);
1143 622: 606: free(c.l);
1144 622: 607: return rc;
1145 -: 608:}
1146 -: 609:
1147 -: 610:typedef struct {
1148 -: 611: OmegaGpuMathInfo *info;
1149 -: 612: OmegaGpuScratch *buf[3];
1150 -: 613: uint32_t tw_n, tw_inverse;
1151 -: 614:} ChipRun;
1152 -: 615:
1153 -: 616:/* Caller holds the lock: one launch of a plan step on the chip. */
1154function chip_launch called 0 returned 0% blocks executed 0%
1155 #####: 617:static int chip_launch(void *ctx, const OmegaGpuFftLaunch *l) {
1156 #####: 618: ChipRun *r = (ChipRun *)ctx;
1157 -: 619: Slot *s;
1158 -: 620: bool hit;
1159 #####: 621: int rc = kernel_for(l->kind, l->a, l->b, l->threads, true, &s, &hit);
1160call 0 never executed
1161 #####: 622: if (rc != OMEGA_GPU_ML_OK) return rc;
1162branch 0 never executed (fallthrough)
1163branch 1 never executed
1164 #####: 623: info_kernel(r->info, s, hit);
1165call 0 never executed
1166 #####: 624: if (l->tw_n && (l->tw_n != r->tw_n || l->tw_inverse != r->tw_inverse)) {
1167branch 0 never executed (fallthrough)
1168branch 1 never executed
1169branch 2 never executed (fallthrough)
1170branch 3 never executed
1171branch 4 never executed (fallthrough)
1172branch 5 never executed
1173 #####: 625: memcpy(g_tw.mem.cpu, l->tw, (size_t)8 * l->tw_n);
1174 #####: 626: if (omega_gpu_session_sync_to_gpu(&g_tw.mem) != 0) return OMEGA_GPU_ML_CHIP_FAIL;
1175call 0 never executed
1176branch 1 never executed (fallthrough)
1177branch 2 never executed
1178 #####: 627: r->tw_n = l->tw_n;
1179 #####: 628: r->tw_inverse = l->tw_inverse;
1180 -: 629: }
1181 -: 630: uint32_t args[6]; /* 0x380 in, 0x388 out, 0x390 twiddles (kind 5: element count, first element) */
1182 #####: 631: put64(&args[0], r->buf[l->src]->mem.va + l->src_off);
1183call 0 never executed
1184 #####: 632: put64(&args[2], r->buf[l->dst]->mem.va + l->dst_off);
1185call 0 never executed
1186 #####: 633: if (l->kind == 5) {
1187branch 0 never executed (fallthrough)
1188branch 1 never executed
1189 #####: 634: args[4] = l->total;
1190 #####: 635: args[5] = l->first;
1191 -: 636: } else {
1192 #####: 637: put64(&args[4], g_tw.mem.va);
1193call 0 never executed
1194 -: 638: }
1195 #####: 639: return launch(s, args, 6, l->grid, l->elements, l->shared_bytes, r->info);
1196call 0 never executed
1197 -: 640:}
1198 -: 641:
1199function run_plan called 26 returned 100% blocks executed 28%
1200 26: 642:static int run_plan(OmegaGpuFftPlanMode mode, uint32_t ndim, const uint32_t *dims, uint32_t batch, int inverse,
1201 -: 643: const float *in, float *out, OmegaGpuMathInfo *info) {
1202 26*: 644: if (!in || !out) return OMEGA_GPU_ML_BAD_ARGS;
1203branch 0 taken 26 (fallthrough)
1204branch 1 taken 0
1205branch 2 taken 0 (fallthrough)
1206branch 3 taken 26
1207 26*: 645: if (info) memset(info, 0, sizeof *info);
1208branch 0 taken 0 (fallthrough)
1209branch 1 taken 26
1210 26: 646: uint64_t t0 = now_ns();
1211call 0 returned 26
1212 -: 647: size_t bytes[3];
1213 26: 648: omega_gpu_session_lock();
1214call 0 returned 26
1215 26: 649: int rc = walk_locked(mode, ndim, dims, batch, inverse, bytes, NULL, NULL);
1216call 0 returned 26
1217 26: 650: const char *pi = (const char *)in, *po = (const char *)out;
1218 26: 651: if (rc == OMEGA_GPU_ML_OK && ml_overlap(pi, bytes[0], po, bytes[1])) rc = OMEGA_GPU_ML_BAD_ARGS;
1219branch 0 taken 10 (fallthrough)
1220branch 1 taken 16
1221branch 2 taken 10 (fallthrough)
1222branch 3 taken 0
1223branch 4 taken 10 (fallthrough)
1224branch 5 taken 0
1225 26: 652: if (rc == OMEGA_GPU_ML_OK) {
1226branch 0 taken 0 (fallthrough)
1227branch 1 taken 26
1228 #####: 653: if (!g_hooked) { (void)omega_gpu_session_on_close(on_session_close); g_hooked = true; }
1229branch 0 never executed (fallthrough)
1230branch 1 never executed
1231call 2 never executed
1232 #####: 654: if (!omega_gpu_session_open()) rc = OMEGA_GPU_ML_CHIP_FAIL;
1233call 0 never executed
1234branch 1 never executed (fallthrough)
1235branch 2 never executed
1236 -: 655: }
1237 26*: 656: if (rc == OMEGA_GPU_ML_OK && (omega_gpu_session_scratch(&g_in, bytes[0]) != 0 ||
1238branch 0 taken 0 (fallthrough)
1239branch 1 taken 26
1240call 2 never executed
1241branch 3 never executed (fallthrough)
1242branch 4 never executed
1243branch 5 never executed (fallthrough)
1244branch 6 never executed
1245 #####: 657: omega_gpu_session_scratch(&g_out, bytes[1]) != 0 ||
1246call 0 never executed
1247branch 1 never executed (fallthrough)
1248branch 2 never executed
1249 #####: 658: omega_gpu_session_scratch(&g_scr, bytes[2]) != 0 ||
1250call 0 never executed
1251branch 1 never executed (fallthrough)
1252branch 2 never executed
1253 #####: 659: omega_gpu_session_scratch(&g_tw, (size_t)8 * OMEGA_GPU_FFT_REAL_MAX_N) != 0))
1254call 0 never executed
1255 #####: 660: rc = OMEGA_GPU_ML_CHIP_FAIL;
1256 26: 661: if (rc == OMEGA_GPU_ML_OK) {
1257branch 0 taken 0 (fallthrough)
1258branch 1 taken 26
1259 #####: 662: memcpy(g_in.mem.cpu, in, bytes[0]);
1260 #####: 663: uint32_t *dev = (uint32_t *)g_out.mem.cpu, *scr = (uint32_t *)g_scr.mem.cpu;
1261 #####: 664: for (size_t i = 0; i < bytes[1] / 4u; i++) dev[i] = ML_POISON32;
1262branch 0 never executed
1263branch 1 never executed (fallthrough)
1264 #####: 665: for (size_t i = 0; i < bytes[2] / 4u; i++) scr[i] = ML_POISON32;
1265branch 0 never executed
1266branch 1 never executed (fallthrough)
1267 #####: 666: if (omega_gpu_session_sync_to_gpu(&g_in.mem) != 0 || omega_gpu_session_sync_to_gpu(&g_out.mem) != 0 ||
1268call 0 never executed
1269branch 1 never executed (fallthrough)
1270branch 2 never executed
1271call 3 never executed
1272branch 4 never executed (fallthrough)
1273branch 5 never executed
1274branch 6 never executed (fallthrough)
1275branch 7 never executed
1276 #####: 667: omega_gpu_session_sync_to_gpu(&g_scr.mem) != 0)
1277call 0 never executed
1278 #####: 668: rc = OMEGA_GPU_ML_CHIP_FAIL;
1279 #####: 669: ChipRun r = {info, {&g_in, &g_out, &g_scr}, 0, 0};
1280 #####: 670: if (rc == OMEGA_GPU_ML_OK) rc = walk_locked(mode, ndim, dims, batch, inverse, bytes, chip_launch, &r);
1281branch 0 never executed (fallthrough)
1282branch 1 never executed
1283call 2 never executed
1284 #####: 671: if (rc == OMEGA_GPU_ML_OK && omega_gpu_session_sync_to_cpu(&g_out.mem) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL;
1285branch 0 never executed (fallthrough)
1286branch 1 never executed
1287call 2 never executed
1288branch 3 never executed (fallthrough)
1289branch 4 never executed
1290 #####: 672: if (rc == OMEGA_GPU_ML_OK) {
1291branch 0 never executed (fallthrough)
1292branch 1 never executed
1293 #####: 673: memcpy(out, dev, bytes[1]);
1294 #####: 674: uint64_t unwritten = 0;
1295 #####: 675: for (size_t i = 0; i < bytes[1] / 4u; i++) unwritten = ml_scan(unwritten, dev[i]);
1296branch 0 never executed
1297branch 1 never executed (fallthrough)
1298 #####: 676: if (info) info->unwritten_words = unwritten;
1299branch 0 never executed (fallthrough)
1300branch 1 never executed
1301 #####: 677: if (unwritten) rc = OMEGA_GPU_ML_UNWRITTEN;
1302branch 0 never executed (fallthrough)
1303branch 1 never executed
1304 -: 678: }
1305 -: 679: }
1306 26: 680: omega_gpu_session_unlock();
1307call 0 returned 26
1308 26*: 681: if (info) info->call_ns = ml_sub(now_ns(), t0);
1309branch 0 taken 0 (fallthrough)
1310branch 1 taken 26
1311call 2 never executed
1312 26: 682: return rc;
1313 -: 683:}
1314 -: 684:
1315function oracle_r2c called 18 returned 100% blocks executed 100%
1316 18: 685:int omega_gpu_fft_r2c(const float *in, float *out, uint32_t n, uint32_t batch, OmegaGpuMathInfo *info) {
1317 18: 686: if (lg_in(n, OMEGA_GPU_FFT_REAL_MIN_N, OMEGA_GPU_FFT_REAL_MAX_N) < 0 && n >= 2 && n <= OMEGA_GPU_FFT_MANY_MAX_N)
1318call 0 returned 18
1319branch 1 taken 14 (fallthrough)
1320branch 2 taken 4
1321branch 3 taken 10 (fallthrough)
1322branch 4 taken 4
1323branch 5 taken 6 (fallthrough)
1324branch 6 taken 4
1325 6: 687: return many_basic(OMEGA_GPU_FFT_TYPE_R2C, 1, &n, batch, 0, in, out, info);
1326call 0 returned 6
1327 12: 688: return run_plan(OMEGA_GPU_FFT_R2C, 1, &n, batch, 0, in, out, info);
1328call 0 returned 12
1329 -: 689:}
1330 -: 690:
1331function oracle_c2r called 18 returned 100% blocks executed 100%
1332 18: 691:int omega_gpu_fft_c2r(const float *in, float *out, uint32_t n, uint32_t batch, OmegaGpuMathInfo *info) {
1333 18: 692: if (lg_in(n, OMEGA_GPU_FFT_REAL_MIN_N, OMEGA_GPU_FFT_REAL_MAX_N) < 0 && n >= 2 && n <= OMEGA_GPU_FFT_MANY_MAX_N)
1334call 0 returned 18
1335branch 1 taken 14 (fallthrough)
1336branch 2 taken 4
1337branch 3 taken 10 (fallthrough)
1338branch 4 taken 4
1339branch 5 taken 6 (fallthrough)
1340branch 6 taken 4
1341 6: 693: return many_basic(OMEGA_GPU_FFT_TYPE_C2R, 1, &n, batch, 0, in, out, info);
1342call 0 returned 6
1343 12: 694: return run_plan(OMEGA_GPU_FFT_C2R, 1, &n, batch, 0, in, out, info);
1344call 0 returned 12
1345 -: 695:}
1346 -: 696:
1347function oracle_nd called 2 returned 100% blocks executed 76%
1348 2: 697:int omega_gpu_fft_c2c_nd(const float *in, float *out, uint32_t ndim, const uint32_t *dims, uint32_t batch, int inverse,
1349 -: 698: OmegaGpuMathInfo *info) {
1350 2: 699: if (dims && ndim >= 1 && ndim <= 3) {
1351branch 0 taken 2 (fallthrough)
1352branch 1 taken 0
1353branch 2 taken 2 (fallthrough)
1354branch 3 taken 0
1355branch 4 taken 2 (fallthrough)
1356branch 5 taken 0
1357 2: 700: int legacy = 1, any = 1;
1358 8: 701: for (uint32_t i = 0; i < ndim; i++) {
1359branch 0 taken 6
1360branch 1 taken 2 (fallthrough)
1361 6: 702: legacy &= fft_log2(dims[i]) >= 0;
1362call 0 returned 6
1363 6*: 703: any &= dims[i] >= 2 && dims[i] <= OMEGA_GPU_FFT_MANY_MAX_N;
1364branch 0 taken 6 (fallthrough)
1365branch 1 taken 0
1366branch 2 taken 6 (fallthrough)
1367branch 3 taken 0
1368 -: 704: }
1369 2*: 705: if (!legacy && any) return many_basic(OMEGA_GPU_FFT_TYPE_C2C, ndim, dims, batch, inverse, in, out, info);
1370branch 0 taken 0 (fallthrough)
1371branch 1 taken 2
1372branch 2 never executed (fallthrough)
1373branch 3 never executed
1374call 4 never executed
1375 -: 706: }
1376 2: 707: return run_plan(OMEGA_GPU_FFT_C2C_ND, ndim, dims, batch, inverse, in, out, info);
1377call 0 returned 2
1378 -: 708:}
1379 -: 709:
1380 -: 710:/* ------------------------------------------------------------------ FFT many (cufftPlanMany layouts) */
1381 -: 711:
1382 -: 712:/* A layout: element (b, x) at base + b * bs + sum x[i] * st[i] (mod 2^32), i the logical axis. */
1383 -: 713:typedef struct { uint32_t base, bs, st[3]; } Lay;
1384 -: 714:
1385 -: 715:typedef struct {
1386 -: 716: OmegaGpuFftManyLaunch *l;
1387 -: 717: size_t n, cap;
1388 -: 718: uint64_t *tab; /* the constant table: the unit's u64 (re, im) words */
1389 -: 719:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
1390 -: 720: size_t ntab, tabcap;
1391 -: 721: struct { uint32_t kind, a, b; size_t at; } tk[16];
1392 -: 722: uint32_t ntk;
1393 -: 723: int alias;
1394 -: 724: uint64_t w_bytes, b_bytes;
1395 -: 725:#endif
1396 -: 726:} Many;
1397 -: 727:typedef struct {
1398 -: 728: uint32_t rank, batch, oext[3], owords; /* output: extents, f32 words per element */
1399 -: 729: Lay olay;
1400 -: 730: uint64_t oextent;
1401 -: 731: int obasic;
1402 -: 732:} ManyOut;
1403 -: 733:
1404function many_free called 4114 returned 100% blocks executed 100%
1405 4114: 734:static void many_free(Many *m) {
1406 4114: 735: free(m->l);
1407 4114: 736: free(m->tab);
1408 4114: 737: memset(m, 0, sizeof *m);
1409 4114: 738:}
1410 -: 739:
1411 -: 740:static int many_build(const OmegaGpuFftMany *p, int in_place, int alias, Many *m, size_t bytes[OMEGA_GPU_FFT_MANY_BUFS],
1412 -: 741: ManyOut *o);
1413 -: 742:static int many_each(uint32_t rank, const Lay *l, const uint32_t *ext, uint32_t batch,
1414 -: 743: int (*f)(void *, uint32_t), void *ctx);
1415 -: 744:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
1416 -: 745:/* Caller holds the lock: byte offset of the unit's table (kind 10 twiddles, 11 chirp) of a points, appended once. */
1417function many_table called 8178 returned 100% blocks executed 83%
1418 8178: 746:static int many_table(Many *m, uint32_t kind, uint32_t a, uint32_t b, uint64_t *off) {
1419 16078: 747: for (uint32_t i = 0; i < m->ntk; i++)
1420branch 0 taken 8404
1421branch 1 taken 7674 (fallthrough)
1422 8404: 748: if (m->tk[i].kind == kind && m->tk[i].a == a && m->tk[i].b == b) { *off = 8u * m->tk[i].at; return OMEGA_GPU_ML_OK; }
1423branch 0 taken 5788 (fallthrough)
1424branch 1 taken 2616
1425branch 2 taken 1356 (fallthrough)
1426branch 3 taken 4432
1427branch 4 taken 504 (fallthrough)
1428branch 5 taken 852
1429 7674*: 749: if (m->ntk == sizeof m->tk / sizeof m->tk[0]) return OMEGA_GPU_ML_CODEGEN_FAIL;
1430branch 0 taken 0 (fallthrough)
1431branch 1 taken 7674
1432 7674*: 750: if (omega_gpu_om_ir_data(kind, a, b, 0, g_words) != OMEGA_OM_IR_OK) return OMEGA_GPU_ML_CODEGEN_FAIL;
1433call 0 returned 7674
1434branch 1 taken 0 (fallthrough)
1435branch 2 taken 7674
1436 7674: 751: if (m->ntab + a > m->tabcap) {
1437branch 0 taken 6202 (fallthrough)
1438branch 1 taken 1472
1439 6202: 752: size_t cap = (m->ntab + a) * 2u;
1440 6202: 753: uint64_t *t = (uint64_t *)realloc(m->tab, cap * sizeof *t);
1441 6202*: 754: if (!t) return OMEGA_GPU_ML_CHIP_FAIL;
1442branch 0 taken 0 (fallthrough)
1443branch 1 taken 6202
1444 6202: 755: m->tab = t;
1445 6202: 756: m->tabcap = cap;
1446 -: 757: }
1447 7674: 758: memcpy(&m->tab[m->ntab], g_words, (size_t)a * 8u);
1448 7674: 759: m->tk[m->ntk].kind = kind; m->tk[m->ntk].a = a; m->tk[m->ntk].b = b; m->tk[m->ntk].at = m->ntab;
1449 7674: 760: m->ntk++;
1450 7674: 761: *off = 8u * m->ntab;
1451 7674: 762: m->ntab += a;
1452 7674: 763: return OMEGA_GPU_ML_OK;
1453 -: 764:}
1454 -: 765:
1455 -: 766:/* Caller holds the lock: the unit's magic divisor of d (kind 13). */
1456function many_magic called 79520 returned 100% blocks executed 80%
1457 79520: 767:static int many_magic(uint32_t d, uint32_t *mg) {
1458 79520*: 768: if (omega_gpu_om_ir_data(13, d, 0, 0, g_words) != OMEGA_OM_IR_OK) return OMEGA_GPU_ML_CODEGEN_FAIL;
1459call 0 returned 79520
1460branch 1 taken 0 (fallthrough)
1461branch 2 taken 79520
1462 79520: 769: *mg = (uint32_t)g_words[0];
1463 79520: 770: return OMEGA_GPU_ML_OK;
1464 -: 771:}
1465 -: 772:
1466 -: 773:/* One step of `total` threads as launches of at most OMEGA_GPU_FFT_MAX_CTAS CTAs (word 1: first thread). */
1467function many_step called 37576 returned 100% blocks executed 96%
1468 37576: 774:static int many_step(Many *m, uint32_t kind, uint32_t a, uint32_t b, uint32_t nptr, const uint32_t *buf,
1469 -: 775: const uint64_t *off, uint32_t nw, const uint32_t *w, uint64_t total, uint32_t out_words) {
1470 -: 776: OmegaGpuFftManyLaunch L;
1471 37576: 777: memset(&L, 0, sizeof L);
1472 37576: 778: L.kind = kind; L.a = a; L.b = b; L.nptr = nptr; L.nwords = nw;
1473 139120: 779: for (uint32_t i = 0; i < nptr; i++) {
1474branch 0 taken 101544
1475branch 1 taken 37576 (fallthrough)
1476 101544: 780: L.buf[i] = m->alias && buf[i] == OMEGA_GPU_FFT_BUF_OUT ? (uint32_t)OMEGA_GPU_FFT_BUF_IN : buf[i];
1477branch 0 taken 22212 (fallthrough)
1478branch 1 taken 79332
1479branch 2 taken 21520 (fallthrough)
1480branch 3 taken 692
1481 101544: 781: L.off[i] = off[i];
1482 -: 782: }
1483 37576: 783: memcpy(L.words, w, nw * sizeof w[0]);
1484 37576: 784: L.words[0] = (uint32_t)total;
1485 37576: 785: L.threads = OMEGA_GPU_FFT_MANY_THREADS;
1486 37576: 786: uint64_t ctas = (total + OMEGA_GPU_FFT_MANY_THREADS - 1u) / OMEGA_GPU_FFT_MANY_THREADS;
1487 190192: 787: for (uint64_t c0 = 0; c0 < ctas; c0 += OMEGA_GPU_FFT_MAX_CTAS) {
1488branch 0 taken 152616
1489branch 1 taken 37576 (fallthrough)
1490 152616: 788: L.grid = (uint32_t)(ctas - c0 < OMEGA_GPU_FFT_MAX_CTAS ? ctas - c0 : OMEGA_GPU_FFT_MAX_CTAS);
1491branch 0 taken 37220 (fallthrough)
1492branch 1 taken 115396
1493 152616: 789: L.words[1] = (uint32_t)(c0 * OMEGA_GPU_FFT_MANY_THREADS);
1494 152616: 790: uint64_t left = total - L.words[1], here = (uint64_t)L.grid * OMEGA_GPU_FFT_MANY_THREADS;
1495 152616: 791: L.elements = (size_t)out_words * (here < left ? here : left);
1496 152616: 792: if (m->n == m->cap) {
1497branch 0 taken 3460 (fallthrough)
1498branch 1 taken 149156
1499 3460: 793: size_t cap = m->cap ? 2u * m->cap : 64u;
1500branch 0 taken 128 (fallthrough)
1501branch 1 taken 3332
1502 3460: 794: OmegaGpuFftManyLaunch *l = (OmegaGpuFftManyLaunch *)realloc(m->l, cap * sizeof *l);
1503 3460*: 795: if (!l) return OMEGA_GPU_ML_CHIP_FAIL;
1504branch 0 taken 0 (fallthrough)
1505branch 1 taken 3460
1506 3460: 796: m->l = l;
1507 3460: 797: m->cap = cap;
1508 -: 798: }
1509 152616: 799: m->l[m->n++] = L;
1510 -: 800: }
1511 37576: 801: return OMEGA_GPU_ML_OK;
1512 -: 802:}
1513 -: 803:
1514 -: 804:/* Stockham passes (kind 7) over rows of n points, radices rad[0..np-1], from buffer src ping-ponging with alt; the
1515 -: 805: * last pass writes fin when fin >= 0. *res: the buffer holding the result. */
1516function many_stockham called 8178 returned 100% blocks executed 90%
1517 8178: 806:static int many_stockham(Many *m, uint32_t n, uint64_t rows, uint32_t dir, uint32_t np, const uint32_t *rad,
1518 -: 807: uint32_t src, uint32_t alt, int fin, uint64_t tw_off, uint32_t *res) {
1519 8178: 808: uint32_t cur = src, ns = 1;
1520 31162: 809: for (uint32_t i = 0; i < np; i++) {
1521branch 0 taken 22984
1522branch 1 taken 8178 (fallthrough)
1523 22984: 810: uint32_t R = rad[i], nr = n / R, dst = (i + 1 == np && fin >= 0) ? (uint32_t)fin : cur == src ? alt : src;
1524branch 0 taken 8178 (fallthrough)
1525branch 1 taken 14806
1526branch 2 taken 7326 (fallthrough)
1527branch 3 taken 852
1528branch 4 taken 14086 (fallthrough)
1529branch 5 taken 8046
1530 22984: 811: uint32_t w[8] = { 0, 0, nr, 0, ns, 0, n / (ns * R), n };
1531 22984: 812: int rc = many_magic(nr, &w[3]);
1532call 0 returned 22984
1533 22984: 813: if (rc == OMEGA_GPU_ML_OK) rc = many_magic(ns, &w[5]);
1534branch 0 taken 22984 (fallthrough)
1535branch 1 taken 0
1536call 2 returned 22984
1537 22984: 814: uint32_t buf[3] = { cur, dst, OMEGA_GPU_FFT_BUF_TABLE };
1538 22984: 815: uint64_t off[3] = { 0, 0, tw_off };
1539 22984: 816: if (rc == OMEGA_GPU_ML_OK) rc = many_step(m, 7, R, dir, 3, buf, off, 8, w, rows * nr, 2u * R);
1540branch 0 taken 22984 (fallthrough)
1541branch 1 taken 0
1542call 2 returned 22984
1543 22984*: 817: if (rc != OMEGA_GPU_ML_OK) return rc;
1544branch 0 taken 0 (fallthrough)
1545branch 1 taken 22984
1546 22984: 818: cur = dst;
1547 22984: 819: ns *= R;
1548 -: 820: }
1549 8178: 821: *res = cur;
1550 8178: 822: return OMEGA_GPU_ML_OK;
1551 -: 823:}
1552 -: 824:
1553 -: 825:/* One 1-D transform along contiguous rows of n points in buffer *cur (other: the second scratch array). The result
1554 -: 826: * lands in *cur (Bluestein, or an even pass count) or in other; *cur is updated. */
1555function many_axis called 6476 returned 100% blocks executed 94%
1556 6476: 827:static int many_axis(Many *m, uint32_t n, uint64_t rows, uint32_t dir, uint32_t *cur, uint32_t other) {
1557 6476*: 828: if (omega_gpu_om_ir_data(12, n, 0, 0, g_words) != OMEGA_OM_IR_OK) return OMEGA_GPU_ML_CODEGEN_FAIL;
1558call 0 returned 6476
1559branch 1 taken 0 (fallthrough)
1560branch 2 taken 6476
1561 6476: 829: uint32_t M = (uint32_t)g_words[0], blue = (uint32_t)g_words[1], np = (uint32_t)g_words[2], rad[16];
1562 6476*: 830: if (np == 0 || np > 16) return OMEGA_GPU_ML_CODEGEN_FAIL;
1563branch 0 taken 6476 (fallthrough)
1564branch 1 taken 0
1565branch 2 taken 0 (fallthrough)
1566branch 3 taken 6476
1567 20770: 831: for (uint32_t i = 0; i < np; i++) rad[i] = (uint32_t)g_words[3 + i];
1568branch 0 taken 14294
1569branch 1 taken 6476 (fallthrough)
1570 -: 832: uint64_t tw, twi, ch;
1571 -: 833: int rc;
1572 6476: 834: if (!blue) {
1573branch 0 taken 5622 (fallthrough)
1574branch 1 taken 854
1575 5622: 835: rc = many_table(m, 10, n, dir, &tw);
1576call 0 returned 5622
1577 5622: 836: if (rc == OMEGA_GPU_ML_OK) rc = many_stockham(m, n, rows, dir, np, rad, *cur, other, -1, tw, cur);
1578branch 0 taken 5622 (fallthrough)
1579branch 1 taken 0
1580call 2 returned 5622
1581 5622: 837: return rc;
1582 -: 838: }
1583 854: 839: if (rows * M > ((uint64_t)1 << 28)) return OMEGA_GPU_ML_TOO_LARGE;
1584branch 0 taken 2 (fallthrough)
1585branch 1 taken 852
1586 852: 840: if (rows * M * 8u > m->w_bytes) m->w_bytes = rows * M * 8u;
1587branch 0 taken 824 (fallthrough)
1588branch 1 taken 28
1589 852: 841: if ((uint64_t)M * 8u > m->b_bytes) m->b_bytes = (uint64_t)M * 8u;
1590branch 0 taken 820 (fallthrough)
1591branch 1 taken 32
1592 852: 842: uint32_t lgm = 0;
1593 9028: 843: while ((1u << lgm) < M) lgm++;
1594branch 0 taken 8176
1595branch 1 taken 852 (fallthrough)
1596 852: 844: rc = many_table(m, 11, n, dir, &ch);
1597call 0 returned 852
1598 852: 845: if (rc == OMEGA_GPU_ML_OK) rc = many_table(m, 10, M, 0, &tw);
1599branch 0 taken 852 (fallthrough)
1600branch 1 taken 0
1601call 2 returned 852
1602 852: 846: if (rc == OMEGA_GPU_ML_OK) rc = many_table(m, 10, M, 1, &twi);
1603branch 0 taken 852 (fallthrough)
1604branch 1 taken 0
1605call 2 returned 852
1606 852*: 847: if (rc != OMEGA_GPU_ML_OK) return rc;
1607branch 0 taken 0 (fallthrough)
1608branch 1 taken 852
1609 852: 848: const uint32_t W = OMEGA_GPU_FFT_BUF_W, W2 = OMEGA_GPU_FFT_BUF_W2, B = OMEGA_GPU_FFT_BUF_B, T = OMEGA_GPU_FFT_BUF_TABLE;
1610 852: 849: uint32_t w[3] = { 0, 0, n }, x, y;
1611 -: 850: /* the filter: b[m] = conj chirp[min(m, M - m)] (0 past n), forward FFT into B */
1612 852: 851: uint32_t bb[3] = { T, W, T };
1613 852: 852: uint64_t ob[3] = { ch, 0, ch };
1614 852: 853: rc = many_step(m, 8, 3, lgm, 3, bb, ob, 3, w, M, 2);
1615call 0 returned 852
1616 852: 854: if (rc == OMEGA_GPU_ML_OK) rc = many_stockham(m, M, 1, 0, np, rad, W, W2, (int)B, tw, &x);
1617branch 0 taken 852 (fallthrough)
1618branch 1 taken 0
1619call 2 returned 852
1620 -: 855: /* a = x chirp zero-padded to M, A = FFT(a), A B, inverse FFT, chirp / M on the first n points */
1621 852: 856: uint32_t pb[3] = { *cur, W, T };
1622 852: 857: uint64_t po[3] = { 0, 0, ch };
1623 852: 858: if (rc == OMEGA_GPU_ML_OK) rc = many_step(m, 8, 0, lgm, 3, pb, po, 3, w, rows * M, 2);
1624branch 0 taken 852 (fallthrough)
1625branch 1 taken 0
1626call 2 returned 852
1627 852: 859: if (rc == OMEGA_GPU_ML_OK) rc = many_stockham(m, M, rows, 0, np, rad, W, W2, -1, tw, &x);
1628branch 0 taken 852 (fallthrough)
1629branch 1 taken 0
1630call 2 returned 852
1631 852: 860: uint32_t mb[3] = { x, x, B };
1632 852: 861: uint64_t mo[3] = { 0, 0, 0 };
1633 852: 862: if (rc == OMEGA_GPU_ML_OK) rc = many_step(m, 8, 1, lgm, 3, mb, mo, 3, w, rows * M, 2);
1634branch 0 taken 852 (fallthrough)
1635branch 1 taken 0
1636call 2 returned 852
1637 852: 863: if (rc == OMEGA_GPU_ML_OK) rc = many_stockham(m, M, rows, 1, np, rad, x, x == W ? W2 : W, -1, twi, &y);
1638branch 0 taken 852 (fallthrough)
1639branch 1 taken 0
1640branch 2 taken 288 (fallthrough)
1641branch 3 taken 564
1642call 4 returned 852
1643 852: 864: uint32_t qb[3] = { y, *cur, T };
1644 852: 865: if (rc == OMEGA_GPU_ML_OK) rc = many_step(m, 8, 2, lgm, 3, qb, po, 3, w, rows * M, 2);
1645branch 0 taken 852 (fallthrough)
1646branch 1 taken 0
1647call 2 returned 852
1648 852: 866: return rc;
1649 -: 867:}
1650 -: 868:
1651 -: 869:/* A strided copy (kind 9): slot k (i0 fastest) walks logical axis ord[k] (-1: none) over ext[k] points. */
1652function many_copy called 11184 returned 100% blocks executed 91%
1653 11184: 870:static int many_copy(Many *m, uint32_t mode, uint32_t sbuf, const Lay *s, uint32_t dbuf, const Lay *d, const int ord[3],
1654 -: 871: const uint32_t ext[3], uint32_t batch) {
1655 -: 872: uint32_t w[18];
1656 11184: 873: memset(w, 0, sizeof w);
1657 11184: 874: uint64_t total = batch;
1658 44736: 875: for (int k = 0; k < 3; k++) {
1659branch 0 taken 33552
1660branch 1 taken 11184 (fallthrough)
1661 33552: 876: uint32_t e = ord[k] < 0 ? 1u : ext[k];
1662branch 0 taken 23736 (fallthrough)
1663branch 1 taken 9816
1664 33552*: 877: if (e == 0) return OMEGA_GPU_ML_OK;
1665branch 0 taken 0 (fallthrough)
1666branch 1 taken 33552
1667 33552: 878: total *= e;
1668 33552: 879: w[2 + 2 * k] = e;
1669 33552: 880: int rc = many_magic(e, &w[3 + 2 * k]);
1670call 0 returned 33552
1671 33552*: 881: if (rc != OMEGA_GPU_ML_OK) return rc;
1672branch 0 taken 0 (fallthrough)
1673branch 1 taken 33552
1674 33552: 882: w[10 + k] = ord[k] < 0 ? 0u : s->st[ord[k]];
1675branch 0 taken 23736 (fallthrough)
1676branch 1 taken 9816
1677 33552: 883: w[15 + k] = ord[k] < 0 ? 0u : d->st[ord[k]];
1678branch 0 taken 23736 (fallthrough)
1679branch 1 taken 9816
1680 -: 884: }
1681 11184: 885: w[8] = s->base; w[9] = s->bs; w[13] = d->base; w[14] = d->bs;
1682 11184: 886: uint32_t buf[2] = { sbuf, dbuf };
1683 11184: 887: uint64_t off[2] = { 0, 0 };
1684 11184: 888: return many_step(m, 9, mode, 0, 2, buf, off, 18, w, total, mode == 2 ? 1u : 2u);
1685branch 0 taken 834 (fallthrough)
1686branch 1 taken 10350
1687call 2 returned 11184
1688 -: 889:}
1689 -: 890:
1690 -: 891:/* The contiguous layout of extents e with axis perm[0] slowest. */
1691function many_dense called 7310 returned 100% blocks executed 100%
1692 7310: 892:static Lay many_dense(uint32_t rank, const uint32_t *perm, const uint32_t *e) {
1693 -: 893: Lay l;
1694 7310: 894: memset(&l, 0, sizeof l);
1695 7310: 895: uint32_t p = 1;
1696 23744: 896: for (int k = (int)rank - 1; k >= 0; k--) { l.st[perm[k]] = p; p *= e[perm[k]]; }
1697branch 0 taken 16434
1698branch 1 taken 7310 (fallthrough)
1699 7310: 897: l.bs = p;
1700 7310: 898: return l;
1701 -: 899:}
1702 -: 900:
1703 -: 901:/* Rows of a transform along axis ax: batch times the other extents. */
1704function many_rows called 6476 returned 100% blocks executed 100%
1705 6476: 902:static uint64_t many_rows(uint32_t rank, const uint32_t *e, uint32_t ax, uint32_t batch) {
1706 6476: 903: uint64_t rows = batch;
1707 21248: 904: for (uint32_t i = 0; i < rank; i++)
1708branch 0 taken 14772
1709branch 1 taken 6476 (fallthrough)
1710 14772: 905: if (i != ax) rows *= e[i];
1711branch 0 taken 8296 (fallthrough)
1712branch 1 taken 6476
1713 6476: 906: return rows;
1714 -: 907:}
1715 -: 908:
1716 -: 909:/* Slots of a copy that walks the destination order perm (fastest first). */
1717function many_slots called 10640 returned 100% blocks executed 100%
1718 10640: 910:static void many_slots(uint32_t rank, const uint32_t *perm, const uint32_t *e, int ord[3], uint32_t ext[3]) {
1719 42560: 911: for (uint32_t k = 0; k < 3; k++) {
1720branch 0 taken 31920
1721branch 1 taken 10640 (fallthrough)
1722 31920: 912: ord[k] = k < rank ? (int)perm[rank - 1 - k] : -1;
1723branch 0 taken 22908 (fallthrough)
1724branch 1 taken 9012
1725 31920: 913: ext[k] = k < rank ? e[perm[rank - 1 - k]] : 1u;
1726branch 0 taken 22908 (fallthrough)
1727branch 1 taken 9012
1728 -: 914: }
1729 10640: 915:}
1730 -: 916:
1731 -: 917:/* A user side: extents ext, embed (all zero: basic), stride, dist; real pads the basic last axis to pad points. */
1732function many_side called 7994 returned 100% blocks executed 97%
1733 7994: 918:static int many_side(uint32_t rank, const uint32_t *ext, const uint32_t *emb, uint32_t stride, uint32_t dist,
1734 -: 919: uint32_t batch, int basic, uint32_t pad, Lay *l, uint64_t *extent) {
1735 -: 920: uint32_t e[3];
1736 7994: 921: uint64_t st[3], prod = 1;
1737 23604: 922: for (uint32_t i = 0; i < rank; i++) e[i] = basic ? ext[i] : emb[i];
1738branch 0 taken 7272 (fallthrough)
1739branch 1 taken 8338
1740branch 2 taken 15610
1741branch 3 taken 7994 (fallthrough)
1742 7994: 923: if (basic) {
1743branch 0 taken 3816 (fallthrough)
1744branch 1 taken 4178
1745 3816: 924: if (pad) e[rank - 1] = pad;
1746branch 0 taken 408 (fallthrough)
1747branch 1 taken 3408
1748 3816: 925: stride = 1;
1749 11088: 926: for (uint32_t i = 0; i < rank; i++) prod *= e[i];
1750branch 0 taken 7272
1751branch 1 taken 3816 (fallthrough)
1752 3816*: 927: if (prod >= ((uint64_t)1 << 32)) return OMEGA_GPU_ML_TOO_LARGE;
1753branch 0 taken 0 (fallthrough)
1754branch 1 taken 3816
1755 3816: 928: dist = (uint32_t)prod;
1756 -: 929: } else {
1757 4178: 930: if (stride == 0) return OMEGA_GPU_ML_BAD_ARGS;
1758branch 0 taken 310 (fallthrough)
1759branch 1 taken 3868
1760 7702: 931: for (uint32_t i = 1; i < rank; i++)
1761branch 0 taken 3850
1762branch 1 taken 3852 (fallthrough)
1763 3850: 932: if (e[i] < ext[i]) return OMEGA_GPU_ML_BAD_ARGS;
1764branch 0 taken 16 (fallthrough)
1765branch 1 taken 3834
1766 -: 933: }
1767 7668: 934: uint64_t p = stride, hi = (uint64_t)dist * (batch - 1u);
1768 22622: 935: for (int i = (int)rank - 1; i >= 0; i--) {
1769branch 0 taken 14958
1770branch 1 taken 7664 (fallthrough)
1771 14958: 936: if (p >= ((uint64_t)1 << 32)) return OMEGA_GPU_ML_TOO_LARGE;
1772branch 0 taken 4 (fallthrough)
1773branch 1 taken 14954
1774 14954: 937: st[i] = p;
1775 14954: 938: hi += (ext[i] - 1u) * p;
1776 14954: 939: p *= e[i];
1777 -: 940: }
1778 7664: 941: if (hi >= ((uint64_t)1 << 32) || hi + 1u > ((uint64_t)1 << 28)) return OMEGA_GPU_ML_TOO_LARGE;
1779branch 0 taken 7656 (fallthrough)
1780branch 1 taken 8
1781branch 2 taken 2 (fallthrough)
1782branch 3 taken 7654
1783 7654: 942: memset(l, 0, sizeof *l);
1784 7654: 943: l->bs = dist;
1785 22586: 944: for (uint32_t i = 0; i < rank; i++) l->st[i] = (uint32_t)st[i];
1786branch 0 taken 14932
1787branch 1 taken 7654 (fallthrough)
1788 7654: 945: *extent = hi + 1u;
1789 7654: 946: return OMEGA_GPU_ML_OK;
1790 -: 947:}
1791 -: 948:
1792 -: 949:/* Visits every element index of a side (batch major, last axis fastest); stops on a nonzero return. */
1793function many_each called 1758 returned 100% blocks executed 100%
1794 1758: 950:static int many_each(uint32_t rank, const Lay *l, const uint32_t *ext, uint32_t batch,
1795 -: 951: int (*f)(void *ctx, uint32_t idx), void *ctx) {
1796 1758: 952: uint32_t e[3] = { 1, 1, 1 }, s[3] = { 0, 0, 0 };
1797 5266: 953: for (uint32_t i = 0; i < rank; i++) { e[3 - rank + i] = ext[i]; s[3 - rank + i] = l->st[i]; }
1798branch 0 taken 3508
1799branch 1 taken 1758 (fallthrough)
1800 4940: 954: for (uint32_t b = 0; b < batch; b++)
1801branch 0 taken 3516
1802branch 1 taken 1424 (fallthrough)
1803 850232: 955: for (uint32_t x0 = 0; x0 < e[0]; x0++)
1804branch 0 taken 847050
1805branch 1 taken 3182 (fallthrough)
1806 4227440: 956: for (uint32_t x1 = 0; x1 < e[1]; x1++)
1807branch 0 taken 3380724
1808branch 1 taken 846716 (fallthrough)
1809 11409910: 957: for (uint32_t x2 = 0; x2 < e[2]; x2++) {
1810branch 0 taken 8029520
1811branch 1 taken 3380390 (fallthrough)
1812 8029520: 958: int rc = f(ctx, l->base + b * l->bs + x0 * s[0] + x1 * s[1] + x2 * s[2]);
1813call 0 returned 8029520
1814 8029520: 959: if (rc) return rc;
1815branch 0 taken 334 (fallthrough)
1816branch 1 taken 8029186
1817 -: 960: }
1818 1424: 961: return 0;
1819 -: 962:}
1820 -: 963:
1821function many_mark called 8029520 returned 100% blocks executed 100%
1822 8029520: 964:static int many_mark(void *ctx, uint32_t idx) {
1823 8029520: 965: uint8_t *bits = (uint8_t *)ctx;
1824 8029520: 966: uint8_t bit = (uint8_t)(1u << (idx & 7u));
1825 8029520: 967: if (bits[idx >> 3] & bit) return 1;
1826branch 0 taken 334 (fallthrough)
1827branch 1 taken 8029186
1828 8029186: 968: bits[idx >> 3] |= bit;
1829 8029186: 969: return 0;
1830 -: 970:}
1831 -: 971:
1832 -: 972:
1833 -: 973:/* Caller holds the lock. Validates p, fills bytes[] and m's launches and table; *o describes the output side. */
1834function many_build called 4114 returned 100% blocks executed 99%
1835 4114: 974:static int many_build(const OmegaGpuFftMany *p, int in_place, int alias, Many *m, size_t bytes[OMEGA_GPU_FFT_MANY_BUFS],
1836 -: 975: ManyOut *o) {
1837 4114: 976: memset(m, 0, sizeof *m);
1838 4114: 977: m->alias = alias;
1839 4114: 978: if (!p || !bytes || p->rank < 1 || p->rank > 3 || p->batch == 0 || (unsigned)p->type > OMEGA_GPU_FFT_TYPE_C2R)
1840branch 0 taken 4112 (fallthrough)
1841branch 1 taken 2
1842branch 2 taken 4110 (fallthrough)
1843branch 3 taken 2
1844branch 4 taken 4108 (fallthrough)
1845branch 5 taken 2
1846branch 6 taken 4104 (fallthrough)
1847branch 7 taken 4
1848branch 8 taken 4064 (fallthrough)
1849branch 9 taken 40
1850branch 10 taken 4 (fallthrough)
1851branch 11 taken 4060
1852 54: 979: return OMEGA_GPU_ML_BAD_ARGS;
1853 4060: 980: if (p->type == OMEGA_GPU_FFT_TYPE_C2C ? (p->inverse != 0 && p->inverse != 1) : p->inverse != 0)
1854branch 0 taken 1972 (fallthrough)
1855branch 1 taken 2088
1856branch 2 taken 254 (fallthrough)
1857branch 3 taken 1718
1858branch 4 taken 2 (fallthrough)
1859branch 5 taken 252
1860branch 6 taken 14 (fallthrough)
1861branch 7 taken 4046
1862 14: 981: return OMEGA_GPU_ML_BAD_ARGS;
1863 4046: 982: const uint32_t r = p->rank, last = r - 1u, L = p->n[last], h = L / 2u + 1u;
1864 4046: 983: uint64_t P = 1;
1865 4046: 984: int ibasic = 1, obasic = 1;
1866 11904: 985: for (uint32_t i = 0; i < r; i++) {
1867branch 0 taken 7890
1868branch 1 taken 4014 (fallthrough)
1869 7890: 986: if (p->n[i] < 2 || p->n[i] > OMEGA_GPU_FFT_MANY_MAX_N) return OMEGA_GPU_ML_BAD_ARGS;
1870branch 0 taken 7874 (fallthrough)
1871branch 1 taken 16
1872branch 2 taken 16 (fallthrough)
1873branch 3 taken 7858
1874 7858: 987: P *= p->n[i];
1875 7858: 988: ibasic &= p->inembed[i] == 0;
1876 7858: 989: obasic &= p->onembed[i] == 0;
1877 -: 990: }
1878 4014: 991: if (ibasic != obasic) return OMEGA_GPU_ML_BAD_ARGS;
1879branch 0 taken 2 (fallthrough)
1880branch 1 taken 4012
1881 4012: 992: if (P * p->batch > OMEGA_GPU_FFT_MAX_ELEMENTS) return OMEGA_GPU_ML_TOO_LARGE;
1882branch 0 taken 6 (fallthrough)
1883branch 1 taken 4006
1884 -: 993: uint32_t iext[3], oext[3];
1885 4006: 994: memcpy(iext, p->n, sizeof iext);
1886 4006: 995: memcpy(oext, p->n, sizeof oext);
1887 4006: 996: int r2c = p->type == OMEGA_GPU_FFT_TYPE_R2C, c2r = p->type == OMEGA_GPU_FFT_TYPE_C2R;
1888 4006: 997: if (c2r) iext[last] = h;
1889branch 0 taken 1038 (fallthrough)
1890branch 1 taken 2968
1891 4006: 998: if (r2c) oext[last] = h;
1892branch 0 taken 1038 (fallthrough)
1893branch 1 taken 2968
1894 -: 999: Lay il, ol;
1895 -: 1000: uint64_t iextent, oextent;
1896 4006: 1001: int rc = many_side(r, iext, p->inembed, p->istride, p->idist, p->batch, ibasic, r2c && in_place ? 2u * h : 0u, &il,
1897branch 0 taken 1038 (fallthrough)
1898branch 1 taken 2968
1899branch 2 taken 204 (fallthrough)
1900branch 3 taken 834
1901call 4 returned 4006
1902 -: 1002: &iextent);
1903 4006: 1003: if (rc == OMEGA_GPU_ML_OK)
1904branch 0 taken 3988 (fallthrough)
1905branch 1 taken 18
1906 3988: 1004: rc = many_side(r, oext, p->onembed, p->ostride, p->odist, p->batch, obasic, c2r && in_place ? 2u * h : 0u, &ol,
1907branch 0 taken 1038 (fallthrough)
1908branch 1 taken 2950
1909branch 2 taken 204 (fallthrough)
1910branch 3 taken 834
1911call 4 returned 3988
1912 -: 1005: &oextent);
1913 4006: 1006: if (rc != OMEGA_GPU_ML_OK) return rc;
1914branch 0 taken 340 (fallthrough)
1915branch 1 taken 3666
1916 3666: 1007: if (!obasic) {
1917branch 0 taken 1758 (fallthrough)
1918branch 1 taken 1908
1919 1758: 1008: uint8_t *bits = (uint8_t *)calloc((size_t)(oextent + 7u) / 8u, 1);
1920 1758*: 1009: if (!bits) return OMEGA_GPU_ML_CHIP_FAIL;
1921branch 0 taken 0 (fallthrough)
1922branch 1 taken 1758
1923 1758: 1010: int dup = many_each(r, &ol, oext, p->batch, many_mark, bits);
1924call 0 returned 1758
1925 1758: 1011: free(bits);
1926 1758: 1012: if (dup) return OMEGA_GPU_ML_BAD_ARGS;
1927branch 0 taken 334 (fallthrough)
1928branch 1 taken 1424
1929 -: 1013: }
1930 3332: 1014: const uint32_t S0 = OMEGA_GPU_FFT_BUF_S0, S1 = OMEGA_GPU_FFT_BUF_S1;
1931 3332: 1015: const uint32_t dir = c2r ? 1u : (uint32_t)p->inverse;
1932branch 0 taken 2498 (fallthrough)
1933branch 1 taken 834
1934 3332: 1016: uint32_t perm[3] = { 0, 1, 2 }, e[3], cur = S0, ext[3];
1935 -: 1017: int ord[3];
1936 3332: 1018: memcpy(e, iext, sizeof e);
1937 3332: 1019: if (r2c) e[last] = L;
1938branch 0 taken 834 (fallthrough)
1939branch 1 taken 2498
1940 3332: 1020: if (c2r) /* the last axis slowest: the outer inverses come first */
1941branch 0 taken 834 (fallthrough)
1942branch 1 taken 2498
1943 2496: 1021: for (uint32_t k = 0; k < r; k++) perm[k] = k == 0 ? last : k - 1u;
1944branch 0 taken 828 (fallthrough)
1945branch 1 taken 834
1946branch 2 taken 1662
1947branch 3 taken 834 (fallthrough)
1948 3332: 1022: Lay cl = many_dense(r, perm, e);
1949call 0 returned 3332
1950 3332: 1023: many_slots(r, perm, e, ord, ext);
1951call 0 returned 3332
1952 3332: 1024: rc = many_copy(m, r2c ? 1u : 0u, OMEGA_GPU_FFT_BUF_IN, &il, S0, &cl, ord, ext, p->batch);
1953branch 0 taken 834 (fallthrough)
1954branch 1 taken 2498
1955call 2 returned 3332
1956 3332: 1025: uint32_t nax = c2r ? r - 1u : r;
1957branch 0 taken 834 (fallthrough)
1958branch 1 taken 2498
1959 6476: 1026: for (uint32_t t = 0; t < nax && rc == OMEGA_GPU_ML_OK; t++) {
1960branch 0 taken 5642 (fallthrough)
1961branch 1 taken 834
1962branch 2 taken 5642
1963branch 3 taken 0 (fallthrough)
1964 5642: 1027: uint32_t ax = perm[r - 1u], other = cur == S0 ? S1 : S0;
1965branch 0 taken 5546 (fallthrough)
1966branch 1 taken 96
1967 5642: 1028: rc = many_axis(m, p->n[ax], many_rows(r, e, ax, p->batch), dir, &cur, other);
1968call 0 returned 5642
1969call 1 returned 5642
1970 5642: 1029: if (r2c && ax == last) e[last] = h;
1971branch 0 taken 1662 (fallthrough)
1972branch 1 taken 3980
1973branch 2 taken 834 (fallthrough)
1974branch 3 taken 828
1975 5642: 1030: if (rc != OMEGA_GPU_ML_OK || (t + 1u == nax && !c2r)) break;
1976branch 0 taken 5640 (fallthrough)
1977branch 1 taken 2
1978branch 2 taken 3052 (fallthrough)
1979branch 3 taken 2588
1980branch 4 taken 556 (fallthrough)
1981branch 5 taken 2496
1982 -: 1031: /* rotate: the fastest axis becomes the slowest */
1983 -: 1032: uint32_t np[3];
1984 11440: 1033: for (uint32_t k = 0; k < r; k++) np[k] = k == 0 ? perm[r - 1u] : perm[k - 1u];
1985branch 0 taken 3144 (fallthrough)
1986branch 1 taken 5152
1987branch 2 taken 8296
1988branch 3 taken 3144 (fallthrough)
1989 3144: 1034: Lay nl = many_dense(r, np, e);
1990call 0 returned 3144
1991 3144: 1035: many_slots(r, np, e, ord, ext);
1992call 0 returned 3144
1993 3144: 1036: other = cur == S0 ? S1 : S0;
1994branch 0 taken 428 (fallthrough)
1995branch 1 taken 2716
1996 3144: 1037: rc = many_copy(m, 0, cur, &cl, other, &nl, ord, ext, p->batch);
1997call 0 returned 3144
1998 3144: 1038: memcpy(perm, np, sizeof perm);
1999 3144: 1039: cl = nl;
2000 3144: 1040: cur = other;
2001 -: 1041: }
2002 3332: 1042: if (rc == OMEGA_GPU_ML_OK && c2r) {
2003branch 0 taken 3330 (fallthrough)
2004branch 1 taken 2
2005branch 2 taken 834 (fallthrough)
2006branch 3 taken 2496
2007 -: 1043: /* Hermitian extension of the last axis: k < h as it is, k in [h, L) the conjugate of point L - k */
2008 834: 1044: uint32_t other = cur == S0 ? S1 : S0, fe[3];
2009branch 0 taken 502 (fallthrough)
2010branch 1 taken 332
2011 834: 1045: memcpy(fe, e, sizeof fe);
2012 834: 1046: fe[last] = L;
2013 834: 1047: Lay fl = many_dense(r, perm, fe);
2014call 0 returned 834
2015 834: 1048: many_slots(r, perm, e, ord, ext);
2016call 0 returned 834
2017 834: 1049: rc = many_copy(m, 0, cur, &cl, other, &fl, ord, ext, p->batch);
2018call 0 returned 834
2019 834: 1050: if (rc == OMEGA_GPU_ML_OK && L > h) {
2020branch 0 taken 834 (fallthrough)
2021branch 1 taken 0
2022branch 2 taken 544 (fallthrough)
2023branch 3 taken 290
2024 544: 1051: Lay sl = cl, dl = fl;
2025 544: 1052: sl.base = L - h;
2026 544: 1053: sl.st[last] = 0xFFFFFFFFu;
2027 544: 1054: dl.base = h;
2028 544: 1055: ext[0] = L - h;
2029 544: 1056: rc = many_copy(m, 3, cur, &sl, other, &dl, ord, ext, p->batch);
2030call 0 returned 544
2031 -: 1057: }
2032 834: 1058: cl = fl;
2033 834: 1059: cur = other;
2034 834: 1060: e[last] = L;
2035 834: 1061: if (rc == OMEGA_GPU_ML_OK) rc = many_axis(m, L, many_rows(r, e, last, p->batch), dir, &cur, cur == S0 ? S1 : S0);
2036branch 0 taken 834 (fallthrough)
2037branch 1 taken 0
2038call 2 returned 834
2039branch 3 taken 332 (fallthrough)
2040branch 4 taken 502
2041call 5 returned 834
2042 -: 1062: }
2043 3332: 1063: if (rc == OMEGA_GPU_ML_OK) {
2044branch 0 taken 3330 (fallthrough)
2045branch 1 taken 2
2046 3330: 1064: uint32_t id[3] = { 0, 1, 2 };
2047 3330: 1065: many_slots(r, id, e, ord, ext);
2048call 0 returned 3330
2049 3330: 1066: rc = many_copy(m, c2r ? 2u : 0u, cur, &cl, OMEGA_GPU_FFT_BUF_OUT, &ol, ord, ext, p->batch);
2050branch 0 taken 834 (fallthrough)
2051branch 1 taken 2496
2052call 2 returned 3330
2053 -: 1067: }
2054 3332: 1068: if (rc != OMEGA_GPU_ML_OK) return rc;
2055branch 0 taken 2 (fallthrough)
2056branch 1 taken 3330
2057 3330: 1069: uint64_t ib = iextent * (r2c ? 4u : 8u), ob = oextent * (c2r ? 4u : 8u);
2058branch 0 taken 834 (fallthrough)
2059branch 1 taken 2496
2060branch 2 taken 834 (fallthrough)
2061branch 3 taken 2496
2062 3330: 1070: bytes[OMEGA_GPU_FFT_BUF_IN] = alias ? (ib > ob ? ib : ob) : ib;
2063branch 0 taken 692 (fallthrough)
2064branch 1 taken 2638
2065 3330: 1071: bytes[OMEGA_GPU_FFT_BUF_OUT] = alias ? 0u : ob;
2066branch 0 taken 2638 (fallthrough)
2067branch 1 taken 692
2068 3330: 1072: bytes[OMEGA_GPU_FFT_BUF_S0] = bytes[OMEGA_GPU_FFT_BUF_S1] = (size_t)(P * p->batch * 8u);
2069 3330: 1073: bytes[OMEGA_GPU_FFT_BUF_W] = bytes[OMEGA_GPU_FFT_BUF_W2] = (size_t)m->w_bytes;
2070 3330: 1074: bytes[OMEGA_GPU_FFT_BUF_B] = (size_t)m->b_bytes;
2071 3330: 1075: bytes[OMEGA_GPU_FFT_BUF_TABLE] = m->ntab * 8u;
2072 3330: 1076: if (o) {
2073branch 0 taken 20 (fallthrough)
2074branch 1 taken 3310
2075 20: 1077: o->rank = r;
2076 20: 1078: o->batch = p->batch;
2077 20: 1079: memcpy(o->oext, oext, sizeof oext);
2078 20: 1080: o->owords = c2r ? 1u : 2u;
2079branch 0 taken 6 (fallthrough)
2080branch 1 taken 14
2081 20: 1081: o->olay = ol;
2082 20: 1082: o->oextent = oextent;
2083 20: 1083: o->obasic = obasic;
2084 -: 1084: }
2085 3330: 1085: return OMEGA_GPU_ML_OK;
2086 -: 1086:}
2087 -: 1087:#endif
2088 -: 1088:
2089function oracle_many_walk called 4098 returned 100% blocks executed 100%
2090 4098: 1089:int omega_gpu_fft_many_walk(const OmegaGpuFftMany *plan, int in_place, size_t bytes[OMEGA_GPU_FFT_MANY_BUFS],
2091 -: 1090: OmegaGpuFftManyLaunchFn fn, void *ctx) {
2092 4098: 1091: if (in_place != 0 && in_place != 1) return OMEGA_GPU_ML_BAD_ARGS;
2093branch 0 taken 696 (fallthrough)
2094branch 1 taken 3402
2095branch 2 taken 4 (fallthrough)
2096branch 3 taken 692
2097 -: 1092: Many m;
2098 4094: 1093: omega_gpu_session_lock();
2099call 0 returned 4094
2100 4094: 1094: int rc = many_build(plan, in_place, in_place, &m, bytes, NULL);
2101call 0 returned 4094
2102 4094: 1095: omega_gpu_session_unlock();
2103call 0 returned 4094
2104 79656: 1096: for (size_t i = 0; fn && rc == OMEGA_GPU_ML_OK && i < m.n; i++) {
2105branch 0 taken 77218 (fallthrough)
2106branch 1 taken 2438
2107branch 2 taken 77216 (fallthrough)
2108branch 3 taken 2
2109branch 4 taken 75562
2110branch 5 taken 1654 (fallthrough)
2111 75562: 1097: m.l[i].table = m.tab;
2112 75562: 1098: rc = fn(ctx, &m.l[i]);
2113call 0 returned 75562
2114 -: 1099: }
2115 4094: 1100: many_free(&m);
2116call 0 returned 4094
2117 4094: 1101: return rc;
2118 -: 1102:}
2119 -: 1103:
2120 -: 1104:typedef struct { const uint32_t *dev; uint32_t *out; uint32_t words; uint64_t unwritten; } ManyScan;
2121 -: 1105:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
2122function many_scan called 18 returned 100% blocks executed 100%
2123 18: 1106:static int many_scan(void *ctx, uint32_t idx) {
2124 18: 1107: ManyScan *c = (ManyScan *)ctx;
2125 36: 1108: for (uint32_t k = 0; k < c->words; k++) c->unwritten += c->dev[(size_t)idx * c->words + k] == ML_POISON32;
2126branch 0 taken 18
2127branch 1 taken 18 (fallthrough)
2128 18: 1109: return 0;
2129 -: 1110:}
2130 -: 1111:#else
2131 -: 1112:static int many_scan(void *ctx, uint32_t idx) {
2132 -: 1113: ManyScan *c = (ManyScan *)ctx;
2133 -: 1114: size_t first = omega_mh_mul(idx, c->words);
2134 -: 1115: for (uint32_t k = 0; k < c->words; k++)
2135 -: 1116: c->unwritten = omega_mh_add(c->unwritten, omega_mh_poison(c->dev[first + k], 0, 0, 0));
2136 -: 1117: return 0;
2137 -: 1118:}
2138 -: 1119:#endif
2139function many_copy_back called 0 returned 0% blocks executed 0%
2140 #####: 1120:static int many_copy_back(void *ctx, uint32_t idx) {
2141 #####: 1121: ManyScan *c = (ManyScan *)ctx;
2142 #####: 1122: size_t at = ml_mul(idx, c->words);
2143 #####: 1123: memcpy(&c->out[at], &c->dev[at], ml_mul(4, c->words));
2144 #####: 1124: return 0;
2145 -: 1125:}
2146 -: 1126:
2147function oracle_many called 20 returned 100% blocks executed 29%
2148 20: 1127:int omega_gpu_fft_many(const OmegaGpuFftMany *plan, const float *in, float *out, OmegaGpuMathInfo *info) {
2149 20*: 1128: if (!plan || !in || !out) return OMEGA_GPU_ML_BAD_ARGS;
2150branch 0 taken 20 (fallthrough)
2151branch 1 taken 0
2152branch 2 taken 20 (fallthrough)
2153branch 3 taken 0
2154branch 4 taken 0 (fallthrough)
2155branch 5 taken 20
2156 20*: 1129: if (info) memset(info, 0, sizeof *info);
2157branch 0 taken 0 (fallthrough)
2158branch 1 taken 20
2159 20: 1130: uint64_t t0 = now_ns();
2160call 0 returned 20
2161 20: 1131: int in_place = (const void *)in == (const void *)out;
2162 -: 1132: size_t bytes[OMEGA_GPU_FFT_MANY_BUFS];
2163 -: 1133: Many m;
2164 -: 1134: ManyOut o;
2165 20: 1135: omega_gpu_session_lock();
2166call 0 returned 20
2167 20: 1136: int rc = many_build(plan, in_place, 0, &m, bytes, &o);
2168call 0 returned 20
2169 20: 1137: const char *pi = (const char *)in, *po = (const char *)out;
2170 20: 1138: if (rc == OMEGA_GPU_ML_OK && !in_place &&
2171branch 0 taken 20 (fallthrough)
2172branch 1 taken 0
2173branch 2 taken 20 (fallthrough)
2174branch 3 taken 0
2175 20: 1139: ml_overlap(pi, bytes[OMEGA_GPU_FFT_BUF_IN], po, bytes[OMEGA_GPU_FFT_BUF_OUT]))
2176branch 0 taken 20 (fallthrough)
2177branch 1 taken 0
2178branch 2 taken 20 (fallthrough)
2179branch 3 taken 0
2180 20: 1140: rc = OMEGA_GPU_ML_BAD_ARGS;
2181 20: 1141: if (rc == OMEGA_GPU_ML_OK) {
2182branch 0 taken 0 (fallthrough)
2183branch 1 taken 20
2184 #####: 1142: if (!g_hooked) { (void)omega_gpu_session_on_close(on_session_close); g_hooked = true; }
2185branch 0 never executed (fallthrough)
2186branch 1 never executed
2187call 2 never executed
2188 #####: 1143: if (!omega_gpu_session_open()) rc = OMEGA_GPU_ML_CHIP_FAIL;
2189call 0 never executed
2190branch 1 never executed (fallthrough)
2191branch 2 never executed
2192 -: 1144: }
2193 20: 1145: OmegaGpuScratch *buf[OMEGA_GPU_FFT_MANY_BUFS] = { &g_in, &g_out, &g_scr, &g_s1, &g_w, &g_w2, &g_b, &g_tw };
2194 20*: 1146: for (int i = 0; rc == OMEGA_GPU_ML_OK && i < OMEGA_GPU_FFT_MANY_BUFS; i++)
2195branch 0 taken 0 (fallthrough)
2196branch 1 taken 20
2197branch 2 never executed
2198branch 3 never executed (fallthrough)
2199 #####: 1147: if (omega_gpu_session_scratch(buf[i], bytes[i] ? bytes[i] : 8u) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL;
2200branch 0 never executed (fallthrough)
2201branch 1 never executed
2202call 2 never executed
2203branch 3 never executed (fallthrough)
2204branch 4 never executed
2205 20: 1148: if (rc == OMEGA_GPU_ML_OK) {
2206branch 0 taken 0 (fallthrough)
2207branch 1 taken 20
2208 #####: 1149: memcpy(g_in.mem.cpu, in, bytes[OMEGA_GPU_FFT_BUF_IN]);
2209 #####: 1150: memcpy(g_tw.mem.cpu, m.tab, bytes[OMEGA_GPU_FFT_BUF_TABLE]);
2210 #####: 1151: uint32_t *dev = (uint32_t *)g_out.mem.cpu;
2211 #####: 1152: for (size_t i = 0; i < bytes[OMEGA_GPU_FFT_BUF_OUT] / 4u; i++) dev[i] = ML_POISON32;
2212branch 0 never executed
2213branch 1 never executed (fallthrough)
2214 #####: 1153: if (omega_gpu_session_sync_to_gpu(&g_in.mem) != 0 || omega_gpu_session_sync_to_gpu(&g_tw.mem) != 0 ||
2215call 0 never executed
2216branch 1 never executed (fallthrough)
2217branch 2 never executed
2218call 3 never executed
2219branch 4 never executed (fallthrough)
2220branch 5 never executed
2221branch 6 never executed (fallthrough)
2222branch 7 never executed
2223 #####: 1154: omega_gpu_session_sync_to_gpu(&g_out.mem) != 0)
2224call 0 never executed
2225 #####: 1155: rc = OMEGA_GPU_ML_CHIP_FAIL;
2226 #####: 1156: for (size_t i = 0; rc == OMEGA_GPU_ML_OK && i < m.n; i++) {
2227branch 0 never executed (fallthrough)
2228branch 1 never executed
2229branch 2 never executed
2230branch 3 never executed (fallthrough)
2231 #####: 1157: const OmegaGpuFftManyLaunch *l = &m.l[i];
2232 -: 1158: Slot *s;
2233 -: 1159: bool hit;
2234 #####: 1160: rc = kernel_for(l->kind, l->a, l->b, l->threads, true, &s, &hit);
2235call 0 never executed
2236 #####: 1161: if (rc != OMEGA_GPU_ML_OK) break;
2237branch 0 never executed (fallthrough)
2238branch 1 never executed
2239 #####: 1162: info_kernel(info, s, hit);
2240call 0 never executed
2241 -: 1163: uint32_t args[OMEGA_GPU_SESSION_MAX_ARGS];
2242 #####: 1164: for (uint32_t k = 0; k < l->nptr; k++) put64(&args[2 * k], buf[l->buf[k]]->mem.va + l->off[k]);
2243call 0 never executed
2244branch 1 never executed
2245branch 2 never executed (fallthrough)
2246 #####: 1165: memcpy(&args[2 * l->nptr], l->words, l->nwords * sizeof l->words[0]);
2247 #####: 1166: rc = launch(s, args, 2 * l->nptr + l->nwords, l->grid, l->elements, 0, info);
2248call 0 never executed
2249 -: 1167: }
2250 #####: 1168: if (rc == OMEGA_GPU_ML_OK && omega_gpu_session_sync_to_cpu(&g_out.mem) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL;
2251branch 0 never executed (fallthrough)
2252branch 1 never executed
2253call 2 never executed
2254branch 3 never executed (fallthrough)
2255branch 4 never executed
2256 #####: 1169: if (rc == OMEGA_GPU_ML_OK) {
2257branch 0 never executed (fallthrough)
2258branch 1 never executed
2259 -: 1170: /* only the addressed output elements are checked and copied back */
2260 #####: 1171: ManyScan c = { dev, (uint32_t *)(void *)out, o.owords, 0 };
2261 #####: 1172: (void)many_each(o.rank, &o.olay, o.oext, o.batch, many_scan, &c);
2262call 0 never executed
2263 #####: 1173: if (info) info->unwritten_words = c.unwritten;
2264branch 0 never executed (fallthrough)
2265branch 1 never executed
2266 #####: 1174: if (c.unwritten) rc = OMEGA_GPU_ML_UNWRITTEN;
2267branch 0 never executed (fallthrough)
2268branch 1 never executed
2269 #####: 1175: else (void)many_each(o.rank, &o.olay, o.oext, o.batch, many_copy_back, &c);
2270call 0 never executed
2271 -: 1176: }
2272 -: 1177: }
2273 20: 1178: omega_gpu_session_unlock();
2274call 0 returned 20
2275 20: 1179: many_free(&m);
2276call 0 returned 20
2277 20*: 1180: if (info) info->call_ns = ml_sub(now_ns(), t0);
2278branch 0 taken 0 (fallthrough)
2279branch 1 taken 20
2280call 2 never executed
2281 20: 1181: return rc;
2282 -: 1182:}
2283 -: 1183:
2284 -: 1184:/* The legacy entry points' other lengths: basic layout, in and out may not overlap. */
2285function many_basic called 22 returned 100% blocks executed 100%
2286 22: 1185:static int many_basic(OmegaGpuFftType type, uint32_t rank, const uint32_t *n, uint32_t batch, int inverse,
2287 -: 1186: const float *in, float *out, OmegaGpuMathInfo *info) {
2288 -: 1187:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
2289 22: 1188: if (!in || !out || in == out || !n || rank < 1 || rank > 3) return OMEGA_GPU_ML_BAD_ARGS;
2290branch 0 taken 22 (fallthrough)
2291branch 1 taken 0
2292branch 2 taken 22 (fallthrough)
2293branch 3 taken 0
2294branch 4 taken 22 (fallthrough)
2295branch 5 taken 0
2296branch 6 taken 22 (fallthrough)
2297branch 7 taken 0
2298branch 8 taken 20 (fallthrough)
2299branch 9 taken 2
2300branch 10 taken 0 (fallthrough)
2301branch 11 taken 20
2302 -: 1189:#else
2303 -: 1190: if (omega_mh_basic(rank, (uintptr_t)in, (uintptr_t)out, (uintptr_t)n)) return OMEGA_GPU_ML_BAD_ARGS;
2304 -: 1191:#endif
2305 -: 1192: OmegaGpuFftMany p;
2306 20: 1193: memset(&p, 0, sizeof p);
2307 20: 1194: p.rank = rank;
2308 20: 1195: memcpy(p.n, n, rank * sizeof n[0]);
2309 20: 1196: p.batch = batch;
2310 20: 1197: p.type = type;
2311 20: 1198: p.inverse = inverse;
2312 20: 1199: return omega_gpu_fft_many(&p, in, out, info);
2313call 0 returned 20
2314 -: 1200:}
2315 -: 1201:
2316 -: 1202:#if !CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST
2317 -: 1203:#include "omega_gpu_mathlibs_host.inc"
2318 -: 1204:#endif