CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tests / regalloc_om / packers.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Source-derived partition: 16-row/column A tiles, 8-column B tiles, row0 |
| 3 | * partial/empty/extra padded blocks, every source bit class, and guard words. |
| 4 | * The driver is identical for the migration oracle and the Omega successor. */ |
| 5 | #include "omega_blackwell_codegen.h" |
| 6 | #include <stdint.h> |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
| 10 | static uint32_t rng = 0x516a9be3u; |
| 11 | static uint32_t next(void) { rng ^= rng << 13; rng ^= rng >> 17; rng ^= rng << 5; return rng; } |
| 12 | static void dump(const uint16_t *d, size_t n) { if (fwrite(d, sizeof *d, n, stdout) != n) abort(); } |
| 13 | static void row0_regression(void) { |
| 14 | uint16_t *s = malloc(sizeof *s), d[16 * 48]; |
| 15 | if (!s) abort(); |
| 16 | *s = 0x1234; memset(d, 0x5a, sizeof d); |
| 17 | omega_matmul_frag_pack_a_row0(s, 1, 48, d); |
| 18 | if (d[0] != *s || d[256] != 0 || d[512] != 0 || d[2] != 0x5a5a) abort(); |
| 19 | free(s); |
| 20 | } |
| 21 | static void sentinels(const uint32_t *dims, size_t nd, const uint32_t *bits, size_t nb) { |
| 22 | for (size_t mi = 0; mi < nd; ++mi) for (size_t ni = 0; ni < nd; ++ni) { |
| 23 | uint32_t m = dims[mi], n = dims[ni], np = n + 3; |
| 24 | size_t size = (size_t)m * np; |
| 25 | float *d = malloc((size + 2) * sizeof *d); |
| 26 | if (!d) abort(); |
| 27 | for (size_t pi = 0; pi < nb; ++pi) { |
| 28 | float poison; |
| 29 | memcpy(&poison, bits + pi, sizeof poison); |
| 30 | for (size_t i = 0; i < size + 2; ++i) memcpy(d + i, bits + i % nb, sizeof *d); |
| 31 | uint64_t counts[3]; |
| 32 | counts[0] = omega_matmul_result_sentinels(d + 1, m, n, np, poison, 0); |
| 33 | counts[1] = omega_matmul_result_sentinels(d + 1, m, n, np, poison, pi & 1 ? -1 : 1); |
| 34 | counts[2] = omega_matmul_result_sentinels(d + 1, m, n, np, poison, 0); |
| 35 | if (fwrite(counts, sizeof *counts, 3, stdout) != 3 || |
| 36 | fwrite(d, sizeof *d, size + 2, stdout) != size + 2) abort(); |
| 37 | } |
| 38 | free(d); |
| 39 | } |
| 40 | } |
| 41 | int main(int argc, char **argv) { |
| 42 | if (argc == 1 || strcmp(argv[1], "--mutant") != 0) row0_regression(); |
| 43 | if (argc > 1 && strcmp(argv[1], "--row0") == 0) return 0; |
| 44 | if (argc > 1 && strcmp(argv[1], "--red") == 0) putchar('!'); |
| 45 | const uint32_t dims[] = {0, 1, 2, 7, 8, 15, 16, 17, 31, 32, 47}; |
| 46 | const uint32_t bits[] = {0, 0x80000000u, 0x3f800000u, 0x3f808000u, |
| 47 | 0x3f818000u, 0x7f800000u, 0xff800000u, 0x7f800001u, 0xffc12345u, |
| 48 | 0x00000001u, 0x007fffffu, 0x7fffffffu, 0xffffffffu}; |
| 49 | sentinels(dims, sizeof dims / sizeof *dims, bits, sizeof bits / sizeof *bits); |
| 50 | for (unsigned mi = 0; mi < sizeof dims / sizeof *dims; ++mi) { |
| 51 | uint32_t m = dims[mi], mp = ((m + 15u) / 16u + 1u) * 16u; |
| 52 | for (unsigned ki = 0; ki < sizeof dims / sizeof *dims; ++ki) { |
| 53 | uint32_t k = dims[ki], kp = ((k + 15u) / 16u + 2u) * 16u; |
| 54 | size_t sn = (size_t)m * k, dn = (size_t)mp * kp; |
| 55 | uint16_t *s = malloc((sn + k + 1) * sizeof *s); |
| 56 | float *f = malloc((sn + k + 1) * sizeof *f); |
| 57 | uint16_t *d = malloc((dn + 2) * sizeof *d); |
| 58 | if (!s || !f || !d) abort(); |
| 59 | for (size_t i = 0; i < sn + k + 1; ++i) { |
| 60 | uint32_t x = i < sizeof bits / sizeof *bits ? bits[i] : next(); |
| 61 | s[i] = (uint16_t)next(); memcpy(f + i, &x, sizeof x); |
| 62 | } |
| 63 | memset(d, 0xa5, (dn + 2) * sizeof *d); |
| 64 | omega_matmul_frag_pack_a(s, m, k, mp, kp, d + 1); dump(d, dn + 2); |
| 65 | memset(d, 0xa5, (dn + 2) * sizeof *d); |
| 66 | omega_matmul_frag_pack_a_f32(f, m, k, mp, kp, d + 1); dump(d, dn + 2); |
| 67 | memset(d, 0xa5, (dn + 2) * sizeof *d); |
| 68 | omega_matmul_frag_pack_a_row0(s, k, kp, d + 1); dump(d, dn + 2); |
| 69 | memset(d, 0xa5, (dn + 2) * sizeof *d); |
| 70 | omega_matmul_frag_pack_a_row0_f32(f, k, kp, d + 1); dump(d, dn + 2); |
| 71 | free(s); free(f); free(d); |
| 72 | } |
| 73 | } |
| 74 | for (unsigned ki = 0; ki < sizeof dims / sizeof *dims; ++ki) { |
| 75 | uint32_t k = dims[ki], kp = ((k + 15u) / 16u + 1u) * 16u; |
| 76 | for (unsigned ni = 0; ni < sizeof dims / sizeof *dims; ++ni) { |
| 77 | uint32_t n = dims[ni], nt = (n + 7u) / 8u; |
| 78 | uint16_t *s = malloc(((size_t)k * n + 1) * sizeof *s); |
| 79 | if (!s) abort(); |
| 80 | for (size_t i = 0; i < (size_t)k * n + 1; ++i) s[i] = (uint16_t)next(); |
| 81 | for (uint32_t nt0 = 0; nt0 <= nt + 1; ++nt0) { |
| 82 | uint32_t nt1 = nt + 1; |
| 83 | size_t dn = (size_t)(nt1 - nt0) * kp * 8; |
| 84 | uint16_t *d = malloc((dn + 2) * sizeof *d); |
| 85 | if (!d) abort(); |
| 86 | memset(d, 0xa5, (dn + 2) * sizeof *d); |
| 87 | omega_matmul_frag_pack_b(s, k, n, kp, nt0, nt1, d + 1); |
| 88 | dump(d, dn + 2); free(d); |
| 89 | } |
| 90 | free(s); |
| 91 | } |
| 92 | } |
| 93 | return 0; |
| 94 | } |