Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/evidence/mathlibs-host-20261106/omega_gpu_mathlibs_api.c.gcov # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 12 -: 8:#include 13 -: 9:#include 14 -: 10:#include 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: 57 function 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); 61 call 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: 69 function 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); 73 call 0 never executed 74 #####: 66: memset(s, 0, sizeof *s); 75 #####: 67:} 76 -: 68: 77 function 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++) 80 branch 0 never executed 81 branch 1 never executed (fallthrough) 82 #####: 71: if (g_cache[i].used) slot_clear(&g_cache[i]); 83 branch 0 never executed (fallthrough) 84 branch 1 never executed 85 call 2 never executed 86 #####: 72:} 87 -: 73: 88 function 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(); 91 call 0 never executed 92 #####: 76: cache_clear_locked(); 93 call 0 never executed 94 #####: 77: omega_gpu_session_unlock(); 95 call 0 never executed 96 #####: 78:} 97 -: 79: 98 function on_session_close called 0 returned 0% blocks executed 0% 99 #####: 80:static void on_session_close(void) { 100 #####: 81: cache_clear_locked(); 101 call 0 never executed 102 #####: 82: omega_gpu_session_scratch_free(&g_in); 103 call 0 never executed 104 #####: 83: omega_gpu_session_scratch_free(&g_out); 105 call 0 never executed 106 #####: 84: omega_gpu_session_scratch_free(&g_tw); 107 call 0 never executed 108 #####: 85: omega_gpu_session_scratch_free(&g_scr); 109 call 0 never executed 110 #####: 86: omega_gpu_session_scratch_free(&g_s1); 111 call 0 never executed 112 #####: 87: omega_gpu_session_scratch_free(&g_w); 113 call 0 never executed 114 #####: 88: omega_gpu_session_scratch_free(&g_w2); 115 call 0 never executed 116 #####: 89: omega_gpu_session_scratch_free(&g_b); 117 call 0 never executed 118 #####: 90:} 119 -: 91: 120 function 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(); 123 call 0 never executed 124 #####: 94: g_mutant_which = which; 125 #####: 95: g_mutant_level = level < 0 ? 0 : level > 6 ? 6 : level; 126 branch 0 never executed (fallthrough) 127 branch 1 never executed 128 #####: 96: cache_clear_locked(); 129 call 0 never executed 130 #####: 97: omega_gpu_session_unlock(); 131 call 0 never executed 132 #####: 98:} 133 -: 99: 134 function 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(); } 136 call 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). */ 141 function 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) || 144 branch 0 never executed (fallthrough) 145 branch 1 never executed 146 branch 2 never executed (fallthrough) 147 branch 3 never executed 148 branch 4 never executed (fallthrough) 149 branch 5 never executed 150 branch 6 never executed (fallthrough) 151 branch 7 never executed 152 #####: 107: (g_mutant_which >= 3 && (uint64_t)g_mutant_which == kind); 153 branch 0 never executed (fallthrough) 154 branch 1 never executed 155 branch 2 never executed (fallthrough) 156 branch 3 never executed 157 #####: 108: uint64_t mutant = target ? (uint64_t)g_mutant_level : 0; 158 branch 0 never executed (fallthrough) 159 branch 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++) 163 branch 0 never executed 164 branch 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 && 166 branch 0 never executed (fallthrough) 167 branch 1 never executed 168 branch 2 never executed (fallthrough) 169 branch 3 never executed 170 branch 4 never executed (fallthrough) 171 branch 5 never executed 172 branch 6 never executed (fallthrough) 173 branch 7 never executed 174 #####: 113: g_cache[i].mutant == mutant) { 175 branch 0 never executed (fallthrough) 176 branch 1 never executed 177 #####: 114: s = &g_cache[i]; 178 #####: 115: *hit = true; 179 #####: 116: break; 180 -: 117: } 181 #####: 118: if (!s) { 182 branch 0 never executed (fallthrough) 183 branch 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, 189 branch 0 never executed (fallthrough) 190 branch 1 never executed 191 call 2 never executed 192 -: 124: &k, &declared, NULL) 193 #####: 125: : OMEGA_OM_IR_REPLAY; 194 branch 0 never executed (fallthrough) 195 branch 1 never executed 196 #####: 126: free(prog); 197 #####: 127: if (rc != OMEGA_OM_IR_OK) { 198 branch 0 never executed (fallthrough) 199 branch 1 never executed 200 #####: 128: free(buf); 201 #####: 129: omega_gpu_session_set_error(omega_gpu_om_ir_rc_name(rc)); 202 call 0 never executed 203 call 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++) 208 branch 0 never executed 209 branch 1 never executed (fallthrough) 210 #####: 134: if (!g_cache[i].used) { slot = i; break; } 211 branch 0 never executed (fallthrough) 212 branch 1 never executed 213 #####: 135: s = &g_cache[slot]; 214 #####: 136: if (s->used) slot_clear(s); /* full: evict slot 0 */ 215 branch 0 never executed (fallthrough) 216 branch 1 never executed 217 call 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) { 225 branch 0 never executed (fallthrough) 226 branch 1 never executed 227 branch 2 never executed (fallthrough) 228 branch 3 never executed 229 #####: 144: if (omega_gpu_session_alloc_code(s->kernel.code_size, &s->code) != 0) return OMEGA_GPU_ML_CHIP_FAIL; 230 call 0 never executed 231 branch 1 never executed (fallthrough) 232 branch 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; } 235 call 0 never executed 236 branch 1 never executed (fallthrough) 237 branch 2 never executed 238 call 3 never executed 239 -: 147: } 240 #####: 148: *out = s; 241 #####: 149: return OMEGA_GPU_ML_OK; 242 -: 150:} 243 -: 151: 244 function 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; 247 branch 0 never executed (fallthrough) 248 branch 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: 257 function 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; 260 branch 0 never executed (fallthrough) 261 branch 1 never executed 262 #####: 164: memset(info, 0, sizeof *info); 263 #####: 165: info_kernel(info, s, hit); 264 call 0 never executed 265 -: 166:} 266 -: 167: 267 function 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(); 270 call 0 never executed 271 -: 170: Slot *s; 272 -: 171: bool hit; 273 #####: 172: int rc = kernel_for(kind, a, b, threads, false, &s, &hit); 274 call 0 never executed 275 #####: 173: if (rc == OMEGA_GPU_ML_OK) info_begin(info, s, hit); 276 branch 0 never executed (fallthrough) 277 branch 1 never executed 278 call 2 never executed 279 #####: 174: omega_gpu_session_unlock(); 280 call 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. */ 285 function 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; } 288 branch 0 never executed (fallthrough) 289 branch 1 never executed 290 call 2 never executed 291 #####: 181: if (!omega_gpu_session_open()) return OMEGA_GPU_ML_CHIP_FAIL; 292 call 0 never executed 293 branch 1 never executed (fallthrough) 294 branch 2 never executed 295 -: 182: bool hit; 296 #####: 183: int rc = kernel_for(kind, a, b, threads, true, s, &hit); 297 call 0 never executed 298 #####: 184: if (rc == OMEGA_GPU_ML_OK) info_begin(info, *s, hit); 299 branch 0 never executed (fallthrough) 300 branch 1 never executed 301 call 2 never executed 302 #####: 185: return rc; 303 -: 186:} 304 -: 187: 305 function 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; 316 call 0 never executed 317 branch 1 never executed (fallthrough) 318 branch 2 never executed 319 #####: 198: if (info) { 320 branch 0 never executed (fallthrough) 321 branch 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: 330 function 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 336 function 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; 339 branch 0 taken 548 (fallthrough) 340 branch 1 taken 182 341 branch 2 taken 486 (fallthrough) 342 branch 3 taken 62 343 branch 4 taken 50 (fallthrough) 344 branch 5 taken 436 345 436: 214: if (nstreams > OMEGA_GPU_RNG_MAX_STREAMS || (uint64_t)nstreams * per > OMEGA_GPU_RNG_MAX_OUTPUTS) 346 branch 0 taken 324 (fallthrough) 347 branch 1 taken 112 348 branch 2 taken 48 (fallthrough) 349 branch 3 taken 276 350 160: 215: return OMEGA_GPU_ML_TOO_LARGE; 351 276: 216: return OMEGA_GPU_ML_OK; 352 -: 217:} 353 -: 218: 354 function 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; 357 branch 0 never executed (fallthrough) 358 branch 1 never executed 359 #####: 221: return codegen_only(0, (uint64_t)kind, 0, OMEGA_GPU_RNG_THREADS, info); 360 call 0 never executed 361 -: 222:} 362 -: 223: 363 function 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; 367 branch 0 taken 2 (fallthrough) 368 branch 1 taken 10 369 10: 227: int rc = rng_args_ok(kind, nstreams, per_stream); 370 call 0 returned 10 371 10: 228: if (rc != OMEGA_GPU_ML_OK) return rc; 372 branch 0 taken 10 (fallthrough) 373 branch 1 taken 0 374 #####: 229: uint64_t t0 = now_ns(); 375 call 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; 378 branch 0 never executed (fallthrough) 379 branch 1 never executed 380 #####: 232: size_t bytes = count * esize; 381 #####: 233: omega_gpu_session_lock(); 382 call 0 never executed 383 -: 234: Slot *s; 384 #####: 235: rc = begin(0, (uint64_t)kind, 0, OMEGA_GPU_RNG_THREADS, &s, info); 385 call 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; 387 branch 0 never executed (fallthrough) 388 branch 1 never executed 389 call 2 never executed 390 branch 3 never executed (fallthrough) 391 branch 4 never executed 392 #####: 237: if (rc == OMEGA_GPU_ML_OK) { 393 branch 0 never executed (fallthrough) 394 branch 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; 397 branch 0 never executed 398 branch 1 never executed (fallthrough) 399 #####: 240: if (omega_gpu_session_sync_to_gpu(&g_out.mem) != 0) rc = OMEGA_GPU_ML_CHIP_FAIL; 400 call 0 never executed 401 branch 1 never executed (fallthrough) 402 branch 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); 406 call 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); } 409 call 0 never executed 410 branch 1 never executed 411 branch 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); 417 branch 0 never executed (fallthrough) 418 branch 1 never executed 419 call 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; 421 branch 0 never executed (fallthrough) 422 branch 1 never executed 423 call 2 never executed 424 branch 3 never executed (fallthrough) 425 branch 4 never executed 426 #####: 252: if (rc == OMEGA_GPU_ML_OK) { 427 branch 0 never executed (fallthrough) 428 branch 1 never executed 429 #####: 253: memcpy(out, g_out.mem.cpu, bytes); 430 #####: 254: uint64_t unwritten = 0; 431 #####: 255: if (esize == 8) { 432 branch 0 never executed (fallthrough) 433 branch 1 never executed 434 #####: 256: for (size_t i = 0; i < count; i++) unwritten += ((const uint64_t *)out)[i] == ML_POISON64; 435 branch 0 never executed 436 branch 1 never executed 437 -: 257: } else { 438 #####: 258: for (size_t i = 0; i < count; i++) unwritten += ((const uint32_t *)out)[i] == ML_POISON32; 439 branch 0 never executed 440 branch 1 never executed (fallthrough) 441 -: 259: } 442 #####: 260: if (info) info->unwritten_words = unwritten; 443 branch 0 never executed (fallthrough) 444 branch 1 never executed 445 #####: 261: if (unwritten) rc = OMEGA_GPU_ML_UNWRITTEN; 446 branch 0 never executed (fallthrough) 447 branch 1 never executed 448 -: 262: } 449 -: 263: } 450 #####: 264: omega_gpu_session_unlock(); 451 call 0 never executed 452 #####: 265: if (info) info->call_ns = now_ns() - t0; 453 branch 0 never executed (fallthrough) 454 branch 1 never executed 455 call 2 never executed 456 #####: 266: return rc; 457 -: 267:} 458 -: 268:#endif 459 -: 269: 460 -: 270:/* ------------------------------------------------------------------ FFT */ 461 -: 271: 462 function 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; 466 branch 0 taken 838 (fallthrough) 467 branch 1 taken 86 468 branch 2 taken 766 (fallthrough) 469 branch 3 taken 72 470 branch 4 taken 30 (fallthrough) 471 branch 5 taken 736 472 736: 275: int k = 0; 473 4170: 276: while ((1u << k) < n) k++; 474 branch 0 taken 3434 475 branch 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: 483 function 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); } 485 call 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). */ 491 function 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; 494 call 0 returned 664 495 branch 1 taken 0 (fallthrough) 496 branch 2 taken 664 497 190088: 292: for (uint32_t m = 0; m < (1u << lg); m++) { 498 branch 0 taken 189424 499 branch 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: 507 function 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); 510 call 0 never executed 511 #####: 302: if (lg < 0 || (inverse != 0 && inverse != 1)) return OMEGA_GPU_ML_BAD_ARGS; 512 branch 0 never executed (fallthrough) 513 branch 1 never executed 514 branch 2 never executed (fallthrough) 515 branch 3 never executed 516 branch 4 never executed (fallthrough) 517 branch 5 never executed 518 #####: 303: return codegen_only(1, (uint64_t)lg, (uint64_t)inverse, n / 4, info); 519 call 0 never executed 520 -: 304:} 521 -: 305: 522 function 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); 525 call 0 never executed 526 #####: 308: if (lg < 0 || !tw || (inverse != 0 && inverse != 1)) return OMEGA_GPU_ML_BAD_ARGS; 527 branch 0 never executed (fallthrough) 528 branch 1 never executed 529 branch 2 never executed (fallthrough) 530 branch 3 never executed 531 branch 4 never executed (fallthrough) 532 branch 5 never executed 533 branch 6 never executed (fallthrough) 534 branch 7 never executed 535 #####: 309: omega_gpu_session_lock(); 536 call 0 never executed 537 #####: 310: int rc = twiddles_locked((uint64_t)lg, (uint64_t)inverse); 538 call 0 never executed 539 #####: 311: if (rc == OMEGA_GPU_ML_OK) memcpy(tw, g_twf, (size_t)8 * n); 540 branch 0 never executed (fallthrough) 541 branch 1 never executed 542 #####: 312: omega_gpu_session_unlock(); 543 call 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 551 function 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); 554 call 0 returned 18 555 18: 322: if (lg < 0 && n >= 2 && n <= OMEGA_GPU_FFT_MANY_MAX_N) 556 branch 0 taken 14 (fallthrough) 557 branch 1 taken 4 558 branch 2 taken 10 (fallthrough) 559 branch 3 taken 4 560 branch 4 taken 6 (fallthrough) 561 branch 5 taken 4 562 6: 323: return many_basic(OMEGA_GPU_FFT_TYPE_C2C, 1, &n, batch, inverse, in, out, info); 563 call 0 returned 6 564 12*: 324: if (lg < 0 || !in || !out || batch == 0 || (inverse != 0 && inverse != 1)) return OMEGA_GPU_ML_BAD_ARGS; 565 branch 0 taken 4 (fallthrough) 566 branch 1 taken 8 567 branch 2 taken 4 (fallthrough) 568 branch 3 taken 0 569 branch 4 taken 4 (fallthrough) 570 branch 5 taken 0 571 branch 6 taken 4 (fallthrough) 572 branch 7 taken 0 573 branch 8 taken 0 (fallthrough) 574 branch 9 taken 4 575 branch 10 never executed (fallthrough) 576 branch 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; 579 branch 0 taken 0 (fallthrough) 580 branch 1 taken 4 581 4: 327: if ((out < in + floats) && (in < out + floats)) return OMEGA_GPU_ML_BAD_ARGS; 582 branch 0 taken 4 (fallthrough) 583 branch 1 taken 0 584 branch 2 taken 4 (fallthrough) 585 branch 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; 588 branch 0 never executed (fallthrough) 589 branch 1 never executed 590 #####: 330: int rc = omega_gpu_fft_twiddles(n, inverse, tw); 591 call 0 never executed 592 #####: 331: if (rc != OMEGA_GPU_ML_OK) { free(tw); return rc; } 593 branch 0 never executed (fallthrough) 594 branch 1 never executed 595 #####: 332: uint64_t t0 = now_ns(); 596 call 0 never executed 597 #####: 333: size_t bytes = floats * 4; 598 #####: 334: omega_gpu_session_lock(); 599 call 0 never executed 600 -: 335: Slot *s; 601 #####: 336: rc = begin(1, (uint64_t)lg, (uint64_t)inverse, n / 4, &s, info); 602 call 0 never executed 603 #####: 337: if (rc == OMEGA_GPU_ML_OK && (omega_gpu_session_scratch(&g_in, bytes) != 0 || 604 branch 0 never executed (fallthrough) 605 branch 1 never executed 606 call 2 never executed 607 branch 3 never executed (fallthrough) 608 branch 4 never executed 609 branch 5 never executed (fallthrough) 610 branch 6 never executed 611 #####: 338: omega_gpu_session_scratch(&g_out, bytes) != 0 || 612 call 0 never executed 613 branch 1 never executed (fallthrough) 614 branch 2 never executed 615 #####: 339: omega_gpu_session_scratch(&g_tw, (size_t)8 * n) != 0)) 616 call 0 never executed 617 #####: 340: rc = OMEGA_GPU_ML_CHIP_FAIL; 618 #####: 341: if (rc == OMEGA_GPU_ML_OK) { 619 branch 0 never executed (fallthrough) 620 branch 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; 625 branch 0 never executed 626 branch 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 || 628 call 0 never executed 629 branch 1 never executed (fallthrough) 630 branch 2 never executed 631 call 3 never executed 632 branch 4 never executed (fallthrough) 633 branch 5 never executed 634 branch 6 never executed (fallthrough) 635 branch 7 never executed 636 #####: 347: omega_gpu_session_sync_to_gpu(&g_out.mem) != 0) 637 call 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) { 640 branch 0 never executed (fallthrough) 641 branch 1 never executed 642 branch 2 never executed 643 branch 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); 648 call 0 never executed 649 #####: 354: put64(&args[2], g_out.mem.va + off); 650 call 0 never executed 651 #####: 355: put64(&args[4], g_tw.mem.va); 652 call 0 never executed 653 #####: 356: rc = launch(s, args, 6, grid, (size_t)grid * n * 2u, 8u * n, info); 654 call 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; 657 branch 0 never executed (fallthrough) 658 branch 1 never executed 659 call 2 never executed 660 branch 3 never executed (fallthrough) 661 branch 4 never executed 662 #####: 359: if (rc == OMEGA_GPU_ML_OK) { 663 branch 0 never executed (fallthrough) 664 branch 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++) { 668 branch 0 never executed 669 branch 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; 675 branch 0 never executed (fallthrough) 676 branch 1 never executed 677 #####: 368: if (unwritten) rc = OMEGA_GPU_ML_UNWRITTEN; 678 branch 0 never executed (fallthrough) 679 branch 1 never executed 680 -: 369: } 681 -: 370: } 682 #####: 371: omega_gpu_session_unlock(); 683 call 0 never executed 684 #####: 372: free(tw); 685 #####: 373: if (info) info->call_ns = now_ns() - t0; 686 branch 0 never executed (fallthrough) 687 branch 1 never executed 688 call 2 never executed 689 #####: 374: return rc; 690 -: 375:} 691 -: 376:#endif 692 -: 377: 693 -: 378:/* ------------------------------------------------------------------ Philox */ 694 -: 379: 695 function 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); } 697 call 0 never executed 698 -: 381: 699 -: 382:/* Caller holds the lock: fill g_out with poison, run, read back into out. */ 700 function 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; 705 branch 0 never executed 706 branch 1 never executed (fallthrough) 707 #####: 387: if (omega_gpu_session_sync_to_gpu(&g_out.mem) != 0) return OMEGA_GPU_ML_CHIP_FAIL; 708 call 0 never executed 709 branch 1 never executed (fallthrough) 710 branch 2 never executed 711 #####: 388: int rc = launch(s, args, 11, grid, count, 0, info); 712 call 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; 714 branch 0 never executed (fallthrough) 715 branch 1 never executed 716 call 2 never executed 717 branch 3 never executed (fallthrough) 718 branch 4 never executed 719 #####: 390: if (rc == OMEGA_GPU_ML_OK) memcpy(out, dev, count * 4u); 720 branch 0 never executed (fallthrough) 721 branch 1 never executed 722 #####: 391: return rc; 723 -: 392:} 724 -: 393: 725 -: 394:#if CUDAPP_MIGRATION_PENDING_C_MATHLIBS_HOST 726 function 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) 730 branch 0 taken 10 (fallthrough) 731 branch 1 taken 2 732 branch 2 taken 8 (fallthrough) 733 branch 3 taken 2 734 branch 4 taken 6 (fallthrough) 735 branch 5 taken 2 736 branch 6 taken 2 (fallthrough) 737 branch 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) 740 branch 0 taken 0 (fallthrough) 741 branch 1 taken 4 742 branch 2 never executed (fallthrough) 743 branch 3 never executed 744 4: 400: return OMEGA_GPU_ML_TOO_LARGE; 745 #####: 401: uint64_t t0 = now_ns(); 746 call 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; 749 branch 0 never executed (fallthrough) 750 branch 1 never executed 751 #####: 404: uint32_t esz = dist == OMEGA_GPU_PHILOX_UNIFORM_DOUBLE || dist == OMEGA_GPU_PHILOX_UNIFORM2_DOUBLE ? 2u : 1u; 752 branch 0 never executed (fallthrough) 753 branch 1 never executed 754 branch 2 never executed (fallthrough) 755 branch 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(); 759 call 0 never executed 760 -: 408: Slot *s; 761 #####: 409: int rc = begin(3, (uint64_t)dist, offset % 4u, OMEGA_GPU_PHILOX_THREADS, &s, info); 762 call 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; 764 branch 0 never executed (fallthrough) 765 branch 1 never executed 766 call 2 never executed 767 branch 3 never executed (fallthrough) 768 branch 4 never executed 769 #####: 411: if (rc == OMEGA_GPU_ML_OK) { 770 branch 0 never executed (fallthrough) 771 branch 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); 776 call 0 never executed 777 #####: 416: put64(&args[2], seed); 778 call 0 never executed 779 #####: 417: put64(&args[4], subseq0); 780 call 0 never executed 781 #####: 418: put64(&args[6], offset / 4u); 782 call 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; 787 branch 0 never executed (fallthrough) 788 branch 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); 791 call 0 never executed 792 #####: 425: uint64_t unwritten = 0; 793 #####: 426: if (dist == OMEGA_GPU_PHILOX_RAW) { 794 branch 0 never executed (fallthrough) 795 branch 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; 800 branch 0 never executed (fallthrough) 801 branch 1 never executed 802 branch 2 never executed 803 branch 3 never executed (fallthrough) 804 #####: 431: if (rc == OMEGA_GPU_ML_OK && hits) { 805 branch 0 never executed (fallthrough) 806 branch 1 never executed 807 branch 2 never executed (fallthrough) 808 branch 3 never executed 809 #####: 432: uint32_t *first = (uint32_t *)malloc(count * 4u); 810 #####: 433: if (!first) rc = OMEGA_GPU_ML_CHIP_FAIL; 811 branch 0 never executed (fallthrough) 812 branch 1 never executed 813 #####: 434: if (first) { 814 branch 0 never executed (fallthrough) 815 branch 1 never executed 816 #####: 435: memcpy(first, words, count * 4u); 817 #####: 436: rc = philox_pass(s, args, grid, count, ML_POISON32_ALT, words, info); 818 call 0 never executed 819 #####: 437: for (size_t i = 0; rc == OMEGA_GPU_ML_OK && i < count; i++) 820 branch 0 never executed (fallthrough) 821 branch 1 never executed 822 branch 2 never executed 823 branch 3 never executed (fallthrough) 824 #####: 438: unwritten += first[i] == ML_POISON32 && words[i] == ML_POISON32_ALT; 825 branch 0 never executed (fallthrough) 826 branch 1 never executed 827 branch 2 never executed (fallthrough) 828 branch 3 never executed 829 #####: 439: free(first); 830 -: 440: } 831 -: 441: } 832 #####: 442: } else if (esz == 1) { 833 branch 0 never executed (fallthrough) 834 branch 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; 837 branch 0 never executed (fallthrough) 838 branch 1 never executed 839 branch 2 never executed 840 branch 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; 845 branch 0 never executed (fallthrough) 846 branch 1 never executed 847 branch 2 never executed 848 branch 3 never executed (fallthrough) 849 -: 449: } 850 #####: 450: if (info) info->unwritten_words = unwritten; 851 branch 0 never executed (fallthrough) 852 branch 1 never executed 853 #####: 451: if (rc == OMEGA_GPU_ML_OK && unwritten) rc = OMEGA_GPU_ML_UNWRITTEN; 854 branch 0 never executed (fallthrough) 855 branch 1 never executed 856 branch 2 never executed (fallthrough) 857 branch 3 never executed 858 -: 452: } 859 #####: 453: omega_gpu_session_unlock(); 860 call 0 never executed 861 #####: 454: if (info) info->call_ns = now_ns() - t0; 862 branch 0 never executed (fallthrough) 863 branch 1 never executed 864 call 2 never executed 865 #####: 455: return rc; 866 -: 456:} 867 -: 457:#endif 868 -: 458: 869 function 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); 873 call 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 883 function 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; 887 branch 0 taken 646 (fallthrough) 888 branch 1 taken 2 889 branch 2 taken 644 (fallthrough) 890 branch 3 taken 2 891 branch 4 taken 564 (fallthrough) 892 branch 5 taken 80 893 branch 6 taken 164 (fallthrough) 894 branch 7 taken 400 895 branch 8 taken 2 (fallthrough) 896 branch 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) { 900 branch 0 taken 466 (fallthrough) 901 branch 1 taken 96 902 466: 477: if (ndim < 1 || ndim > 3) return OMEGA_GPU_ML_BAD_ARGS; 903 branch 0 taken 464 (fallthrough) 904 branch 1 taken 2 905 branch 2 taken 20 (fallthrough) 906 branch 3 taken 444 907 1108: 478: for (uint32_t i = 0; i < ndim; i++) { 908 branch 0 taken 744 909 branch 1 taken 364 910 744: 479: int k = fft_log2(dims[i]); 911 call 0 returned 744 912 744: 480: if (k < 0) return OMEGA_GPU_ML_BAD_ARGS; 913 branch 0 taken 80 (fallthrough) 914 branch 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) { 919 branch 0 taken 48 (fallthrough) 920 branch 1 taken 48 921 branch 2 taken 44 (fallthrough) 922 branch 3 taken 4 923 92: 485: if (ndim != 1 || inverse != 0) return OMEGA_GPU_ML_BAD_ARGS; 924 branch 0 taken 90 (fallthrough) 925 branch 1 taken 2 926 branch 2 taken 2 (fallthrough) 927 branch 3 taken 88 928 88: 486: int k = lg_in(dims[0], OMEGA_GPU_FFT_REAL_MIN_N, OMEGA_GPU_FFT_REAL_MAX_N); 929 call 0 returned 88 930 88: 487: if (k < 0) return OMEGA_GPU_ML_BAD_ARGS; 931 branch 0 taken 40 (fallthrough) 932 branch 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; 939 branch 0 taken 410 (fallthrough) 940 branch 1 taken 2 941 branch 2 taken 2 (fallthrough) 942 branch 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; } 946 branch 0 taken 24 (fallthrough) 947 branch 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; } 949 branch 0 taken 24 (fallthrough) 950 branch 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); 952 call 0 returned 408 953 408*: 499: if (rc == OMEGA_OM_IR_REFUSED) return OMEGA_GPU_ML_BAD_ARGS; 954 branch 0 taken 0 (fallthrough) 955 branch 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; 957 branch 0 taken 408 (fallthrough) 958 branch 1 taken 0 959 branch 2 taken 408 (fallthrough) 960 branch 3 taken 0 961 branch 4 taken 0 (fallthrough) 962 branch 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++) { 967 branch 0 taken 1482 (fallthrough) 968 branch 1 taken 10 969 branch 2 taken 1084 970 branch 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; 980 branch 0 taken 1084 (fallthrough) 981 branch 1 taken 0 982 branch 2 taken 0 (fallthrough) 983 branch 3 taken 1084 984 1748: 514: if (L.kind == 1 || L.kind == 4) { 985 branch 0 taken 460 (fallthrough) 986 branch 1 taken 624 987 branch 2 taken 40 (fallthrough) 988 branch 3 taken 420 989 664: 515: rc = twiddles_locked(L.a, L.b); 990 call 0 returned 664 991 664*: 516: if (rc != OMEGA_GPU_ML_OK) return rc; 992 branch 0 taken 0 (fallthrough) 993 branch 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; 1000 branch 0 taken 624 (fallthrough) 1001 branch 1 taken 40 1002 664: 523: if (L.kind == 4) { si = n / 2u + L.b; so = n / 2u + 1u - L.b; } 1003 branch 0 taken 40 (fallthrough) 1004 branch 1 taken 624 1005 50932: 524: for (uint64_t r0 = 0; r0 < rows; r0 += OMEGA_GPU_FFT_MAX_CTAS) { 1006 branch 0 taken 50268 1007 branch 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); 1009 branch 0 taken 500 (fallthrough) 1010 branch 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); 1015 call 0 returned 50268 1016 50268*: 530: if (rc != OMEGA_GPU_ML_OK) return rc; 1017 branch 0 taken 0 (fallthrough) 1018 branch 1 taken 50268 1019 -: 531: } 1020 420: 532: } else if (L.kind == 5) { 1021 branch 0 taken 420 (fallthrough) 1022 branch 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) { 1028 branch 0 taken 1836 1029 branch 1 taken 420 1030 1836: 538: L.grid = (uint32_t)(ctas - c0 < OMEGA_GPU_FFT_MAX_CTAS ? ctas - c0 : OMEGA_GPU_FFT_MAX_CTAS); 1031 branch 0 taken 372 (fallthrough) 1032 branch 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); 1037 call 0 returned 1836 1038 1836*: 543: if (rc != OMEGA_GPU_ML_OK) return rc; 1039 branch 0 taken 0 (fallthrough) 1040 branch 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: 1058 function 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) { 1062 branch 0 taken 736 (fallthrough) 1063 branch 1 taken 51368 1064 736: 564: size_t cap = c->cap ? 2u * c->cap : 32u; 1065 branch 0 taken 338 (fallthrough) 1066 branch 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; 1069 branch 0 taken 0 (fallthrough) 1070 branch 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) { 1076 branch 0 taken 50268 (fallthrough) 1077 branch 1 taken 1836 1078 50268: 572: const OmegaGpuFftLaunch *p = NULL; 1079 51202: 573: for (size_t i = c->n; i-- > 0;) 1080 branch 0 taken 50804 1081 branch 1 taken 398 (fallthrough) 1082 50804: 574: if (c->l[i].tw_n) { p = &c->l[i]; break; } 1083 branch 0 taken 49870 (fallthrough) 1084 branch 1 taken 934 1085 50268: 575: if (p && p->tw_n == L->tw_n && p->tw_inverse == L->tw_inverse) { 1086 branch 0 taken 49870 (fallthrough) 1087 branch 1 taken 398 1088 branch 2 taken 49662 (fallthrough) 1089 branch 3 taken 208 1090 branch 4 taken 49662 (fallthrough) 1091 branch 5 taken 0 1092 49662: 576: x.tw = p->tw; 1093 -: 577: } else { 1094 606: 578: if (c->ntw == c->twcap) { 1095 branch 0 taken 398 (fallthrough) 1096 branch 1 taken 208 1097 398*: 579: size_t cap = c->twcap ? 2u * c->twcap : 8u; 1098 branch 0 taken 0 (fallthrough) 1099 branch 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; 1102 branch 0 taken 0 (fallthrough) 1103 branch 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; 1109 branch 0 taken 0 (fallthrough) 1110 branch 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: 1120 function 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(); 1126 call 0 returned 622 1127 622: 601: int rc = walk_locked(mode, ndim, dims, batch, inverse, bytes, fn ? collect : NULL, &c); 1128 branch 0 taken 618 (fallthrough) 1129 branch 1 taken 4 1130 call 2 returned 622 1131 622: 602: omega_gpu_session_unlock(); 1132 call 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]); 1134 call 0 returned 52104 1135 branch 1 taken 52500 (fallthrough) 1136 branch 2 taken 226 1137 branch 3 taken 52104 1138 branch 4 taken 396 (fallthrough) 1139 1228: 604: for (size_t i = 0; i < c.ntw; i++) free(c.tw[i]); 1140 branch 0 taken 606 1141 branch 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. */ 1154 function 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); 1160 call 0 never executed 1161 #####: 622: if (rc != OMEGA_GPU_ML_OK) return rc; 1162 branch 0 never executed (fallthrough) 1163 branch 1 never executed 1164 #####: 623: info_kernel(r->info, s, hit); 1165 call 0 never executed 1166 #####: 624: if (l->tw_n && (l->tw_n != r->tw_n || l->tw_inverse != r->tw_inverse)) { 1167 branch 0 never executed (fallthrough) 1168 branch 1 never executed 1169 branch 2 never executed (fallthrough) 1170 branch 3 never executed 1171 branch 4 never executed (fallthrough) 1172 branch 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; 1175 call 0 never executed 1176 branch 1 never executed (fallthrough) 1177 branch 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); 1183 call 0 never executed 1184 #####: 632: put64(&args[2], r->buf[l->dst]->mem.va + l->dst_off); 1185 call 0 never executed 1186 #####: 633: if (l->kind == 5) { 1187 branch 0 never executed (fallthrough) 1188 branch 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); 1193 call 0 never executed 1194 -: 638: } 1195 #####: 639: return launch(s, args, 6, l->grid, l->elements, l->shared_bytes, r->info); 1196 call 0 never executed 1197 -: 640:} 1198 -: 641: 1199 function 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; 1203 branch 0 taken 26 (fallthrough) 1204 branch 1 taken 0 1205 branch 2 taken 0 (fallthrough) 1206 branch 3 taken 26 1207 26*: 645: if (info) memset(info, 0, sizeof *info); 1208 branch 0 taken 0 (fallthrough) 1209 branch 1 taken 26 1210 26: 646: uint64_t t0 = now_ns(); 1211 call 0 returned 26 1212 -: 647: size_t bytes[3]; 1213 26: 648: omega_gpu_session_lock(); 1214 call 0 returned 26 1215 26: 649: int rc = walk_locked(mode, ndim, dims, batch, inverse, bytes, NULL, NULL); 1216 call 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; 1219 branch 0 taken 10 (fallthrough) 1220 branch 1 taken 16 1221 branch 2 taken 10 (fallthrough) 1222 branch 3 taken 0 1223 branch 4 taken 10 (fallthrough) 1224 branch 5 taken 0 1225 26: 652: if (rc == OMEGA_GPU_ML_OK) { 1226 branch 0 taken 0 (fallthrough) 1227 branch 1 taken 26 1228 #####: 653: if (!g_hooked) { (void)omega_gpu_session_on_close(on_session_close); g_hooked = true; } 1229 branch 0 never executed (fallthrough) 1230 branch 1 never executed 1231 call 2 never executed 1232 #####: 654: if (!omega_gpu_session_open()) rc = OMEGA_GPU_ML_CHIP_FAIL; 1233 call 0 never executed 1234 branch 1 never executed (fallthrough) 1235 branch 2 never executed 1236 -: 655: } 1237 26*: 656: if (rc == OMEGA_GPU_ML_OK && (omega_gpu_session_scratch(&g_in, bytes[0]) != 0 || 1238 branch 0 taken 0 (fallthrough) 1239 branch 1 taken 26 1240 call 2 never executed 1241 branch 3 never executed (fallthrough) 1242 branch 4 never executed 1243 branch 5 never executed (fallthrough) 1244 branch 6 never executed 1245 #####: 657: omega_gpu_session_scratch(&g_out, bytes[1]) != 0 || 1246 call 0 never executed 1247 branch 1 never executed (fallthrough) 1248 branch 2 never executed 1249 #####: 658: omega_gpu_session_scratch(&g_scr, bytes[2]) != 0 || 1250 call 0 never executed 1251 branch 1 never executed (fallthrough) 1252 branch 2 never executed 1253 #####: 659: omega_gpu_session_scratch(&g_tw, (size_t)8 * OMEGA_GPU_FFT_REAL_MAX_N) != 0)) 1254 call 0 never executed 1255 #####: 660: rc = OMEGA_GPU_ML_CHIP_FAIL; 1256 26: 661: if (rc == OMEGA_GPU_ML_OK) { 1257 branch 0 taken 0 (fallthrough) 1258 branch 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; 1262 branch 0 never executed 1263 branch 1 never executed (fallthrough) 1264 #####: 665: for (size_t i = 0; i < bytes[2] / 4u; i++) scr[i] = ML_POISON32; 1265 branch 0 never executed 1266 branch 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 || 1268 call 0 never executed 1269 branch 1 never executed (fallthrough) 1270 branch 2 never executed 1271 call 3 never executed 1272 branch 4 never executed (fallthrough) 1273 branch 5 never executed 1274 branch 6 never executed (fallthrough) 1275 branch 7 never executed 1276 #####: 667: omega_gpu_session_sync_to_gpu(&g_scr.mem) != 0) 1277 call 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); 1281 branch 0 never executed (fallthrough) 1282 branch 1 never executed 1283 call 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; 1285 branch 0 never executed (fallthrough) 1286 branch 1 never executed 1287 call 2 never executed 1288 branch 3 never executed (fallthrough) 1289 branch 4 never executed 1290 #####: 672: if (rc == OMEGA_GPU_ML_OK) { 1291 branch 0 never executed (fallthrough) 1292 branch 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]); 1296 branch 0 never executed 1297 branch 1 never executed (fallthrough) 1298 #####: 676: if (info) info->unwritten_words = unwritten; 1299 branch 0 never executed (fallthrough) 1300 branch 1 never executed 1301 #####: 677: if (unwritten) rc = OMEGA_GPU_ML_UNWRITTEN; 1302 branch 0 never executed (fallthrough) 1303 branch 1 never executed 1304 -: 678: } 1305 -: 679: } 1306 26: 680: omega_gpu_session_unlock(); 1307 call 0 returned 26 1308 26*: 681: if (info) info->call_ns = ml_sub(now_ns(), t0); 1309 branch 0 taken 0 (fallthrough) 1310 branch 1 taken 26 1311 call 2 never executed 1312 26: 682: return rc; 1313 -: 683:} 1314 -: 684: 1315 function 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) 1318 call 0 returned 18 1319 branch 1 taken 14 (fallthrough) 1320 branch 2 taken 4 1321 branch 3 taken 10 (fallthrough) 1322 branch 4 taken 4 1323 branch 5 taken 6 (fallthrough) 1324 branch 6 taken 4 1325 6: 687: return many_basic(OMEGA_GPU_FFT_TYPE_R2C, 1, &n, batch, 0, in, out, info); 1326 call 0 returned 6 1327 12: 688: return run_plan(OMEGA_GPU_FFT_R2C, 1, &n, batch, 0, in, out, info); 1328 call 0 returned 12 1329 -: 689:} 1330 -: 690: 1331 function 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) 1334 call 0 returned 18 1335 branch 1 taken 14 (fallthrough) 1336 branch 2 taken 4 1337 branch 3 taken 10 (fallthrough) 1338 branch 4 taken 4 1339 branch 5 taken 6 (fallthrough) 1340 branch 6 taken 4 1341 6: 693: return many_basic(OMEGA_GPU_FFT_TYPE_C2R, 1, &n, batch, 0, in, out, info); 1342 call 0 returned 6 1343 12: 694: return run_plan(OMEGA_GPU_FFT_C2R, 1, &n, batch, 0, in, out, info); 1344 call 0 returned 12 1345 -: 695:} 1346 -: 696: 1347 function 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) { 1351 branch 0 taken 2 (fallthrough) 1352 branch 1 taken 0 1353 branch 2 taken 2 (fallthrough) 1354 branch 3 taken 0 1355 branch 4 taken 2 (fallthrough) 1356 branch 5 taken 0 1357 2: 700: int legacy = 1, any = 1; 1358 8: 701: for (uint32_t i = 0; i < ndim; i++) { 1359 branch 0 taken 6 1360 branch 1 taken 2 (fallthrough) 1361 6: 702: legacy &= fft_log2(dims[i]) >= 0; 1362 call 0 returned 6 1363 6*: 703: any &= dims[i] >= 2 && dims[i] <= OMEGA_GPU_FFT_MANY_MAX_N; 1364 branch 0 taken 6 (fallthrough) 1365 branch 1 taken 0 1366 branch 2 taken 6 (fallthrough) 1367 branch 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); 1370 branch 0 taken 0 (fallthrough) 1371 branch 1 taken 2 1372 branch 2 never executed (fallthrough) 1373 branch 3 never executed 1374 call 4 never executed 1375 -: 706: } 1376 2: 707: return run_plan(OMEGA_GPU_FFT_C2C_ND, ndim, dims, batch, inverse, in, out, info); 1377 call 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: 1404 function 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. */ 1417 function 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++) 1420 branch 0 taken 8404 1421 branch 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; } 1423 branch 0 taken 5788 (fallthrough) 1424 branch 1 taken 2616 1425 branch 2 taken 1356 (fallthrough) 1426 branch 3 taken 4432 1427 branch 4 taken 504 (fallthrough) 1428 branch 5 taken 852 1429 7674*: 749: if (m->ntk == sizeof m->tk / sizeof m->tk[0]) return OMEGA_GPU_ML_CODEGEN_FAIL; 1430 branch 0 taken 0 (fallthrough) 1431 branch 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; 1433 call 0 returned 7674 1434 branch 1 taken 0 (fallthrough) 1435 branch 2 taken 7674 1436 7674: 751: if (m->ntab + a > m->tabcap) { 1437 branch 0 taken 6202 (fallthrough) 1438 branch 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; 1442 branch 0 taken 0 (fallthrough) 1443 branch 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). */ 1456 function 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; 1459 call 0 returned 79520 1460 branch 1 taken 0 (fallthrough) 1461 branch 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). */ 1467 function 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++) { 1474 branch 0 taken 101544 1475 branch 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]; 1477 branch 0 taken 22212 (fallthrough) 1478 branch 1 taken 79332 1479 branch 2 taken 21520 (fallthrough) 1480 branch 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) { 1488 branch 0 taken 152616 1489 branch 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); 1491 branch 0 taken 37220 (fallthrough) 1492 branch 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) { 1497 branch 0 taken 3460 (fallthrough) 1498 branch 1 taken 149156 1499 3460: 793: size_t cap = m->cap ? 2u * m->cap : 64u; 1500 branch 0 taken 128 (fallthrough) 1501 branch 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; 1504 branch 0 taken 0 (fallthrough) 1505 branch 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. */ 1516 function 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++) { 1521 branch 0 taken 22984 1522 branch 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; 1524 branch 0 taken 8178 (fallthrough) 1525 branch 1 taken 14806 1526 branch 2 taken 7326 (fallthrough) 1527 branch 3 taken 852 1528 branch 4 taken 14086 (fallthrough) 1529 branch 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]); 1532 call 0 returned 22984 1533 22984: 813: if (rc == OMEGA_GPU_ML_OK) rc = many_magic(ns, &w[5]); 1534 branch 0 taken 22984 (fallthrough) 1535 branch 1 taken 0 1536 call 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); 1540 branch 0 taken 22984 (fallthrough) 1541 branch 1 taken 0 1542 call 2 returned 22984 1543 22984*: 817: if (rc != OMEGA_GPU_ML_OK) return rc; 1544 branch 0 taken 0 (fallthrough) 1545 branch 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. */ 1555 function 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; 1558 call 0 returned 6476 1559 branch 1 taken 0 (fallthrough) 1560 branch 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; 1563 branch 0 taken 6476 (fallthrough) 1564 branch 1 taken 0 1565 branch 2 taken 0 (fallthrough) 1566 branch 3 taken 6476 1567 20770: 831: for (uint32_t i = 0; i < np; i++) rad[i] = (uint32_t)g_words[3 + i]; 1568 branch 0 taken 14294 1569 branch 1 taken 6476 (fallthrough) 1570 -: 832: uint64_t tw, twi, ch; 1571 -: 833: int rc; 1572 6476: 834: if (!blue) { 1573 branch 0 taken 5622 (fallthrough) 1574 branch 1 taken 854 1575 5622: 835: rc = many_table(m, 10, n, dir, &tw); 1576 call 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); 1578 branch 0 taken 5622 (fallthrough) 1579 branch 1 taken 0 1580 call 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; 1584 branch 0 taken 2 (fallthrough) 1585 branch 1 taken 852 1586 852: 840: if (rows * M * 8u > m->w_bytes) m->w_bytes = rows * M * 8u; 1587 branch 0 taken 824 (fallthrough) 1588 branch 1 taken 28 1589 852: 841: if ((uint64_t)M * 8u > m->b_bytes) m->b_bytes = (uint64_t)M * 8u; 1590 branch 0 taken 820 (fallthrough) 1591 branch 1 taken 32 1592 852: 842: uint32_t lgm = 0; 1593 9028: 843: while ((1u << lgm) < M) lgm++; 1594 branch 0 taken 8176 1595 branch 1 taken 852 (fallthrough) 1596 852: 844: rc = many_table(m, 11, n, dir, &ch); 1597 call 0 returned 852 1598 852: 845: if (rc == OMEGA_GPU_ML_OK) rc = many_table(m, 10, M, 0, &tw); 1599 branch 0 taken 852 (fallthrough) 1600 branch 1 taken 0 1601 call 2 returned 852 1602 852: 846: if (rc == OMEGA_GPU_ML_OK) rc = many_table(m, 10, M, 1, &twi); 1603 branch 0 taken 852 (fallthrough) 1604 branch 1 taken 0 1605 call 2 returned 852 1606 852*: 847: if (rc != OMEGA_GPU_ML_OK) return rc; 1607 branch 0 taken 0 (fallthrough) 1608 branch 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); 1615 call 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); 1617 branch 0 taken 852 (fallthrough) 1618 branch 1 taken 0 1619 call 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); 1624 branch 0 taken 852 (fallthrough) 1625 branch 1 taken 0 1626 call 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); 1628 branch 0 taken 852 (fallthrough) 1629 branch 1 taken 0 1630 call 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); 1634 branch 0 taken 852 (fallthrough) 1635 branch 1 taken 0 1636 call 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); 1638 branch 0 taken 852 (fallthrough) 1639 branch 1 taken 0 1640 branch 2 taken 288 (fallthrough) 1641 branch 3 taken 564 1642 call 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); 1645 branch 0 taken 852 (fallthrough) 1646 branch 1 taken 0 1647 call 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. */ 1652 function 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++) { 1659 branch 0 taken 33552 1660 branch 1 taken 11184 (fallthrough) 1661 33552: 876: uint32_t e = ord[k] < 0 ? 1u : ext[k]; 1662 branch 0 taken 23736 (fallthrough) 1663 branch 1 taken 9816 1664 33552*: 877: if (e == 0) return OMEGA_GPU_ML_OK; 1665 branch 0 taken 0 (fallthrough) 1666 branch 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]); 1670 call 0 returned 33552 1671 33552*: 881: if (rc != OMEGA_GPU_ML_OK) return rc; 1672 branch 0 taken 0 (fallthrough) 1673 branch 1 taken 33552 1674 33552: 882: w[10 + k] = ord[k] < 0 ? 0u : s->st[ord[k]]; 1675 branch 0 taken 23736 (fallthrough) 1676 branch 1 taken 9816 1677 33552: 883: w[15 + k] = ord[k] < 0 ? 0u : d->st[ord[k]]; 1678 branch 0 taken 23736 (fallthrough) 1679 branch 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); 1685 branch 0 taken 834 (fallthrough) 1686 branch 1 taken 10350 1687 call 2 returned 11184 1688 -: 889:} 1689 -: 890: 1690 -: 891:/* The contiguous layout of extents e with axis perm[0] slowest. */ 1691 function 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]]; } 1697 branch 0 taken 16434 1698 branch 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. */ 1704 function 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++) 1708 branch 0 taken 14772 1709 branch 1 taken 6476 (fallthrough) 1710 14772: 905: if (i != ax) rows *= e[i]; 1711 branch 0 taken 8296 (fallthrough) 1712 branch 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). */ 1717 function 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++) { 1720 branch 0 taken 31920 1721 branch 1 taken 10640 (fallthrough) 1722 31920: 912: ord[k] = k < rank ? (int)perm[rank - 1 - k] : -1; 1723 branch 0 taken 22908 (fallthrough) 1724 branch 1 taken 9012 1725 31920: 913: ext[k] = k < rank ? e[perm[rank - 1 - k]] : 1u; 1726 branch 0 taken 22908 (fallthrough) 1727 branch 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. */ 1732 function 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]; 1738 branch 0 taken 7272 (fallthrough) 1739 branch 1 taken 8338 1740 branch 2 taken 15610 1741 branch 3 taken 7994 (fallthrough) 1742 7994: 923: if (basic) { 1743 branch 0 taken 3816 (fallthrough) 1744 branch 1 taken 4178 1745 3816: 924: if (pad) e[rank - 1] = pad; 1746 branch 0 taken 408 (fallthrough) 1747 branch 1 taken 3408 1748 3816: 925: stride = 1; 1749 11088: 926: for (uint32_t i = 0; i < rank; i++) prod *= e[i]; 1750 branch 0 taken 7272 1751 branch 1 taken 3816 (fallthrough) 1752 3816*: 927: if (prod >= ((uint64_t)1 << 32)) return OMEGA_GPU_ML_TOO_LARGE; 1753 branch 0 taken 0 (fallthrough) 1754 branch 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; 1758 branch 0 taken 310 (fallthrough) 1759 branch 1 taken 3868 1760 7702: 931: for (uint32_t i = 1; i < rank; i++) 1761 branch 0 taken 3850 1762 branch 1 taken 3852 (fallthrough) 1763 3850: 932: if (e[i] < ext[i]) return OMEGA_GPU_ML_BAD_ARGS; 1764 branch 0 taken 16 (fallthrough) 1765 branch 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--) { 1769 branch 0 taken 14958 1770 branch 1 taken 7664 (fallthrough) 1771 14958: 936: if (p >= ((uint64_t)1 << 32)) return OMEGA_GPU_ML_TOO_LARGE; 1772 branch 0 taken 4 (fallthrough) 1773 branch 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; 1779 branch 0 taken 7656 (fallthrough) 1780 branch 1 taken 8 1781 branch 2 taken 2 (fallthrough) 1782 branch 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]; 1786 branch 0 taken 14932 1787 branch 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. */ 1793 function 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]; } 1798 branch 0 taken 3508 1799 branch 1 taken 1758 (fallthrough) 1800 4940: 954: for (uint32_t b = 0; b < batch; b++) 1801 branch 0 taken 3516 1802 branch 1 taken 1424 (fallthrough) 1803 850232: 955: for (uint32_t x0 = 0; x0 < e[0]; x0++) 1804 branch 0 taken 847050 1805 branch 1 taken 3182 (fallthrough) 1806 `4227440`: 956: for (uint32_t x1 = 0; x1 < e[1]; x1++) 1807 branch 0 taken `3380724` 1808 branch 1 taken 846716 (fallthrough) 1809 `11409910`: 957: for (uint32_t x2 = 0; x2 < e[2]; x2++) { 1810 branch 0 taken `8029520` 1811 branch 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]); 1813 call 0 returned `8029520` 1814 `8029520`: 959: if (rc) return rc; 1815 branch 0 taken 334 (fallthrough) 1816 branch 1 taken `8029186` 1817 -: 960: } 1818 1424: 961: return 0; 1819 -: 962:} 1820 -: 963: 1821 function 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; 1826 branch 0 taken 334 (fallthrough) 1827 branch 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. */ 1834 function 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) 1840 branch 0 taken 4112 (fallthrough) 1841 branch 1 taken 2 1842 branch 2 taken 4110 (fallthrough) 1843 branch 3 taken 2 1844 branch 4 taken 4108 (fallthrough) 1845 branch 5 taken 2 1846 branch 6 taken 4104 (fallthrough) 1847 branch 7 taken 4 1848 branch 8 taken 4064 (fallthrough) 1849 branch 9 taken 40 1850 branch 10 taken 4 (fallthrough) 1851 branch 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) 1854 branch 0 taken 1972 (fallthrough) 1855 branch 1 taken 2088 1856 branch 2 taken 254 (fallthrough) 1857 branch 3 taken 1718 1858 branch 4 taken 2 (fallthrough) 1859 branch 5 taken 252 1860 branch 6 taken 14 (fallthrough) 1861 branch 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++) { 1867 branch 0 taken 7890 1868 branch 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; 1870 branch 0 taken 7874 (fallthrough) 1871 branch 1 taken 16 1872 branch 2 taken 16 (fallthrough) 1873 branch 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; 1879 branch 0 taken 2 (fallthrough) 1880 branch 1 taken 4012 1881 4012: 992: if (P * p->batch > OMEGA_GPU_FFT_MAX_ELEMENTS) return OMEGA_GPU_ML_TOO_LARGE; 1882 branch 0 taken 6 (fallthrough) 1883 branch 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; 1889 branch 0 taken 1038 (fallthrough) 1890 branch 1 taken 2968 1891 4006: 998: if (r2c) oext[last] = h; 1892 branch 0 taken 1038 (fallthrough) 1893 branch 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, 1897 branch 0 taken 1038 (fallthrough) 1898 branch 1 taken 2968 1899 branch 2 taken 204 (fallthrough) 1900 branch 3 taken 834 1901 call 4 returned 4006 1902 -: 1002: &iextent); 1903 4006: 1003: if (rc == OMEGA_GPU_ML_OK) 1904 branch 0 taken 3988 (fallthrough) 1905 branch 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, 1907 branch 0 taken 1038 (fallthrough) 1908 branch 1 taken 2950 1909 branch 2 taken 204 (fallthrough) 1910 branch 3 taken 834 1911 call 4 returned 3988 1912 -: 1005: &oextent); 1913 4006: 1006: if (rc != OMEGA_GPU_ML_OK) return rc; 1914 branch 0 taken 340 (fallthrough) 1915 branch 1 taken 3666 1916 3666: 1007: if (!obasic) { 1917 branch 0 taken 1758 (fallthrough) 1918 branch 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; 1921 branch 0 taken 0 (fallthrough) 1922 branch 1 taken 1758 1923 1758: 1010: int dup = many_each(r, &ol, oext, p->batch, many_mark, bits); 1924 call 0 returned 1758 1925 1758: 1011: free(bits); 1926 1758: 1012: if (dup) return OMEGA_GPU_ML_BAD_ARGS; 1927 branch 0 taken 334 (fallthrough) 1928 branch 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; 1932 branch 0 taken 2498 (fallthrough) 1933 branch 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; 1938 branch 0 taken 834 (fallthrough) 1939 branch 1 taken 2498 1940 3332: 1020: if (c2r) /* the last axis slowest: the outer inverses come first */ 1941 branch 0 taken 834 (fallthrough) 1942 branch 1 taken 2498 1943 2496: 1021: for (uint32_t k = 0; k < r; k++) perm[k] = k == 0 ? last : k - 1u; 1944 branch 0 taken 828 (fallthrough) 1945 branch 1 taken 834 1946 branch 2 taken 1662 1947 branch 3 taken 834 (fallthrough) 1948 3332: 1022: Lay cl = many_dense(r, perm, e); 1949 call 0 returned 3332 1950 3332: 1023: many_slots(r, perm, e, ord, ext); 1951 call 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); 1953 branch 0 taken 834 (fallthrough) 1954 branch 1 taken 2498 1955 call 2 returned 3332 1956 3332: 1025: uint32_t nax = c2r ? r - 1u : r; 1957 branch 0 taken 834 (fallthrough) 1958 branch 1 taken 2498 1959 6476: 1026: for (uint32_t t = 0; t < nax && rc == OMEGA_GPU_ML_OK; t++) { 1960 branch 0 taken 5642 (fallthrough) 1961 branch 1 taken 834 1962 branch 2 taken 5642 1963 branch 3 taken 0 (fallthrough) 1964 5642: 1027: uint32_t ax = perm[r - 1u], other = cur == S0 ? S1 : S0; 1965 branch 0 taken 5546 (fallthrough) 1966 branch 1 taken 96 1967 5642: 1028: rc = many_axis(m, p->n[ax], many_rows(r, e, ax, p->batch), dir, &cur, other); 1968 call 0 returned 5642 1969 call 1 returned 5642 1970 5642: 1029: if (r2c && ax == last) e[last] = h; 1971 branch 0 taken 1662 (fallthrough) 1972 branch 1 taken 3980 1973 branch 2 taken 834 (fallthrough) 1974 branch 3 taken 828 1975 5642: 1030: if (rc != OMEGA_GPU_ML_OK || (t + 1u == nax && !c2r)) break; 1976 branch 0 taken 5640 (fallthrough) 1977 branch 1 taken 2 1978 branch 2 taken 3052 (fallthrough) 1979 branch 3 taken 2588 1980 branch 4 taken 556 (fallthrough) 1981 branch 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]; 1985 branch 0 taken 3144 (fallthrough) 1986 branch 1 taken 5152 1987 branch 2 taken 8296 1988 branch 3 taken 3144 (fallthrough) 1989 3144: 1034: Lay nl = many_dense(r, np, e); 1990 call 0 returned 3144 1991 3144: 1035: many_slots(r, np, e, ord, ext); 1992 call 0 returned 3144 1993 3144: 1036: other = cur == S0 ? S1 : S0; 1994 branch 0 taken 428 (fallthrough) 1995 branch 1 taken 2716 1996 3144: 1037: rc = many_copy(m, 0, cur, &cl, other, &nl, ord, ext, p->batch); 1997 call 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) { 2003 branch 0 taken 3330 (fallthrough) 2004 branch 1 taken 2 2005 branch 2 taken 834 (fallthrough) 2006 branch 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]; 2009 branch 0 taken 502 (fallthrough) 2010 branch 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); 2014 call 0 returned 834 2015 834: 1048: many_slots(r, perm, e, ord, ext); 2016 call 0 returned 834 2017 834: 1049: rc = many_copy(m, 0, cur, &cl, other, &fl, ord, ext, p->batch); 2018 call 0 returned 834 2019 834: 1050: if (rc == OMEGA_GPU_ML_OK && L > h) { 2020 branch 0 taken 834 (fallthrough) 2021 branch 1 taken 0 2022 branch 2 taken 544 (fallthrough) 2023 branch 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); 2030 call 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); 2036 branch 0 taken 834 (fallthrough) 2037 branch 1 taken 0 2038 call 2 returned 834 2039 branch 3 taken 332 (fallthrough) 2040 branch 4 taken 502 2041 call 5 returned 834 2042 -: 1062: } 2043 3332: 1063: if (rc == OMEGA_GPU_ML_OK) { 2044 branch 0 taken 3330 (fallthrough) 2045 branch 1 taken 2 2046 3330: 1064: uint32_t id[3] = { 0, 1, 2 }; 2047 3330: 1065: many_slots(r, id, e, ord, ext); 2048 call 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); 2050 branch 0 taken 834 (fallthrough) 2051 branch 1 taken 2496 2052 call 2 returned 3330 2053 -: 1067: } 2054 3332: 1068: if (rc != OMEGA_GPU_ML_OK) return rc; 2055 branch 0 taken 2 (fallthrough) 2056 branch 1 taken 3330 2057 3330: 1069: uint64_t ib = iextent * (r2c ? 4u : 8u), ob = oextent * (c2r ? 4u : 8u); 2058 branch 0 taken 834 (fallthrough) 2059 branch 1 taken 2496 2060 branch 2 taken 834 (fallthrough) 2061 branch 3 taken 2496 2062 3330: 1070: bytes[OMEGA_GPU_FFT_BUF_IN] = alias ? (ib > ob ? ib : ob) : ib; 2063 branch 0 taken 692 (fallthrough) 2064 branch 1 taken 2638 2065 3330: 1071: bytes[OMEGA_GPU_FFT_BUF_OUT] = alias ? 0u : ob; 2066 branch 0 taken 2638 (fallthrough) 2067 branch 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) { 2073 branch 0 taken 20 (fallthrough) 2074 branch 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; 2079 branch 0 taken 6 (fallthrough) 2080 branch 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: 2089 function 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; 2093 branch 0 taken 696 (fallthrough) 2094 branch 1 taken 3402 2095 branch 2 taken 4 (fallthrough) 2096 branch 3 taken 692 2097 -: 1092: Many m; 2098 4094: 1093: omega_gpu_session_lock(); 2099 call 0 returned 4094 2100 4094: 1094: int rc = many_build(plan, in_place, in_place, &m, bytes, NULL); 2101 call 0 returned 4094 2102 4094: 1095: omega_gpu_session_unlock(); 2103 call 0 returned 4094 2104 79656: 1096: for (size_t i = 0; fn && rc == OMEGA_GPU_ML_OK && i < m.n; i++) { 2105 branch 0 taken 77218 (fallthrough) 2106 branch 1 taken 2438 2107 branch 2 taken 77216 (fallthrough) 2108 branch 3 taken 2 2109 branch 4 taken 75562 2110 branch 5 taken 1654 (fallthrough) 2111 75562: 1097: m.l[i].table = m.tab; 2112 75562: 1098: rc = fn(ctx, &m.l[i]); 2113 call 0 returned 75562 2114 -: 1099: } 2115 4094: 1100: many_free(&m); 2116 call 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 2122 function 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; 2126 branch 0 taken 18 2127 branch 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 2139 function 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: 2147 function 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; 2150 branch 0 taken 20 (fallthrough) 2151 branch 1 taken 0 2152 branch 2 taken 20 (fallthrough) 2153 branch 3 taken 0 2154 branch 4 taken 0 (fallthrough) 2155 branch 5 taken 20 2156 20*: 1129: if (info) memset(info, 0, sizeof *info); 2157 branch 0 taken 0 (fallthrough) 2158 branch 1 taken 20 2159 20: 1130: uint64_t t0 = now_ns(); 2160 call 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(); 2166 call 0 returned 20 2167 20: 1136: int rc = many_build(plan, in_place, 0, &m, bytes, &o); 2168 call 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 && 2171 branch 0 taken 20 (fallthrough) 2172 branch 1 taken 0 2173 branch 2 taken 20 (fallthrough) 2174 branch 3 taken 0 2175 20: 1139: ml_overlap(pi, bytes[OMEGA_GPU_FFT_BUF_IN], po, bytes[OMEGA_GPU_FFT_BUF_OUT])) 2176 branch 0 taken 20 (fallthrough) 2177 branch 1 taken 0 2178 branch 2 taken 20 (fallthrough) 2179 branch 3 taken 0 2180 20: 1140: rc = OMEGA_GPU_ML_BAD_ARGS; 2181 20: 1141: if (rc == OMEGA_GPU_ML_OK) { 2182 branch 0 taken 0 (fallthrough) 2183 branch 1 taken 20 2184 #####: 1142: if (!g_hooked) { (void)omega_gpu_session_on_close(on_session_close); g_hooked = true; } 2185 branch 0 never executed (fallthrough) 2186 branch 1 never executed 2187 call 2 never executed 2188 #####: 1143: if (!omega_gpu_session_open()) rc = OMEGA_GPU_ML_CHIP_FAIL; 2189 call 0 never executed 2190 branch 1 never executed (fallthrough) 2191 branch 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++) 2195 branch 0 taken 0 (fallthrough) 2196 branch 1 taken 20 2197 branch 2 never executed 2198 branch 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; 2200 branch 0 never executed (fallthrough) 2201 branch 1 never executed 2202 call 2 never executed 2203 branch 3 never executed (fallthrough) 2204 branch 4 never executed 2205 20: 1148: if (rc == OMEGA_GPU_ML_OK) { 2206 branch 0 taken 0 (fallthrough) 2207 branch 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; 2212 branch 0 never executed 2213 branch 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 || 2215 call 0 never executed 2216 branch 1 never executed (fallthrough) 2217 branch 2 never executed 2218 call 3 never executed 2219 branch 4 never executed (fallthrough) 2220 branch 5 never executed 2221 branch 6 never executed (fallthrough) 2222 branch 7 never executed 2223 #####: 1154: omega_gpu_session_sync_to_gpu(&g_out.mem) != 0) 2224 call 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++) { 2227 branch 0 never executed (fallthrough) 2228 branch 1 never executed 2229 branch 2 never executed 2230 branch 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); 2235 call 0 never executed 2236 #####: 1161: if (rc != OMEGA_GPU_ML_OK) break; 2237 branch 0 never executed (fallthrough) 2238 branch 1 never executed 2239 #####: 1162: info_kernel(info, s, hit); 2240 call 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]); 2243 call 0 never executed 2244 branch 1 never executed 2245 branch 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); 2248 call 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; 2251 branch 0 never executed (fallthrough) 2252 branch 1 never executed 2253 call 2 never executed 2254 branch 3 never executed (fallthrough) 2255 branch 4 never executed 2256 #####: 1169: if (rc == OMEGA_GPU_ML_OK) { 2257 branch 0 never executed (fallthrough) 2258 branch 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); 2262 call 0 never executed 2263 #####: 1173: if (info) info->unwritten_words = c.unwritten; 2264 branch 0 never executed (fallthrough) 2265 branch 1 never executed 2266 #####: 1174: if (c.unwritten) rc = OMEGA_GPU_ML_UNWRITTEN; 2267 branch 0 never executed (fallthrough) 2268 branch 1 never executed 2269 #####: 1175: else (void)many_each(o.rank, &o.olay, o.oext, o.batch, many_copy_back, &c); 2270 call 0 never executed 2271 -: 1176: } 2272 -: 1177: } 2273 20: 1178: omega_gpu_session_unlock(); 2274 call 0 returned 20 2275 20: 1179: many_free(&m); 2276 call 0 returned 20 2277 20*: 1180: if (info) info->call_ns = ml_sub(now_ns(), t0); 2278 branch 0 taken 0 (fallthrough) 2279 branch 1 taken 20 2280 call 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. */ 2285 function 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; 2290 branch 0 taken 22 (fallthrough) 2291 branch 1 taken 0 2292 branch 2 taken 22 (fallthrough) 2293 branch 3 taken 0 2294 branch 4 taken 22 (fallthrough) 2295 branch 5 taken 0 2296 branch 6 taken 22 (fallthrough) 2297 branch 7 taken 0 2298 branch 8 taken 20 (fallthrough) 2299 branch 9 taken 2 2300 branch 10 taken 0 (fallthrough) 2301 branch 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); 2313 call 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