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/omega-blas/blob/main/tests/gb10/hooks.c # omega-blas aien-dev/omega-blas 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 `omega-blas / tests / gb10 / hooks.c` 69 lines ยท 3199 bytes Raw Blame History 1 /* tests/gb10/hooks.c: test-only constructor linked into the netlib drivers of a GB10=1 build 2 * (tests/netlib/run.sh with GB10_HOOKS=1). libomegablas itself has neither knob. 3 * OMB_TEST_BACKEND=model replace CUDApp's chip core with the chip-exact HMMA model of CUDApp 4 * tests/bw_hmma_model.h ({16, 2, RZ, nominal 2}, evidence 5 * OWN30B-T3-HMMA-MODEL): the device glue runs on the host, no GPU opened 6 * OMB_TEST_MUTANT= plant CUDApp gemm_ex mutant n (1: the last k element is dropped), the 7 * negative control; the drivers must report failures 8 * MIGRATION-PENDING C test glue: it exists because the backend hook is a C function pointer; its 9 * successor is the same model as an Omega unit once CUDApp's gemm_ex core is one (docs/EXTENSIONS.md). 10 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 11 #include "omega_gpu_gemm_ex.h" 12 #include "omega_gpu_gemm.h" 13 #include "bw_hmma_model.h" 14 15 #include 16 #include 17 18 static const HmmaModel HM = { 16, 2, 0, 2, 0 }; 19 20 static float bf(const void *p, uint64_t i) 21 { 22 uint32_t u = (uint32_t)((const uint16_t *)p)[i] << 16; 23 float f; 24 memcpy(&f, &u, 4); 25 return f; 26 } 27 28 /* the bf16 core only: the bf16x3 route of an f32 gemm_ex call is the one omega-blas sends */ 29 static int model_core(void *ctx, OmegaGpuGemmType t, unsigned lay, uint32_t M, uint32_t N, uint32_t K, 30 const void *A, uint64_t lda, const void *B, uint64_t ldb, float *C) 31 { 32 (void)ctx; 33 if (t != OMEGA_GPU_GEMM_BF16) { 34 fprintf(stderr, "omega-blas test model: core type %d is not modelled\n", (int)t); 35 return OMEGA_GPU_GEMM_UNSUPPORTED; 36 } 37 const int acol = (lay & OMEGA_GPU_GEMM_A_COL) != 0, bcol = (lay & OMEGA_GPU_GEMM_B_COL) != 0; 38 const uint64_t ea = lda ? lda : acol ? M : K, eb = ldb ? ldb : bcol ? K : N; 39 for (uint32_t m = 0; m < M; m++) 40 for (uint32_t n = 0; n < N; n++) { 41 float acc = 0.0f; 42 for (uint32_t k0 = 0; k0 < K; k0 += 16) { 43 float av[16], bv[16]; 44 for (uint32_t k = 0; k < 16; k++) { 45 uint64_t kk = k0 + k; 46 if (kk >= K) { av[k] = bv[k] = 0.0f; continue; } 47 av[k] = bf(A, acol ? kk * ea + m : (uint64_t)m * ea + kk); 48 bv[k] = bf(B, bcol ? (uint64_t)n * eb + kk : kk * eb + n); 49 } 50 acc = hm_dot16(&HM, av, bv, acc); 51 } 52 C[(uint64_t)m * N + n] = acc; 53 } 54 return OMEGA_GPU_GEMM_OK; 55 } 56 57 __attribute__((constructor)) static void omb_test_hooks(void) 58 { 59 const char *b = getenv("OMB_TEST_BACKEND"), *m = getenv("OMB_TEST_MUTANT"); 60 if (b && *b) { 61 if (strcmp(b, "model")) { fprintf(stderr, "omega-blas test hooks: OMB_TEST_BACKEND must be model\n"); abort(); } 62 omega_gpu_gemm_ex_set_backend(model_core, NULL); 63 fprintf(stderr, "omega-blas test hooks: backend model (bw_hmma_model {16,2,RZ,nominal 2})\n"); 64 } 65 if (m && *m) { 66 omega_gpu_gemm_ex_test_set_mutant(atoi(m)); 67 fprintf(stderr, "omega-blas test hooks: gemm_ex mutant %d planted\n", atoi(m)); 68 } 69 }